Skip to content

Commit

Permalink
Fixed syntatical errors, moved token class definition to context.h an…
Browse files Browse the repository at this point in the history
…d added the contextvars_context.h file
  • Loading branch information
satac2 committed Jun 8, 2020
1 parent d047ff7 commit f283cc6
Show file tree
Hide file tree
Showing 3 changed files with 80 additions and 26 deletions.
28 changes: 19 additions & 9 deletions api/include/opentelemetry/context/context.h
Original file line number Diff line number Diff line change
@@ -1,41 +1,48 @@
#ifndef CONTEXT_H_
#define CONTEXT_H_


/*The context class provides a context identifier*/
class Context{
public:

/*The identifier itself*/
std::map<std::string, int> _ctx;

/* Context: contructor
*
* Args:
* ctx: a map containing the context identifier
*/
Context(std::map<std::string, int> ctx);

/* Context operator[]: Prevents the modification of the identifier
*
* Args: none
*/
Context operator[] (std::string i);
}
};

/* The token class provides:????*/
class Token{
Token();
};



/* The RuntimeContext class provides a wrapper for
* propogating context through cpp*/
class RuntimeContext {
public:

/* attach: Sets the current 'Context' object. Returns a token
* that can be used to reset to the previous Context.
*
* Args:
* context : the context to set.
*/
virtual int attach(Context context);


/* get_current: Return the current context.
*
Expand All @@ -50,6 +57,9 @@ class RuntimeContext {
* token: A reference to a previous context
*/
virtual void detach(int);


}


};


#endif //CONTEXT_H_
50 changes: 50 additions & 0 deletions api/include/opentelemetry/context/contextvars_context.h
Original file line number Diff line number Diff line change
@@ -0,0 +1,50 @@
#ifndef CONTEXT_VARS_CONTEXT_H_
#define CONTEXT_VARS_CONTEXT_H_

#include "context.h"
#include <string>


/* An implementation of the RuntimeContext interface which wraps
* ContextVar under the hood */
class ContextVarsRuntimeContext: public RuntimeContext{

std::string _CONTEXT_KEY = "current_context";


/* ContextVarsRuntimeContext: Default constructor to set the
* current context to the thread local context
*
* Args: None
*/
ContextVarsRuntimeContext();


/* attach: Sets the current 'Context' object. Returns a token
* that can be used to reset to the previous Context.
*
* Args:
* context : the context to set.
*/
Context attach(Context context);


/* get_current: Return the current context.
*
* Args: None
*/
Context get_current();

/* detach: Resets the context to a previous value.
*
* Args:
* token: A reference to a previous context
*/
Token detach(Token token);

};



#endif //CONTEXT_VARS_CONTEXT_H_

28 changes: 11 additions & 17 deletions api/include/opentelemetry/context/threadlocal_context.h
Original file line number Diff line number Diff line change
@@ -1,22 +1,16 @@
#ifndef THREAD_LOCAL_CONTEXT_H_
#define THREAD_LOCAL_CONTEXT_H_




#include "context.h"


#include <string>

/* An implementation of the runtime context that uses thread local storage*/
class ThreadLocalRuntimeContext :public RuntimeContext(){
class ThreadLocalRuntimeContext: public RuntimeContext(){




class Token{
Token();
}
std::string _CONTEXT_KEY = "current_context";



/* ThreadLocalRuntimeContext: Default constructor to set the
* current context to the thread local context
Expand All @@ -33,11 +27,11 @@ class ThreadLocalRuntimeContext :public RuntimeContext(){
*/
Token attach(Context context)

/* get_current: Return the current context.
*
* Args: None
*/
Context get_current();
/* get_current: Return the current context.
*
* Args: None
*/
Context get_current();



Expand All @@ -48,7 +42,7 @@ class ThreadLocalRuntimeContext :public RuntimeContext(){
*/
void detach(Token token);

}
};


#endif // THREAD_LOCAL_CONTEXT_H_

0 comments on commit f283cc6

Please sign in to comment.