11 #ifndef HPP_SERVICE_LOG_ADVLOG_CONTEXT_CONTEXT_HPP_
12 #define HPP_SERVICE_LOG_ADVLOG_CONTEXT_CONTEXT_HPP_
17 #include "advlog/advlog_context.h"
18 #include "dds_c/dds_c_domain_impl.h"
19 #include "routingservice/routingservice_log.h"
21 #include <rti/service/log/LogConfig.hpp>
23 namespace rti {
namespace service {
namespace log {
25 class AdvLogContextGuard {
29 const struct ADVLOGContext *context,
31 const void *pointerParam) :
33 worker_(DDS_DomainParticipantFactory_get_workerI(DDS_TheParticipantFactory))
43 const struct ADVLOGContext *context,
44 const void *pointerParam = NULL) :
46 worker_(DDS_DomainParticipantFactory_get_workerI(DDS_TheParticipantFactory))
57 if (context_ != NULL) {
58 ADVLOGContext_leave(worker_, context_);
70 const struct ADVLOGContext *context_;
71 struct REDAWorker *worker_;
74 class AdvLogContextStackGuard {
77 AdvLogContextStackGuard(
78 const struct ADVLOGContext *context,
79 const char *string_param)
80 : worker_(DDS_DomainParticipantFactory_get_workerI(DDS_TheParticipantFactory))
82 push(context, string_param);
85 virtual ~AdvLogContextStackGuard()
90 AdvLogContextStackGuard& push(
91 const struct ADVLOGContext *context,
92 const char *string_param = NULL)
99 context_stack_.push_back(context);
104 AdvLogContextStackGuard& pop()
106 if (!context_stack_.empty()) {
107 ADVLOGContext_leave(worker_, context_stack_.back());
108 context_stack_.pop_back();
116 std::vector<const ADVLOGContext*>::reverse_iterator it = context_stack_.rbegin();
117 for (; it != context_stack_.rend(); ++it) {
118 ADVLOGContext_leave(worker_, *it);
123 std::vector<const ADVLOGContext*> context_stack_;
124 struct REDAWorker *worker_;
127 class AdvlogContextStackLeaveGuard
130 AdvlogContextStackLeaveGuard(
const ADVLOGContext *context)
135 ~AdvlogContextStackLeaveGuard()
137 std::vector<const ADVLOGContext*>::iterator it = context_stack_.begin();
138 for (; it != context_stack_.end(); ++it) {
139 ADVLOGContext_leave(NULL, *it);
143 void push(
const struct ADVLOGContext *context)
145 context_stack_.push_back(context);
150 if (!context_stack_.empty()) {
151 ADVLOGContext_leave(NULL, context_stack_.front());
156 std::vector<const ADVLOGContext*> context_stack_;
159 #define RTI_ACTIVITY_CONTEXT_LEAVE() \
160 context_guard.leave()
162 #define RTI_ACTIVITY_CONTEXT_ENTER(...) \
163 rti::service::log::AdvLogContextStackGuard context_guard(__VA_ARGS__);
165 #define RTI_LOG_ACTIVITY_CONTEXT_ENTER(...) \
166 RTI_ACTIVITY_CONTEXT_ENTER(__VA_ARGS__); \
167 SERVICELog_flushActivityContext(RTI_LOG_BIT_LOCAL)
169 #define RTI_ACTIVITY_CONTEXT_RESOURCE_ENTER(CONTEXT, RESOURCE_ID) \
170 rti::service::log::AdvLogContextStackGuard context_guard(\
174 #define RTI_ACTIVITY_CONTEXT_RESOURCE_METHOD_ENTER(\
177 rti::service::log::AdvLogContextStackGuard context_guard(\
178 (&RTI_ADVLOG_CONTEXT_RESOURCE_ID_s), \
180 context_guard.push(__VA_ARGS__)
183 #define RTI_LOG_ACTIVITY_CONTEXT_RESOURCE_METHOD_ENTER(\
186 RTI_ACTIVITY_CONTEXT_RESOURCE_METHOD_ENTER(\
189 SERVICELog_flushActivityContext(RTI_LOG_BIT_LOCAL)
191 #define RTI_LOG_ACTIVITY_RESOURCE_SCOPED_LEAVE(CONTEXT) \
192 rti::service::log::AdvlogContextStackLeaveGuard leave_guard((CONTEXT)); \
193 leave_guard.push((&RTI_ADVLOG_CONTEXT_RESOURCE_ID_s))