RTI Routing Service  Version 6.0.1
 All Data Structures Files Functions Typedefs Enumerations Enumerator Groups Pages
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 struct ScopedPort;
35 
36 }
37 
38 class Route;
39 
40 template <typename PORT> struct port_list;
41 
42 template <> struct port_list<Input>
43 {
44  static std::vector<Input>& get(Route& route);
45 };
46 
47 template <> struct port_list<Output>
48 {
49  static std::vector<Output>& get(Route& route);
50 };
51 
85 class Route {
86 
87 public:
88 
89  template <typename DataRep, typename InfoRep = dds::sub::SampleInfo>
90  struct Inputs {
91  typedef PortIterator<Input, DataRep, InfoRep> iterator;
92 
93  Inputs(RTI_RoutingServiceRoute *native_route)
94  : native_route_(native_route)
95  {
96  }
97 
98  iterator begin()
99  {
100  return iterator(native_route_);
101  }
102 
103  iterator end()
104  {
105  return iterator();
106  }
107 
108  private:
109  RTI_RoutingServiceRoute *native_route_;
110  };
111 
112  template <typename DataRep, typename InfoRep = dds::sub::SampleInfo>
113  struct Outputs {
114  typedef PortIterator<Output, DataRep, InfoRep> iterator;
115 
116  Outputs(RTI_RoutingServiceRoute *native_route)
117  : native_route_(native_route)
118  {
119  }
120 
121  iterator begin()
122  {
123  return iterator(native_route_);
124  }
125 
126  iterator end()
127  {
128  return iterator();
129  }
130 
131  private:
132  RTI_RoutingServiceRoute *native_route_;
133  };
134 
135 
136 public:
137 
142  int32_t input_count() const
143  {
144  return RTI_RoutingServiceRoute_get_input_count(native_route_);
145  }
146 
151  int32_t output_count() const
152  {
153  return RTI_RoutingServiceRoute_get_output_count(native_route_);
154  }
155 
174  Input& input(int32_t index)
175  {
176  return *(get_input_at_index(index));
177  }
178 
189  Input& input(const std::string& name)
190  {
191  return *(lookup_input(name));
192  }
193 
215  template <typename DataRep, typename InfoRep>
217  {
218  return &input(index);
219  }
220 
226  template <typename DataRep>
227  TypedInput<DataRep> input(int32_t index)
228  {
229  return input<DataRep, dds::sub::SampleInfo>(index);
230  }
231 
237  template <typename DataRep, typename InfoRep>
238  TypedInput<DataRep, InfoRep> input(const std::string& name)
239  {
240  return &input(name);
241  }
242 
247  template <typename DataRep>
248  TypedInput<DataRep> input(const std::string& name)
249  {
250  return input<DataRep, dds::sub::SampleInfo>(name);
251  }
252 
271  Output& output(int32_t index)
272  {
273  return *(get_output_at_index(index));
274  }
275 
286  Output& output(const std::string& name)
287  {
288  return *(lookup_output(name));
289  }
290 
311  template <typename DataRep, typename InfoRep>
313  {
314  return &output(index);
315  }
316 
322  template <typename DataRep>
324  {
325  return output<DataRep, dds::sub::SampleInfo>(index);
326  }
327 
333  template <typename DataRep, typename InfoRep>
334  TypedOutput<DataRep, InfoRep> output(const std::string& name)
335  {
336  return &output(name);
337  }
338 
343  template <typename DataRep>
344  TypedOutput<DataRep> output(const std::string& name)
345  {
346  return output<DataRep, dds::sub::SampleInfo>(name);
347  }
348 
358  template <typename DataRep, typename InfoRep>
359  Inputs<DataRep, InfoRep> inputs()
360  {
361  return Inputs<DataRep, InfoRep>(native_route_);
362  }
363 
368  template <typename DataRep>
369  Inputs<DataRep> inputs()
370  {
371  return inputs<DataRep, dds::sub::SampleInfo>();
372  }
373 
383  template <typename DataRep, typename InfoRep>
384  Outputs<DataRep, InfoRep> outputs()
385  {
386  return Outputs<DataRep, InfoRep>(native_route_);
387  }
388 
393  template <typename DataRep>
394  Outputs<DataRep> outputs()
395  {
396  return outputs<DataRep, dds::sub::SampleInfo>();
397  }
398 
413  void period(const dds::core::Duration& period)
414  {
415  RTI_RoutingServiceRoute_set_session_period(
416  native_route_,
417  period.to_millisecs());
418  }
419 
420 
421 private:
422  friend class detail::ProcessorForwarder;
423  friend class Output;
424  friend struct port_list<Input>;
425  friend struct port_list<Output>;
426 
427  typedef std::vector<Input>::iterator private_input_it;
428  typedef std::vector<Output>::iterator private_output_it;
429 
430  Route& operator= (const Route& other);
431 
432  Route(RTI_RoutingServiceRoute *native_route,
433  RTI_RoutingServiceEnvironment *native_env)
434  : native_route_(native_route),
435  native_env_(native_env)
436  {
437  }
438 
439  template<typename PORT>
440  PORT * get_port_from_native(void *native)
441  {
442  return static_cast<PORT*>(
443  RTI_RoutingServiceRoute_get_stream_port_user_data(
444  native_route_,
445  native));
446  }
447 
448  Input* get_input_at_index(int32_t index)
449  {
450  RTI_RoutingServiceStreamReaderExt *native_input =
451  RTI_RoutingServiceRoute_get_input_at(
452  native_route_,
453  index);
454  if (native_input == NULL) {
455  throw dds::core::InvalidArgumentError(
456  RTI_RoutingServiceEnvironment_get_error_message(native_env_));
457  }
458 
459  return get_port_from_native<Input>(native_input->stream_reader_data);
460  }
461 
462  Output* get_output_at_index(int32_t index)
463  {
464  RTI_RoutingServiceStreamWriterExt *native_output =
465  RTI_RoutingServiceRoute_get_output_at(
466  native_route_,
467  index);
468  if (native_output == NULL) {
469  throw dds::core::InvalidArgumentError(
470  RTI_RoutingServiceEnvironment_get_error_message(native_env_));
471  }
472 
473  return get_port_from_native<Output>(
474  native_output->stream_writer_data);
475  }
476 
477 
478  Input* lookup_input(const std::string& name)
479  {
480  RTI_RoutingServiceStreamReaderExt *native_input =
481  RTI_RoutingServiceRoute_lookup_input_by_name(
482  native_route_,
483  name.c_str());
484  if (native_input == NULL) {
485  throw dds::core::InvalidArgumentError(
486  RTI_RoutingServiceEnvironment_get_error_message(native_env_));
487  }
488  return get_port_from_native<Input>(native_input->stream_reader_data);
489 
490  }
491 
492  Output* lookup_output(const std::string& name)
493  {
494  RTI_RoutingServiceStreamWriterExt *native_output =
495  RTI_RoutingServiceRoute_lookup_output_by_name(
496  native_route_,
497  name.c_str());
498  if (native_output == NULL) {
499  throw dds::core::InvalidArgumentError(
500  RTI_RoutingServiceEnvironment_get_error_message(native_env_));
501  }
502  return get_port_from_native<Output>(
503  native_output->stream_writer_data);
504 
505  }
506 
507 private:
508  RTI_RoutingServiceRoute *native_route_;
509  RTI_RoutingServiceEnvironment *native_env_;
510 
511 };
512 
513 
514 } } }
515 
516 #endif // RTI_ROUTING_PROCESSOR_ROUTE_HPP_

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