OpenDDS  Snapshot(2023/04/28-20:55)
QOS_XML_Loader.cpp
Go to the documentation of this file.
1 #include "QOS_XML_Loader.h"
2 #include "XML_File_Intf.h"
3 #include "ace/Tokenizer_T.h"
4 #include "dds/DCPS/debug.h"
5 
7 
8 namespace OpenDDS {
9 namespace DCPS {
10 
11  QOS_XML_Loader::QOS_XML_Loader(XML::XML_Error_Handler* error_handler)
12  : xml_file_ (error_handler)
13  {
14  }
15 
17  {
18  }
19 
22  {
23  if (qos_profile)
24  {
25  ACE_TCHAR* buf = ACE_OS::strdup(qos_profile);
27  tok.delimiter_replace('#', 0);
28  const ACE_TCHAR * file_name = tok.next();
29 
30  if (file_name == 0)
31  {
32  ACE_OS::free(buf);
33  if (DCPS_debug_level > 5)
34  {
36  "get_xml_file_name <%s> - "
37  "Error: malformed qos_profile. Expected format: "
38  "<xml_file_base_name>#<profile_name>\n",
39  qos_profile));
40  }
41  return ACE_TString();
42  }
43 
44  ACE_TString ret(file_name);
45  ret += ACE_TEXT(".xml");
46  ACE_OS::free(buf);
47  return ret;
48  }
49 
50  return ACE_TString();
51  }
52 
55  {
56  if (qos_profile)
57  {
58  ACE_TCHAR* buf = ACE_OS::strdup(qos_profile);
60  tok.delimiter_replace('#', 0);
61  const ACE_TCHAR * lib_name = tok.next();
62  const ACE_TCHAR * prof_name = tok.next();
63 
64  if (lib_name == 0 || prof_name == 0 || tok.next() != 0)
65  {
66  ACE_OS::free(buf);
67  if (DCPS_debug_level > 5)
68  {
70  "get_profile_name <%s> - "
71  "Error: malformed qos_profile. Expected format: "
72  "<xml_file_base_name>#<profile_name>\n",
73  qos_profile));
74  }
75  return ACE_TString();
76  }
77 
78  ACE_TString ret(prof_name);
79  ACE_OS::free(buf);
80  return ret;
81  }
82 
83  return ACE_TString();
84  }
85 
86 
88  QOS_XML_Loader::init(const ACE_TCHAR* qos_profile)
89  {
90  if (!qos_profile)
91  {
92  if (DCPS_debug_level > 5)
93  {
95  ACE_TEXT("QOS_XML_Loader::init - ")
96  ACE_TEXT("Passed an empty qos_profile, returning.\n")));
97  }
99  }
100 
101  const ACE_TString filename = get_xml_file_name(qos_profile);
102 
103  if (filename.empty())
104  {
105  if (DCPS_debug_level > 5)
106  {
108  ACE_TEXT("QOS_XML_Loader::init - ")
109  ACE_TEXT("Unable to extract a file name from <%s>, returning.\n"),
110  qos_profile));
111  }
113  }
114 
116  ACE_TEXT("DDS_ROOT"),
117  ACE_TEXT("/docs/schema/"));
118 
119  DDS::ReturnCode_t const retcode = xml_file_.init(filename.c_str());
120 
121  return retcode;
122  }
123 
126  ::DDS::DataWriterQos& dw_qos,
127  const ACE_TCHAR * qos_profile,
128  const ACE_TCHAR * topic_name)
129  {
130  if (!qos_profile)
131  {
132  if (DCPS_debug_level > 9)
133  {
135  ACE_TEXT("QOS_XML_Loader::get_datawriter_qos - ")
136  ACE_TEXT("No QOS profile provided. Can't do anything, ")
137  ACE_TEXT("returning\n")));
138  }
139 
140  return DDS::RETCODE_OK;
141  }
142 
143  const ACE_TString profile_name = get_profile_name(qos_profile);
144 
145  if (profile_name.empty())
146  {
147  if (DCPS_debug_level > 5)
148  {
150  ACE_TEXT("QOS_XML_Loader::get_datawriter_qos - ")
151  ACE_TEXT("Error parsing profile string <%s>, returning.\n"),
152  qos_profile));
153  }
155  }
156 
158 
159  try
160  {
161  retcode = xml_file_.get_datawriter_qos(dw_qos,
162  profile_name.c_str(),
163  topic_name);
164  }
165  catch (...)
166  {
167  if (DCPS_debug_level > 5)
168  {
170  ACE_TEXT("QOS_XML_Loader::get_datawriter_qos - ")
171  ACE_TEXT("Caught unexpected exception.\n")));
172  }
173  retcode = DDS::RETCODE_ERROR;
174  }
175 
176  return retcode;
177  }
178 
181  DDS::DataReaderQos& dr_qos,
182  const ACE_TCHAR * qos_profile,
183  const ACE_TCHAR * topic_name)
184  {
185  if (!qos_profile)
186  {
187  if (DCPS_debug_level > 9)
188  {
190  ACE_TEXT("QOS_XML_Loader::get_datareader_qos - ")
191  ACE_TEXT("No QOS profile provided. Can't do anything, ")
192  ACE_TEXT("returning\n")));
193  }
194 
195  return DDS::RETCODE_OK;
196  }
197 
198  const ACE_TString profile_name = get_profile_name(qos_profile);
199 
200  if (profile_name.empty())
201  {
202  if (DCPS_debug_level > 5)
203  {
205  ACE_TEXT("QOS_XML_Loader::get_datareader_qos - ")
206  ACE_TEXT("Error parsing profile string <%s>, returning.\n"),
207  qos_profile));
208  }
210  }
211 
213 
214  try
215  {
216  retcode = xml_file_.get_datareader_qos(dr_qos,
217  profile_name.c_str(),
218  topic_name);
219  }
220  catch (...)
221  {
222  if (DCPS_debug_level > 5)
223  {
225  ACE_TEXT("QOS_XML_Loader::get_datareader_qos - ")
226  ACE_TEXT("Caught unexpected exception.\n")));
227  }
228  retcode = ::DDS::RETCODE_ERROR;
229  }
230 
231  return retcode;
232  }
233 
236  DDS::PublisherQos& pub_qos,
237  const ACE_TCHAR * qos_profile)
238  {
239  if (!qos_profile)
240  {
241  if (DCPS_debug_level > 9)
242  {
244  ACE_TEXT("QOS_XML_Loader::get_publisher_qos - ")
245  ACE_TEXT("No QOS profile provided. Can't do anything, ")
246  ACE_TEXT("returning\n")));
247  }
248 
249  return DDS::RETCODE_OK;
250  }
251 
252  const ACE_TString profile_name = get_profile_name(qos_profile);
253 
254  if (profile_name.empty())
255  {
256  if (DCPS_debug_level > 5)
257  {
259  ACE_TEXT("QOS_XML_Loader::get_publisher_qos - ")
260  ACE_TEXT("Error parsing profile string <%s>, returning.\n"),
261  qos_profile));
262  }
264  }
265 
267 
268  try
269  {
270  retcode = xml_file_.get_publisher_qos(pub_qos, profile_name.c_str());
271  }
272  catch (...)
273  {
274  if (DCPS_debug_level > 5)
275  {
277  ACE_TEXT("QOS_XML_Loader::get_publisher_qos - ")
278  ACE_TEXT("Caught unexpected exception.\n")));
279  }
280  retcode = DDS::RETCODE_ERROR;
281  }
282 
283  return retcode;
284  }
285 
288  DDS::SubscriberQos& sub_qos,
289  const ACE_TCHAR * qos_profile)
290  {
291  if (!qos_profile)
292  {
293  if (DCPS_debug_level > 9)
294  {
296  ACE_TEXT("QOS_XML_Loader::get_subscriber_qos - ")
297  ACE_TEXT("No QOS profile provided. Can't do anything, ")
298  ACE_TEXT("returning\n")));
299  }
300 
301  return DDS::RETCODE_OK;
302  }
303 
304  const ACE_TString profile_name = get_profile_name(qos_profile);
305 
306  if (profile_name.empty())
307  {
308  if (DCPS_debug_level > 5)
309  {
311  ACE_TEXT("QOS_XML_Loader::get_subscriber_qos - ")
312  ACE_TEXT("Error parsing profile string <%s>, returning.\n"),
313  qos_profile));
314  }
316  }
317 
319 
320  try
321  {
322  retcode = xml_file_.get_subscriber_qos(sub_qos, profile_name.c_str());
323  }
324  catch (...)
325  {
326  if (DCPS_debug_level > 5)
327  {
329  ACE_TEXT("QOS_XML_Loader::get_subscriber_qos - ")
330  ACE_TEXT("Caught unexpected exception.\n")));
331  }
332  retcode = DDS::RETCODE_ERROR;
333  }
334 
335  return retcode;
336  }
337 
340  DDS::TopicQos& topic_qos,
341  const ACE_TCHAR * qos_profile,
342  const ACE_TCHAR * topic_name)
343  {
344  if (!qos_profile)
345  {
346  if (DCPS_debug_level > 9)
347  {
349  ACE_TEXT("QOS_XML_Loader::get_topic_qos - ")
350  ACE_TEXT("No QOS profile provided. Can't do anything, ")
351  ACE_TEXT("returning\n")));
352  }
353 
354  return DDS::RETCODE_OK;
355  }
356 
357  const ACE_TString profile_name = get_profile_name(qos_profile);
358 
359  if (profile_name.empty())
360  {
361  if (DCPS_debug_level > 5)
362  {
364  ACE_TEXT("QOS_XML_Loader::get_topic_qos - ")
365  ACE_TEXT("Error parsing profile string <%s>, returning.\n"),
366  qos_profile));
367  }
369  }
370 
372 
373  try
374  {
375  retcode = xml_file_.get_topic_qos(topic_qos,
376  profile_name.c_str(),
377  topic_name);
378  }
379  catch (...)
380  {
381  if (DCPS_debug_level > 5)
382  {
384  ACE_TEXT("QOS_XML_Loader::get_topic_qos - ")
385  ACE_TEXT("Caught unexpected exception.\n")));
386  }
387  retcode = DDS::RETCODE_ERROR;
388  }
389 
390  return retcode;
391  }
392 
395  DDS::DomainParticipantQos& part_qos,
396  const ACE_TCHAR * qos_profile)
397  {
398  if (!qos_profile)
399  {
400  if (DCPS_debug_level > 9)
401  {
403  ACE_TEXT("QOS_XML_Loader::get_participant_qos - ")
404  ACE_TEXT("No QOS profile provided. Can't do anything, ")
405  ACE_TEXT("returning\n")));
406  }
407 
408  return DDS::RETCODE_OK;
409  }
410 
411  const ACE_TString profile_name = get_profile_name(qos_profile);
412 
413  if (profile_name.empty())
414  {
415  if (DCPS_debug_level > 5)
416  {
418  ACE_TEXT("QOS_XML_Loader::get_participant_qos - ")
419  ACE_TEXT("Error parsing profile string <%s>, returning.\n"),
420  qos_profile));
421  }
423  }
424 
426 
427  try
428  {
429  retcode = xml_file_.get_participant_qos(part_qos, profile_name.c_str());
430  }
431  catch (...)
432  {
433  if (DCPS_debug_level > 5)
434  {
436  ACE_TEXT("QOS_XML_Loader::get_participant_qos - ")
437  ACE_TEXT("Caught unexpected exception.\n")));
438  }
439  retcode = DDS::RETCODE_ERROR;
440  }
441 
442  return retcode;
443  }
444 }
445 }
446 
#define ACE_DEBUG(X)
DDS::ReturnCode_t get_participant_qos(::DDS::DomainParticipantQos &sub_qos, const ACE_TCHAR *profile_name)
Definition: XML_Intf.cpp:354
#define ACE_ERROR(X)
const char * c_str(void) const
DDS::ReturnCode_t get_datareader_qos(::DDS::DataReaderQos &dr_qos, const ACE_TCHAR *profile_name, const ACE_TCHAR *topic_name)
Definition: XML_Intf.cpp:208
void free(void *)
DDS::ReturnCode_t get_datareader_qos(DDS::DataReaderQos &dr_qos, const ACE_TCHAR *qos_profile, const ACE_TCHAR *topic_name)
QOS_XML_Loader(XML::XML_Error_Handler *error_handler=0)
int delimiter_replace(ACE_CHAR_T d, ACE_CHAR_T replacement)
DDS::ReturnCode_t get_publisher_qos(::DDS::PublisherQos &pub_qos, const ACE_TCHAR *profile_name)
Definition: XML_Intf.cpp:284
DDS::ReturnCode_t get_datawriter_qos(DDS::DataWriterQos &dw_qos, const ACE_TCHAR *qos_profile, const ACE_TCHAR *topic_name)
DDS::ReturnCode_t get_publisher_qos(DDS::PublisherQos &pub_qos, const ACE_TCHAR *qos_profile)
DDS::ReturnCode_t get_topic_qos(::DDS::TopicQos &tp_qos, const ACE_TCHAR *profile_name, const ACE_TCHAR *topic_name)
Definition: XML_Intf.cpp:246
DDS::ReturnCode_t get_datawriter_qos(::DDS::DataWriterQos &dw_qos, const ACE_TCHAR *profile_name, const ACE_TCHAR *topic_name)
Definition: XML_Intf.cpp:170
LM_DEBUG
QOS_XML_File_Handler xml_file_
DDS::ReturnCode_t get_topic_qos(DDS::TopicQos &topic_qos, const ACE_TCHAR *qos_profile, const ACE_TCHAR *topic_name)
char ACE_TCHAR
DDS::ReturnCode_t get_subscriber_qos(DDS::SubscriberQos &sub_qos, const ACE_TCHAR *qos_profile)
void add_search_path(const ACE_TCHAR *environment, const ACE_TCHAR *relpath)
DDS::ReturnCode_t get_participant_qos(DDS::DomainParticipantQos &part_qos, const ACE_TCHAR *qos_profile)
ACE_TString get_xml_file_name(const ACE_TCHAR *qos_profile)
DDS::ReturnCode_t get_subscriber_qos(::DDS::SubscriberQos &sub_qos, const ACE_TCHAR *profile_name)
Definition: XML_Intf.cpp:319
bool empty(void) const
DDS::ReturnCode_t init(const ACE_TCHAR *qos_profile)
ACE_TEXT("TCP_Factory")
OpenDDS_Dcps_Export unsigned int DCPS_debug_level
Definition: debug.cpp:30
DDS::ReturnCode_t init(const ACE_TCHAR *file)
const ReturnCode_t RETCODE_ERROR
#define OPENDDS_END_VERSIONED_NAMESPACE_DECL
char * strdup(const char *s)
const ReturnCode_t RETCODE_OK
ACE_CHAR_T * next(void)
ACE_TString get_profile_name(const ACE_TCHAR *qos_profile)
LM_ERROR
The Internal API and Implementation of OpenDDS.
Definition: AddressCache.h:28
const ReturnCode_t RETCODE_BAD_PARAMETER