UniSet
1.4.0
|
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 // Убрать UniXML.h, сменить unixml на указатель!!!!!!!! 00029 #include <string> 00030 #include <ostream> 00031 #include "UniXML.h" 00032 #include "UniSetTypes.h" 00033 #include "ObjectIndex.h" 00034 #include "IORFile.h" 00035 #include "MessageInterface.h" 00036 #include "Debug.h" 00037 00038 class SystemGuard; 00039 /* 00040 В функции main нужно вызвать конструктор класса Configuration 00041 fileConf - название файла конфигурации, который будет открываться 00042 из в каталоге conf того каталога, откуда была запущена программа. 00043 getTopDir позволяет получить каталог, откуда запущена программа 00044 */ 00045 00046 namespace UniSetTypes 00047 { 00053 class Configuration 00054 { 00055 public: 00056 virtual ~Configuration(); 00057 00059 Configuration( int argc, const char* const* argv, const std::string xmlfile="" ); 00060 00062 Configuration( int argc, const char* const* argv, ObjectIndex* oind, const std::string xmlfile="" ); 00063 00065 Configuration( int argc, const char* const* argv, 00066 const std::string fileConf, UniSetTypes::ObjectInfo* objectsMap ); 00067 00069 std::string getField(const std::string path); 00071 int getIntField(const std::string path); 00073 int getPIntField(const std::string path, int def); 00074 00075 xmlNode* findNode(xmlNode* node, const std::string searchnode, const std::string name = "" ); 00076 00077 // Получить узел 00078 xmlNode* getNode(const std::string& path); 00079 // Получить указанное свойство пути 00080 std::string getProp(xmlNode*, const std::string name); 00081 int getIntProp(xmlNode*, const std::string name); 00082 int getPIntProp(xmlNode*, const std::string name, int def); 00083 // Получить указанное свойство по имени узла 00084 std::string getPropByNodeName(const std::string& nodename, const std::string& prop); 00085 00086 static std::ostream& help(std::ostream& os); 00087 00088 std::string getRootDir(); 00089 inline int getArgc(){ return _argc; } 00090 inline const char* const* getArgv() const { return _argv; } 00091 inline ObjectId getTimerService() const { return localTimerService; } 00092 inline ObjectId getDBServer() const { return localDBServer; } 00093 inline ObjectId getInfoServer() const { return localInfoServer; } 00094 inline ObjectId getLocalNode() const { return localNode; } 00095 inline std::string getLocalNodeName() const { return localNodeName; } 00096 inline const std::string getNSName() const { return NSName; } 00097 00098 // repository 00099 inline std::string getRootSection() const { return secRoot; } 00100 inline std::string getSensorsSection() const { return secSensors; } 00101 inline std::string getObjectsSection() const { return secObjects; } 00102 inline std::string getControllersSection() const { return secControlles; } 00103 inline std::string getServicesSection() const { return secServices; } 00104 // xml 00105 xmlNode* getXMLSensorsSection(); 00106 xmlNode* getXMLObjectsSection(); 00107 xmlNode* getXMLControllersSection(); 00108 xmlNode* getXMLServicesSection(); 00109 xmlNode* getXMLNodesSection(); 00110 xmlNode* getXMLObjectNode( UniSetTypes::ObjectId ); 00111 UniversalIO::IOTypes getIOType( UniSetTypes::ObjectId ); 00112 UniversalIO::IOTypes getIOType( const std::string name ); 00113 00114 // net 00115 inline unsigned int getCountOfNet() const { return countOfNet; } 00116 inline unsigned int getRepeatTimeout() const { return repeatTimeout; } 00117 inline unsigned int getRepeatCount() const { return repeatCount; } 00118 00119 UniSetTypes::ObjectId getSensorID( const std::string name ); 00120 UniSetTypes::ObjectId getControllerID( const std::string name ); 00121 UniSetTypes::ObjectId getObjectID( const std::string name ); 00122 UniSetTypes::ObjectId getServiceID( const std::string name ); 00123 UniSetTypes::ObjectId getNodeID( const std::string name, const std::string alias="" ); 00124 00125 inline const std::string getConfFileName() const { return fileConfName; } 00126 inline std::string getImagesDir() const { return imagesDir; } // временно 00127 00128 inline int getHeartBeatTime(){ return heartbeat_msec; } 00129 00130 // dirs 00131 inline const std::string getConfDir() const { return confDir; } 00132 inline const std::string getDataDir() const { return dataDir; } 00133 inline const std::string getBinDir() const { return binDir; } 00134 inline const std::string getLogDir() const { return logDir; } 00135 inline const std::string getLockDir() const { return lockDir; } 00136 inline const std::string getDocDir() const { return docDir; } 00137 00138 00139 inline bool isLocalIOR(){ return localIOR; } 00140 inline bool isTransientIOR(){ return transientIOR; } 00141 00143 std::string getArgParam(const std::string name, const std::string defval=""); 00145 int getArgInt(const std::string name, const std::string defval=""); 00147 int getArgPInt(const std::string name, int defval); 00148 int getArgPInt(const std::string name, const std::string strdefval, int defval); 00149 00150 xmlNode* initDebug( DebugStream& deb, const std::string& nodename ); 00151 00152 UniSetTypes::ListOfNode::const_iterator listNodesBegin() 00153 { 00154 return lnodes.begin(); 00155 } 00156 00157 inline UniSetTypes::ListOfNode::const_iterator listNodesEnd() 00158 { 00159 return lnodes.end(); 00160 } 00161 00163 MessageInterface* mi; 00164 00166 ObjectIndex* oind; 00167 00169 IORFile iorfile; 00170 00172 inline UniXML* getConfXML(){ return &unixml; } 00173 00174 CORBA::ORB_ptr getORB() { return CORBA::ORB::_duplicate(orb); } 00175 CORBA::PolicyList getPolicy() const { return policyList; } 00176 00177 protected: 00178 Configuration(); 00179 00180 virtual void initConfiguration(int argc, const char* const* argv); 00181 00182 void createNodesList(); 00183 virtual void initNode( UniSetTypes::NodeInfo& ninfo, UniXML_iterator& it); 00184 00185 void initRepSections(); 00186 std::string getRepSectionName(const std::string sec, xmlNode* secnode=0 ); 00187 void setConfFileName(const std::string fn=""); 00188 void initParameters(); 00189 void setLocalNode( std::string nodename ); 00190 00191 std::string getPort(const std::string port=""); 00192 00193 friend class ::SystemGuard; 00194 // friend bool SystemGuard::pingNode(); 00195 std::string rootDir; 00196 UniXML unixml; 00197 00198 int _argc; 00199 const char* const* _argv; 00200 CORBA::ORB_var orb; 00201 CORBA::PolicyList policyList; 00202 00203 std::string NSName; 00204 unsigned int countOfNet; 00205 unsigned int repeatCount; 00208 unsigned int repeatTimeout; 00210 UniSetTypes::ListOfNode lnodes; 00211 00212 // repository 00213 std::string secRoot; 00214 std::string secSensors; 00215 std::string secObjects; 00216 std::string secControlles; 00217 std::string secServices; 00218 00219 // xml 00220 static xmlNode* xmlSensorsSec; 00221 static xmlNode* xmlObjectsSec; 00222 static xmlNode* xmlControllersSec; 00223 static xmlNode* xmlServicesSec; 00224 static xmlNode* xmlNodesSec; 00225 00226 ObjectId localTimerService; 00227 ObjectId localDBServer; 00228 ObjectId localInfoServer; 00229 ObjectId localNode; 00230 00231 std::string localNodeName; 00232 std::string fileConfName; 00233 std::string imagesDir; 00234 00235 std::string confDir; 00236 std::string dataDir; 00237 std::string binDir; 00238 std::string logDir; 00239 std::string docDir; 00240 std::string lockDir; 00241 bool localIOR; 00242 bool transientIOR; 00243 00244 int heartbeat_msec; 00245 }; 00246 00248 extern Configuration* conf; 00249 00251 extern DebugStream unideb; 00252 00253 00254 // Инициализация UniSetTypes::conf. 00255 // ( учитываются параметры командной строки --confile и --id-from-config ) 00256 void uniset_init( int argc, const char* const* argv, const std::string xmlfile="configure.xml" ); 00257 00258 00259 } // end of UniSetTypes namespace 00260 00261 #endif // Configuration_H_