11 #ifndef RTI_SERVICE_REQUEST_INTERCEPTOR_HPP_
12 #define RTI_SERVICE_REQUEST_INTERCEPTOR_HPP_
14 #include "routingservice/routingservice_remote_config.h"
16 #include "rti/service/ServiceException.hpp"
17 #include "rti/service/log/LogConfig.hpp"
19 namespace rti {
namespace service {
namespace admin {
25 const char* to_native_string(
const RTI_Service_Admin_CommandActionKind command_kind)
27 switch (command_kind) {
28 case RTI_SERVICE_COMMAND_ACTION_UPDATE:
30 case RTI_SERVICE_COMMAND_ACTION_GET:
32 case RTI_SERVICE_COMMAND_ACTION_CREATE:
34 case RTI_SERVICE_COMMAND_ACTION_DELETE:
45 const std::string to_string(
const RTI_Service_Admin_CommandActionKind command_kind)
47 switch (command_kind) {
48 case RTI_SERVICE_COMMAND_ACTION_UPDATE:
50 case RTI_SERVICE_COMMAND_ACTION_GET:
52 case RTI_SERVICE_COMMAND_ACTION_CREATE:
54 case RTI_SERVICE_COMMAND_ACTION_DELETE:
57 std::ostringstream string_stream;
58 string_stream << (int) command_kind;
59 return string_stream.str();
63 class RequestInterceptor {
66 virtual void on_command(
67 const RTI_Service_Admin_CommandRequest& incoming_request,
68 const DDS_SampleInfo& request_info,
69 RTI_RoutingServiceAdminReplier& replier) = 0;
71 virtual ~RequestInterceptor() {}
75 class RequestInterceptorForwarder {
78 typedef RTI_RoutingServiceConfigInterceptor native;
80 static native create(RequestInterceptor *interceptor)
82 native native_interceptor;
83 native_interceptor.on_command_request = on_request_forwarder;
84 native_interceptor.interceptor_data =
static_cast<void*
>(interceptor);
86 return native_interceptor;
90 static void on_request_forwarder(
91 void *interceptor_data,
92 const RTI_Service_Admin_CommandRequest *incoming_request,
93 const DDS_SampleInfo *request_info,
94 RTI_RoutingServiceAdminReplier *replier)
96 RequestInterceptor *interceptor =
97 static_cast<RequestInterceptor *
>(interceptor_data);
99 interceptor->on_command(*incoming_request, *request_info, *replier);
100 }
catch (ServiceException& ex) {
101 SERVICELog_fromException(ex);
103 SERVICELog_exception(&RTI_LOG_UNEXPECTED_EXCEPTION);
112 #endif // RTI_SERVICE_REQUEST_INTERCEPTOR_HPP_