UniSet  2.0.0
Configuration.h
См. документацию.
00001 /* This file is part of the UniSet project
00002  * Copyright (c) 2002 Free Software Foundation, Inc.
00003  * Copyright (c) 2002 Pavel Vainerman, Vitaly Lipatov
00004  *
00005  * This program is free software; you can redistribute it and/or modify
00006  * it under the terms of the GNU General Public License as published by
00007  * the Free Software Foundation; either version 2 of the License, or
00008  * (at your option) any later version.
00009  *
00010  * This program is distributed in the hope that it will be useful,
00011  * but WITHOUT ANY WARRANTY; without even the implied warranty of
00012  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
00013  * GNU General Public License for more details.
00014  *
00015  * You should have received a copy of the GNU General Public License
00016  * along with this program; if not, write to the Free Software
00017  * Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.
00018  */
00019 // --------------------------------------------------------------------------
00024 // --------------------------------------------------------------------------
00025 #ifndef Configuration_H_
00026 #define Configuration_H_
00027 // --------------------------------------------------------------------------
00028 #include <memory>
00029 #include <string>
00030 #include <ostream>
00031 #include "UniXML.h"
00032 #include "UniSetTypes.h"
00033 #include "ObjectIndex.h"
00034 #include "IORFile.h"
00035 #include "Debug.h"
00036 // --------------------------------------------------------------------------
00037 /*
00038     В функции main нужно обязательно вызывать UniSetTypes::uniset_init(argc,argv);
00039 */
00040 namespace UniSetTypes
00041 {
00047     class Configuration
00048     {
00049         public:
00050             virtual ~Configuration();
00051 
00053             Configuration( int argc, const char* const* argv, const std::string& xmlfile="" );
00054 
00056             Configuration( int argc, const char* const* argv, std::shared_ptr<ObjectIndex> oind, const std::string& xmlfile="" );
00057 
00059             Configuration( int argc, const char* const* argv,
00060                             const std::string& fileConf, UniSetTypes::ObjectInfo* objectsMap );
00061 
00063         std::string getField(const std::string& path);
00065         int getIntField(const std::string& path);
00067         int getPIntField(const std::string& path, int def);
00068 
00069         xmlNode* findNode(xmlNode* node, const std::string& searchnode, const std::string& name="" );
00070 
00071         // Получить узел
00072         xmlNode* getNode(const std::string& path);
00073         // Получить указанное свойство пути
00074         std::string getProp(xmlNode*, const std::string& name);
00075         int getIntProp(xmlNode*, const std::string& name);
00076         int getPIntProp(xmlNode*, const std::string& name, int def);
00077         // Получить указанное свойство по имени узла
00078         std::string getPropByNodeName(const std::string& nodename, const std::string& prop);
00079 
00080         static std::ostream& help(std::ostream& os);
00081 
00082         std::string getRootDir(); 
00083         inline int getArgc()const { return _argc; }
00084         inline const char* const* getArgv() const { return _argv; }
00085         inline ObjectId getDBServer() const { return localDBServer; }        
00086         inline ObjectId getLocalNode() const { return localNode; }        
00087         inline std::string getLocalNodeName() const { return localNodeName; }        
00088         inline const std::string getNSName() const { return NSName; }
00089 
00090         // repository
00091         inline std::string getRootSection() const { return secRoot; }
00092         inline std::string getSensorsSection() const { return secSensors; }
00093         inline std::string getObjectsSection() const { return secObjects; }
00094         inline std::string getControllersSection() const { return secControlles; }
00095         inline std::string getServicesSection() const { return secServices; }
00096         // xml
00097         xmlNode* getXMLSensorsSection();
00098         xmlNode* getXMLObjectsSection();
00099         xmlNode* getXMLControllersSection();
00100         xmlNode* getXMLServicesSection();
00101         xmlNode* getXMLNodesSection();
00102         xmlNode* getXMLObjectNode( UniSetTypes::ObjectId );
00103         UniversalIO::IOType getIOType( UniSetTypes::ObjectId );
00104         UniversalIO::IOType getIOType( const std::string& name );
00105 
00106         // net
00107         inline unsigned int getCountOfNet() const { return countOfNet; }
00108         inline unsigned int getRepeatTimeout() const { return repeatTimeout; }
00109         inline unsigned int getRepeatCount() const { return repeatCount; }
00110 
00111         UniSetTypes::ObjectId getSensorID( const std::string& name );
00112         UniSetTypes::ObjectId getControllerID( const std::string& name );
00113         UniSetTypes::ObjectId getObjectID( const std::string& name );
00114         UniSetTypes::ObjectId getServiceID( const std::string& name );
00115         UniSetTypes::ObjectId getNodeID( const std::string& name );
00116 
00117         inline const std::string getConfFileName() const { return fileConfName; }
00118         inline std::string getImagesDir() const { return imagesDir; }    // временно
00119 
00120         inline int getHeartBeatTime(){ return heartbeat_msec; }
00121 
00122         // dirs
00123         inline const std::string getConfDir() const { return confDir; }
00124         inline const std::string getDataDir() const { return dataDir; }
00125         inline const std::string getBinDir() const { return binDir; }
00126         inline const std::string getLogDir() const { return logDir; }
00127         inline const std::string getLockDir() const { return lockDir; }
00128         inline const std::string getDocDir() const { return docDir; }
00129 
00130 
00131         inline bool isLocalIOR() const { return localIOR; }
00132         inline bool isTransientIOR() const { return transientIOR; }
00133 
00135         std::string getArgParam(const std::string& name, const std::string& defval="");
00137         int getArgInt(const std::string& name, const std::string& defval="");
00139         int getArgPInt(const std::string& name, int defval);
00140         int getArgPInt(const std::string& name, const std::string& strdefval, int defval);
00141 
00142         xmlNode* initDebug( DebugStream& deb, const std::string& nodename );
00143 
00144         UniSetTypes::ListOfNode::const_iterator listNodesBegin()
00145         {
00146             return lnodes.begin();
00147         }
00148 
00149         inline UniSetTypes::ListOfNode::const_iterator listNodesEnd()
00150         {
00151             return lnodes.end();
00152         }
00153 
00155         std::shared_ptr<ObjectIndex> oind;
00156 
00158         std::shared_ptr<IORFile> iorfile;
00159 
00161         inline const std::shared_ptr<UniXML> getConfXML() const { return unixml; }
00162 
00163         CORBA::ORB_ptr getORB()const { return CORBA::ORB::_duplicate(orb); }
00164         CORBA::PolicyList getPolicy() const { return policyList; }
00165 
00166     protected:
00167         Configuration();
00168 
00169         virtual void initConfiguration(int argc, const char* const* argv);
00170 
00171         void createNodesList();
00172         virtual void initNode( UniSetTypes::NodeInfo& ninfo, UniXML::iterator& it);
00173 
00174         void initRepSections();
00175         std::string getRepSectionName(const std::string& sec, xmlNode* secnode=0 );
00176         void setConfFileName( const std::string& fn="" );
00177         void initParameters();
00178         void setLocalNode( const std::string& nodename );
00179 
00180         std::string getPort( const std::string& port="" );
00181 
00182         std::string rootDir;
00183         std::shared_ptr<UniXML> unixml;
00184 
00185         int _argc;
00186         const char* const* _argv;
00187         CORBA::ORB_var orb;
00188         CORBA::PolicyList policyList;
00189 
00190         std::string NSName;        
00191         unsigned int countOfNet;    
00192         unsigned int repeatCount;    
00195         unsigned int repeatTimeout;    
00197         UniSetTypes::ListOfNode lnodes;
00198 
00199         // repository
00200         std::string secRoot;
00201         std::string secSensors;
00202         std::string secObjects;
00203         std::string secControlles;
00204         std::string secServices;
00205 
00206         // xml
00207         xmlNode* xmlSensorsSec;
00208         xmlNode* xmlObjectsSec;
00209         xmlNode* xmlControllersSec;
00210         xmlNode* xmlServicesSec;
00211         xmlNode* xmlNodesSec;
00212 
00213         ObjectId localDBServer;
00214         ObjectId localNode;
00215 
00216         std::string localNodeName;
00217         std::string fileConfName;
00218         std::string imagesDir;
00219 
00220         std::string confDir;
00221         std::string dataDir;
00222         std::string binDir;
00223         std::string logDir;
00224         std::string docDir;
00225         std::string lockDir;
00226         bool localIOR;
00227         bool transientIOR;
00228 
00229         int heartbeat_msec;
00230     };
00231 
00233     std::shared_ptr<Configuration> uniset_conf();
00234 
00236     extern DebugStream ulog;
00237 
00239     std::shared_ptr<Configuration> uniset_init( int argc, const char* const* argv, const std::string& xmlfile="configure.xml" );
00240 
00241 }    // end of UniSetTypes namespace
00242 // --------------------------------------------------------------------------
00243 // "синтаксический сахар"..для логов
00244 #define uinfo if( UniSetTypes::ulog.debugging(Debug::INFO) ) UniSetTypes::ulog[Debug::INFO]
00245 #define uwarn if( UniSetTypes::ulog.debugging(Debug::WARN) ) UniSetTypes::ulog[Debug::WARN]
00246 #define ucrit if( UniSetTypes::ulog.debugging(Debug::CRIT) ) UniSetTypes::ulog[Debug::CRIT]
00247 #define ulog1 if( UniSetTypes::ulog.debugging(Debug::LEVEL1) ) UniSetTypes::ulog[Debug::LEVEL1]
00248 #define ulog2 if( UniSetTypes::ulog.debugging(Debug::LEVEL2) ) UniSetTypes::ulog[Debug::LEVEL2]
00249 #define ulog3 if( UniSetTypes::ulog.debugging(Debug::LEVEL3) ) UniSetTypes::ulog[Debug::LEVEL3]
00250 #define ulog4 if( UniSetTypes::ulog.debugging(Debug::LEVEL4) ) UniSetTypes::ulog[Debug::LEVEL4]
00251 #define ulog5 if( UniSetTypes::ulog.debugging(Debug::LEVEL5) ) UniSetTypes::ulog[Debug::LEVEL5]
00252 #define ulog6 if( UniSetTypes::ulog.debugging(Debug::LEVEL6) ) UniSetTypes::ulog[Debug::LEVEL6]
00253 #define ulog7 if( UniSetTypes::ulog.debugging(Debug::LEVEL7) ) UniSetTypes::ulog[Debug::LEVEL7]
00254 #define ulog8 if( UniSetTypes::ulog.debugging(Debug::LEVEL8) ) UniSetTypes::ulog[Debug::LEVEL8]
00255 #define ulog9 if( UniSetTypes::ulog.debugging(Debug::LEVEL9) ) UniSetTypes::ulog[Debug::LEVEL9]
00256 #define ulogsys if( UniSetTypes::ulog.debugging(Debug::SYSTEM) ) UniSetTypes::ulog[Debug::SYSTEM]
00257 #define ulogrep if( UniSetTypes::ulog.debugging(Debug::REPOSITORY) ) UniSetTypes::ulog[Debug::REPOSITORY]
00258 // --------------------------------------------------------------------------
00259 #endif // Configuration_H_