UniSet  2.8.0
Configuration.h
1 /*
2  * Copyright (c) 2015 Pavel Vainerman.
3  *
4  * This program is free software: you can redistribute it and/or modify
5  * it under the terms of the GNU Lesser General Public License as
6  * published by the Free Software Foundation, version 2.1.
7  *
8  * This program is distributed in the hope that it will be useful, but
9  * WITHOUT ANY WARRANTY; without even the implied warranty of
10  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
11  * Lesser General Lesser Public License for more details.
12  *
13  * You should have received a copy of the GNU Lesser General Public License
14  * along with this program. If not, see <http://www.gnu.org/licenses/>.
15  */
16 // --------------------------------------------------------------------------
21 // --------------------------------------------------------------------------
22 #ifndef Configuration_H_
23 #define Configuration_H_
24 // --------------------------------------------------------------------------
25 #include <memory>
26 #include <string>
27 #include <ostream>
28 #include "UniXML.h"
29 #include "UniSetTypes.h"
30 #include "ObjectIndex.h"
31 #include "PassiveTimer.h" // for timeout_t
32 #include "IORFile.h"
33 #include "Debug.h"
34 // --------------------------------------------------------------------------
35 /*
36  В функции main нужно обязательно вызывать uniset::uniset_init(argc,argv);
37 */
38 namespace uniset
39 {
46  {
47  public:
48  virtual ~Configuration();
49 
50  static std::ostream& help(std::ostream& os);
51 
53  Configuration( int argc, const char* const* argv, const std::string& xmlfile = "" );
54 
56  Configuration( int argc, const char* const* argv, std::shared_ptr<ObjectIndex> oind, const std::string& xmlfile = "" );
57 
59  Configuration( int argc, const char* const* argv,
60  const std::string& fileConf, uniset::ObjectInfo* objectsMap );
61 
63  std::string getField(const std::string& path) const noexcept;
65  int getIntField(const std::string& path) const noexcept;
67  int getPIntField(const std::string& path, int def) const noexcept;
68 
69  xmlNode* findNode(xmlNode* node, const std::string& searchnode, const std::string& name = "" ) const noexcept;
70 
71  // Получить узел
72  xmlNode* getNode(const std::string& path) const noexcept;
73 
74  // Получить указанное свойство пути
75  std::string getProp(xmlNode*, const std::string& name) const noexcept;
76  int getIntProp(xmlNode*, const std::string& name) const noexcept;
77  int getPIntProp(xmlNode*, const std::string& name, int def) const noexcept;
78 
79  // Получить указанное свойство по имени узла
80  std::string getPropByNodeName(const std::string& nodename, const std::string& prop) const noexcept;
81 
82  std::string getRootDir() const noexcept;
83  int getArgc() const noexcept;
84  const char* const* getArgv() const noexcept;
85  ObjectId getDBServer() const noexcept;
86  ObjectId getLocalNode() const noexcept;
87  std::string getLocalNodeName() const noexcept;
88  const std::string getNSName() const noexcept;
89 
90  // repository
91  std::string getRootSection() const noexcept;
92  std::string getSensorsSection() const noexcept;
93  std::string getObjectsSection() const noexcept;
94  std::string getControllersSection() const noexcept;
95  std::string getServicesSection() const noexcept;
96  // xml
97  xmlNode* getXMLSensorsSection() noexcept;
98  xmlNode* getXMLObjectsSection() noexcept;
99  xmlNode* getXMLControllersSection() noexcept;
100  xmlNode* getXMLServicesSection() noexcept;
101  xmlNode* getXMLNodesSection() noexcept;
102  xmlNode* getXMLObjectNode( uniset::ObjectId ) const noexcept;
103 
104  UniversalIO::IOType getIOType( uniset::ObjectId ) const noexcept;
105  UniversalIO::IOType getIOType( const std::string& name ) const noexcept;
106 
107  // net
108  size_t getCountOfNet() const noexcept;
109  timeout_t getRepeatTimeout() const noexcept;
110  size_t getRepeatCount() const noexcept;
111 
112  uniset::ObjectId getSensorID( const std::string& name ) const noexcept;
113  uniset::ObjectId getControllerID( const std::string& name ) const noexcept;
114  uniset::ObjectId getObjectID( const std::string& name ) const noexcept;
115  uniset::ObjectId getServiceID( const std::string& name ) const noexcept;
116  uniset::ObjectId getNodeID( const std::string& name ) const noexcept;
117 
118  // поиск в sensors,objects,controlles,services,nodes
119  uniset::ObjectId getAnyID( const std::string& name ) const noexcept;
120 
121 
122  const std::string getConfFileName() const noexcept;
123  std::string getImagesDir() const noexcept;
124 
125  timeout_t getHeartBeatTime() const noexcept;
126  timeout_t getNCReadyTimeout() const noexcept;
127  timeout_t getStartupIgnoreTimeout() const noexcept;
128 
129  // dirs
130  const std::string getConfDir() const noexcept;
131  const std::string getDataDir() const noexcept;
132  const std::string getBinDir() const noexcept;
133  const std::string getLogDir() const noexcept;
134  const std::string getLockDir() const noexcept;
135  const std::string getDocDir() const noexcept;
136 
137  bool isLocalIOR() const noexcept;
138  bool isTransientIOR() const noexcept;
139 
141  std::string getArgParam(const std::string& name, const std::string& defval = "") const noexcept;
142 
144  std::string getArg2Param(const std::string& name, const std::string& defval, const std::string& defval2 = "") const noexcept;
145 
147  int getArgInt(const std::string& name, const std::string& defval = "") const noexcept;
148 
150  int getArgPInt(const std::string& name, int defval) const noexcept;
151  int getArgPInt(const std::string& name, const std::string& strdefval, int defval) const noexcept;
152 
153  xmlNode* initLogStream( DebugStream& deb, const std::string& nodename ) noexcept;
154  xmlNode* initLogStream( std::shared_ptr<DebugStream> deb, const std::string& nodename ) noexcept;
155  xmlNode* initLogStream( DebugStream* deb, const std::string& nodename ) noexcept;
156 
157  uniset::ListOfNode::const_iterator listNodesBegin() const noexcept;
158  uniset::ListOfNode::const_iterator listNodesEnd() const noexcept;
159 
161  std::shared_ptr<ObjectIndex> oind;
162 
164  std::shared_ptr<IORFile> iorfile;
165 
167  const std::shared_ptr<UniXML> getConfXML() const noexcept;
168 
169  CORBA::ORB_ptr getORB() const;
170  const CORBA::PolicyList getPolicy() const noexcept;
171 
172  static bool checkOmniORBendPoint( const std::string& endPoint );
173 
174  protected:
175  Configuration();
176 
177  virtual void initConfiguration(int argc, const char* const* argv);
178 
179  void createNodesList();
180  virtual void initNode( uniset::NodeInfo& ninfo, UniXML::iterator& it) noexcept;
181 
182  void initRepSections();
183  std::pair<std::string,xmlNode*> getRepSectionName( const std::string& sec );
184  void setConfFileName( const std::string& fn = "" );
185  void initParameters();
186  void setLocalNode( const std::string& nodename );
187 
188  std::string getPort( const std::string& port = "" ) const noexcept;
189 
190  std::string rootDir = { "" };
191  std::shared_ptr<UniXML> unixml;
192 
193  int _argc = { 0 };
194  const char** _argv = { nullptr };
195  CORBA::ORB_var orb;
196  CORBA::PolicyList policyList;
197 
198  std::string NSName = { "" };
199  size_t countOfNet = { 1 };
200  size_t repeatCount = { 3 };
203  timeout_t repeatTimeout = { 50 };
205  uniset::ListOfNode lnodes;
206 
207  // repository
208  std::string secRoot = { "" };
209  std::string secSensors = { "" };
210  std::string secObjects = { "" };
211  std::string secControlles = { "" };
212  std::string secServices = { "" };
213 
214  // xml
215  xmlNode* xmlSensorsSec = { 0 };
216  xmlNode* xmlObjectsSec = { 0 };
217  xmlNode* xmlControllersSec = { 0 };
218  xmlNode* xmlServicesSec = { 0 };
219  xmlNode* xmlNodesSec = { 0 };
220 
221  ObjectId localDBServer = { uniset::DefaultObjectId };
222  ObjectId localNode = { uniset::DefaultObjectId };
223 
224  std::string localNodeName = { "" };
225  std::string fileConfName = { "" };
226  std::string imagesDir = { "" };
227 
228  std::string confDir = { "" };
229  std::string dataDir = { "" };
230  std::string binDir = { "" };
231  std::string logDir = { "" };
232  std::string docDir = { "" };
233  std::string lockDir = { "" };
234  bool localIOR = { false };
235  bool transientIOR = { false };
236 
237  timeout_t heartbeat_msec = { 3000 };
238  timeout_t ncreadytimeout_msec = { 180000 };
239  timeout_t startupIgnoretimeout_msec = { 5000 };
240  };
241 
243  std::shared_ptr<Configuration> uniset_conf() noexcept;
244 
246  std::shared_ptr<DebugStream> ulog() noexcept;
247 
249  std::shared_ptr<Configuration> uniset_init( int argc, const char* const* argv, const std::string& xmlfile = "configure.xml" );
250  // --------------------------------------------------------------------------
251 } // end of uniset namespace
252 // --------------------------------------------------------------------------
253 // "синтаксический сахар" для логов
254 #define uinfo if( uniset::ulog()->debugging(Debug::INFO) ) uniset::ulog()->info()
255 #define uwarn if( uniset::ulog()->debugging(Debug::WARN) ) uniset::ulog()->warn()
256 #define ucrit if( uniset::ulog()->debugging(Debug::CRIT) ) uniset::ulog()->crit()
257 #define ulog1 if( uniset::ulog()->debugging(Debug::LEVEL1) ) uniset::ulog()->level1()
258 #define ulog2 if( uniset::ulog()->debugging(Debug::LEVEL2) ) uniset::ulog()->level2()
259 #define ulog3 if( uniset::ulog()->debugging(Debug::LEVEL3) ) uniset::ulog()->level3()
260 #define ulog4 if( uniset::ulog()->debugging(Debug::LEVEL4) ) uniset::ulog()->level4()
261 #define ulog5 if( uniset::ulog()->debugging(Debug::LEVEL5) ) uniset::ulog()->level5()
262 #define ulog6 if( uniset::ulog()->debugging(Debug::LEVEL6) ) uniset::ulog()->level6()
263 #define ulog7 if( uniset::ulog()->debugging(Debug::LEVEL7) ) uniset::ulog()->level7()
264 #define ulog8 if( uniset::ulog()->debugging(Debug::LEVEL8) ) uniset::ulog()->level8()
265 #define ulog9 if( uniset::ulog()->debugging(Debug::LEVEL9) ) uniset::ulog()->level9()
266 #define ulogsys if( uniset::ulog()->debugging(Debug::SYSTEM) ) uniset::ulog()->system()
267 #define ulogrep if( uniset::ulog()->debugging(Debug::REPOSITORY) ) uniset::ulog()->repository()
268 #define ulogany uniset::ulog()->any()
269 // --------------------------------------------------------------------------
270 #endif // Configuration_H_
ObjectId getDBServer() const noexcept
Definition: Configuration.cc:801
std::string getArg2Param(const std::string &name, const std::string &defval, const std::string &defval2="") const noexcept
Definition: Configuration.cc:517
Definition: DebugStream.h:91
timeout_t repeatTimeout
Definition: Configuration.h:203
std::string getArgParam(const std::string &name, const std::string &defval="") const noexcept
Definition: Configuration.cc:522
Definition: CommonEventLoop.h:14
ObjectId getLocalNode() const noexcept
Definition: Configuration.cc:806
std::string getField(const std::string &path) const noexcept
Получить значение полей с путём path.
Definition: Configuration.cc:755
std::shared_ptr< IORFile > iorfile
Definition: Configuration.h:164
int getArgInt(const std::string &name, const std::string &defval="") const noexcept
Definition: Configuration.cc:527
Definition: UniXML.h:116
std::string getRootDir() const noexcept
Definition: Configuration.cc:786
Definition: Configuration.h:45
std::shared_ptr< Configuration > uniset_conf() noexcept
Definition: Configuration.cc:91
const ObjectId DefaultObjectId
Definition: UniSetTypes.h:69
int getPIntField(const std::string &path, int def) const noexcept
Получить число из поле с путём path (или def, если значение <= 0)
Definition: Configuration.cc:767
size_t repeatCount
Definition: Configuration.h:200
std::string getLocalNodeName() const noexcept
Definition: Configuration.cc:811
size_t countOfNet
Definition: Configuration.h:199
std::shared_ptr< DebugStream > ulog() noexcept
Definition: Configuration.cc:81
const std::shared_ptr< UniXML > getConfXML() const noexcept
Definition: Configuration.cc:1067
int getIntField(const std::string &path) const noexcept
Получить число из поле с путём path.
Definition: Configuration.cc:761
Definition: UniSetTypes.h:144
std::shared_ptr< Configuration > uniset_init(int argc, const char *const *argv, const std::string &xmlfile="configure.xml")
Definition: Configuration.cc:1436
std::string NSName
Definition: Configuration.h:198
std::shared_ptr< ObjectIndex > oind
Definition: Configuration.h:161
int getArgPInt(const std::string &name, int defval) const noexcept
Definition: Configuration.cc:532
Definition: UniSetTypes_i.idl:54
long ObjectId
Definition: UniSetTypes_i.idl:30