11#ifndef RTI_ROUTING_ENTITY_LISTENER_HPP_
12#define RTI_ROUTING_ENTITY_LISTENER_HPP_
14#include "routingservice/routingservice_service_impl.h"
16#include <rti/apputils/ServiceException.hpp>
17#include <rti/apputils/log/LogConfig.hpp>
18#include <rti/routing/StreamInfo.hpp>
20namespace rti {
namespace routing {
24struct EntityKind_def {
29 SERVICE = RTI_ROUTING_SERVICE_SERVICE_ENTITY,
30 DOMAIN_ROUTE = RTI_ROUTING_SERVICE_DOMAIN_ROUTE_ENTITY,
31 CONNECTION = RTI_ROUTING_SERVICE_CONNECTION_ENTITY,
32 SESSION = RTI_ROUTING_SERVICE_SESSION_ENTITY,
33 AUTO_TOPIC_ROUTE = RTI_ROUTING_SERVICE_AUTO_TOPIC_ROUTE_ENTITY,
34 TOPIC_ROUTE = RTI_ROUTING_SERVICE_TOPIC_ROUTE_ENTITY,
35 INPUT = RTI_ROUTING_SERVICE_INPUT_ENTITY,
36 OUTPUT = RTI_ROUTING_SERVICE_OUTPUT_ENTITY,
44typedef dds::core::safe_enum<EntityKind_def> EntityKind;
49struct EntityStateKind_def {
54 INVALID = RTI_SERVICE_INVALID_ENTITY_STATE,
55 ENABLED = RTI_SERVICE_ENABLED_ENTITY_STATE,
56 DISABLED = RTI_SERVICE_DISABLED_ENTITY_STATE,
57 STARTED = RTI_SERVICE_STARTED_ENTITY_STATE,
58 STOPPED = RTI_SERVICE_STOPPED_ENTITY_STATE,
59 RUNNING = RTI_SERVICE_RUNNING_ENTITY_STATE,
60 PAUSED = RTI_SERVICE_PAUSED_ENTITY_STATE
65typedef dds::core::safe_enum<EntityStateKind_def> EntityStateKind;
71const std::string to_string(
const rti::routing::EntityStateKind& kind)
73 static const char * ENTITY_STATE_KIND_AS_STRING[] = {
83 return ENTITY_STATE_KIND_AS_STRING[kind.underlying()];
87const char* to_action_native_string(
const rti::routing::EntityStateKind& kind)
89 static const char * ENTITY_STATE_ACTION_AS_STRING[] = {
100 return ENTITY_STATE_ACTION_AS_STRING[kind.underlying()];
104const std::string to_action_string(
const rti::routing::EntityStateKind& kind)
106 return to_action_native_string(kind);
109class EntityListener {
115 friend EntityListener::Context from_native(
116 RTI_RoutingServiceEntityListenerContext*);
118 const rti::routing::EntityKind& entity_kind()
const
123 const std::string& entity_name()
const
128 const rti::routing::EntityStateKind& entity_state_kind()
const
130 return entity_state_kind_;
138 rti::advlog::Entries logging_context_entries()
140 return logging_context_entries_;
145 rti::routing::EntityKind entity_kind_;
147 std::string entity_name_;
149 rti::routing::EntityStateKind entity_state_kind_;
170 rti::advlog::Entries logging_context_entries_;
173 virtual void on_before_create( EntityListener::Context&)
177 virtual void on_after_create(EntityListener::Context&)
181 virtual void on_before_state_change(EntityListener::Context&)
185 virtual void on_after_state_change(EntityListener::Context&)
189 virtual void on_before_delete(EntityListener::Context&)
193 virtual void on_after_delete(EntityListener::Context&)
197 virtual void on_before_stream_event(
198 EntityListener::Context&,
203 virtual void on_after_stream_event(
204 EntityListener::Context&,
209 virtual ~EntityListener() {}
214 EntityListener::Context from_native(
215 RTI_RoutingServiceEntityListenerContext *native)
217 EntityListener::Context context;
218 context.entity_kind_ =
static_cast<EntityKind::type
> (
219 native->entity_kind);
220 context.entity_name_ = native->entity_name;
221 context.entity_state_kind_ =
static_cast<EntityStateKind::type
> (
222 native->entity_state_kind);
223 context.ok_ = native->ok ? true :
false;
224 context.logging_context_entries_.from_native(
225 native->logging_context_entries,
226 native->logging_context_params);
231class EntityListenerForwarder {
234 typedef RTI_RoutingServiceEntityListener native;
236 static native create(
237 EntityListener *listener)
239 native native_listener = RTI_RoutingServiceEntityListener_INITIALIZER;
240 native_listener.on_before_create =
241 on_before_create_forwarder;
242 native_listener.on_after_create =
243 on_after_create_forwarder;
244 native_listener.on_before_state_change =
245 on_before_state_change_forwarder;
246 native_listener.on_after_state_change =
247 on_after_state_change_forwarder;
248 native_listener.on_before_delete =
249 on_before_delete_forwarder;
250 native_listener.on_after_delete =
251 on_after_delete_forwarder;
252 native_listener.on_before_stream_event =
253 on_before_stream_event_forwarder;
254 native_listener.on_after_stream_event =
255 on_after_stream_event_forwarder;
256 native_listener.listener_data =
static_cast<void*
>(listener);
258 return native_listener;
262 static void on_before_create_forwarder(
264 RTI_RoutingServiceEntityListenerContext *context_native)
266 EntityListener *listener =
267 static_cast<EntityListener *
>(listener_data);
269 EntityListener::Context context =
270 rti::routing::from_native(context_native);
271 listener->on_before_create(context);
272 }
catch (rti::apputils::ServiceException& ex) {
273 SERVICELog_fromException(ex);
274 }
catch (std::exception& ex) {
275 SERVICELog_exception(&RTI_LOG_ANY_s, ex.what());
277 SERVICELog_exception(&RTI_LOG_UNEXPECTED_EXCEPTION);
280 static void on_after_create_forwarder(
282 RTI_RoutingServiceEntityListenerContext *context_native)
284 EntityListener *listener =
285 static_cast<EntityListener *
>(listener_data);
287 EntityListener::Context context =
288 rti::routing::from_native(context_native);
289 listener->on_after_create(context);
290 }
catch (rti::apputils::ServiceException& ex) {
291 SERVICELog_fromException(ex);
292 }
catch (std::exception& ex) {
293 SERVICELog_exception(&RTI_LOG_ANY_s, ex.what());
295 SERVICELog_exception(&RTI_LOG_UNEXPECTED_EXCEPTION);
299 static void on_before_state_change_forwarder(
301 RTI_RoutingServiceEntityListenerContext *context_native)
303 EntityListener *listener =
304 static_cast<EntityListener *
>(listener_data);
306 EntityListener::Context context =
307 rti::routing::from_native(context_native);
308 listener->on_before_state_change(context);
309 }
catch (rti::apputils::ServiceException& ex) {
310 SERVICELog_fromException(ex);
311 }
catch (std::exception& ex) {
312 SERVICELog_exception(&RTI_LOG_ANY_s, ex.what());
314 SERVICELog_exception(&RTI_LOG_UNEXPECTED_EXCEPTION);
318 static void on_after_state_change_forwarder(
320 RTI_RoutingServiceEntityListenerContext *context_native)
322 EntityListener *listener =
323 static_cast<EntityListener *
>(listener_data);
325 EntityListener::Context context =
326 rti::routing::from_native(context_native);
327 listener->on_after_state_change(context);
328 }
catch (rti::apputils::ServiceException& ex) {
329 SERVICELog_fromException(ex);
330 }
catch (std::exception& ex) {
331 SERVICELog_exception(&RTI_LOG_ANY_s, ex.what());
333 SERVICELog_exception(&RTI_LOG_UNEXPECTED_EXCEPTION);
337 static void on_before_delete_forwarder(
339 RTI_RoutingServiceEntityListenerContext *context_native)
341 EntityListener *listener =
342 static_cast<EntityListener *
>(listener_data);
344 EntityListener::Context context =
345 rti::routing::from_native(context_native);
346 listener->on_before_delete(context);
347 }
catch (rti::apputils::ServiceException& ex) {
348 SERVICELog_fromException(ex);
349 }
catch (std::exception& ex) {
350 SERVICELog_exception(&RTI_LOG_ANY_s, ex.what());
352 SERVICELog_exception(&RTI_LOG_UNEXPECTED_EXCEPTION);
356 static void on_after_delete_forwarder(
358 RTI_RoutingServiceEntityListenerContext *context_native)
360 EntityListener *listener =
361 static_cast<EntityListener *
>(listener_data);
363 EntityListener::Context context =
364 rti::routing::from_native(context_native);
365 listener->on_after_delete(context);
366 }
catch (rti::apputils::ServiceException& ex) {
367 SERVICELog_fromException(ex);
368 }
catch (std::exception& ex) {
369 SERVICELog_exception(&RTI_LOG_ANY_s, ex.what());
371 SERVICELog_exception(&RTI_LOG_UNEXPECTED_EXCEPTION);
375 static void on_before_stream_event_forwarder(
377 RTI_RoutingServiceEntityListenerContext *context_native,
378 const RTI_RoutingServiceStreamInfo *stream_info)
380 EntityListener *listener =
381 static_cast<EntityListener *
>(listener_data);
383 EntityListener::Context context =
384 rti::routing::from_native(context_native);
385 listener->on_before_stream_event(
388 }
catch (rti::apputils::ServiceException& ex) {
389 SERVICELog_fromException(ex);
390 }
catch (std::exception& ex) {
391 SERVICELog_exception(&RTI_LOG_ANY_s, ex.what());
393 SERVICELog_exception(&RTI_LOG_UNEXPECTED_EXCEPTION);
397 static void on_after_stream_event_forwarder(
399 RTI_RoutingServiceEntityListenerContext *context_native,
400 const RTI_RoutingServiceStreamInfo *stream_info)
402 EntityListener *listener =
403 static_cast<EntityListener *
>(listener_data);
405 EntityListener::Context context =
406 rti::routing::from_native(context_native);
407 listener->on_after_stream_event(
410 }
catch (rti::apputils::ServiceException& ex) {
411 SERVICELog_fromException(ex);
412 }
catch (std::exception& ex) {
413 SERVICELog_exception(&RTI_LOG_ANY_s, ex.what());
415 SERVICELog_exception(&RTI_LOG_UNEXPECTED_EXCEPTION);
Definition of the stream information that RTI Routing Service needs to manage user data streams.
Definition: StreamInfo.hpp:106