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