00001 #include "QosSettings.h"
00002 #include "dds/DCPS/Service_Participant.h"
00003
00004 #include <cstring>
00005
00006 namespace OpenDDS { namespace FaceTSS { namespace config {
00007
00008 QosSettings::QosSettings() :
00009 publisher_qos_(TheServiceParticipant->initial_PublisherQos())
00010 , subscriber_qos_(TheServiceParticipant->initial_SubscriberQos())
00011 , datawriter_qos_(TheServiceParticipant->initial_DataWriterQos())
00012 , datareader_qos_(TheServiceParticipant->initial_DataReaderQos())
00013 {
00014
00015 }
00016
00017 void
00018 QosSettings::apply_to(DDS::PublisherQos& target) const
00019 {
00020 target = publisher_qos_;
00021 }
00022
00023 void
00024 QosSettings::apply_to(DDS::SubscriberQos& target) const
00025 {
00026 target = subscriber_qos_;
00027 }
00028
00029 void
00030 QosSettings::apply_to(DDS::DataWriterQos& target) const
00031 {
00032 target = datawriter_qos_;
00033 }
00034
00035 void
00036 QosSettings::apply_to(DDS::DataReaderQos& target) const
00037 {
00038 target = datareader_qos_;
00039 }
00040
00041 int
00042 QosSettings::set_qos(QosLevel level, const char* name, const char* value)
00043 {
00044 int status = 0;
00045 switch (level) {
00046 case publisher:
00047 status = set_qos(publisher_qos_, name, value);
00048 break;
00049 case subscriber:
00050 status = set_qos(subscriber_qos_, name, value);
00051 break;
00052 case datawriter:
00053 status = set_qos(datawriter_qos_, name, value);
00054 break;
00055 case datareader:
00056 status = set_qos(datareader_qos_, name, value);
00057 break;
00058 }
00059 return status;
00060 }
00061
00062 bool
00063 set_presentation_access_scope_qos(
00064 DDS::PresentationQosPolicy& target,
00065 const char* name,
00066 const char* value)
00067 {
00068 bool matched = false;
00069 if (!std::strcmp(name, "presentation.access_scope")) {
00070 if (!std::strcmp(value, "INSTANCE")) {
00071 target.access_scope = DDS::INSTANCE_PRESENTATION_QOS;
00072 matched = true;
00073 }
00074 if (!std::strcmp(value, "TOPIC")) {
00075 target.access_scope = DDS::TOPIC_PRESENTATION_QOS;
00076 matched = true;
00077 }
00078 if (!std::strcmp(value, "GROUP")) {
00079 target.access_scope = DDS::GROUP_PRESENTATION_QOS;
00080 matched = true;
00081 }
00082 }
00083 return matched;
00084 }
00085
00086
00087 bool
00088 set_bool_qos_value(bool& target, const char* value)
00089 {
00090 bool matched = false;
00091 if (!std::strcmp(value, "true")) {
00092 target = true;
00093 matched = true;
00094 } else if (!std::strcmp(value, "false")) {
00095 target = false;
00096 matched = true;
00097 }
00098 return matched;
00099 }
00100
00101
00102 bool
00103 set_duration_qos_value(DDS::Duration_t& target,
00104 const char* prefix_match,
00105 const char* name,
00106 const char* value)
00107 {
00108 char buffer[64];
00109 std::strncpy(buffer, prefix_match, 64 - 4);
00110 std::strcat(buffer, ".sec");
00111 if (!std::strcmp(name, buffer)) {
00112 if (!std::strcmp(value, "DURATION_INFINITE_SEC")) {
00113 target.sec=DDS::DURATION_INFINITE_SEC;
00114 return true;
00115 }
00116 target.sec = atoi(value);
00117 return true;
00118 }
00119 std::strncpy(buffer, prefix_match, 64 - 7);
00120 std::strcat(buffer, ".nanosec");
00121 if (!std::strcmp(name, buffer)) {
00122 if (!std::strcmp(value, "DURATION_INFINITE_NSEC")) {
00123 target.nanosec=DDS::DURATION_INFINITE_NSEC;
00124 return true;
00125 }
00126 target.nanosec = atoi(value);
00127 return true;
00128 }
00129 return false;
00130 }
00131
00132 bool
00133 set_presentation_coherent_access_qos(
00134 DDS::PresentationQosPolicy& target,
00135 const char* name,
00136 const char* value)
00137 {
00138 bool matched = false;
00139 if (!std::strcmp(name, "presentation.coherent_access")) {
00140 matched = set_bool_qos_value(target.coherent_access, value);
00141 }
00142 return matched;
00143 }
00144
00145 bool
00146 set_presentation_ordered_access_qos(
00147 DDS::PresentationQosPolicy& target,
00148 const char* name,
00149 const char* value)
00150 {
00151 bool matched = false;
00152 if (!std::strcmp(name, "presentation.ordered_access")) {
00153 matched = set_bool_qos_value(target.ordered_access, value);
00154 }
00155 return matched;
00156 }
00157
00158 bool
00159 set_partition_name_qos(
00160 DDS::PartitionQosPolicy& target, const char* name, const char* value)
00161 {
00162 bool matched = false;
00163 if (!std::strcmp(name, "partition.name")) {
00164
00165 const char* start = value;
00166 char buffer[128];
00167 std::memset(buffer, 0, sizeof(buffer));
00168 while (const char* next_comma = std::strchr(start, ',')) {
00169
00170 std::strncpy(buffer, start, next_comma - start);
00171
00172 buffer[next_comma - start] = '\0';
00173
00174 target.name.length(target.name.length() + 1);
00175 target.name[target.name.length() - 1] = static_cast<const char*>(buffer);
00176
00177 start = next_comma + 1;
00178 }
00179
00180 target.name.length(target.name.length() + 1);
00181 target.name[target.name.length() - 1] = start;
00182
00183 matched = true;
00184 }
00185 return matched;
00186 }
00187
00188 bool
00189 set_durability_kind_qos(
00190 DDS::DurabilityQosPolicy& target, const char* name, const char* value)
00191 {
00192 bool matched = false;
00193 if (!std::strcmp(name, "durability.kind")) {
00194 if (!std::strcmp(value, "VOLATILE")) {
00195 target.kind = DDS::VOLATILE_DURABILITY_QOS;
00196 matched = true;
00197 } else if (!std::strcmp(value, "TRANSIENT_LOCAL")) {
00198 target.kind = DDS::TRANSIENT_LOCAL_DURABILITY_QOS;
00199 matched = true;
00200 #ifndef OPENDDS_NO_PERSISTENCE_PROFILE
00201 } else if (!std::strcmp(value, "TRANSIENT")) {
00202 target.kind = DDS::TRANSIENT_DURABILITY_QOS;
00203 matched = true;
00204 } else if (!std::strcmp(value, "PERSISTENT")) {
00205 target.kind = DDS::PERSISTENT_DURABILITY_QOS;
00206 matched = true;
00207 #endif
00208 }
00209 }
00210 return matched;
00211 }
00212
00213 bool
00214 set_deadline_period_qos(
00215 DDS::DeadlineQosPolicy& target, const char* name, const char* value)
00216 {
00217 return set_duration_qos_value(target.period, "deadline.period", name, value);
00218 }
00219
00220 bool
00221 set_latency_budget_duration_qos(
00222 DDS::LatencyBudgetQosPolicy& target, const char* name, const char* value)
00223 {
00224 return set_duration_qos_value(
00225 target.duration, "latency_budget.duration", name, value);
00226 }
00227
00228 bool set_liveliness_kind_qos(
00229 DDS::LivelinessQosPolicy& target, const char* name, const char* value)
00230 {
00231 bool matched = false;
00232 if (!std::strcmp(name, "liveliness.kind")) {
00233 if (!std::strcmp(value, "AUTOMATIC")) {
00234 target.kind = DDS::AUTOMATIC_LIVELINESS_QOS;
00235 matched = true;
00236 } else if (!std::strcmp(value, "MANUAL_BY_TOPIC")) {
00237 target.kind = DDS::MANUAL_BY_TOPIC_LIVELINESS_QOS;
00238 matched = true;
00239 } else if (!std::strcmp(value, "MANUAL_BY_PARTICIPANT")) {
00240 target.kind = DDS::MANUAL_BY_PARTICIPANT_LIVELINESS_QOS;
00241 matched = true;
00242 }
00243 }
00244 return matched;
00245 }
00246
00247 bool set_liveliness_lease_duration_qos(
00248 DDS::LivelinessQosPolicy& target, const char* name, const char* value)
00249 {
00250 return set_duration_qos_value(
00251 target.lease_duration, "liveliness.lease_duration", name, value);
00252 }
00253
00254 bool set_reliability_kind_qos(
00255 DDS::ReliabilityQosPolicy& target, const char* name, const char* value)
00256 {
00257 bool matched = false;
00258 if (!std::strcmp(name, "reliability.kind")) {
00259 if (!std::strcmp(value, "BEST_EFFORT")) {
00260 target.kind = DDS::BEST_EFFORT_RELIABILITY_QOS;
00261 matched = true;
00262 } else if (!std::strcmp(value, "RELIABLE")) {
00263 target.kind = DDS::RELIABLE_RELIABILITY_QOS;
00264 matched = true;
00265 }
00266 }
00267 return matched;
00268 }
00269
00270 bool set_reliability_max_blocking_time_qos(
00271 DDS::ReliabilityQosPolicy& target, const char* name, const char* value)
00272 {
00273 return set_duration_qos_value(
00274 target.max_blocking_time, "reliability.max_blocking_time", name, value);
00275 }
00276
00277 bool set_destination_order_kind_qos(
00278 DDS::DestinationOrderQosPolicy& target, const char* name, const char* value)
00279 {
00280 bool matched = false;
00281 if (!std::strcmp(name, "destination_order.kind")) {
00282 if (!std::strcmp(value, "BY_RECEPTION_TIMESTAMP")) {
00283 target.kind = DDS::BY_RECEPTION_TIMESTAMP_DESTINATIONORDER_QOS;
00284 matched = true;
00285 } else if (!std::strcmp(value, "BY_SOURCE_TIMESTAMP")) {
00286 target.kind = DDS::BY_SOURCE_TIMESTAMP_DESTINATIONORDER_QOS;
00287 matched = true;
00288 }
00289 }
00290 return matched;
00291 }
00292
00293 bool set_history_kind_qos(
00294 DDS::HistoryQosPolicy& target, const char* name, const char* value)
00295 {
00296 bool matched = false;
00297 if (!std::strcmp(name, "history.kind")) {
00298 if (!std::strcmp(value, "KEEP_ALL")) {
00299 target.kind = DDS::KEEP_ALL_HISTORY_QOS;
00300 matched = true;
00301 } else if (!std::strcmp(value, "KEEP_LAST")) {
00302 target.kind = DDS::KEEP_LAST_HISTORY_QOS;
00303 matched = true;
00304 }
00305 }
00306 return matched;
00307 }
00308
00309 bool set_history_depth_qos(
00310 DDS::HistoryQosPolicy& target, const char* name, const char* value)
00311 {
00312 bool matched = false;
00313 if (!std::strcmp(name, "history.depth")) {
00314 target.depth = atoi(value);
00315 matched = true;
00316 }
00317 return matched;
00318 }
00319
00320 bool set_resource_limits_max_samples_qos(
00321 DDS::ResourceLimitsQosPolicy& target, const char* name, const char* value)
00322 {
00323 bool matched = false;
00324 if (!std::strcmp(name, "resource_limits.max_samples")) {
00325 target.max_samples = atoi(value);
00326 matched = true;
00327 }
00328 return matched;
00329 }
00330
00331 bool set_resource_limits_max_instances_qos(
00332 DDS::ResourceLimitsQosPolicy& target, const char* name, const char* value)
00333 {
00334 bool matched = false;
00335 if (!std::strcmp(name, "resource_limits.max_instances")) {
00336 target.max_instances = atoi(value);
00337 matched = true;
00338 }
00339 return matched;
00340 }
00341
00342 bool set_resource_limits_max_samples_per_instance_qos(
00343 DDS::ResourceLimitsQosPolicy& target, const char* name, const char* value)
00344 {
00345 bool matched = false;
00346 if (!std::strcmp(name, "resource_limits.max_samples_per_instance")) {
00347 target.max_samples_per_instance = atoi(value);
00348 matched = true;
00349 }
00350 return matched;
00351 }
00352
00353 bool set_transport_priority_qos(
00354 DDS::TransportPriorityQosPolicy& target, const char* name, const char* value)
00355 {
00356 bool matched = false;
00357 if (!std::strcmp(name, "transport_priority.value")) {
00358 target.value = atoi(value);
00359 matched = true;
00360 }
00361 return matched;
00362 }
00363
00364 bool set_lifespan_duration_qos(
00365 DDS::LifespanQosPolicy& target, const char* name, const char* value)
00366 {
00367 return set_duration_qos_value(
00368 target.duration, "lifespan.duration", name, value);
00369 }
00370
00371 bool set_ownership_kind_qos(
00372 DDS::OwnershipQosPolicy& target, const char* name, const char* value)
00373 {
00374 bool matched = false;
00375 if (!std::strcmp(name, "ownership.kind")) {
00376 if (!std::strcmp(value, "SHARED")) {
00377 target.kind = DDS::SHARED_OWNERSHIP_QOS;
00378 matched = true;
00379 } else if (!std::strcmp(value, "EXCLUSIVE")) {
00380 target.kind = DDS::EXCLUSIVE_OWNERSHIP_QOS;
00381 matched = true;
00382 }
00383 }
00384 return matched;
00385 }
00386
00387 bool set_ownership_strength_value_qos(
00388 DDS::OwnershipStrengthQosPolicy& target, const char* name, const char* value)
00389 {
00390 bool matched = false;
00391 if (!std::strcmp(name, "ownership_strength.value")) {
00392 target.value = atoi(value);
00393 matched = true;
00394 }
00395 return matched;
00396 }
00397
00398 bool set_time_based_filter_minimum_separation(
00399 DDS::TimeBasedFilterQosPolicy& target, const char* name, const char* value)
00400 {
00401 return set_duration_qos_value(
00402 target.minimum_separation, "time_based_filter.minimum_separation", name, value);
00403 }
00404
00405 bool set_reader_data_lifecycle_autopurge_nowriter_samples_delay(
00406 DDS::ReaderDataLifecycleQosPolicy& target, const char* name, const char* value)
00407 {
00408 return set_duration_qos_value(
00409 target.autopurge_nowriter_samples_delay,
00410 "reader_data_lifecycle.autopurge_nowriter_samples_delay", name, value);
00411 }
00412
00413 bool set_reader_data_lifecycle_autopurge_disposed_samples_delay(
00414 DDS::ReaderDataLifecycleQosPolicy& target, const char* name, const char* value)
00415 {
00416 return set_duration_qos_value(
00417 target.autopurge_disposed_samples_delay,
00418 "reader_data_lifecycle.autopurge_disposed_samples_delay", name, value);
00419 }
00420
00421 void
00422 log_parser_error(const char* section, const char* name, const char* value)
00423 {
00424 ACE_DEBUG((LM_ERROR, "Could not set %s QOS setting %s to value %s\n",
00425 section, name, value));
00426 }
00427
00428 int QosSettings::set_qos(
00429 DDS::PublisherQos& target, const char* name, const char* value)
00430 {
00431 bool matched =
00432 set_presentation_access_scope_qos(target.presentation, name, value) ||
00433 set_presentation_coherent_access_qos(target.presentation, name, value) ||
00434 set_presentation_ordered_access_qos(target.presentation, name, value) ||
00435 set_partition_name_qos(target.partition, name, value);
00436
00437
00438
00439 if (!matched) {
00440 log_parser_error("publisher", name, value);
00441 }
00442 return matched ? 0 : 1;
00443 }
00444
00445 int QosSettings::set_qos(
00446 DDS::SubscriberQos& target, const char* name, const char* value)
00447 {
00448 bool matched =
00449 set_presentation_access_scope_qos(target.presentation, name, value) ||
00450 set_presentation_coherent_access_qos(target.presentation, name, value) ||
00451 set_presentation_ordered_access_qos(target.presentation, name, value) ||
00452 set_partition_name_qos(target.partition, name, value);
00453
00454
00455 if (!matched) {
00456 log_parser_error("subscriber", name, value);
00457 }
00458 return matched ? 0 : 1;
00459 }
00460
00461 int QosSettings::set_qos(
00462 DDS::DataWriterQos& target, const char* name, const char* value)
00463 {
00464 bool matched =
00465 set_durability_kind_qos(target.durability, name, value) ||
00466
00467 set_deadline_period_qos(target.deadline, name, value) ||
00468 set_latency_budget_duration_qos(target.latency_budget, name, value) ||
00469 set_liveliness_kind_qos(target.liveliness, name, value) ||
00470 set_liveliness_lease_duration_qos(target.liveliness, name, value) ||
00471 set_reliability_kind_qos(target.reliability, name, value) ||
00472 set_reliability_max_blocking_time_qos(target.reliability, name, value) ||
00473 set_destination_order_kind_qos(target.destination_order, name, value) ||
00474 set_history_kind_qos(target.history, name, value) ||
00475 set_history_depth_qos(target.history, name, value) ||
00476 set_resource_limits_max_samples_qos(target.resource_limits, name, value) ||
00477 set_resource_limits_max_instances_qos(target.resource_limits, name, value) ||
00478 set_resource_limits_max_samples_per_instance_qos(target.resource_limits, name, value) ||
00479 set_transport_priority_qos(target.transport_priority, name, value) ||
00480 set_lifespan_duration_qos(target.lifespan, name, value) ||
00481
00482 set_ownership_kind_qos(target.ownership, name, value) ||
00483 set_ownership_strength_value_qos(target.ownership_strength, name, value);
00484
00485
00486 if (!matched) {
00487 log_parser_error("data writer", name, value);
00488 }
00489 return matched ? 0 : 1;
00490 }
00491
00492 int QosSettings::set_qos(
00493 DDS::DataReaderQos& target, const char* name, const char* value)
00494 {
00495 bool matched =
00496 set_durability_kind_qos(target.durability, name, value) ||
00497
00498 set_deadline_period_qos(target.deadline, name, value) ||
00499 set_latency_budget_duration_qos(target.latency_budget, name, value) ||
00500 set_liveliness_kind_qos(target.liveliness, name, value) ||
00501 set_liveliness_lease_duration_qos(target.liveliness, name, value) ||
00502 set_reliability_kind_qos(target.reliability, name, value) ||
00503 set_reliability_max_blocking_time_qos(target.reliability, name, value) ||
00504 set_destination_order_kind_qos(target.destination_order, name, value) ||
00505 set_history_kind_qos(target.history, name, value) ||
00506 set_history_depth_qos(target.history, name, value) ||
00507 set_resource_limits_max_samples_qos(target.resource_limits, name, value) ||
00508 set_resource_limits_max_instances_qos(
00509 target.resource_limits, name, value) ||
00510 set_resource_limits_max_samples_per_instance_qos(
00511 target.resource_limits, name, value) ||
00512 set_ownership_kind_qos(target.ownership, name, value) ||
00513 set_time_based_filter_minimum_separation(
00514 target.time_based_filter, name, value) ||
00515 set_reader_data_lifecycle_autopurge_nowriter_samples_delay(
00516 target.reader_data_lifecycle, name, value) ||
00517 set_reader_data_lifecycle_autopurge_disposed_samples_delay(
00518 target.reader_data_lifecycle, name, value);
00519
00520 if (!matched) {
00521 log_parser_error("data reader", name, value);
00522 }
00523 return matched ? 0 : 1;
00524 }
00525
00526 } } }
00527