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

RTI Routing Service Version 6.0.1 Copyright © Sun Nov 17 2019 Real-Time Innovations, Inc