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