OpenDDS  Snapshot(2023/04/28-20:55)
QosSettings.cpp
Go to the documentation of this file.
1 #include "QosSettings.h"
3 
4 #include <cstring>
5 
7 
8 namespace OpenDDS { namespace FaceTSS { namespace config {
9 
11  publisher_qos_(TheServiceParticipant->initial_PublisherQos())
12 , subscriber_qos_(TheServiceParticipant->initial_SubscriberQos())
13 , datawriter_qos_(TheServiceParticipant->initial_DataWriterQos())
14 , datareader_qos_(TheServiceParticipant->initial_DataReaderQos())
15 {
16 
17 }
18 
19 void
21 {
22  target = publisher_qos_;
23 }
24 
25 void
27 {
28  target = subscriber_qos_;
29 }
30 
31 void
33 {
34  target = datawriter_qos_;
35 }
36 
37 void
39 {
40  target = datareader_qos_;
41 }
42 
43 int
44 QosSettings::set_qos(QosLevel level, const char* name, const char* value)
45 {
46  int status = 0;
47  switch (level) {
48  case publisher:
49  status = set_qos(publisher_qos_, name, value);
50  break;
51  case subscriber:
52  status = set_qos(subscriber_qos_, name, value);
53  break;
54  case datawriter:
55  status = set_qos(datawriter_qos_, name, value);
56  break;
57  case datareader:
58  status = set_qos(datareader_qos_, name, value);
59  break;
60  }
61  return status;
62 }
63 
64 bool
67  const char* name,
68  const char* value)
69 {
70  bool matched = false;
71  if (!std::strcmp(name, "presentation.access_scope")) {
72  if (!std::strcmp(value, "INSTANCE")) {
74  matched = true;
75  }
76  if (!std::strcmp(value, "TOPIC")) {
78  matched = true;
79  }
80  if (!std::strcmp(value, "GROUP")) {
82  matched = true;
83  }
84  }
85  return matched;
86 }
87 
88 // Set boolean value on the target and return true if it was a valid value
89 bool
90 set_bool_qos_value(bool& target, const char* value)
91 {
92  bool matched = false;
93  if (!std::strcmp(value, "true")) {
94  target = true;
95  matched = true;
96  } else if (!std::strcmp(value, "false")) {
97  target = false;
98  matched = true;
99  }
100  return matched;
101 }
102 
103 // Set duration on the target and return true if it was a valid value
104 bool
106  const char* prefix_match, // prefix to match
107  const char* name, // config name provided
108  const char* value) // config value provided
109 {
110  char buffer[64];
111  std::strncpy(buffer, prefix_match, 64 - 4);
112  std::strcat(buffer, ".sec");
113  if (!std::strcmp(name, buffer)) {
114  if (!std::strcmp(value, "DURATION_INFINITE_SEC")) {
116  return true;
117  }
118  target.sec = atoi(value);
119  return true;
120  }
121  std::strncpy(buffer, prefix_match, 64 - 7);
122  std::strcat(buffer, ".nanosec");
123  if (!std::strcmp(name, buffer)) {
124  if (!std::strcmp(value, "DURATION_INFINITE_NSEC")) {
126  return true;
127  }
128  target.nanosec = atoi(value);
129  return true;
130  }
131  return false;
132 }
133 
134 bool
137  const char* name,
138  const char* value)
139 {
140  bool matched = false;
141  if (!std::strcmp(name, "presentation.coherent_access")) {
142  matched = set_bool_qos_value(target.coherent_access, value);
143  }
144  return matched;
145 }
146 
147 bool
150  const char* name,
151  const char* value)
152 {
153  bool matched = false;
154  if (!std::strcmp(name, "presentation.ordered_access")) {
155  matched = set_bool_qos_value(target.ordered_access, value);
156  }
157  return matched;
158 }
159 
160 bool
162  DDS::PartitionQosPolicy& target, const char* name, const char* value)
163 {
164  bool matched = false;
165  if (!std::strcmp(name, "partition.name")) {
166  // Value can be a comma-separated list
167  const char* start = value;
168  while (const char* next_comma = std::strchr(start, ',')) {
169  const size_t size = next_comma - start;
170  const OPENDDS_STRING temp(start, size);
171  // Add to QOS
172  target.name.length(target.name.length() + 1);
173  target.name[target.name.length() - 1] = temp.c_str();
174  // Advance pointer
175  start = next_comma + 1;
176  }
177  // Append everything after last comma
178  target.name.length(target.name.length() + 1);
179  target.name[target.name.length() - 1] = start;
180 
181  matched = true;
182  }
183  return matched;
184 }
185 
186 bool
188  DDS::DurabilityQosPolicy& target, const char* name, const char* value)
189 {
190  bool matched = false;
191  if (!std::strcmp(name, "durability.kind")) {
192  if (!std::strcmp(value, "VOLATILE")) {
194  matched = true;
195  } else if (!std::strcmp(value, "TRANSIENT_LOCAL")) {
197  matched = true;
198 #ifndef OPENDDS_NO_PERSISTENCE_PROFILE
199  } else if (!std::strcmp(value, "TRANSIENT")) {
201  matched = true;
202  } else if (!std::strcmp(value, "PERSISTENT")) {
204  matched = true;
205 #endif
206  }
207  }
208  return matched;
209 }
210 
211 bool
213  DDS::DeadlineQosPolicy& target, const char* name, const char* value)
214 {
215  return set_duration_qos_value(target.period, "deadline.period", name, value);
216 }
217 
218 bool
220  DDS::LatencyBudgetQosPolicy& target, const char* name, const char* value)
221 {
222  return set_duration_qos_value(
223  target.duration, "latency_budget.duration", name, value);
224 }
225 
227  DDS::LivelinessQosPolicy& target, const char* name, const char* value)
228 {
229  bool matched = false;
230  if (!std::strcmp(name, "liveliness.kind")) {
231  if (!std::strcmp(value, "AUTOMATIC")) {
233  matched = true;
234  } else if (!std::strcmp(value, "MANUAL_BY_TOPIC")) {
236  matched = true;
237  } else if (!std::strcmp(value, "MANUAL_BY_PARTICIPANT")) {
239  matched = true;
240  }
241  }
242  return matched;
243 }
244 
246  DDS::LivelinessQosPolicy& target, const char* name, const char* value)
247 {
248  return set_duration_qos_value(
249  target.lease_duration, "liveliness.lease_duration", name, value);
250 }
251 
253  DDS::ReliabilityQosPolicy& target, const char* name, const char* value)
254 {
255  bool matched = false;
256  if (!std::strcmp(name, "reliability.kind")) {
257  if (!std::strcmp(value, "BEST_EFFORT")) {
259  matched = true;
260  } else if (!std::strcmp(value, "RELIABLE")) {
262  matched = true;
263  }
264  }
265  return matched;
266 }
267 
269  DDS::ReliabilityQosPolicy& target, const char* name, const char* value)
270 {
271  return set_duration_qos_value(
272  target.max_blocking_time, "reliability.max_blocking_time", name, value);
273 }
274 
276  DDS::DestinationOrderQosPolicy& target, const char* name, const char* value)
277 {
278  bool matched = false;
279  if (!std::strcmp(name, "destination_order.kind")) {
280  if (!std::strcmp(value, "BY_RECEPTION_TIMESTAMP")) {
282  matched = true;
283  } else if (!std::strcmp(value, "BY_SOURCE_TIMESTAMP")) {
285  matched = true;
286  }
287  }
288  return matched;
289 }
290 
292  DDS::HistoryQosPolicy& target, const char* name, const char* value)
293 {
294  bool matched = false;
295  if (!std::strcmp(name, "history.kind")) {
296  if (!std::strcmp(value, "KEEP_ALL")) {
298  matched = true;
299  } else if (!std::strcmp(value, "KEEP_LAST")) {
301  matched = true;
302  }
303  }
304  return matched;
305 }
306 
308  DDS::HistoryQosPolicy& target, const char* name, const char* value)
309 {
310  bool matched = false;
311  if (!std::strcmp(name, "history.depth")) {
312  target.depth = atoi(value);
313  matched = true;
314  }
315  return matched;
316 }
317 
319  DDS::ResourceLimitsQosPolicy& target, const char* name, const char* value)
320 {
321  bool matched = false;
322  if (!std::strcmp(name, "resource_limits.max_samples")) {
323  target.max_samples = atoi(value);
324  matched = true;
325  }
326  return matched;
327 }
328 
330  DDS::ResourceLimitsQosPolicy& target, const char* name, const char* value)
331 {
332  bool matched = false;
333  if (!std::strcmp(name, "resource_limits.max_instances")) {
334  target.max_instances = atoi(value);
335  matched = true;
336  }
337  return matched;
338 }
339 
341  DDS::ResourceLimitsQosPolicy& target, const char* name, const char* value)
342 {
343  bool matched = false;
344  if (!std::strcmp(name, "resource_limits.max_samples_per_instance")) {
345  target.max_samples_per_instance = atoi(value);
346  matched = true;
347  }
348  return matched;
349 }
350 
352  DDS::TransportPriorityQosPolicy& target, const char* name, const char* value)
353 {
354  bool matched = false;
355  if (!std::strcmp(name, "transport_priority.value")) {
356  target.value = atoi(value);
357  matched = true;
358  }
359  return matched;
360 }
361 
363  DDS::LifespanQosPolicy& target, const char* name, const char* value)
364 {
365  return set_duration_qos_value(
366  target.duration, "lifespan.duration", name, value);
367 }
368 
370  DDS::OwnershipQosPolicy& target, const char* name, const char* value)
371 {
372  bool matched = false;
373  if (!std::strcmp(name, "ownership.kind")) {
374  if (!std::strcmp(value, "SHARED")) {
376  matched = true;
377  } else if (!std::strcmp(value, "EXCLUSIVE")) {
379  matched = true;
380  }
381  }
382  return matched;
383 }
384 
386  DDS::OwnershipStrengthQosPolicy& target, const char* name, const char* value)
387 {
388  bool matched = false;
389  if (!std::strcmp(name, "ownership_strength.value")) {
390  target.value = atoi(value);
391  matched = true;
392  }
393  return matched;
394 }
395 
397  DDS::TimeBasedFilterQosPolicy& target, const char* name, const char* value)
398 {
399  return set_duration_qos_value(
400  target.minimum_separation, "time_based_filter.minimum_separation", name, value);
401 }
402 
404  DDS::ReaderDataLifecycleQosPolicy& target, const char* name, const char* value)
405 {
406  return set_duration_qos_value(
408  "reader_data_lifecycle.autopurge_nowriter_samples_delay", name, value);
409 }
410 
412  DDS::ReaderDataLifecycleQosPolicy& target, const char* name, const char* value)
413 {
414  return set_duration_qos_value(
416  "reader_data_lifecycle.autopurge_disposed_samples_delay", name, value);
417 }
418 
419 void
420 log_parser_error(const char* section, const char* name, const char* value)
421 {
422  ACE_ERROR((LM_ERROR, "Could not set %C QOS setting %C to value %C\n",
423  section, name, value));
424 }
425 
427  DDS::PublisherQos& target, const char* name, const char* value)
428 {
429  bool matched =
430  set_presentation_access_scope_qos(target.presentation, name, value) ||
431  set_presentation_coherent_access_qos(target.presentation, name, value) ||
432  set_presentation_ordered_access_qos(target.presentation, name, value) ||
433  set_partition_name_qos(target.partition, name, value);
434  // group data not settable
435  // entity factory not settable
436 
437  if (!matched) {
438  log_parser_error("publisher", name, value);
439  }
440  return matched ? 0 : 1;
441 }
442 
444  DDS::SubscriberQos& target, const char* name, const char* value)
445 {
446  bool matched =
447  set_presentation_access_scope_qos(target.presentation, name, value) ||
448  set_presentation_coherent_access_qos(target.presentation, name, value) ||
449  set_presentation_ordered_access_qos(target.presentation, name, value) ||
450  set_partition_name_qos(target.partition, name, value);
451  // group data not settable
452  // entity factory not settable
453  if (!matched) {
454  log_parser_error("subscriber", name, value);
455  }
456  return matched ? 0 : 1;
457 }
458 
460  DDS::DataWriterQos& target, const char* name, const char* value)
461 {
462  bool matched =
463  set_durability_kind_qos(target.durability, name, value) ||
464  // durability service not settable - not supporting those durabilities
465  set_deadline_period_qos(target.deadline, name, value) ||
466  set_latency_budget_duration_qos(target.latency_budget, name, value) ||
467  set_liveliness_kind_qos(target.liveliness, name, value) ||
468  set_liveliness_lease_duration_qos(target.liveliness, name, value) ||
469  set_reliability_kind_qos(target.reliability, name, value) ||
470  set_reliability_max_blocking_time_qos(target.reliability, name, value) ||
471  set_destination_order_kind_qos(target.destination_order, name, value) ||
472  set_history_kind_qos(target.history, name, value) ||
473  set_history_depth_qos(target.history, name, value) ||
477  set_transport_priority_qos(target.transport_priority, name, value) ||
478  set_lifespan_duration_qos(target.lifespan, name, value) ||
479  // user_data not settable - can't be retrieved
480  set_ownership_kind_qos(target.ownership, name, value) ||
482  // writer_data_lifecycle not settable - no interface to dispose
483 
484  if (!matched) {
485  log_parser_error("data writer", name, value);
486  }
487  return matched ? 0 : 1;
488 }
489 
491  DDS::DataReaderQos& target, const char* name, const char* value)
492 {
493  bool matched =
494  set_durability_kind_qos(target.durability, name, value) ||
495  // durability service not settable
496  set_deadline_period_qos(target.deadline, name, value) ||
497  set_latency_budget_duration_qos(target.latency_budget, name, value) ||
498  set_liveliness_kind_qos(target.liveliness, name, value) ||
499  set_liveliness_lease_duration_qos(target.liveliness, name, value) ||
500  set_reliability_kind_qos(target.reliability, name, value) ||
501  set_reliability_max_blocking_time_qos(target.reliability, name, value) ||
502  set_destination_order_kind_qos(target.destination_order, name, value) ||
503  set_history_kind_qos(target.history, name, value) ||
504  set_history_depth_qos(target.history, name, value) ||
507  target.resource_limits, name, value) ||
509  target.resource_limits, name, value) ||
510  set_ownership_kind_qos(target.ownership, name, value) ||
512  target.time_based_filter, name, value) ||
514  target.reader_data_lifecycle, name, value) ||
516  target.reader_data_lifecycle, name, value);
517 
518  if (!matched) {
519  log_parser_error("data reader", name, value);
520  }
521  return matched ? 0 : 1;
522 }
523 
524 } } }
525 
bool set_resource_limits_max_samples_qos(DDS::ResourceLimitsQosPolicy &target, const char *name, const char *value)
bool set_latency_budget_duration_qos(DDS::LatencyBudgetQosPolicy &target, const char *name, const char *value)
PartitionQosPolicy partition
HistoryQosPolicy history
#define ACE_ERROR(X)
bool set_presentation_ordered_access_qos(DDS::PresentationQosPolicy &target, const char *name, const char *value)
const LogLevel::Value value
Definition: debug.cpp:61
bool set_presentation_access_scope_qos(DDS::PresentationQosPolicy &target, const char *name, const char *value)
Definition: QosSettings.cpp:65
ReliabilityQosPolicy reliability
bool set_reader_data_lifecycle_autopurge_disposed_samples_delay(DDS::ReaderDataLifecycleQosPolicy &target, const char *name, const char *value)
bool set_resource_limits_max_instances_qos(DDS::ResourceLimitsQosPolicy &target, const char *name, const char *value)
OwnershipQosPolicy ownership
const long DURATION_INFINITE_SEC
Definition: DdsDcpsCore.idl:72
DurabilityQosPolicy durability
HistoryQosPolicyKind kind
bool set_time_based_filter_minimum_separation(DDS::TimeBasedFilterQosPolicy &target, const char *name, const char *value)
TimeBasedFilterQosPolicy time_based_filter
bool set_liveliness_lease_duration_qos(DDS::LivelinessQosPolicy &target, const char *name, const char *value)
bool set_history_kind_qos(DDS::HistoryQosPolicy &target, const char *name, const char *value)
PresentationQosPolicyAccessScopeKind access_scope
bool set_reader_data_lifecycle_autopurge_nowriter_samples_delay(DDS::ReaderDataLifecycleQosPolicy &target, const char *name, const char *value)
OwnershipQosPolicy ownership
bool set_liveliness_kind_qos(DDS::LivelinessQosPolicy &target, const char *name, const char *value)
LivelinessQosPolicy liveliness
DeadlineQosPolicy deadline
int set_qos(QosLevel level, const char *name, const char *value)
Definition: QosSettings.cpp:44
OwnershipQosPolicyKind kind
DestinationOrderQosPolicy destination_order
bool set_lifespan_duration_qos(DDS::LifespanQosPolicy &target, const char *name, const char *value)
DestinationOrderQosPolicyKind kind
LatencyBudgetQosPolicy latency_budget
#define OPENDDS_STRING
bool set_ownership_kind_qos(DDS::OwnershipQosPolicy &target, const char *name, const char *value)
PresentationQosPolicy presentation
void apply_to(DDS::PublisherQos &target) const
Definition: QosSettings.cpp:20
bool set_durability_kind_qos(DDS::DurabilityQosPolicy &target, const char *name, const char *value)
ReliabilityQosPolicyKind kind
DurabilityQosPolicyKind kind
DurabilityQosPolicy durability
unsigned long nanosec
Definition: DdsDcpsCore.idl:69
OwnershipStrengthQosPolicy ownership_strength
bool set_ownership_strength_value_qos(DDS::OwnershipStrengthQosPolicy &target, const char *name, const char *value)
DestinationOrderQosPolicy destination_order
bool set_partition_name_qos(DDS::PartitionQosPolicy &target, const char *name, const char *value)
bool set_history_depth_qos(DDS::HistoryQosPolicy &target, const char *name, const char *value)
ResourceLimitsQosPolicy resource_limits
bool set_reliability_kind_qos(DDS::ReliabilityQosPolicy &target, const char *name, const char *value)
const char *const name
Definition: debug.cpp:60
ReaderDataLifecycleQosPolicy reader_data_lifecycle
int atoi(const char *s)
bool set_resource_limits_max_samples_per_instance_qos(DDS::ResourceLimitsQosPolicy &target, const char *name, const char *value)
HistoryQosPolicy history
const unsigned long DURATION_INFINITE_NSEC
Definition: DdsDcpsCore.idl:73
TransportPriorityQosPolicy transport_priority
bool set_presentation_coherent_access_qos(DDS::PresentationQosPolicy &target, const char *name, const char *value)
ReliabilityQosPolicy reliability
#define OPENDDS_END_VERSIONED_NAMESPACE_DECL
LifespanQosPolicy lifespan
void log_parser_error(const char *section, const char *name, const char *value)
LivelinessQosPolicyKind kind
LivelinessQosPolicy liveliness
DeadlineQosPolicy deadline
#define TheServiceParticipant
bool set_deadline_period_qos(DDS::DeadlineQosPolicy &target, const char *name, const char *value)
LM_ERROR
PartitionQosPolicy partition
bool set_duration_qos_value(DDS::Duration_t &target, const char *prefix_match, const char *name, const char *value)
The Internal API and Implementation of OpenDDS.
Definition: AddressCache.h:28
PresentationQosPolicy presentation
bool set_transport_priority_qos(DDS::TransportPriorityQosPolicy &target, const char *name, const char *value)
bool set_reliability_max_blocking_time_qos(DDS::ReliabilityQosPolicy &target, const char *name, const char *value)
ResourceLimitsQosPolicy resource_limits
bool set_destination_order_kind_qos(DDS::DestinationOrderQosPolicy &target, const char *name, const char *value)
bool set_bool_qos_value(bool &target, const char *value)
Definition: QosSettings.cpp:90
LatencyBudgetQosPolicy latency_budget