00001 00002 #include "XML_File_Intf.h" 00003 #include "ace/XML_Utils/XML_Typedefs.h" 00004 #include "ace/XML_Utils/XMLSchema/id_map.hpp" 00005 00006 #include "DataReaderQos_Handler.h" 00007 #include "DataWriterQos_Handler.h" 00008 #include "TopicQos_Handler.h" 00009 #include "PublisherQos_Handler.h" 00010 #include "SubscriberQos_Handler.h" 00011 #include "ParticipantQos_Handler.h" 00012 00013 #include "dds/DCPS/debug.h" 00014 00015 namespace OpenDDS { 00016 namespace DCPS { 00017 00018 QOS_XML_File_Handler::QOS_XML_File_Handler (void) 00019 { 00020 } 00021 00022 QOS_XML_File_Handler::~QOS_XML_File_Handler (void) 00023 { 00024 } 00025 00026 DDS::ReturnCode_t 00027 QOS_XML_File_Handler::init (const ACE_TCHAR * file) 00028 { 00029 DDS::ReturnCode_t retcode = DDS::RETCODE_OK; 00030 try 00031 { 00032 if (!XML_Helper_type::XML_HELPER.is_initialized ()) 00033 { 00034 ACE_ERROR ((LM_ERROR, 00035 ACE_TEXT ("QOS_XML_File_Handler::init - ") 00036 ACE_TEXT ("Unable to initialize XML_Helper.\n"))); 00037 return DDS::RETCODE_ERROR; 00038 } 00039 00040 if (DCPS_debug_level > 9) 00041 { 00042 ACE_DEBUG ((LM_TRACE, 00043 ACE_TEXT ("QOS_XML_File_Handler::init - ") 00044 ACE_TEXT ("Constructing DOM\n"))); 00045 } 00046 00047 XERCES_CPP_NAMESPACE::DOMDocument *dom = 00048 XML_Helper_type::XML_HELPER.create_dom (file); 00049 00050 if (dom == 0) 00051 { 00052 if (DCPS_debug_level > 1) 00053 { 00054 ACE_ERROR ((LM_ERROR, 00055 ACE_TEXT ("QOS_XML_File_Handler::init - ") 00056 ACE_TEXT ("Failed to open file %s\n"), 00057 file)); 00058 } 00059 return DDS::RETCODE_ERROR; 00060 } 00061 00062 XERCES_CPP_NAMESPACE::DOMElement *profile_dom = dom->getDocumentElement (); 00063 00064 if (DCPS_debug_level > 9) 00065 { 00066 ACE_DEBUG ((LM_TRACE, 00067 ACE_TEXT ("QOS_XML_File_Handler::init - ") 00068 ACE_TEXT ("DOMElement pointer: %u\n"), profile_dom)); 00069 } 00070 00071 ID_Map::TSS_ID_Map* TSS_ID_Map (ACE_Singleton<ID_Map::TSS_ID_Map, ACE_Null_Mutex>::instance()); 00072 (*TSS_ID_Map)->reset (); 00073 00074 this->profiles_ = dds::reader::dds (dom); 00075 } 00076 catch (const CORBA::Exception &ex) 00077 { 00078 ACE_ERROR ((LM_ERROR, 00079 ACE_TEXT ("QOS_XML_File_Handler::init - ") 00080 ACE_TEXT ("Caught CORBA exception whilst parsing XML <%C> into IDL: %C\n"), 00081 file, 00082 ex._info ().c_str ())); 00083 retcode = DDS::RETCODE_ERROR; 00084 } 00085 catch (...) 00086 { 00087 ACE_ERROR ((LM_ERROR, 00088 ACE_TEXT ("QOS_XML_File_Handler::init - ") 00089 ACE_TEXT ("Unexpected exception whilst parsing XML <%C> into IDL.\n"), 00090 file)); 00091 retcode = DDS::RETCODE_ERROR; 00092 } 00093 return retcode; 00094 } 00095 00096 ::dds::qosProfile * 00097 QOS_XML_File_Handler::get_profile (const char * profile_name) 00098 { 00099 for (::dds::qosProfile_seq::qos_profile_const_iterator it = this->profiles_.begin_qos_profile (); 00100 it != this->profiles_.end_qos_profile (); 00101 ++it) 00102 { 00103 if (ACE_OS::strcmp ((*it)->name ().c_str (), profile_name) == 0) 00104 { 00105 if (DCPS_debug_level > 7) 00106 { 00107 ACE_DEBUG ((LM_TRACE, 00108 ACE_TEXT ("QOS_XML_File_Handler::get_profile - ") 00109 ACE_TEXT ("Found profile <%C>\n"), 00110 (*it)->name ().c_str ())); 00111 } 00112 return it->get(); 00113 } 00114 } 00115 if (ACE_OS::strlen (profile_name) == 0) 00116 { 00117 ACE_ERROR ((LM_DEBUG, 00118 ACE_TEXT ("QOS_XML_File_Handler::get_profile - ") 00119 ACE_TEXT ("No profile specified\n"))); 00120 } 00121 else 00122 { 00123 ACE_ERROR ((LM_TRACE, 00124 ACE_TEXT ("QOS_XML_File_Handler::get_profile - ") 00125 ACE_TEXT ("Did not find profile <%C>\n"), 00126 profile_name)); 00127 } 00128 return 0; 00129 } 00130 00131 DDS::ReturnCode_t 00132 QOS_XML_File_Handler::get_datawriter_qos (::DDS::DataWriterQos& dw_qos, 00133 const char * profile_name, 00134 const char * topic_name) 00135 { 00136 ACE_UNUSED_ARG (topic_name); 00137 00138 DDS::ReturnCode_t retcode = DDS::RETCODE_ERROR; 00139 try 00140 { 00141 ::dds::qosProfile * profile = this->get_profile (profile_name); 00142 if (profile != 0) 00143 { 00144 DataWriterQos_Handler::get_datawriter_qos (dw_qos, profile); 00145 retcode = ::DDS::RETCODE_OK; 00146 } 00147 else 00148 retcode = DDS::RETCODE_BAD_PARAMETER; 00149 } 00150 catch (const CORBA::Exception &ex) 00151 { 00152 ACE_ERROR ((LM_ERROR, 00153 ACE_TEXT ("QOS_XML_File_Handler::get_datawriter_qos - ") 00154 ACE_TEXT ("Caught CORBA exception whilst parsing XML into IDL: %C\n"), 00155 ex._info ().c_str ())); 00156 retcode = DDS::RETCODE_ERROR; 00157 } 00158 catch (...) 00159 { 00160 ACE_ERROR ((LM_ERROR, 00161 ACE_TEXT ("QOS_XML_File_Handler::get_datawriter_qos - ") 00162 ACE_TEXT ("Unexpected exception whilst parsing XML into IDL.\n"))); 00163 retcode = DDS::RETCODE_ERROR; 00164 } 00165 00166 return retcode; 00167 } 00168 00169 DDS::ReturnCode_t 00170 QOS_XML_File_Handler::get_datareader_qos (::DDS::DataReaderQos& dr_qos, 00171 const char * profile_name, 00172 const char * topic_name) 00173 { 00174 ACE_UNUSED_ARG (topic_name); 00175 00176 DDS::ReturnCode_t retcode = DDS::RETCODE_ERROR; 00177 try 00178 { 00179 ::dds::qosProfile * profile = this->get_profile (profile_name); 00180 if (profile != 0) 00181 { 00182 DataReaderQos_Handler::get_datareader_qos (dr_qos, profile); 00183 retcode = ::DDS::RETCODE_OK; 00184 } 00185 else 00186 retcode = DDS::RETCODE_BAD_PARAMETER; 00187 } 00188 catch (const CORBA::Exception &ex) 00189 { 00190 ACE_ERROR ((LM_ERROR, 00191 ACE_TEXT ("QOS_XML_File_Handler::get_datareader_qos - ") 00192 ACE_TEXT ("Caught CORBA exception whilst parsing XML into IDL: %C\n"), 00193 ex._info ().c_str ())); 00194 retcode = DDS::RETCODE_ERROR; 00195 } 00196 catch (...) 00197 { 00198 ACE_ERROR ((LM_ERROR, 00199 ACE_TEXT ("QOS_XML_File_Handler::get_datareader_qos - ") 00200 ACE_TEXT ("Unexpected exception whilst parsing XML into IDL.\n"))); 00201 retcode = DDS::RETCODE_ERROR; 00202 } 00203 00204 return retcode; 00205 } 00206 00207 DDS::ReturnCode_t 00208 QOS_XML_File_Handler::get_topic_qos (::DDS::TopicQos& tp_qos, 00209 const char * profile_name, 00210 const char * topic_name) 00211 { 00212 ACE_UNUSED_ARG (topic_name); 00213 00214 DDS::ReturnCode_t retcode = DDS::RETCODE_ERROR; 00215 try 00216 { 00217 ::dds::qosProfile * profile = this->get_profile (profile_name); 00218 if (profile != 0) 00219 { 00220 TopicQos_Handler::get_topic_qos (tp_qos, profile); 00221 retcode = ::DDS::RETCODE_OK; 00222 } 00223 else 00224 retcode = DDS::RETCODE_BAD_PARAMETER; 00225 } 00226 catch (const CORBA::Exception &ex) 00227 { 00228 ACE_ERROR ((LM_ERROR, 00229 ACE_TEXT ("QOS_XML_File_Handler::get_topic_qos - ") 00230 ACE_TEXT ("Caught CORBA exception whilst parsing XML into IDL: %C\n"), 00231 ex._info ().c_str ())); 00232 retcode = DDS::RETCODE_ERROR; 00233 } 00234 catch (...) 00235 { 00236 ACE_ERROR ((LM_ERROR, 00237 ACE_TEXT ("QOS_XML_File_Handler::get_topic_qos - ") 00238 ACE_TEXT ("Unexpected exception whilst parsing XML into IDL.\n"))); 00239 retcode = DDS::RETCODE_ERROR; 00240 } 00241 00242 return retcode; 00243 } 00244 00245 DDS::ReturnCode_t 00246 QOS_XML_File_Handler::get_publisher_qos (::DDS::PublisherQos& pub_qos, 00247 const char * profile_name) 00248 { 00249 DDS::ReturnCode_t retcode = DDS::RETCODE_ERROR; 00250 try 00251 { 00252 ::dds::qosProfile * profile = this->get_profile (profile_name); 00253 if (profile != 0) 00254 { 00255 PublisherQos_Handler::get_publisher_qos (pub_qos, profile); 00256 retcode = ::DDS::RETCODE_OK; 00257 } 00258 else 00259 retcode = DDS::RETCODE_BAD_PARAMETER; 00260 } 00261 catch (const CORBA::Exception &ex) 00262 { 00263 ACE_ERROR ((LM_ERROR, 00264 ACE_TEXT ("QOS_XML_File_Handler::get_publisher_qos - ") 00265 ACE_TEXT ("Caught CORBA exception whilst parsing XML into IDL: %C\n"), 00266 ex._info ().c_str ())); 00267 retcode = DDS::RETCODE_ERROR; 00268 } 00269 catch (...) 00270 { 00271 ACE_ERROR ((LM_ERROR, 00272 ACE_TEXT ("QOS_XML_File_Handler::get_publisher_qos - ") 00273 ACE_TEXT ("Unexpected exception whilst parsing XML into IDL.\n"))); 00274 retcode = DDS::RETCODE_ERROR; 00275 } 00276 00277 return retcode; 00278 } 00279 00280 DDS::ReturnCode_t 00281 QOS_XML_File_Handler::get_subscriber_qos (::DDS::SubscriberQos& sub_qos, 00282 const char * profile_name) 00283 { 00284 DDS::ReturnCode_t retcode = DDS::RETCODE_ERROR; 00285 try 00286 { 00287 ::dds::qosProfile * profile = this->get_profile (profile_name); 00288 if (profile != 0) 00289 { 00290 SubscriberQos_Handler::get_subscriber_qos (sub_qos, profile); 00291 retcode = ::DDS::RETCODE_OK; 00292 } 00293 else 00294 retcode = DDS::RETCODE_BAD_PARAMETER; 00295 } 00296 catch (const CORBA::Exception &ex) 00297 { 00298 ACE_ERROR ((LM_ERROR, 00299 ACE_TEXT ("QOS_XML_File_Handler::get_subscriber_qos - ") 00300 ACE_TEXT ("Caught CORBA exception whilst parsing XML into IDL: %C\n"), 00301 ex._info ().c_str ())); 00302 retcode = DDS::RETCODE_ERROR; 00303 } 00304 catch (...) 00305 { 00306 ACE_ERROR ((LM_ERROR, 00307 ACE_TEXT ("QOS_XML_File_Handler::get_subscriber_qos - ") 00308 ACE_TEXT ("Unexpected exception whilst parsing XML into IDL.\n"))); 00309 retcode = DDS::RETCODE_ERROR; 00310 } 00311 00312 return retcode; 00313 } 00314 00315 DDS::ReturnCode_t 00316 QOS_XML_File_Handler::get_participant_qos (::DDS::DomainParticipantQos& sub_qos, 00317 const char * profile_name) 00318 { 00319 DDS::ReturnCode_t retcode = DDS::RETCODE_ERROR; 00320 try 00321 { 00322 ::dds::qosProfile * profile = this->get_profile (profile_name); 00323 if (profile != 0) 00324 { 00325 ParticipantQos_Handler::get_participant_qos (sub_qos, profile); 00326 retcode = ::DDS::RETCODE_OK; 00327 } 00328 else 00329 retcode = DDS::RETCODE_BAD_PARAMETER; 00330 } 00331 catch (const CORBA::Exception &ex) 00332 { 00333 ACE_ERROR ((LM_ERROR, 00334 ACE_TEXT ("QOS_XML_File_Handler::get_participant_qos - ") 00335 ACE_TEXT ("Caught CORBA exception whilst parsing XML into IDL: %C\n"), 00336 ex._info ().c_str ())); 00337 retcode = DDS::RETCODE_ERROR; 00338 } 00339 catch (...) 00340 { 00341 ACE_ERROR ((LM_ERROR, 00342 ACE_TEXT ("QOS_XML_File_Handler::get_participant_qos - ") 00343 ACE_TEXT ("Unexpected exception whilst parsing XML into IDL.\n"))); 00344 retcode = DDS::RETCODE_ERROR; 00345 } 00346 00347 return retcode; 00348 } 00349 00350 void 00351 QOS_XML_File_Handler::add_search_path (const ACE_TCHAR *environment, 00352 const ACE_TCHAR *relpath) 00353 { 00354 XML_Helper_type::XML_HELPER.get_resolver ().get_resolver ().add_path (environment, relpath); 00355 } 00356 00357 } 00358 }