RTI Routing Service  Version 6.0.0
 All Data Structures Files Functions Typedefs Enumerations Enumerator Groups Pages
SessionForwarder.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_ROUTING_ADAPTER_DETAIL_SESSION_FORWARDER_HPP_
12 #define RTI_ROUTING_ADAPTER_DETAIL_SESSION_FORWARDER_HPP_
13 
14 #include <rti/core/Exception.hpp>
15 
16 #include <rti/routing/adapter/Connection.hpp>
17 #include <rti/routing/detail/UpdatableEntityForwarder.hpp>
18 #include <rti/routing/detail/ForwarderUtils.hpp>
19 
20 namespace rti { namespace routing { namespace adapter { namespace detail {
21 
22 
23 class SessionForwarder {
24 public:
25  static RTI_RoutingServiceSessionExt* create_native(
26  Connection *connection,
27  const RTI_RoutingServiceProperties *native_properties,
28  RTI_RoutingServiceEnvironment *environment)
29  {
30 
31  try {
32  // Set properties
33  std::map<std::string, std::string> properties;
34  rti::routing::PropertyAdapter::add_properties_from_native(
35  properties,
36  native_properties);
37 
38  SessionForwarder *forwarder = new SessionForwarder();
39  ScopedForwarder<Connection, SessionForwarder> scoped(
40  connection,
41  forwarder,
42  environment);
43  // Create session: Note we don't check for NULL because a Session
44  // is not required
45  forwarder->session_ = connection->create_session(properties);
46 
47  scoped.release();
48  return forwarder->native();
49  } catch(const std::exception& ex) {
50  RTI_RoutingServiceEnvironment_set_error(
51  environment,
52  "%s",
53  ex.what());
54  return NULL;
55  } catch (...) {
56  RTI_RoutingServiceEnvironment_set_error(
57  environment,
58  "unexpected exception");
59  return NULL;
60  }
61 
62  }
63 
64  static void delete_native(
65  Connection *connection,
66  RTI_RoutingServiceSessionExt *native_session,
67  RTI_RoutingServiceEnvironment *environment)
68  {
69  SessionForwarder *forwarder = static_cast<SessionForwarder*>(
70  native_session->session_data);
71  try {
72  // delete session
73  if (forwarder->session_ != NULL) {
74  connection->delete_session(forwarder->session_);
75  forwarder->session_ = NULL;
76  }
77 
78  } catch(const std::exception& ex) {
79  RTI_RoutingServiceEnvironment_set_error(
80  environment,
81  "%s",
82  ex.what());
83  } catch (...) {
84  }
85 
86  delete forwarder;
87  }
88 
89  Session * session()
90  {
91  return session_;
92  }
93 
94  RTI_RoutingServiceSessionExt* native()
95  {
96  return &this->native_;
97  }
98 
99  static void update(
100  void *native_session_data,
101  const struct RTI_RoutingServiceProperties * native_properties,
102  RTI_RoutingServiceEnvironment * environment)
103  {
104  SessionForwarder *forwarder =
105  static_cast<SessionForwarder*> (native_session_data);
106 
107  rti::routing::detail::UpdatableEntityForwarder::update(
108  forwarder->session_,
109  native_properties,
110  environment);
111  }
112 
113 private:
114  SessionForwarder() : session_(NULL)
115  {
116  RTIOsapiMemory_zero(&native_, sizeof(native_));
117  native_.session_data =
118  static_cast<void*>(this);
119  native_.update =
120  SessionForwarder::update;
121  }
122 
123  ~SessionForwarder()
124  {
125  }
126 
127 private:
128  RTI_RoutingServiceSessionExt native_;
129  Session *session_;
130 
131 };
132 
133 }}}}
134 
135 #endif // RTI_ROUTING_ADAPTER_DETAIL_SESSION_FORWARDER_HPP_

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