RTI Routing Service  Version 6.0.0
 All Data Structures Files Functions Typedefs Enumerations Enumerator Groups Pages
ServiceProperty.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_ROUTING_SERVICE_PROPERTY_HPP_
12 #define RTI_ROUTING_ROUTING_SERVICE_PROPERTY_HPP_
13 
14 // IMPORTANT: macros.hpp must be the first RTI header included in every header
15 // file so that symbols are exported correctly on Windows
16 #include <dds/core/macros.hpp>
17 #include <rti/core/NativeValueType.hpp>
18 
19 #include "routingservice/routingservice_service.h"
20 #include <rti/routing/detail/ForwarderUtils.hpp>
21 
22 namespace rti { namespace routing {
23 
24 class PropertyAdapter {
25 public:
26  typedef RTI_RoutingServiceProperty native_type;
27 
28  static void initialize(native_type& native_value)
29  {
30  static const native_type DEFAULT
31  = RTI_RoutingServiceProperty_INITIALIZER;
32  native_value = DEFAULT;
33  native_value.service_verbosity = -1;
34  native_value.dds_verbosity = -1;
35  }
36 
37  static void finalize(native_type& native_value)
38  {
39  if (native_value.cfg_strings != NULL) {
40  RTIOsapiHeap_freeArray(native_value.cfg_strings);
41  native_value.cfg_strings = NULL;
42  }
43 
44  RTI_RoutingServiceProperty_finalize(&native_value);
45  }
46 
47  static void copy(native_type& destination, const native_type& source)
48  {
49  RTIOsapiUtility_unusedParameter(destination);
50  RTIOsapiUtility_unusedParameter(source);
51 
52  throw dds::core::UnsupportedError("Unsupported operation: copy");
53  }
54 
55  static bool equals(const native_type& first, const native_type& second)
56  {
57  RTIOsapiUtility_unusedParameter(first);
58  RTIOsapiUtility_unusedParameter(second);
59 
60  throw dds::core::UnsupportedError("Unsupported operation: equals");
61  }
62 
63  static void add_properties_from_native(
64  std::map<std::string, std::string>& properties,
65  const RTI_RoutingServiceProperties *native_properties)
66  {
67  for (int i = 0; i < native_properties->count; i++) {
68  properties[native_properties->properties[i].name] =
69  (const char *) native_properties->properties[i].value;
70  }
71  }
72 
73  static void add_properties_to_native(
74  RTI_RoutingServiceProperties *native_properties,
75  const std::map<std::string, std::string>& properties)
76  {
77  RTI_RoutingServiceProperties_finalize(native_properties);
78  RTI_RoutingServiceProperties_initialize(native_properties);
79 
80  std::map<std::string, std::string>::const_iterator it = properties.begin();
81  for (; it != properties.end(); ++it) {
82  if (!RTI_RoutingServiceProperties_add(
83  native_properties,
84  it->first.c_str(),
85  it->second.c_str())) {
86  throw dds::core::Error("failed to add native property");
87  }
88  }
89  }
90 
91 };
92 
93 class ServiceProperty;
94 
95 }
96 
97 namespace core {
98 
99 template<>
100 struct native_type_traits<rti::routing::ServiceProperty> {
101  typedef rti::routing::PropertyAdapter adapter_type;
102  typedef RTI_RoutingServiceProperty native_type;
103 };
104 
105 }
106 
107 namespace routing {
108 
114 class ServiceProperty : public rti::core::NativeValueType<ServiceProperty> {
115 public:
116  RTI_NATIVE_VALUE_TYPE_DEFINE_DEFAULT_MOVE_OPERATIONS(ServiceProperty)
117 
118  typedef rti::core::NativeValueType<ServiceProperty> Base;
119 
123  ServiceProperty(): Base()
124  {
125  }
126 
127  ServiceProperty(const struct RTI_RoutingServiceProperty &native_property)
128  : Base(native_property)
129  {
130  }
131 
132 
136  std::string cfg_file() const
137  {
138  return native().cfg_file == NULL ? "" : native().cfg_file;
139  }
140 
146  ServiceProperty& cfg_file(const std::string& filename)
147  {
148  DDS_String_replace(
149  &native().cfg_file,
150  filename.c_str());
151  return *this;
152  }
153 
157  const std::vector<std::string>& cfg_strings() const
158  {
159  return cfg_strings_;
160  }
161 
177  const std::vector<std::string>& the_cfg_strings)
178  {
179  cfg_strings_ = the_cfg_strings;
180  if (cfg_strings_.size() > 0) {
181  if (!RTIOsapiHeap_reallocateArray(
182  (char ***) &native().cfg_strings,
183  cfg_strings_.size(),
184  char *)) {
185  throw dds::core::OutOfResourcesError("cfg_strings native array");
186  }
187  for (uint32_t i = 0; i < cfg_strings_.size(); i++) {
188  native().cfg_strings[i] = cfg_strings_[i].c_str();
189  }
190  }
191  native().cfg_strings_count = static_cast<int>(cfg_strings_.size());
192 
193  return *this;
194  }
195 
199  std::string service_name() const
200  {
201  return native().service_name == NULL ? "" : native().service_name;
202  }
203 
214  ServiceProperty& service_name(const std::string& name)
215  {
216  DDS_String_replace(
217  &native().service_name,
218  name.c_str());
219  return *this;
220  }
221 
225  std::string application_name() const
226  {
227  return native().application_name;
228  }
229 
244  ServiceProperty& application_name(const std::string& name)
245  {
246  DDS_String_replace(
247  &native().application_name,
248  name.c_str());
249  return *this;
250  }
251 
256  {
257  return (native().enforce_xsd_validation == DDS_BOOLEAN_TRUE)
258  ? true
259  : false;
260  }
261 
269  {
270  native().enforce_xsd_validation = enforce_xsd_validation;
271  return *this;
272  }
273 
277  int domain_id_base() const
278  {
279  return native().domain_id_base;
280  }
281 
282  /*e
283  * @brief Value that is added to the domain IDs of the
284  * domain routes in the XML configuration.
285  *
286  * By using this, an XML file can use relative domain IDs.
287  *
288  * @default 0
289  */
290  ServiceProperty& domain_id_base(const int domain_id)
291  {
292  native().domain_id_base = domain_id;
293  return *this;
294  }
295 
299  std::string plugin_search_path() const
300  {
301  return native().plugin_search_path == NULL
302  ? ""
303  : native().plugin_search_path;
304  }
305 
315  ServiceProperty& plugin_search_path(const std::string& path)
316  {
317  DDS_String_replace(
318  &native().plugin_search_path,
319  path.c_str());
320  return *this;
321  }
322 
326  bool dont_start_service() const
327  {
328  return (native().dont_start_service == DDS_BOOLEAN_TRUE)
329  ? true
330  : false;
331  }
332 
341  ServiceProperty& dont_start_service(const bool not_start)
342  {
343  native().dont_start_service = not_start
344  ? DDS_BOOLEAN_TRUE
345  : DDS_BOOLEAN_FALSE;
346  return *this;
347  }
348 
353  {
354  return (native().enable_administration == DDS_BOOLEAN_TRUE)
355  ? true
356  : false;
357  }
358 
366  {
367  native().enable_administration = enable
368  ? DDS_BOOLEAN_TRUE
369  : DDS_BOOLEAN_FALSE;
370  return *this;
371  }
372 
377  {
378  return native().administration_domain_id;
379  }
380 
392  {
393  native().administration_domain_id = domain_id;
394  return *this;
395  }
396 
400  bool enable_monitoring() const
401  {
402  return native().enable_monitoring == DDS_BOOLEAN_TRUE
403  ? true
404  : false;
405  }
406 
413  ServiceProperty& enable_monitoring(const bool& enable)
414  {
415  native().enable_monitoring = enable
416  ? DDS_BOOLEAN_TRUE
417  : DDS_BOOLEAN_FALSE;
418  return *this;
419  }
420 
425  {
426  return native().monitoring_domain_id;
427  }
428 
439  ServiceProperty& monitoring_domain_id(const int& domain_id)
440  {
441  native().monitoring_domain_id = domain_id;
442  return *this;
443  }
444 
448  bool skip_default_files() const
449  {
450  return (native().skip_default_files == DDS_BOOLEAN_TRUE)
451  ? true
452  : false;
453  }
454 
465  {
466  native().skip_default_files = skip
467  ? DDS_BOOLEAN_TRUE
468  : DDS_BOOLEAN_FALSE;
469  return *this;
470  }
471 
472 
476  bool identify_execution() const
477  {
478  return (native().identify_execution == DDS_BOOLEAN_TRUE)
479  ? true
480  : false;
481  }
482 
491  ServiceProperty& identify_execution(const bool& identify)
492  {
493  native().identify_execution = identify
494  ? DDS_BOOLEAN_TRUE
495  : DDS_BOOLEAN_FALSE;
496  return *this;
497  }
498 
502  std::string license_file_name() const
503  {
504  return native().license_file_name == NULL? ""
505  : native().license_file_name;
506  }
507 
517  ServiceProperty& license_file_name(const std::string& filename)
518  {
519  DDS_String_replace(
520  &native().license_file_name,
521  filename.c_str());
522  return *this;
523  }
524 
528  std::map<std::string, std::string> user_environment() const
529  {
530  std::map<std::string, std::string> properties;
531 
532  PropertyAdapter::add_properties_from_native(
533  properties,
534  &native().user_environment);
535 
536  return properties;
537  }
538 
548  const std::map<std::string, std::string>& user_environment)
549  {
550  rti::routing::PropertyAdapter::add_properties_to_native(
551  &native().user_environment,
552  user_environment);
553 
554  return *this;
555  }
556 
557 private:
558  std::vector<std::string> cfg_strings_;
559 };
560 
561 }}
562 
563 #endif // RTI_ROUTING_ROUTING_SERVICE_PROPERTY_HPP_

RTI Routing Service Version 6.0.0 Copyright © Sun Mar 3 2019 Real-Time Innovations, Inc