11#ifndef RTI_ROUTING_PROCESSOR_DETAIL_PROCESSOR_FORWARDER_HPP_
12#define RTI_ROUTING_PROCESSOR_DETAIL_PROCESSOR_FORWARDER_HPP_
14#include <rti/core/Exception.hpp>
16#include "rti/apputils/ServiceException.hpp"
18#include "routingservice/routingservice_processor_impl.h"
19#include <rti/routing/detail/ForwarderUtils.hpp>
20#include <rti/routing/detail/UpdatableEntityForwarder.hpp>
21#include <rti/routing/processor/Route.hpp>
22#include <rti/routing/processor/Input.hpp>
23#include <rti/routing/processor/Output.hpp>
25namespace rti {
namespace routing {
namespace processor {
namespace detail {
27class ProcessorForwarder {
31 template <
typename PORT,
typename NATIVE>
35 ScopedPort(Route& route, int32_t index, NATIVE *native)
37 port_(new PORT(native, index, route.native_route_))
66 static RTI_RoutingServiceProcessor * create_native(
67 ProcessorPlugin *plugin,
68 RTI_RoutingServiceRoute *native_route,
69 const struct RTI_RoutingServiceProperties *native_properties,
70 RTI_RoutingServiceEnvironment *environment)
73 using rti::routing::detail::ScopedForwarder;
75 std::map<std::string, std::string> properties;
76 rti::routing::PropertyAdapter::add_properties_from_native(
80 ProcessorForwarder *forwarder =
new ProcessorForwarder(
83 ScopedForwarder<ProcessorPlugin, ProcessorForwarder> scoped(
87 forwarder->processor_ = plugin->create_processor(
90 RTI_ROUTING_THROW_ON_NULL(forwarder->processor_);
99 return forwarder->native();
100 }
catch(
const rti::apputils::FatalServiceException& ex) {
101 RTI_RoutingServiceEnvironment_fatal_error(
105 }
catch(
const std::exception& ex) {
106 RTI_RoutingServiceEnvironment_set_error(
111 RTI_RoutingServiceEnvironment_set_error(
113 "unexpected exception");
120 static void delete_native(
121 ProcessorPlugin *plugin,
122 RTI_RoutingServiceProcessor *native_processor,
123 RTI_RoutingServiceEnvironment *environment)
125 ProcessorForwarder *processor_forwarder =
126 static_cast<ProcessorForwarder*
>(native_processor->processor_data);
128 if (processor_forwarder->processor_ != NULL) {
129 plugin->delete_processor(
130 processor_forwarder->route_,
131 processor_forwarder->processor_);
132 processor_forwarder->processor_ = NULL;
134 }
catch(
const rti::apputils::FatalServiceException& ex) {
135 RTI_RoutingServiceEnvironment_fatal_error(
138 }
catch(
const std::exception& ex) {
139 RTI_RoutingServiceEnvironment_set_error(
143 RTI_RoutingServiceEnvironment_set_error(
145 "unexpected exception");
148 delete processor_forwarder;
152 static void forward_on_route_event(
153 void *native_processor_data,
154 RTI_RoutingServiceRouteEvent *native_route_event,
155 RTI_RoutingServiceEnvironment *environment)
158 ProcessorForwarder *forwarder =
159 static_cast<ProcessorForwarder*
>(native_processor_data);
164 switch (RTI_RoutingServiceRouteEvent_get_kind(native_route_event)) {
166 case RTI_ROUTING_SERVICE_ROUTE_EVENT_DATA_ON_INPUTS:
167 forwarder->processor_->on_data_available(forwarder->route());
170 case RTI_ROUTING_SERVICE_ROUTE_EVENT_PERIODIC_ACTION:
172 forwarder->processor_->on_periodic_action(forwarder->route());
175 case RTI_ROUTING_SERVICE_ROUTE_EVENT_INPUT_ENABLED:
177 void *affected_entity =
178 RTI_RoutingServiceRouteEvent_get_affected_entity(native_route_event);
180 RTI_RoutingServiceRouteEvent_get_event_data(native_route_event);
182 ScopedPort<Input, RTI_RoutingServiceInput> port(
184 *(
static_cast<int32_t*
>(index)),
185 static_cast<RTI_RoutingServiceInput *
>(affected_entity));
186 forwarder->processor_->on_input_enabled(
189 RTI_RoutingServiceInput_set_user_data(
190 static_cast<RTI_RoutingServiceInput *
>(affected_entity),
201 case RTI_ROUTING_SERVICE_ROUTE_EVENT_INPUT_DISABLED:
204 void *affected_entity =
205 RTI_RoutingServiceRouteEvent_get_affected_entity(native_route_event);
206 RTI_RoutingServiceInput *native_input =
207 static_cast<RTI_RoutingServiceInput *
>(affected_entity);
208 Input *input =
reinterpret_cast<Input*
>(
209 RTI_RoutingServiceInput_get_user_data(native_input));
210 forwarder->processor_->on_input_disabled(
213 RTI_RoutingServiceInput_set_user_data(native_input, NULL);
218 case RTI_ROUTING_SERVICE_ROUTE_EVENT_OUTPUT_ENABLED:
220 void *affected_entity =
221 RTI_RoutingServiceRouteEvent_get_affected_entity(native_route_event);
223 RTI_RoutingServiceRouteEvent_get_event_data(native_route_event);
225 ScopedPort<Output, RTI_RoutingServiceOutput> port(
227 *(
static_cast<int32_t*
>(index)),
228 static_cast<RTI_RoutingServiceOutput *
>(affected_entity));
229 forwarder->processor_->on_output_enabled(
232 RTI_RoutingServiceOutput_set_user_data(
233 static_cast<RTI_RoutingServiceOutput *
>(affected_entity),
244 case RTI_ROUTING_SERVICE_ROUTE_EVENT_OUTPUT_DISABLED:
246 void *affected_entity =
247 RTI_RoutingServiceRouteEvent_get_affected_entity(native_route_event);
248 RTI_RoutingServiceOutput *native_output =
249 static_cast<RTI_RoutingServiceOutput *
>(affected_entity);
250 Output *output =
reinterpret_cast<Output*
>(
251 RTI_RoutingServiceOutput_get_user_data(native_output));
252 forwarder->processor_->on_output_disabled(
255 RTI_RoutingServiceOutput_set_user_data(native_output, NULL);
260 case RTI_ROUTING_SERVICE_ROUTE_EVENT_ROUTE_STARTED:
262 forwarder->processor_->on_start(forwarder->route());
265 case RTI_ROUTING_SERVICE_ROUTE_EVENT_ROUTE_STOPPED:
267 forwarder->processor_->on_stop(forwarder->route());
270 case RTI_ROUTING_SERVICE_ROUTE_EVENT_ROUTE_RUNNING:
272 forwarder->processor_->on_run(forwarder->route());
275 case RTI_ROUTING_SERVICE_ROUTE_EVENT_ROUTE_PAUSED:
277 forwarder->processor_->on_pause(forwarder->route());
284 }
catch (
const rti::apputils::FatalServiceException& ex) {
285 RTI_RoutingServiceEnvironment_fatal_error(
288 }
catch (
const std::exception& ex) {
289 RTI_RoutingServiceEnvironment_set_error(
293 RTI_RoutingServiceEnvironment_set_error(
296 "unexpected exception");
300 static void forward_update(
301 void *native_processor_data,
302 const struct RTI_RoutingServiceProperties *native_properties,
303 RTI_RoutingServiceEnvironment *environment)
306 ProcessorForwarder *processorForwarder =
307 static_cast<ProcessorForwarder*
> (native_processor_data);
309 rti::routing::detail::UpdatableEntityForwarder::update(
310 processorForwarder->processor_,
315 RTI_RoutingServiceProcessor* native()
323 RTI_RoutingServiceRoute *native_route,
324 RTI_RoutingServiceEnvironment *native_env) :
326 route_(native_route, native_env)
328 RTIOsapiMemory_zero(&native_,
sizeof(native_));
330 native_.processor_data =
static_cast<void *
>(
this);
331 native_.on_route_event = ProcessorForwarder::forward_on_route_event;
332 native_.update = ProcessorForwarder::forward_update;
340 ~ProcessorForwarder()
345 RTI_RoutingServiceProcessor native_;
346 Processor *processor_;
Representation of the Route object that owns a Processor.
Definition: Route.hpp:84