RTI Routing Service Version 7.7.0
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/apputils/ServiceException.hpp>
17
18#include <rti/routing/adapter/Connection.hpp>
19#include <rti/routing/detail/UpdatableEntityForwarder.hpp>
20#include <rti/routing/detail/ForwarderUtils.hpp>
21
22namespace rti { namespace routing { namespace adapter { namespace detail {
23
24
25class SessionForwarder {
26public:
27 static RTI_RoutingServiceSessionExt* create_native(
28 Connection *connection,
29 const RTI_RoutingServiceProperties *native_properties,
30 RTI_RoutingServiceEnvironment *environment)
31 {
32
33 try {
34 using rti::routing::detail::ScopedForwarder;
35
36 // Set properties
37 std::map<std::string, std::string> properties;
38 rti::routing::PropertyAdapter::add_properties_from_native(
39 properties,
40 native_properties);
41
42 SessionForwarder *forwarder = new SessionForwarder();
43 ScopedForwarder<Connection, SessionForwarder> scoped(
44 connection,
45 forwarder,
46 environment);
47 // Create session: Note we don't check for NULL because a Session
48 // is not required
49 forwarder->session_ = connection->create_session(properties);
50
51 scoped.release();
52
53 // TRUST-134: the forwarder is not leaked here. It might be leaked
54 // if delete_native() were not to be called, but Routing Service
55 // will make sure that is not the case
56
57 /* coverity[leaked_storage : FALSE] */
58 return forwarder->native();
59 } catch(const rti::apputils::FatalServiceException& ex) {
60 RTI_RoutingServiceEnvironment_fatal_error(
61 environment,
62 ex.what());
63 return NULL;
64 } catch(const std::exception& ex) {
65 RTI_RoutingServiceEnvironment_set_error(
66 environment,
67 ex.what());
68 return NULL;
69 } catch (...) {
70 RTI_RoutingServiceEnvironment_set_error(
71 environment,
72 "unexpected exception");
73 return NULL;
74 }
75 }
76
77 static void delete_native(
78 Connection *connection,
79 RTI_RoutingServiceSessionExt *native_session,
80 RTI_RoutingServiceEnvironment *environment)
81 {
82 SessionForwarder *forwarder = static_cast<SessionForwarder*>(
83 native_session->session_data);
84 try {
85 // delete session
86 if (forwarder->session_ != NULL) {
87 connection->delete_session(forwarder->session_);
88 forwarder->session_ = NULL;
89 }
90
91 } catch(const rti::apputils::FatalServiceException& ex) {
92 RTI_RoutingServiceEnvironment_fatal_error(
93 environment,
94 ex.what());
95 } catch(const std::exception& ex) {
96 RTI_RoutingServiceEnvironment_set_error(
97 environment,
98 ex.what());
99 } catch (...) {
100 }
101
102 delete forwarder;
103 }
104
105 Session * session()
106 {
107 return session_;
108 }
109
110 RTI_RoutingServiceSessionExt* native()
111 {
112 return &this->native_;
113 }
114
115 static void update(
116 void *native_session_data,
117 const struct RTI_RoutingServiceProperties * native_properties,
118 RTI_RoutingServiceEnvironment * environment)
119 {
120 SessionForwarder *forwarder =
121 static_cast<SessionForwarder*> (native_session_data);
122
123 rti::routing::detail::UpdatableEntityForwarder::update(
124 forwarder->session_,
125 native_properties,
126 environment);
127 }
128
129private:
130 SessionForwarder() : session_(NULL)
131 {
132 RTIOsapiMemory_zero(&native_, sizeof(native_));
133 native_.session_data =
134 static_cast<void*>(this);
135 native_.update =
136 SessionForwarder::update;
137 }
138
139 ~SessionForwarder()
140 {
141 }
142
143private:
144 RTI_RoutingServiceSessionExt native_;
145 Session *session_;
146
147};
148
149}}}}
150
151#endif // RTI_ROUTING_ADAPTER_DETAIL_SESSION_FORWARDER_HPP_