ConfigUtils.cpp

Go to the documentation of this file.
00001 /*
00002  *
00003  *
00004  * Distributed under the OpenDDS License.
00005  * See: http://www.opendds.org/license.html
00006  */
00007 
00008 #include "DCPS/DdsDcps_pch.h" //Only the _pch include should start with DCPS/
00009 
00010 #include "debug.h"
00011 #include "ConfigUtils.h"
00012 #include "ace/SString.h"
00013 
00014 namespace OpenDDS { namespace DCPS {
00015 
00016   int pullValues( ACE_Configuration_Heap& cf,
00017                   const ACE_Configuration_Section_Key& key,
00018                   ValueMap& values ) {
00019     int index = 0;
00020     ACE_TString name;
00021     ACE_Configuration::VALUETYPE type;
00022 
00023     while (cf.enumerate_values( key, index, name, type ) == 0) {
00024 
00025       ACE_TString value;
00026       if (type == ACE_Configuration::STRING) {
00027         cf.get_string_value( key, name.c_str(), value );
00028         if (DCPS_debug_level > 8) {
00029           ACE_DEBUG((LM_INFO, "Configuration %s=%s\n",
00030                               name.c_str(), value.c_str()));
00031         }
00032         values[ACE_TEXT_ALWAYS_CHAR(name.c_str())] =
00033           ACE_TEXT_ALWAYS_CHAR(value.c_str());
00034       } else {
00035         ACE_DEBUG((LM_WARNING, "Unexpected value type in config file (ignored): "
00036                    "name=%s, type=%d\n", name.c_str(), type));
00037       }
00038       index++;
00039     }
00040     return index;
00041   }
00042 
00043 
00044   int processSections( ACE_Configuration_Heap& cf,
00045                        const ACE_Configuration_Section_Key& key,
00046                        KeyList& subsections ) {
00047     int index = 0;
00048     ACE_TString name;
00049     while (cf.enumerate_sections( key, index, name ) == 0) {
00050       ACE_Configuration_Section_Key subkey;
00051       if (cf.open_section( key, name.c_str(), 0, subkey ) != 0) {
00052         return 1;
00053       }
00054       subsections.push_back( SubsectionPair( ACE_TEXT_ALWAYS_CHAR(name.c_str()),
00055                                              subkey ) );
00056       int subindex = 0;
00057       ACE_TString subname;
00058       if (cf.enumerate_sections( subkey, subindex, subname ) == 0) {
00059         // Found additional nesting of subsections that we don't care
00060         // to allow (e.g. [transport/my/yours]), so return an error.
00061         return 1;
00062       }
00063       index++;
00064     }
00065     return 0;
00066   }
00067 
00068 }  }

Generated on Fri Feb 12 20:05:19 2016 for OpenDDS by  doxygen 1.4.7