|
UniSet
2.2.1
|
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 00084 { 00085 return _argc; 00086 } 00087 inline const char* const* getArgv() const 00088 { 00089 return _argv; 00090 } 00091 inline ObjectId getDBServer() const 00092 { 00093 return localDBServer; 00094 } 00095 inline ObjectId getLocalNode() const 00096 { 00097 return localNode; 00098 } 00099 inline std::string getLocalNodeName() const 00100 { 00101 return localNodeName; 00102 } 00103 inline const std::string getNSName() const 00104 { 00105 return NSName; 00106 } 00107 00108 // repository 00109 inline std::string getRootSection() const 00110 { 00111 return secRoot; 00112 } 00113 inline std::string getSensorsSection() const 00114 { 00115 return secSensors; 00116 } 00117 inline std::string getObjectsSection() const 00118 { 00119 return secObjects; 00120 } 00121 inline std::string getControllersSection() const 00122 { 00123 return secControlles; 00124 } 00125 inline std::string getServicesSection() const 00126 { 00127 return secServices; 00128 } 00129 // xml 00130 xmlNode* getXMLSensorsSection(); 00131 xmlNode* getXMLObjectsSection(); 00132 xmlNode* getXMLControllersSection(); 00133 xmlNode* getXMLServicesSection(); 00134 xmlNode* getXMLNodesSection(); 00135 xmlNode* getXMLObjectNode( UniSetTypes::ObjectId ); 00136 UniversalIO::IOType getIOType( UniSetTypes::ObjectId ); 00137 UniversalIO::IOType getIOType( const std::string& name ); 00138 00139 // net 00140 inline unsigned int getCountOfNet() const 00141 { 00142 return countOfNet; 00143 } 00144 inline unsigned int getRepeatTimeout() const 00145 { 00146 return repeatTimeout; 00147 } 00148 inline unsigned int getRepeatCount() const 00149 { 00150 return repeatCount; 00151 } 00152 00153 UniSetTypes::ObjectId getSensorID( const std::string& name ); 00154 UniSetTypes::ObjectId getControllerID( const std::string& name ); 00155 UniSetTypes::ObjectId getObjectID( const std::string& name ); 00156 UniSetTypes::ObjectId getServiceID( const std::string& name ); 00157 UniSetTypes::ObjectId getNodeID( const std::string& name ); 00158 00159 inline const std::string getConfFileName() const 00160 { 00161 return fileConfName; 00162 } 00163 inline std::string getImagesDir() const 00164 { 00165 return imagesDir; // временно 00166 } 00167 00168 inline int getHeartBeatTime() 00169 { 00170 return heartbeat_msec; 00171 } 00172 00173 // dirs 00174 inline const std::string getConfDir() const 00175 { 00176 return confDir; 00177 } 00178 inline const std::string getDataDir() const 00179 { 00180 return dataDir; 00181 } 00182 inline const std::string getBinDir() const 00183 { 00184 return binDir; 00185 } 00186 inline const std::string getLogDir() const 00187 { 00188 return logDir; 00189 } 00190 inline const std::string getLockDir() const 00191 { 00192 return lockDir; 00193 } 00194 inline const std::string getDocDir() const 00195 { 00196 return docDir; 00197 } 00198 00199 00200 inline bool isLocalIOR() const 00201 { 00202 return localIOR; 00203 } 00204 inline bool isTransientIOR() const 00205 { 00206 return transientIOR; 00207 } 00208 00210 std::string getArgParam(const std::string& name, const std::string& defval = ""); 00212 std::string getArg2Param(const std::string& name, const std::string& defval, const std::string& defval2 = ""); 00214 int getArgInt(const std::string& name, const std::string& defval = ""); 00216 int getArgPInt(const std::string& name, int defval); 00217 int getArgPInt(const std::string& name, const std::string& strdefval, int defval); 00218 00219 xmlNode* initLogStream( DebugStream& deb, const std::string& nodename ); 00220 xmlNode* initLogStream( std::shared_ptr<DebugStream> deb, const std::string& nodename ); 00221 xmlNode* initLogStream( DebugStream* deb, const std::string& nodename ); 00222 00223 UniSetTypes::ListOfNode::const_iterator listNodesBegin() 00224 { 00225 return lnodes.begin(); 00226 } 00227 00228 inline UniSetTypes::ListOfNode::const_iterator listNodesEnd() 00229 { 00230 return lnodes.end(); 00231 } 00232 00234 std::shared_ptr<ObjectIndex> oind; 00235 00237 std::shared_ptr<IORFile> iorfile; 00238 00240 inline const std::shared_ptr<UniXML> getConfXML() const 00241 { 00242 return unixml; 00243 } 00244 00245 inline CORBA::ORB_ptr getORB() const 00246 { 00247 return CORBA::ORB::_duplicate(orb); 00248 } 00249 inline const CORBA::PolicyList getPolicy() const 00250 { 00251 return policyList; 00252 } 00253 00254 protected: 00255 Configuration(); 00256 00257 virtual void initConfiguration(int argc, const char* const* argv); 00258 00259 void createNodesList(); 00260 virtual void initNode( UniSetTypes::NodeInfo& ninfo, UniXML::iterator& it); 00261 00262 void initRepSections(); 00263 std::string getRepSectionName(const std::string& sec, xmlNode* secnode = 0 ); 00264 void setConfFileName( const std::string& fn = "" ); 00265 void initParameters(); 00266 void setLocalNode( const std::string& nodename ); 00267 00268 std::string getPort( const std::string& port = "" ); 00269 00270 std::string rootDir = { "" }; 00271 std::shared_ptr<UniXML> unixml; 00272 00273 int _argc = { 0 }; 00274 const char* const* _argv; 00275 CORBA::ORB_var orb; 00276 CORBA::PolicyList policyList; 00277 00278 std::string NSName = { "" }; 00279 unsigned int countOfNet = { 1 }; 00280 unsigned int repeatCount = { 3 }; 00283 unsigned int repeatTimeout = { 50 }; 00285 UniSetTypes::ListOfNode lnodes; 00286 00287 // repository 00288 std::string secRoot = { "" }; 00289 std::string secSensors = { "" }; 00290 std::string secObjects = { "" }; 00291 std::string secControlles = { "" }; 00292 std::string secServices = { "" }; 00293 00294 // xml 00295 xmlNode* xmlSensorsSec = { 0 }; 00296 xmlNode* xmlObjectsSec = { 0 }; 00297 xmlNode* xmlControllersSec = { 0 }; 00298 xmlNode* xmlServicesSec = { 0 }; 00299 xmlNode* xmlNodesSec = { 0 }; 00300 00301 ObjectId localDBServer = { UniSetTypes::DefaultObjectId }; 00302 ObjectId localNode = { UniSetTypes::DefaultObjectId }; 00303 00304 std::string localNodeName = { "" }; 00305 std::string fileConfName = { "" }; 00306 std::string imagesDir = { "" }; 00307 00308 std::string confDir = { "" }; 00309 std::string dataDir = { "" }; 00310 std::string binDir = { "" }; 00311 std::string logDir = { "" }; 00312 std::string docDir = { "" }; 00313 std::string lockDir = { "" }; 00314 bool localIOR = { false }; 00315 bool transientIOR = { false }; 00316 00317 int heartbeat_msec = { 3000 }; 00318 }; 00319 00321 std::shared_ptr<Configuration> uniset_conf(); 00322 00324 std::shared_ptr<DebugStream> ulog(); 00325 00327 std::shared_ptr<Configuration> uniset_init( int argc, const char* const* argv, const std::string& xmlfile = "configure.xml" ); 00328 00329 } // end of UniSetTypes namespace 00330 // -------------------------------------------------------------------------- 00331 // "синтаксический сахар"..для логов 00332 #define uinfo if( UniSetTypes::ulog()->debugging(Debug::INFO) ) UniSetTypes::ulog()->info() 00333 #define uwarn if( UniSetTypes::ulog()->debugging(Debug::WARN) ) UniSetTypes::ulog()->warn() 00334 #define ucrit if( UniSetTypes::ulog()->debugging(Debug::CRIT) ) UniSetTypes::ulog()->crit() 00335 #define ulog1 if( UniSetTypes::ulog()->debugging(Debug::LEVEL1) ) UniSetTypes::ulog()->level1() 00336 #define ulog2 if( UniSetTypes::ulog()->debugging(Debug::LEVEL2) ) UniSetTypes::ulog()->level2() 00337 #define ulog3 if( UniSetTypes::ulog()->debugging(Debug::LEVEL3) ) UniSetTypes::ulog()->level3() 00338 #define ulog4 if( UniSetTypes::ulog()->debugging(Debug::LEVEL4) ) UniSetTypes::ulog()->level4() 00339 #define ulog5 if( UniSetTypes::ulog()->debugging(Debug::LEVEL5) ) UniSetTypes::ulog()->level5() 00340 #define ulog6 if( UniSetTypes::ulog()->debugging(Debug::LEVEL6) ) UniSetTypes::ulog()->level6() 00341 #define ulog7 if( UniSetTypes::ulog()->debugging(Debug::LEVEL7) ) UniSetTypes::ulog()->level7() 00342 #define ulog8 if( UniSetTypes::ulog()->debugging(Debug::LEVEL8) ) UniSetTypes::ulog()->level8() 00343 #define ulog9 if( UniSetTypes::ulog()->debugging(Debug::LEVEL9) ) UniSetTypes::ulog()->level9() 00344 #define ulogsys if( UniSetTypes::ulog()->debugging(Debug::SYSTEM) ) UniSetTypes::ulog()->system() 00345 #define ulogrep if( UniSetTypes::ulog()->debugging(Debug::REPOSITORY) ) UniSetTypes::ulog()->repository() 00346 #define ulogany UniSetTypes::ulog()->any() 00347 // -------------------------------------------------------------------------- 00348 #endif // Configuration_H_
1.7.6.1