UniSet @VERSION@
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*/
38namespace uniset
39{
46 {
47 public:
48 virtual ~Configuration();
49
50 static std::string help();
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<UniXML> xml );
57
59 Configuration( int argc, const char* const* argv, std::shared_ptr<ObjectIndex> oind, const std::string& xmlfile = "" );
60
62 Configuration( int argc, const char* const* argv,
63 const std::string& fileConf, uniset::ObjectInfo* objectsMap );
64
66 std::string getField(const std::string& path) const noexcept;
68 int getIntField(const std::string& path) const noexcept;
70 int getPIntField(const std::string& path, int def) const noexcept;
71
72 xmlNode* findNode(xmlNode* node, const std::string& searchnode, const std::string& name = "" ) const noexcept;
73
74 // Получить узел
75 xmlNode* getNode(const std::string& path) const noexcept;
76
77 // Получить указанное свойство пути
78 std::string getProp(xmlNode*, const std::string& name) const noexcept;
79 int getIntProp(xmlNode*, const std::string& name) const noexcept;
80 int getPIntProp(xmlNode*, const std::string& name, int def) const noexcept;
81
82 // Получить указанное свойство по имени узла
83 std::string getPropByNodeName(const std::string& nodename, const std::string& prop) const noexcept;
84
85 std::string getRootDir() const noexcept;
86 int getArgc() const noexcept;
87 const char* const* getArgv() const noexcept;
88 ObjectId getDBServer() const noexcept;
89 ObjectId getLocalNode() const noexcept;
90 std::string getLocalNodeName() const noexcept;
91 const std::string getNSName() const noexcept;
92
93 // repository
94 std::string getRootSection() const noexcept;
95 std::string getSensorsSection() const noexcept;
96 std::string getObjectsSection() const noexcept;
97 std::string getControllersSection() const noexcept;
98 std::string getServicesSection() const noexcept;
99 // xml
100 xmlNode* getXMLSensorsSection() noexcept;
101 xmlNode* getXMLObjectsSection() noexcept;
102 xmlNode* getXMLControllersSection() noexcept;
103 xmlNode* getXMLServicesSection() noexcept;
104 xmlNode* getXMLNodesSection() noexcept;
105 xmlNode* getXMLObjectNode( uniset::ObjectId ) const noexcept;
106
107 UniversalIO::IOType getIOType( uniset::ObjectId ) const noexcept;
108 UniversalIO::IOType getIOType( const std::string& name ) const noexcept;
109
110 // net
111 size_t getCountOfNet() const noexcept;
112 timeout_t getRepeatTimeout() const noexcept;
113 size_t getRepeatCount() const noexcept;
114
115 uniset::ObjectId getSensorID( const std::string& name ) const noexcept;
116 uniset::ObjectId getControllerID( const std::string& name ) const noexcept;
117 uniset::ObjectId getObjectID( const std::string& name ) const noexcept;
118 uniset::ObjectId getServiceID( const std::string& name ) const noexcept;
119 uniset::ObjectId getNodeID( const std::string& name ) const noexcept;
120
121 // поиск в sensors,objects,controlles,services,nodes
122 uniset::ObjectId getAnyID( const std::string& name ) const noexcept;
123 uniset::ObjectId getAnyObjectID( const std::string& name ) const noexcept;
124
125 const std::string getConfFileName() const noexcept;
126 std::string getImagesDir() const noexcept;
127 std::string getNodeIp( uniset::ObjectId node );
128
129 timeout_t getHeartBeatTime() const noexcept;
130 timeout_t getNCReadyTimeout() const noexcept;
131 timeout_t getStartupIgnoreTimeout() const noexcept;
132
133 // dirs
134 const std::string getConfDir() const noexcept;
135 const std::string getDataDir() const noexcept;
136 const std::string getBinDir() const noexcept;
137 const std::string getLogDir() const noexcept;
138 const std::string getLockDir() const noexcept;
139 const std::string getDocDir() const noexcept;
140
141 bool isLocalIOR() const noexcept;
142 bool isTransientIOR() const noexcept;
143 size_t getHttpResovlerPort() const noexcept;
144
146 std::string getArgParam(const std::string& name, const std::string& defval = "") const noexcept;
147
149 std::string getArg2Param(const std::string& name, const std::string& defval, const std::string& defval2 = "") const noexcept;
150
152 int getArgInt(const std::string& name, const std::string& defval = "") const noexcept;
153
155 int getArgPInt(const std::string& name, int defval) const noexcept;
156 int getArgPInt(const std::string& name, const std::string& strdefval, int defval) const noexcept;
157
158 xmlNode* initLogStream( DebugStream& deb, const std::string& nodename ) noexcept;
159 xmlNode* initLogStream( std::shared_ptr<DebugStream> deb, const std::string& nodename ) noexcept;
160 xmlNode* initLogStream( DebugStream* deb, const std::string& nodename ) noexcept;
161
162 uniset::ListOfNode::const_iterator listNodesBegin() const noexcept;
163 uniset::ListOfNode::const_iterator listNodesEnd() const noexcept;
164
166 std::shared_ptr<ObjectIndex> oind;
167
169 std::shared_ptr<IORFile> iorfile;
170
172 const std::shared_ptr<UniXML> getConfXML() const noexcept;
173
174 int getORBPort() const noexcept;
175 CORBA::ORB_ptr getORB() const;
176 const CORBA::PolicyList getPolicy() const noexcept;
177
178 static bool checkOmniORBendPoint( const std::string& endPoint );
179
180 protected:
182
183 virtual void initConfiguration(int argc, const char* const* argv);
184
185 void createNodesList();
186 virtual void initNode( uniset::NodeInfo& ninfo, UniXML::iterator& it) noexcept;
187
188 void initRepSections();
189 std::pair<std::string, xmlNode*> getRepSectionName( const std::string& sec );
190 void setConfFileName( const std::string& fn = "" );
191 void initParameters();
192 void setLocalNode( const std::string& nodename );
193
194 std::string getPort( const std::string& port = "" ) const noexcept;
195
196 std::string rootDir = { "" };
197 std::shared_ptr<UniXML> unixml;
198
199 int _argc = { 0 };
200 const char** _argv = { nullptr };
201 CORBA::ORB_var orb;
202 CORBA::PolicyList policyList;
203
204 std::string NSName = { "" };
205 size_t countOfNet = { 1 };
206 size_t repeatCount = { 3 };
209 timeout_t repeatTimeout = { 50 };
211 size_t httpResolverPort = { 8008 };
212
213 uniset::ListOfNode lnodes;
214
215 // repository
216 std::string secRoot = { "" };
217 std::string secSensors = { "" };
218 std::string secObjects = { "" };
219 std::string secControlles = { "" };
220 std::string secServices = { "" };
221
222 // xml
223 xmlNode* xmlSensorsSec = { 0 };
224 xmlNode* xmlObjectsSec = { 0 };
225 xmlNode* xmlControllersSec = { 0 };
226 xmlNode* xmlServicesSec = { 0 };
227 xmlNode* xmlNodesSec = { 0 };
228
229 ObjectId localDBServer = { uniset::DefaultObjectId };
230 ObjectId localNode = { uniset::DefaultObjectId };
231
232 std::string localNodeName = { "" };
233 std::string fileConfName = { "" };
234 std::string imagesDir = { "" };
235
236 std::string confDir = { "" };
237 std::string dataDir = { "" };
238 std::string binDir = { "" };
239 std::string logDir = { "" };
240 std::string docDir = { "" };
241 std::string lockDir = { "" };
242 bool localIOR = { false };
243 bool transientIOR = { false };
244
245 timeout_t heartbeat_msec = { 3000 };
246 timeout_t ncreadytimeout_msec = { 180000 };
247 timeout_t startupIgnoretimeout_msec = { 5000 };
248 };
249
251 std::shared_ptr<Configuration> uniset_conf() noexcept;
252
254 std::shared_ptr<DebugStream> ulog() noexcept;
255
257 std::shared_ptr<Configuration> uniset_init( int argc, const char* const* argv, const std::string& xmlfile = "configure.xml" );
258 std::shared_ptr<Configuration> uniset_init( int argc, const char* const* argv, std::shared_ptr<UniXML> xml );
259 // --------------------------------------------------------------------------
260} // end of uniset namespace
261// --------------------------------------------------------------------------
262// "синтаксический сахар" для логов
263#define uinfo if( uniset::ulog()->debugging(Debug::INFO) ) uniset::ulog()->info()
264#define uwarn if( uniset::ulog()->debugging(Debug::WARN) ) uniset::ulog()->warn()
265#define ucrit if( uniset::ulog()->debugging(Debug::CRIT) ) uniset::ulog()->crit()
266#define ulog1 if( uniset::ulog()->debugging(Debug::LEVEL1) ) uniset::ulog()->level1()
267#define ulog2 if( uniset::ulog()->debugging(Debug::LEVEL2) ) uniset::ulog()->level2()
268#define ulog3 if( uniset::ulog()->debugging(Debug::LEVEL3) ) uniset::ulog()->level3()
269#define ulog4 if( uniset::ulog()->debugging(Debug::LEVEL4) ) uniset::ulog()->level4()
270#define ulog5 if( uniset::ulog()->debugging(Debug::LEVEL5) ) uniset::ulog()->level5()
271#define ulog6 if( uniset::ulog()->debugging(Debug::LEVEL6) ) uniset::ulog()->level6()
272#define ulog7 if( uniset::ulog()->debugging(Debug::LEVEL7) ) uniset::ulog()->level7()
273#define ulog8 if( uniset::ulog()->debugging(Debug::LEVEL8) ) uniset::ulog()->level8()
274#define ulog9 if( uniset::ulog()->debugging(Debug::LEVEL9) ) uniset::ulog()->level9()
275#define ulogsys if( uniset::ulog()->debugging(Debug::SYSTEM) ) uniset::ulog()->system()
276#define ulogrep if( uniset::ulog()->debugging(Debug::REPOSITORY) ) uniset::ulog()->repository()
277#define ulogany uniset::ulog()->any()
278// --------------------------------------------------------------------------
279#endif // Configuration_H_
Definition DebugStream.h:62
Definition Configuration.h:46
const std::shared_ptr< UniXML > getConfXML() const noexcept
Definition Configuration.cc:1151
size_t countOfNet
Definition Configuration.h:205
std::string getRootDir() const noexcept
Definition Configuration.cc:859
std::string getArgParam(const std::string &name, const std::string &defval="") const noexcept
Definition Configuration.cc:551
std::string getArg2Param(const std::string &name, const std::string &defval, const std::string &defval2="") const noexcept
Definition Configuration.cc:546
ObjectId getDBServer() const noexcept
Definition Configuration.cc:874
std::string getLocalNodeName() const noexcept
Definition Configuration.cc:884
std::string getField(const std::string &path) const noexcept
Получить значение полей с путём path.
Definition Configuration.cc:828
timeout_t repeatTimeout
Definition Configuration.h:209
int getPIntField(const std::string &path, int def) const noexcept
Получить число из поле с путём path (или def, если значение <= 0)
Definition Configuration.cc:840
std::string NSName
Definition Configuration.h:204
int getIntField(const std::string &path) const noexcept
Получить число из поле с путём path.
Definition Configuration.cc:834
int getArgPInt(const std::string &name, int defval) const noexcept
Definition Configuration.cc:561
std::shared_ptr< ObjectIndex > oind
Definition Configuration.h:166
std::shared_ptr< IORFile > iorfile
Definition Configuration.h:169
int getArgInt(const std::string &name, const std::string &defval="") const noexcept
Definition Configuration.cc:556
ObjectId getLocalNode() const noexcept
Definition Configuration.cc:879
size_t repeatCount
Definition Configuration.h:206
Definition UniXML.h:124
STL namespace.
Definition AccessConfig.h:30
std::shared_ptr< Configuration > uniset_init(int argc, const char *const *argv, const std::string &xmlfile="configure.xml")
Definition Configuration.cc:1587
const ObjectId DefaultObjectId
Definition UniSetTypes.h:71
std::shared_ptr< Configuration > uniset_conf() noexcept
Definition Configuration.cc:106
std::shared_ptr< DebugStream > ulog() noexcept
Definition Configuration.cc:96
long ObjectId
Definition UniSetTypes_i.idl:30
Definition UniSetTypes_i.idl:55
Definition UniSetTypes.h:156