RTI Routing Service  Version 6.0.0
 All Data Structures Files Functions Typedefs Enumerations Enumerator Groups Pages
RequestInterceptor.hpp
1 /*
2  * (c) Copyright, Real-Time Innovations, 2017.
3  * All rights reserved.
4  *
5  * No duplications, whole or partial, manual or electronic, may be made
6  * without express written permission. Any such copies, or
7  * revisions thereof, must display this notice unaltered.
8  * This code contains trade secrets of Real-Time Innovations, Inc.
9  */
10 
11 #ifndef RTI_SERVICE_REQUEST_INTERCEPTOR_HPP_
12 #define RTI_SERVICE_REQUEST_INTERCEPTOR_HPP_
13 
14 #include "routingservice/routingservice_remote_config.h"
15 
16 #include "rti/service/ServiceException.hpp"
17 #include "rti/service/log/LogConfig.hpp"
18 
19 namespace rti { namespace service { namespace admin {
20 
21 /*
22  * @brief string representation of EntityStateKind
23  */
24 inline
25 const char* to_native_string(const RTI_Service_Admin_CommandActionKind command_kind)
26 {
27  switch (command_kind) {
28  case RTI_SERVICE_COMMAND_ACTION_UPDATE:
29  return "UPDATE";
30  case RTI_SERVICE_COMMAND_ACTION_GET:
31  return "GET";
32  case RTI_SERVICE_COMMAND_ACTION_CREATE:
33  return "CREATE";
34  case RTI_SERVICE_COMMAND_ACTION_DELETE:
35  return "DELETE";
36  default:
37  return "";
38  }
39 }
40 
41 /*
42  * @brief string representation of EntityStateKind
43  */
44 inline
45 const std::string to_string(const RTI_Service_Admin_CommandActionKind command_kind)
46 {
47  switch (command_kind) {
48  case RTI_SERVICE_COMMAND_ACTION_UPDATE:
49  return "UPDATE";
50  case RTI_SERVICE_COMMAND_ACTION_GET:
51  return "GET";
52  case RTI_SERVICE_COMMAND_ACTION_CREATE:
53  return "CREATE";
54  case RTI_SERVICE_COMMAND_ACTION_DELETE:
55  return "DELETE";
56  default:
57  std::ostringstream string_stream;
58  string_stream << (int) command_kind;
59  return string_stream.str();
60  }
61 }
62 
63 class RequestInterceptor {
64 public:
65 
66  virtual void on_command(
67  const RTI_Service_Admin_CommandRequest& incoming_request,
68  const DDS_SampleInfo& request_info,
69  RTI_RoutingServiceAdminReplier& replier) = 0;
70 
71  virtual ~RequestInterceptor() {}
72 
73 };
74 
75 class RequestInterceptorForwarder {
76 public:
77 
78  typedef RTI_RoutingServiceConfigInterceptor native;
79 
80  static native create(RequestInterceptor *interceptor)
81  {
82  native native_interceptor;
83  native_interceptor.on_command_request = on_request_forwarder;
84  native_interceptor.interceptor_data = static_cast<void*>(interceptor);
85 
86  return native_interceptor;
87  }
88 
89 private:
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)
95  {
96  RequestInterceptor *interceptor =
97  static_cast<RequestInterceptor *>(interceptor_data);
98  try {
99  interceptor->on_command(*incoming_request, *request_info, *replier);
100  } catch (ServiceException& ex) {
101  SERVICELog_fromException(ex);
102  } catch (...) {
103  SERVICELog_exception(&RTI_LOG_UNEXPECTED_EXCEPTION);
104  }
105  }
106 
107 };
108 
109 }}}
110 
111 
112 #endif // RTI_SERVICE_REQUEST_INTERCEPTOR_HPP_

RTI Routing Service Version 6.0.0 Copyright © Sun Mar 3 2019 Real-Time Innovations, Inc