RTI Routing Service Version 7.3.0
Route.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_PROCESSOR_ROUTE_HPP_
12#define RTI_ROUTING_PROCESSOR_ROUTE_HPP_
13
14#include <dds/core/Value.hpp>
15#include <dds/core/SafeEnumeration.hpp>
16#include <rti/core/NativeValueType.hpp>
17
18#include "routingservice/routingservice_processor.h"
19#include "routingservice/routingservice_processor_impl.h"
20
21#include <dds/core/xtypes/DynamicData.hpp>
22#include <dds/sub/SampleInfo.hpp>
24#include <rti/routing/processor/Input.hpp>
25#include <rti/routing/processor/Output.hpp>
26#include <rti/routing/processor/LoanedSamples.hpp>
27#include <rti/routing/processor/PortIterator.hpp>
28
29namespace rti { namespace routing { namespace processor {
30
31namespace detail {
32
33class ProcessorForwarder;
34
35}
36
37class Route;
38
39template <typename PORT> struct port_list;
40
41template <> struct port_list<Input>
42{
43 static std::vector<Input>& get(Route& route);
44};
45
46template <> struct port_list<Output>
47{
48 static std::vector<Output>& get(Route& route);
49};
50
84class Route {
85
86public:
87
88 template <typename DataRep, typename InfoRep = dds::sub::SampleInfo>
89 struct Inputs {
90 typedef PortIterator<Input, DataRep, InfoRep> iterator;
91
92 Inputs(RTI_RoutingServiceRoute *native_route)
93 : native_route_(native_route)
94 {
95 }
96
97 iterator begin()
98 {
99 return iterator(native_route_);
100 }
101
102 iterator end()
103 {
104 return iterator();
105 }
106
107 private:
108 RTI_RoutingServiceRoute *native_route_;
109 };
110
111 template <typename DataRep, typename InfoRep = dds::sub::SampleInfo>
112 struct Outputs {
113 typedef PortIterator<Output, DataRep, InfoRep> iterator;
114
115 Outputs(RTI_RoutingServiceRoute *native_route)
116 : native_route_(native_route)
117 {
118 }
119
120 iterator begin()
121 {
122 return iterator(native_route_);
123 }
124
125 iterator end()
126 {
127 return iterator();
128 }
129
130 private:
131 RTI_RoutingServiceRoute *native_route_;
132 };
133
134
139 int32_t input_count() const
140 {
141 return RTI_RoutingServiceRoute_get_input_count(native_route_);
142 }
143
148 int32_t output_count() const
149 {
150 return RTI_RoutingServiceRoute_get_output_count(native_route_);
151 }
152
157 bool input_enabled(int32_t index) const
158 {
159 return RTI_RoutingServiceRoute_is_input_enabled(native_route_, index)
160 ? true
161 : false;
162 }
163
168 bool output_enabled(int32_t index) const
169 {
170 return RTI_RoutingServiceRoute_is_output_enabled(native_route_, index)
171 ? true
172 : false;
173 }
174
193 Input& input(int32_t index)
194 {
195 return *(get_input_at_index(index));
196 }
197
211 Input& input(const std::string& name)
212 {
213 return *(lookup_input(name));
214 }
215
237 template <typename DataRep, typename InfoRep>
239 {
240 return &input(index);
241 }
242
248 template <typename DataRep>
250 {
251 return input<DataRep, dds::sub::SampleInfo>(index);
252 }
253
259 template <typename DataRep, typename InfoRep>
260 TypedInput<DataRep, InfoRep> input(const std::string& name)
261 {
262 return &input(name);
263 }
264
269 template <typename DataRep>
270 TypedInput<DataRep> input(const std::string& name)
271 {
272 return input<DataRep, dds::sub::SampleInfo>(name);
273 }
274
293 Output& output(int32_t index)
294 {
295 return *(get_output_at_index(index));
296 }
297
311 Output& output(const std::string& name)
312 {
313 return *(lookup_output(name));
314 }
315
336 template <typename DataRep, typename InfoRep>
338 {
339 return &output(index);
340 }
341
347 template <typename DataRep>
349 {
350 return output<DataRep, dds::sub::SampleInfo>(index);
351 }
352
358 template <typename DataRep, typename InfoRep>
359 TypedOutput<DataRep, InfoRep> output(const std::string& name)
360 {
361 return &output(name);
362 }
363
368 template <typename DataRep>
369 TypedOutput<DataRep> output(const std::string& name)
370 {
371 return output<DataRep, dds::sub::SampleInfo>(name);
372 }
373
383 template <typename DataRep, typename InfoRep>
384 Inputs<DataRep, InfoRep> inputs()
385 {
386 return Inputs<DataRep, InfoRep>(native_route_);
387 }
388
393 template <typename DataRep>
394 Inputs<DataRep> inputs()
395 {
396 return inputs<DataRep, dds::sub::SampleInfo>();
397 }
398
408 template <typename DataRep, typename InfoRep>
409 Outputs<DataRep, InfoRep> outputs()
410 {
411 return Outputs<DataRep, InfoRep>(native_route_);
412 }
413
418 template <typename DataRep>
419 Outputs<DataRep> outputs()
420 {
421 return outputs<DataRep, dds::sub::SampleInfo>();
422 }
423
437 void period(const dds::core::Duration& period)
438 {
439 struct DDS_Duration_t native_period;
440 rti::core::native_conversions::to_native(native_period, period);
441 RTI_RoutingServiceRoute_set_period(
442 native_route_,
443 &native_period);
444 }
445
446 dds::core::Duration period() const
447 {
448 struct DDS_Duration_t native_period;
449 RTI_RoutingServiceRoute_get_period(
450 native_route_,
451 &native_period);
452
453 return rti::core::native_conversions::from_native(native_period);
454 }
455
461 const std::string& full_name() const
462 {
463 return full_name_;
464 }
465
466
467private:
468 friend class detail::ProcessorForwarder;
469 friend class Output;
470 friend struct port_list<Input>;
471 friend struct port_list<Output>;
472
473 typedef std::vector<Input>::iterator private_input_it;
474 typedef std::vector<Output>::iterator private_output_it;
475
476 Route& operator= (const Route& other);
477
478 Route(RTI_RoutingServiceRoute *native_route,
479 RTI_RoutingServiceEnvironment *native_env)
480 : native_route_(native_route),
481 native_env_(native_env)
482 {
483 const char *native_full_name =
484 RTI_RoutingServiceRoute_get_full_name(native_route);
485 if (native_full_name == nullptr) {
486 throw dds::core::InvalidArgumentError(
487 "Native Route has invalid full name");
488 }
489 full_name_ = native_full_name;
490 }
491
492 Input* get_input_at_index(int32_t index)
493 {
494 RTI_RoutingServiceInput *native_input =
495 RTI_RoutingServiceRoute_get_input_at(native_route_, index);
496 if (native_input == NULL) {
497 throw dds::core::InvalidArgumentError(
498 RTI_RoutingServiceEnvironment_get_error_message(native_env_));
499 }
500
501 return static_cast<Input*>(RTI_RoutingServiceInput_get_user_data(native_input));
502 }
503
504 Output* get_output_at_index(int32_t index)
505 {
506 RTI_RoutingServiceOutput *native_output =
507 RTI_RoutingServiceRoute_get_output_at(native_route_, index);
508 if (native_output == NULL) {
509 throw dds::core::InvalidArgumentError(
510 RTI_RoutingServiceEnvironment_get_error_message(native_env_));
511 }
512
513 return static_cast<Output*>(RTI_RoutingServiceOutput_get_user_data(native_output));
514 }
515
516
517 Input* lookup_input(const std::string& name)
518 {
519 RTI_RoutingServiceInput *native_input =
520 RTI_RoutingServiceRoute_lookup_input_by_name(
521 native_route_,
522 name.c_str());
523 if (native_input == NULL) {
524 throw dds::core::InvalidArgumentError(
525 RTI_RoutingServiceEnvironment_get_error_message(native_env_));
526 }
527 return static_cast<Input*>(RTI_RoutingServiceInput_get_user_data(native_input));
528
529 }
530
531 Output* lookup_output(const std::string& name)
532 {
533 RTI_RoutingServiceOutput *native_output =
534 RTI_RoutingServiceRoute_lookup_output_by_name(
535 native_route_,
536 name.c_str());
537 if (native_output == NULL) {
538 throw dds::core::InvalidArgumentError(
539 RTI_RoutingServiceEnvironment_get_error_message(native_env_));
540 }
541 return static_cast<Output*>(RTI_RoutingServiceOutput_get_user_data(native_output));
542
543 }
544
545private:
546 RTI_RoutingServiceRoute *native_route_;
547 RTI_RoutingServiceEnvironment *native_env_;
548 std::string full_name_;
549
550};
551
552
553} } }
554
555#endif // RTI_ROUTING_PROCESSOR_ROUTE_HPP_
RTI Routing Service C++ Adapter API.
Generic Representation of a Route's input.
Definition: Input.hpp:49
Generic Representation of a Route's output.
Definition: Output.hpp:44
Representation of the Route object that owns a Processor.
Definition: Route.hpp:84
Outputs< DataRep > outputs()
Same as Inputs<DataRep, InfoRep> outputs() with InfoRep = dds::sub::SampleInfo.
Definition: Route.hpp:419
Input & input(const std::string &name)
Returns the Input object with the specified name or throws an exception if the input with the given n...
Definition: Route.hpp:211
Output & output(int32_t index)
Returns the Output object at the specified index.
Definition: Route.hpp:293
TypedOutput< DataRep > output(const std::string &name)
Same as output<DataRep, InfoRep>(std::string&) with InfoRep = dds::sub::SampleInfo.
Definition: Route.hpp:369
int32_t input_count() const
Returns the total number of inputs in this Route.
Definition: Route.hpp:139
Inputs< DataRep > inputs()
Same as Inputs<DataRep, InfoRep> inputs() with InfoRep = dds::sub::SampleInfo.
Definition: Route.hpp:394
TypedInput< DataRep, InfoRep > input(const std::string &name)
Same as input<DataRep, InfoRep>(int32_t) but using the configuration name of the input.
Definition: Route.hpp:260
void period(const dds::core::Duration &period)
Changes the event period of this Route.
Definition: Route.hpp:437
TypedOutput< DataRep > output(int32_t index)
Same as output<DataRep, InfoRep>(int32_t) with InfoRep = dds::sub::SampleInfo.
Definition: Route.hpp:348
Input & input(int32_t index)
Returns the Input object at the specified index.
Definition: Route.hpp:193
Outputs< DataRep, InfoRep > outputs()
Returns an accessor for the contained outputs.
Definition: Route.hpp:409
TypedOutput< DataRep, InfoRep > output(int32_t index)
Returns the TypedOutput object at the specified index.
Definition: Route.hpp:337
const std::string & full_name() const
Returns the fully qualified of this Route, derived from the configuration.
Definition: Route.hpp:461
TypedOutput< DataRep, InfoRep > output(const std::string &name)
Same as output<DataRep, InfoRep>(int32_t) but using the configuration name of the output.
Definition: Route.hpp:359
TypedInput< DataRep > input(const std::string &name)
Same as input<DataRep, InfoRep>(std::string&) with InfoRep = dds::sub::SampleInfo.
Definition: Route.hpp:270
int32_t output_count() const
Returns the total number of outputs in this Route.
Definition: Route.hpp:148
TypedInput< DataRep > input(int32_t index)
Same as input<DataRep, InfoRep>(int32_t) with InfoRep = dds::sub::SampleInfo.
Definition: Route.hpp:249
Inputs< DataRep, InfoRep > inputs()
Returns an accessor for the contained inputs.
Definition: Route.hpp:384
TypedInput< DataRep, InfoRep > input(int32_t index)
Returns the TypedInput object at the specified index.
Definition: Route.hpp:238
bool output_enabled(int32_t index) const
Checks whether the Input at the specified index is enabled.
Definition: Route.hpp:168
Output & output(const std::string &name)
Returns the Output object with the specified name or throws an exception if the output with the given...
Definition: Route.hpp:311
bool input_enabled(int32_t index) const
Checks whether the Input at the specified index is enabled.
Definition: Route.hpp:157
Representation of an Input whose data representation is DataRep, whose info representation is InfoRep...
Definition: Input.hpp:149
Representation of an Output whose data representation is DataRep, whose info representation is InfoRe...
Definition: Output.hpp:133