ConnectionSettings.cpp

Go to the documentation of this file.
00001 #include "ConnectionSettings.h"
00002 
00003 #include "ace/OS_NS_stdio.h"
00004 #include "ace/Log_Priority.h"
00005 #include "ace/Log_Msg.h"
00006 
00007 #include <cstring>
00008 
00009 OPENDDS_BEGIN_VERSIONED_NAMESPACE_DECL
00010 
00011 namespace OpenDDS { namespace FaceTSS { namespace config {
00012 
00013 ConnectionSettings::ConnectionSettings()
00014 : connection_id_(0),
00015   direction_(FACE::SOURCE),
00016   domain_id_(0),
00017   participant_id_(0)
00018 {
00019   std::strcpy(topic_name_, "");
00020   std::strcpy(datawriter_qos_name_, "");
00021   std::strcpy(datareader_qos_name_, "");
00022   std::strcpy(publisher_qos_name_, "");
00023   std::strcpy(subscriber_qos_name_, "");
00024   std::strcpy(config_name_, "");
00025 }
00026 
00027 int
00028 ConnectionSettings::set(const char* name, const char* value)
00029 {
00030   int status = 0;
00031   if (!std::strcmp(name, "id")) {
00032     connection_id_ = atoi(value);
00033   } else if (!std::strcmp(name, "participantid")) {
00034     participant_id_ = atoi(value);
00035   } else if (!std::strcmp(name, "domain")) {
00036     domain_id_ = atoi(value);
00037   } else if (!std::strcmp(name, "topic")) {
00038     if (std::strlen(value) >= ALLOWABLE_NAME_LEN) {
00039       ACE_ERROR((LM_ERROR, ACE_TEXT("topic name %C exceeds allowable length,"
00040         "must be < %B \n"), value, ALLOWABLE_NAME_LEN));
00041       status = 1;
00042     } else {
00043       std::strncpy(topic_name_, value, sizeof(topic_name_));
00044     }
00045   } else if (!std::strcmp(name, "datawriterqos")) {
00046     if (std::strlen(value) >= ALLOWABLE_NAME_LEN) {
00047       ACE_ERROR((LM_ERROR, ACE_TEXT("datawriterqos name %C exceeds allowable length,"
00048         "must be < %B \n"), value, ALLOWABLE_NAME_LEN));
00049       status = 1;
00050     } else {
00051       std::strncpy(datawriter_qos_name_, value, sizeof(datawriter_qos_name_));
00052     }
00053   } else if (!std::strcmp(name, "datareaderqos")) {
00054     if (std::strlen(value) >= ALLOWABLE_NAME_LEN) {
00055       ACE_ERROR((LM_ERROR, ACE_TEXT("datareaderqos name %C exceeds allowable length,"
00056         "must be < %B \n"), value, ALLOWABLE_NAME_LEN));
00057       status = 1;
00058     } else {
00059       std::strncpy(datareader_qos_name_, value, sizeof(datareader_qos_name_));
00060     }
00061   } else if (!std::strcmp(name, "publisherqos")) {
00062     if (std::strlen(value) >= ALLOWABLE_NAME_LEN) {
00063       ACE_ERROR((LM_ERROR, ACE_TEXT("publisherqos name %C exceeds allowable length,"
00064         "must be < %B \n"), value, ALLOWABLE_NAME_LEN));
00065       status = 1;
00066     } else {
00067       std::strncpy(publisher_qos_name_, value, sizeof(publisher_qos_name_));
00068     }
00069   } else if (!std::strcmp(name, "subscriberqos")) {
00070     if (std::strlen(value) >= ALLOWABLE_NAME_LEN) {
00071       ACE_ERROR((LM_ERROR, ACE_TEXT("subscriberqos name %C exceeds allowable length,"
00072         "must be < %B \n"), value, ALLOWABLE_NAME_LEN));
00073       status = 1;
00074     } else {
00075       std::strncpy(subscriber_qos_name_, value, sizeof(subscriber_qos_name_));
00076     }
00077   } else if (!std::strcmp(name, "direction")) {
00078     if (!std::strcmp(value, "source") ||
00079         !std::strcmp(value, "one_way_request_source") ||
00080         !std::strcmp(value, "two_way_request_synchronous_source") ||
00081         !std::strcmp(value, "two_way_request_reply_asynchronous_source")) {
00082       direction_ = FACE::SOURCE;
00083     } else if (!std::strcmp(value, "destination") ||
00084                !std::strcmp(value, "one_way_request_destination") ||
00085                !std::strcmp(value, "two_way_request_synchronous_destination") ||
00086                !std::strcmp(value, "two_way_request_reply_asynchronous_destination")) {
00087       direction_ = FACE::DESTINATION;
00088     } else if (!std::strcmp(value, "bi_directional") ||
00089                !std::strcmp(value, "not_defined_connection_direction_type")) {
00090       ACE_ERROR((LM_ERROR, ACE_TEXT("Direction not supported: %C\n"), value));
00091       status = 1;
00092     } else {
00093       ACE_ERROR((LM_ERROR, ACE_TEXT("Don't know of direction %C\n"), value));
00094       status = 1;
00095     }
00096   } else if (!std::strcmp(name, "config")) {
00097     // Guarantee that value will fit in config_name_ and still be null terminated
00098     // config_name_ is sized to ALLOWABLE_NAME_LEN
00099     if (std::strlen(value) >= sizeof(config_name_)) {
00100       ACE_ERROR((LM_ERROR, ACE_TEXT("config name %C exceeds allowable length,"
00101         "must be < %B \n"), value, ALLOWABLE_NAME_LEN));
00102       status = 1;
00103     } else {
00104       std::strncpy(config_name_, value, sizeof(config_name_));
00105     }
00106   } else {
00107     // no match
00108     ACE_ERROR((LM_ERROR, ACE_TEXT("Don't know of setting %C\n"), name));
00109     status = 1;
00110   }
00111 
00112   return status;
00113 }
00114 
00115 const char*
00116 ConnectionSettings::datawriter_qos_name() const
00117 {
00118   return datawriter_qos_name_;
00119 }
00120 
00121 const char*
00122 ConnectionSettings::datareader_qos_name() const
00123 {
00124   return datareader_qos_name_;
00125 }
00126 
00127 const char*
00128 ConnectionSettings::publisher_qos_name() const
00129 {
00130   return publisher_qos_name_;
00131 }
00132 
00133 const char*
00134 ConnectionSettings::subscriber_qos_name() const
00135 {
00136   return subscriber_qos_name_;
00137 }
00138 
00139 const char*
00140 ConnectionSettings::config_name() const
00141 {
00142   return config_name_;
00143 }
00144 
00145 bool
00146 ConnectionSettings::datawriter_qos_set() const
00147 {
00148   return datawriter_qos_name_[0];
00149 }
00150 
00151 bool
00152 ConnectionSettings::datareader_qos_set() const
00153 {
00154   return datareader_qos_name_[0];
00155 }
00156 
00157 bool
00158 ConnectionSettings::publisher_qos_set() const
00159 {
00160   return publisher_qos_name_[0];
00161 }
00162 
00163 bool
00164 ConnectionSettings::subscriber_qos_set() const
00165 {
00166   return subscriber_qos_name_[0];
00167 }
00168 
00169 bool
00170 ConnectionSettings::config_set() const
00171 {
00172   return config_name_[0];
00173 }
00174 
00175 } } }
00176 
00177 
00178 OPENDDS_END_VERSIONED_NAMESPACE_DECL
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Defines

Generated on 10 Aug 2018 for OpenDDS by  doxygen 1.6.1