OpenDDS  Snapshot(2023/04/28-20:55)
ConnectionSettings.cpp
Go to the documentation of this file.
1 #include "ConnectionSettings.h"
2 
3 #include "ace/OS_NS_stdio.h"
4 #include "ace/Log_Priority.h"
5 #include "ace/Log_Msg.h"
6 
7 #include <cstring>
8 
10 
11 namespace OpenDDS { namespace FaceTSS { namespace config {
12 
14 : connection_id_(0),
15  direction_(FACE::SOURCE),
16  domain_id_(0),
17  participant_id_(0)
18 {
19  std::strcpy(topic_name_, "");
20  std::strcpy(datawriter_qos_name_, "");
21  std::strcpy(datareader_qos_name_, "");
22  std::strcpy(publisher_qos_name_, "");
23  std::strcpy(subscriber_qos_name_, "");
24  std::strcpy(config_name_, "");
25 }
26 
27 int
28 ConnectionSettings::set(const char* name, const char* value)
29 {
30  int status = 0;
31  if (!std::strcmp(name, "id")) {
32  connection_id_ = atoi(value);
33  } else if (!std::strcmp(name, "participantid")) {
34  participant_id_ = atoi(value);
35  } else if (!std::strcmp(name, "domain")) {
36  domain_id_ = atoi(value);
37  } else if (!std::strcmp(name, "topic")) {
38  if (std::strlen(value) >= ALLOWABLE_NAME_LEN) {
39  ACE_ERROR((LM_ERROR, ACE_TEXT("topic name %C exceeds allowable length,"
40  "must be < %B\n"), value, ALLOWABLE_NAME_LEN));
41  status = 1;
42  } else {
43  std::strncpy(topic_name_, value, sizeof(topic_name_));
44  }
45  } else if (!std::strcmp(name, "datawriterqos")) {
46  if (std::strlen(value) >= ALLOWABLE_NAME_LEN) {
47  ACE_ERROR((LM_ERROR, ACE_TEXT("datawriterqos name %C exceeds allowable length,"
48  "must be < %B\n"), value, ALLOWABLE_NAME_LEN));
49  status = 1;
50  } else {
51  std::strncpy(datawriter_qos_name_, value, sizeof(datawriter_qos_name_));
52  }
53  } else if (!std::strcmp(name, "datareaderqos")) {
54  if (std::strlen(value) >= ALLOWABLE_NAME_LEN) {
55  ACE_ERROR((LM_ERROR, ACE_TEXT("datareaderqos name %C exceeds allowable length,"
56  "must be < %B\n"), value, ALLOWABLE_NAME_LEN));
57  status = 1;
58  } else {
59  std::strncpy(datareader_qos_name_, value, sizeof(datareader_qos_name_));
60  }
61  } else if (!std::strcmp(name, "publisherqos")) {
62  if (std::strlen(value) >= ALLOWABLE_NAME_LEN) {
63  ACE_ERROR((LM_ERROR, ACE_TEXT("publisherqos name %C exceeds allowable length,"
64  "must be < %B\n"), value, ALLOWABLE_NAME_LEN));
65  status = 1;
66  } else {
67  std::strncpy(publisher_qos_name_, value, sizeof(publisher_qos_name_));
68  }
69  } else if (!std::strcmp(name, "subscriberqos")) {
70  if (std::strlen(value) >= ALLOWABLE_NAME_LEN) {
71  ACE_ERROR((LM_ERROR, ACE_TEXT("subscriberqos name %C exceeds allowable length,"
72  "must be < %B\n"), value, ALLOWABLE_NAME_LEN));
73  status = 1;
74  } else {
75  std::strncpy(subscriber_qos_name_, value, sizeof(subscriber_qos_name_));
76  }
77  } else if (!std::strcmp(name, "direction")) {
78  if (!std::strcmp(value, "source") ||
79  !std::strcmp(value, "one_way_request_source") ||
80  !std::strcmp(value, "two_way_request_synchronous_source") ||
81  !std::strcmp(value, "two_way_request_reply_asynchronous_source")) {
82  direction_ = FACE::SOURCE;
83  } else if (!std::strcmp(value, "destination") ||
84  !std::strcmp(value, "one_way_request_destination") ||
85  !std::strcmp(value, "two_way_request_synchronous_destination") ||
86  !std::strcmp(value, "two_way_request_reply_asynchronous_destination")) {
87  direction_ = FACE::DESTINATION;
88  } else if (!std::strcmp(value, "bi_directional") ||
89  !std::strcmp(value, "not_defined_connection_direction_type")) {
90  ACE_ERROR((LM_ERROR, ACE_TEXT("Direction not supported: %C\n"), value));
91  status = 1;
92  } else {
93  ACE_ERROR((LM_ERROR, ACE_TEXT("Don't know of direction %C\n"), value));
94  status = 1;
95  }
96  } else if (!std::strcmp(name, "config")) {
97  // Guarantee that value will fit in config_name_ and still be null terminated
98  // config_name_ is sized to ALLOWABLE_NAME_LEN
99  if (std::strlen(value) >= sizeof(config_name_)) {
100  ACE_ERROR((LM_ERROR, ACE_TEXT("config name %C exceeds allowable length,"
101  "must be < %B\n"), value, ALLOWABLE_NAME_LEN));
102  status = 1;
103  } else {
104  std::strncpy(config_name_, value, sizeof(config_name_));
105  }
106  } else {
107  // no match
108  ACE_ERROR((LM_ERROR, ACE_TEXT("Don't know of setting %C\n"), name));
109  status = 1;
110  }
111 
112  return status;
113 }
114 
115 const char*
117 {
118  return datawriter_qos_name_;
119 }
120 
121 const char*
123 {
124  return datareader_qos_name_;
125 }
126 
127 const char*
129 {
130  return publisher_qos_name_;
131 }
132 
133 const char*
135 {
136  return subscriber_qos_name_;
137 }
138 
139 const char*
141 {
142  return config_name_;
143 }
144 
145 bool
147 {
148  return datawriter_qos_name_[0];
149 }
150 
151 bool
153 {
154  return datareader_qos_name_[0];
155 }
156 
157 bool
159 {
160  return publisher_qos_name_[0];
161 }
162 
163 bool
165 {
166  return subscriber_qos_name_[0];
167 }
168 
169 bool
171 {
172  return config_name_[0];
173 }
174 
175 } } }
176 
177 
#define ACE_ERROR(X)
const LogLevel::Value value
Definition: debug.cpp:61
FACE::CONNECTION_DIRECTION_TYPE direction_
const char *const name
Definition: debug.cpp:60
ACE_TEXT("TCP_Factory")
int atoi(const char *s)
#define OPENDDS_END_VERSIONED_NAMESPACE_DECL
LM_ERROR
The Internal API and Implementation of OpenDDS.
Definition: AddressCache.h:28
int set(const char *name, const char *value)
Definition: FaceTSS.cpp:24