RTI Routing Service  Version 6.1.2
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 
29 namespace rti { namespace routing { namespace processor {
30 
31 namespace detail {
32 
33 class ProcessorForwarder;
34 
35 }
36 
37 class Route;
38 
39 template <typename PORT> struct port_list;
40 
41 template <> struct port_list<Input>
42 {
43  static std::vector<Input>& get(Route& route);
44 };
45 
46 template <> struct port_list<Output>
47 {
48  static std::vector<Output>& get(Route& route);
49 };
50 
84 class Route {
85 
86 public:
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 
208  Input& input(const std::string& name)
209  {
210  return *(lookup_input(name));
211  }
212 
234  template <typename DataRep, typename InfoRep>
236  {
237  return &input(index);
238  }
239 
245  template <typename DataRep>
246  TypedInput<DataRep> input(int32_t index)
247  {
248  return input<DataRep, dds::sub::SampleInfo>(index);
249  }
250 
256  template <typename DataRep, typename InfoRep>
257  TypedInput<DataRep, InfoRep> input(const std::string& name)
258  {
259  return &input(name);
260  }
261 
266  template <typename DataRep>
267  TypedInput<DataRep> input(const std::string& name)
268  {
269  return input<DataRep, dds::sub::SampleInfo>(name);
270  }
271 
290  Output& output(int32_t index)
291  {
292  return *(get_output_at_index(index));
293  }
294 
305  Output& output(const std::string& name)
306  {
307  return *(lookup_output(name));
308  }
309 
330  template <typename DataRep, typename InfoRep>
332  {
333  return &output(index);
334  }
335 
341  template <typename DataRep>
343  {
344  return output<DataRep, dds::sub::SampleInfo>(index);
345  }
346 
352  template <typename DataRep, typename InfoRep>
353  TypedOutput<DataRep, InfoRep> output(const std::string& name)
354  {
355  return &output(name);
356  }
357 
362  template <typename DataRep>
363  TypedOutput<DataRep> output(const std::string& name)
364  {
365  return output<DataRep, dds::sub::SampleInfo>(name);
366  }
367 
377  template <typename DataRep, typename InfoRep>
378  Inputs<DataRep, InfoRep> inputs()
379  {
380  return Inputs<DataRep, InfoRep>(native_route_);
381  }
382 
387  template <typename DataRep>
388  Inputs<DataRep> inputs()
389  {
390  return inputs<DataRep, dds::sub::SampleInfo>();
391  }
392 
402  template <typename DataRep, typename InfoRep>
403  Outputs<DataRep, InfoRep> outputs()
404  {
405  return Outputs<DataRep, InfoRep>(native_route_);
406  }
407 
412  template <typename DataRep>
413  Outputs<DataRep> outputs()
414  {
415  return outputs<DataRep, dds::sub::SampleInfo>();
416  }
417 
431  void period(const dds::core::Duration& period)
432  {
433  struct DDS_Duration_t native_period;
434  rti::core::native_conversions::to_native(native_period, period);
435  RTI_RoutingServiceRoute_set_period(
436  native_route_,
437  &native_period);
438  }
439 
440  dds::core::Duration period() const
441  {
442  struct DDS_Duration_t native_period;
443  RTI_RoutingServiceRoute_get_period(
444  native_route_,
445  &native_period);
446 
447  return rti::core::native_conversions::from_native(native_period);
448  }
449 
455  const std::string& full_name() const
456  {
457  return full_name_;
458  }
459 
460 
461 private:
462  friend class detail::ProcessorForwarder;
463  friend class Output;
464  friend struct port_list<Input>;
465  friend struct port_list<Output>;
466 
467  typedef std::vector<Input>::iterator private_input_it;
468  typedef std::vector<Output>::iterator private_output_it;
469 
470  Route& operator= (const Route& other);
471 
472  Route(RTI_RoutingServiceRoute *native_route,
473  RTI_RoutingServiceEnvironment *native_env)
474  : native_route_(native_route),
475  native_env_(native_env),
476  full_name_(RTI_RoutingServiceRoute_get_full_name(native_route))
477  {
478  }
479 
480  Input* get_input_at_index(int32_t index)
481  {
482  RTI_RoutingServiceInput *native_input =
483  RTI_RoutingServiceRoute_get_input_at(native_route_, index);
484  if (native_input == NULL) {
485  throw dds::core::InvalidArgumentError(
486  RTI_RoutingServiceEnvironment_get_error_message(native_env_));
487  }
488 
489  return static_cast<Input*>(RTI_RoutingServiceInput_get_user_data(native_input));
490  }
491 
492  Output* get_output_at_index(int32_t index)
493  {
494  RTI_RoutingServiceOutput *native_output =
495  RTI_RoutingServiceRoute_get_output_at(native_route_, index);
496  if (native_output == NULL) {
497  throw dds::core::InvalidArgumentError(
498  RTI_RoutingServiceEnvironment_get_error_message(native_env_));
499  }
500 
501  return static_cast<Output*>(RTI_RoutingServiceOutput_get_user_data(native_output));
502  }
503 
504 
505  Input* lookup_input(const std::string& name)
506  {
507  RTI_RoutingServiceInput *native_input =
508  RTI_RoutingServiceRoute_lookup_input_by_name(
509  native_route_,
510  name.c_str());
511  if (native_input == NULL) {
512  throw dds::core::InvalidArgumentError(
513  RTI_RoutingServiceEnvironment_get_error_message(native_env_));
514  }
515  return static_cast<Input*>(RTI_RoutingServiceInput_get_user_data(native_input));
516 
517  }
518 
519  Output* lookup_output(const std::string& name)
520  {
521  RTI_RoutingServiceOutput *native_output =
522  RTI_RoutingServiceRoute_lookup_output_by_name(
523  native_route_,
524  name.c_str());
525  if (native_output == NULL) {
526  throw dds::core::InvalidArgumentError(
527  RTI_RoutingServiceEnvironment_get_error_message(native_env_));
528  }
529  return static_cast<Output*>(RTI_RoutingServiceOutput_get_user_data(native_output));
530 
531  }
532 
533 private:
534  RTI_RoutingServiceRoute *native_route_;
535  RTI_RoutingServiceEnvironment *native_env_;
536  std::string full_name_;
537 
538 };
539 
540 
541 } } }
542 
543 #endif // RTI_ROUTING_PROCESSOR_ROUTE_HPP_
TypedOutput< DataRep > output(const std::string &name)
Same as output<DataRep, InfoRep>(std::string&) with InfoRep = dds::sub::SampleInfo.
Definition: Route.hpp:363
TypedOutput< DataRep > output(int32_t index)
Same as output<DataRep, InfoRep>(int32_t) with InfoRep = dds::sub::SampleInfo.
Definition: Route.hpp:342
int32_t output_count() const
Returns the total number of outputs in this Route.
Definition: Route.hpp:148
Generic Representation of a Route&#39;s input.
Definition: Input.hpp:49
bool input_enabled(int32_t index) const
Checks whether the Input at the specified index is enabled.
Definition: Route.hpp:157
Representation of an Output whose data representation is DataRep, whose info representation is InfoRe...
Definition: Output.hpp:28
TypedInput< DataRep > input(const std::string &name)
Same as input<DataRep, InfoRep>(std::string&) with InfoRep = dds::sub::SampleInfo.
Definition: Route.hpp:267
Representation of the Route object that owns a Processor.
Definition: Route.hpp:84
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:257
Outputs< DataRep > outputs()
Same as Inputs<DataRep, InfoRep> outputs() with InfoRep = dds::sub::SampleInfo.
Definition: Route.hpp:413
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:353
bool output_enabled(int32_t index) const
Checks whether the Input at the specified index is enabled.
Definition: Route.hpp:168
Inputs< DataRep > inputs()
Same as Inputs<DataRep, InfoRep> inputs() with InfoRep = dds::sub::SampleInfo.
Definition: Route.hpp:388
TypedOutput< DataRep, InfoRep > output(int32_t index)
Returns the TypedOutput object at the specified index.
Definition: Route.hpp:331
void period(const dds::core::Duration &period)
Changes the event period of this Route.
Definition: Route.hpp:431
TypedInput< DataRep > input(int32_t index)
Same as input<DataRep, InfoRep>(int32_t) with InfoRep = dds::sub::SampleInfo.
Definition: Route.hpp:246
Inputs< DataRep, InfoRep > inputs()
Returns an accessor for the contained inputs.
Definition: Route.hpp:378
Definition: AdapterPlugin.hpp:25
Input & input(const std::string &name)
Returns the Input object with the specified name.
Definition: Route.hpp:208
const std::string & full_name() const
Returns the fully qualified of this Route, derived from the configuration.
Definition: Route.hpp:455
int32_t input_count() const
Returns the total number of inputs in this Route.
Definition: Route.hpp:139
Generic Representation of a Route&#39;s output.
Definition: Output.hpp:44
Outputs< DataRep, InfoRep > outputs()
Returns an accessor for the contained outputs.
Definition: Route.hpp:403
TypedInput< DataRep, InfoRep > input(int32_t index)
Returns the TypedInput object at the specified index.
Definition: Route.hpp:235
Representation of an Input whose data representation is DataRep, whose info representation is InfoRep...
Definition: Input.hpp:32
Output & output(const std::string &name)
Returns the Output object with the specified name.
Definition: Route.hpp:305
RTI Routing Service C++ Adapter API.
Output & output(int32_t index)
Returns the Output object at the specified index.
Definition: Route.hpp:290
Input & input(int32_t index)
Returns the Input object at the specified index.
Definition: Route.hpp:193