QOS_XML_Loader.cpp

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

Generated on 10 Aug 2018 for OpenDDS by  doxygen 1.6.1