00001 00002 #include "dds/DCPS/QOS_XML_Handler/QOS_XML_Loader.h" 00003 #include "dds/DCPS/QOS_XML_Handler/XML_File_Intf.h" 00004 #include "ace/Tokenizer_T.h" 00005 #include "dds/DCPS/debug.h" 00006 00007 namespace OpenDDS { 00008 namespace DCPS { 00009 00010 QOS_XML_Loader::QOS_XML_Loader (void) 00011 { 00012 } 00013 00014 QOS_XML_Loader::~QOS_XML_Loader (void) 00015 { 00016 } 00017 00018 00019 char* 00020 QOS_XML_Loader::get_xml_file_name (const char * qos_profile) 00021 { 00022 if (qos_profile) 00023 { 00024 char* buf = ACE_OS::strdup (qos_profile); 00025 ACE_Tokenizer_T<char> tok (buf); 00026 tok.delimiter_replace ('#', 0); 00027 const char * file_name = tok.next (); 00028 00029 if (file_name == 0) 00030 { 00031 ACE_OS::free (buf); 00032 if (DCPS_debug_level > 5) 00033 { 00034 ACE_ERROR ((LM_ERROR, 00035 "get_xml_file_name <%C> - " 00036 "Error: malformed qos_profile. Expected format: " 00037 "<xml_file_base_name>#<profile_name>\n", 00038 qos_profile)); 00039 } 00040 return 0; 00041 } 00042 00043 char * ret = (char*)ACE_OS::malloc (ACE_OS::strlen (file_name) + 5); 00044 ret = ACE_OS::strcpy (ret, file_name); 00045 ret = ACE_OS::strcat (ret, ".xml"); 00046 ACE_OS::free (buf); 00047 return ret; 00048 } 00049 00050 return 0; 00051 } 00052 00053 char* 00054 QOS_XML_Loader::get_profile_name (const char * qos_profile) 00055 { 00056 if (qos_profile) 00057 { 00058 char* buf = ACE_OS::strdup (qos_profile); 00059 ACE_Tokenizer_T<char> tok (buf); 00060 tok.delimiter_replace ('#', 0); 00061 const char * lib_name = tok.next (); 00062 const char * prof_name = tok.next (); 00063 00064 if (lib_name == 0 || prof_name == 0 || tok.next () != 0) 00065 { 00066 ACE_OS::free (buf); 00067 if (DCPS_debug_level > 5) 00068 { 00069 ACE_ERROR ((LM_ERROR, 00070 "get_profile_name <%C> - " 00071 "Error: malformed qos_profile. Expected format: " 00072 "<xml_file_base_name>#<profile_name>\n", 00073 qos_profile)); 00074 } 00075 return 0; 00076 } 00077 00078 char * ret = ACE_OS::strdup (prof_name); 00079 ACE_OS::free (buf); 00080 return ret; 00081 } 00082 00083 return 0; 00084 } 00085 00086 00087 DDS::ReturnCode_t 00088 QOS_XML_Loader::init (const char * qos_profile) 00089 { 00090 if (!qos_profile) 00091 { 00092 if (DCPS_debug_level > 5) 00093 { 00094 ACE_ERROR ((LM_ERROR, 00095 ACE_TEXT ("QOS_XML_Loader::init - ") 00096 ACE_TEXT ("Passed an empty qos_profile, returning.\n"))); 00097 } 00098 return ::DDS::RETCODE_BAD_PARAMETER; 00099 } 00100 00101 char *filename = this->get_xml_file_name (qos_profile); 00102 00103 if (!filename) 00104 { 00105 if (DCPS_debug_level > 5) 00106 { 00107 ACE_ERROR ((LM_ERROR, 00108 ACE_TEXT ("QOS_XML_Loader::init - ") 00109 ACE_TEXT ("Unable to extract a file name from <%C>, returning.\n"), 00110 qos_profile)); 00111 } 00112 return ::DDS::RETCODE_BAD_PARAMETER; 00113 } 00114 00115 this->xml_file_.add_search_path ( 00116 ACE_TEXT("DDS_ROOT"), 00117 ACE_TEXT("/docs/schema/")); 00118 00119 DDS::ReturnCode_t const retcode = this->xml_file_.init (filename); 00120 00121 ACE_OS::free (filename); 00122 00123 return retcode; 00124 } 00125 00126 DDS::ReturnCode_t 00127 QOS_XML_Loader::get_datawriter_qos ( 00128 ::DDS::DataWriterQos& dw_qos, 00129 const char * qos_profile, 00130 const char * topic_name) 00131 { 00132 if (!qos_profile) 00133 { 00134 if (DCPS_debug_level > 9) 00135 { 00136 ACE_DEBUG ((LM_DEBUG, 00137 ACE_TEXT ("QOS_XML_Loader::get_datawriter_qos - ") 00138 ACE_TEXT ("No QOS profile provided. Can't do anything, ") 00139 ACE_TEXT ("returning\n"))); 00140 } 00141 00142 return DDS::RETCODE_OK; 00143 } 00144 00145 char* profile_name = this->get_profile_name (qos_profile); 00146 00147 if (!profile_name) 00148 { 00149 if (DCPS_debug_level > 5) 00150 { 00151 ACE_ERROR ((LM_ERROR, 00152 ACE_TEXT ("QOS_XML_Loader::get_datawriter_qos - ") 00153 ACE_TEXT ("Error parsing profile string <%C>, returning.\n"), 00154 qos_profile)); 00155 } 00156 return ::DDS::RETCODE_BAD_PARAMETER; 00157 } 00158 00159 DDS::ReturnCode_t retcode = DDS::RETCODE_OK; 00160 00161 try 00162 { 00163 retcode = this->xml_file_.get_datawriter_qos (dw_qos, 00164 profile_name, 00165 topic_name); 00166 } 00167 catch (...) 00168 { 00169 if (DCPS_debug_level > 5) 00170 { 00171 ACE_ERROR ((LM_ERROR, 00172 ACE_TEXT ("QOS_XML_Loader::get_datawriter_qos - ") 00173 ACE_TEXT ("Caught unexpected exception.\n"))); 00174 } 00175 retcode = DDS::RETCODE_ERROR; 00176 } 00177 ACE_OS::free (profile_name); 00178 return retcode; 00179 } 00180 00181 DDS::ReturnCode_t 00182 QOS_XML_Loader::get_datareader_qos ( 00183 DDS::DataReaderQos& dr_qos, 00184 const char * qos_profile, 00185 const char * topic_name) 00186 { 00187 if (!qos_profile) 00188 { 00189 if (DCPS_debug_level > 9) 00190 { 00191 ACE_DEBUG ((LM_DEBUG, 00192 ACE_TEXT ("QOS_XML_Loader::get_datareader_qos - ") 00193 ACE_TEXT ("No QOS profile provided. Can't do anything, ") 00194 ACE_TEXT ("returning\n"))); 00195 } 00196 00197 return DDS::RETCODE_OK; 00198 } 00199 00200 char* profile_name = this->get_profile_name (qos_profile); 00201 00202 if (!profile_name) 00203 { 00204 if (DCPS_debug_level > 5) 00205 { 00206 ACE_ERROR ((LM_ERROR, 00207 ACE_TEXT ("QOS_XML_Loader::get_datareader_qos - ") 00208 ACE_TEXT ("Error parsing profile string <%C>, returning.\n"), 00209 qos_profile)); 00210 } 00211 return ::DDS::RETCODE_BAD_PARAMETER; 00212 } 00213 00214 DDS::ReturnCode_t retcode = DDS::RETCODE_OK; 00215 00216 try 00217 { 00218 retcode = this->xml_file_.get_datareader_qos (dr_qos, 00219 profile_name, 00220 topic_name); 00221 } 00222 catch (...) 00223 { 00224 if (DCPS_debug_level > 5) 00225 { 00226 ACE_ERROR ((LM_ERROR, 00227 ACE_TEXT ("QOS_XML_Loader::get_datareader_qos - ") 00228 ACE_TEXT ("Caught unexpected exception.\n"))); 00229 } 00230 retcode = ::DDS::RETCODE_ERROR; 00231 } 00232 ACE_OS::free (profile_name); 00233 00234 return retcode; 00235 } 00236 00237 DDS::ReturnCode_t 00238 QOS_XML_Loader::get_publisher_qos ( 00239 DDS::PublisherQos& pub_qos, 00240 const char * qos_profile) 00241 { 00242 if (!qos_profile) 00243 { 00244 if (DCPS_debug_level > 9) 00245 { 00246 ACE_DEBUG ((LM_DEBUG, 00247 ACE_TEXT ("QOS_XML_Loader::get_publisher_qos - ") 00248 ACE_TEXT ("No QOS profile provided. Can't do anything, ") 00249 ACE_TEXT ("returning\n"))); 00250 } 00251 00252 return DDS::RETCODE_OK; 00253 } 00254 00255 char* profile_name = this->get_profile_name (qos_profile); 00256 00257 if (!profile_name) 00258 { 00259 if (DCPS_debug_level > 5) 00260 { 00261 ACE_ERROR ((LM_ERROR, 00262 ACE_TEXT ("QOS_XML_Loader::get_publisher_qos - ") 00263 ACE_TEXT ("Error parsing profile string <%C>, returning.\n"), 00264 qos_profile)); 00265 } 00266 return ::DDS::RETCODE_BAD_PARAMETER; 00267 } 00268 00269 DDS::ReturnCode_t retcode = DDS::RETCODE_OK; 00270 00271 try 00272 { 00273 retcode = this->xml_file_.get_publisher_qos (pub_qos, profile_name); 00274 } 00275 catch (...) 00276 { 00277 if (DCPS_debug_level > 5) 00278 { 00279 ACE_ERROR ((LM_ERROR, 00280 ACE_TEXT ("QOS_XML_Loader::get_publisher_qos - ") 00281 ACE_TEXT ("Caught unexpected exception.\n"))); 00282 } 00283 retcode = DDS::RETCODE_ERROR; 00284 } 00285 ACE_OS::free (profile_name); 00286 00287 return retcode; 00288 } 00289 00290 DDS::ReturnCode_t 00291 QOS_XML_Loader::get_subscriber_qos ( 00292 DDS::SubscriberQos& sub_qos, 00293 const char * qos_profile) 00294 { 00295 if (!qos_profile) 00296 { 00297 if (DCPS_debug_level > 9) 00298 { 00299 ACE_DEBUG ((LM_DEBUG, 00300 ACE_TEXT ("QOS_XML_Loader::get_subscriber_qos - ") 00301 ACE_TEXT ("No QOS profile provided. Can't do anything, ") 00302 ACE_TEXT ("returning\n"))); 00303 } 00304 00305 return DDS::RETCODE_OK; 00306 } 00307 00308 char* profile_name = this->get_profile_name (qos_profile); 00309 00310 if (!profile_name) 00311 { 00312 if (DCPS_debug_level > 5) 00313 { 00314 ACE_ERROR ((LM_ERROR, 00315 ACE_TEXT ("QOS_XML_Loader::get_subscriber_qos - ") 00316 ACE_TEXT ("Error parsing profile string <%C>, returning.\n"), 00317 qos_profile)); 00318 } 00319 return ::DDS::RETCODE_BAD_PARAMETER; 00320 } 00321 00322 DDS::ReturnCode_t retcode = DDS::RETCODE_OK; 00323 00324 try 00325 { 00326 retcode = this->xml_file_.get_subscriber_qos (sub_qos, profile_name); 00327 } 00328 catch (...) 00329 { 00330 if (DCPS_debug_level > 5) 00331 { 00332 ACE_ERROR ((LM_ERROR, 00333 ACE_TEXT ("QOS_XML_Loader::get_subscriber_qos - ") 00334 ACE_TEXT ("Caught unexpected exception.\n"))); 00335 } 00336 retcode = DDS::RETCODE_ERROR; 00337 } 00338 00339 ACE_OS::free (profile_name); 00340 00341 return retcode; 00342 } 00343 00344 DDS::ReturnCode_t 00345 QOS_XML_Loader::get_topic_qos ( 00346 DDS::TopicQos& topic_qos, 00347 const char * qos_profile, 00348 const char * topic_name) 00349 { 00350 if (!qos_profile) 00351 { 00352 if (DCPS_debug_level > 9) 00353 { 00354 ACE_DEBUG ((LM_DEBUG, 00355 ACE_TEXT ("QOS_XML_Loader::get_topic_qos - ") 00356 ACE_TEXT ("No QOS profile provided. Can't do anything, ") 00357 ACE_TEXT ("returning\n"))); 00358 } 00359 00360 return DDS::RETCODE_OK; 00361 } 00362 00363 char* profile_name = this->get_profile_name (qos_profile); 00364 00365 if (!profile_name) 00366 { 00367 if (DCPS_debug_level > 5) 00368 { 00369 ACE_ERROR ((LM_ERROR, 00370 ACE_TEXT ("QOS_XML_Loader::get_topic_qos - ") 00371 ACE_TEXT ("Error parsing profile string <%C>, returning.\n"), 00372 qos_profile)); 00373 } 00374 return ::DDS::RETCODE_BAD_PARAMETER; 00375 } 00376 00377 DDS::ReturnCode_t retcode = DDS::RETCODE_OK; 00378 00379 try 00380 { 00381 retcode = this->xml_file_.get_topic_qos (topic_qos, 00382 profile_name, 00383 topic_name); 00384 } 00385 catch (...) 00386 { 00387 if (DCPS_debug_level > 5) 00388 { 00389 ACE_ERROR ((LM_ERROR, 00390 ACE_TEXT ("QOS_XML_Loader::get_topic_qos - ") 00391 ACE_TEXT ("Caught unexpected exception.\n"))); 00392 } 00393 retcode = DDS::RETCODE_ERROR; 00394 } 00395 00396 ACE_OS::free (profile_name); 00397 00398 return retcode; 00399 } 00400 00401 DDS::ReturnCode_t 00402 QOS_XML_Loader::get_participant_qos ( 00403 DDS::DomainParticipantQos& part_qos, 00404 const char * qos_profile) 00405 { 00406 if (!qos_profile) 00407 { 00408 if (DCPS_debug_level > 9) 00409 { 00410 ACE_DEBUG ((LM_DEBUG, 00411 ACE_TEXT ("QOS_XML_Loader::get_participant_qos - ") 00412 ACE_TEXT ("No QOS profile provided. Can't do anything, ") 00413 ACE_TEXT ("returning\n"))); 00414 } 00415 00416 return DDS::RETCODE_OK; 00417 } 00418 00419 char* profile_name = this->get_profile_name (qos_profile); 00420 00421 if (!profile_name) 00422 { 00423 if (DCPS_debug_level > 5) 00424 { 00425 ACE_ERROR ((LM_ERROR, 00426 ACE_TEXT ("QOS_XML_Loader::get_participant_qos - ") 00427 ACE_TEXT ("Error parsing profile string <%C>, returning.\n"), 00428 qos_profile)); 00429 } 00430 return ::DDS::RETCODE_BAD_PARAMETER; 00431 } 00432 00433 DDS::ReturnCode_t retcode = DDS::RETCODE_OK; 00434 00435 try 00436 { 00437 retcode = this->xml_file_.get_participant_qos (part_qos, profile_name); 00438 } 00439 catch (...) 00440 { 00441 if (DCPS_debug_level > 5) 00442 { 00443 ACE_ERROR ((LM_ERROR, 00444 ACE_TEXT ("QOS_XML_Loader::get_participant_qos - ") 00445 ACE_TEXT ("Caught unexpected exception.\n"))); 00446 } 00447 retcode = DDS::RETCODE_ERROR; 00448 } 00449 00450 ACE_OS::free (profile_name); 00451 00452 return retcode; 00453 } 00454 } 00455 }