DABC (Data Acquisition Backbone Core)  2.9.9
ConfigBase.h
Go to the documentation of this file.
1 // $Id: ConfigBase.h 3862 2018-05-11 10:06:18Z linev $
2 
3 /************************************************************
4  * The Data Acquisition Backbone Core (DABC) *
5  ************************************************************
6  * Copyright (C) 2009 - *
7  * GSI Helmholtzzentrum fuer Schwerionenforschung GmbH *
8  * Planckstr. 1, 64291 Darmstadt, Germany *
9  * Contact: http://dabc.gsi.de *
10  ************************************************************
11  * This software can be used under the GPL license *
12  * agreements as stated in LICENSE.txt file *
13  * which is part of the distribution. *
14  ************************************************************/
15 
16 #ifndef DABC_ConfigBase
17 #define DABC_ConfigBase
18 
19 #ifndef DABC_XmlEngine
20 #include "dabc/XmlEngine.h"
21 #endif
22 
23 
24 namespace dabc {
25 
26  extern const char* xmlRootNode;
27  extern const char* xmlVersionAttr;
28  extern const char* xmlContext;
29  extern const char* xmlApplication;
30  extern const char* xmlAppDfltName;
31  extern const char* xmlVariablesNode;
32  extern const char* xmlNameAttr;
33  extern const char* xmlHostAttr;
34  extern const char* xmlPortAttr;
35  extern const char* xmlClassAttr;
36  extern const char* xmlDeviceAttr;
37  extern const char* xmlThreadAttr;
38  extern const char* xmlUseacknAttr;
39  extern const char* xmlOptionalAttr;
40  extern const char* xmlPoolAttr;
41  extern const char* xmlTimeoutAttr;
42  extern const char* xmlAutoAttr;
43  extern const char* xmlReconnectAttr;
44  extern const char* xmlNumReconnAttr;
45  extern const char* xmlValueAttr;
46  extern const char* xmlRunNode;
47  extern const char* xmlUserNode;
48  extern const char* xmlSshUser;
49  extern const char* xmlSshPort;
50  extern const char* xmlSshInit;
51  extern const char* xmlSshTest;
52  extern const char* xmlSshTimeout;
53  extern const char* xmlDABCSYS;
54  extern const char* xmlDABCUSERDIR;
55  extern const char* xmlDABCWORKDIR;
56  extern const char* xmlDABCNODEID;
57  extern const char* xmlDABCNUMNODES;
58  extern const char* xmlActive;
59  extern const char* xmlCopyCfg;
60  extern const char* xmlStdOut;
61  extern const char* xmlErrOut;
62  extern const char* xmlNullOut;
63  extern const char* xmlDebugger;
64  extern const char* xmlWorkDir;
65  extern const char* xmlDebuglevel;
66  extern const char* xmlNoDebugPrefix;
67  extern const char* xmlLogfile;
68  extern const char* xmlLoglevel;
69  extern const char* xmlSysloglevel;
70  extern const char* xmlSyslog;
71  extern const char* xmlLoglimit;
72  extern const char* xmlRunTime;
73  extern const char* xmlHaltTime;
74  extern const char* xmlThrdStopTime;
75  extern const char* xmlNormalMainThrd;
76  extern const char* xmlAffinity;
77  extern const char* xmlThreadsLayout;
78  extern const char* xmlTaskset;
79  extern const char* xmlLDPATH;
80  extern const char* xmlUserLib;
81  extern const char* xmlInitFunc;
82  extern const char* xmlRunFunc;
83  extern const char* xmlCpuInfo;
84  extern const char* xmlSocketHost;
85  extern const char* xmlUseControl;
86  extern const char* xmlMasterProcess;
87  extern const char* xmlPublisher;
88 
89  extern const char* xmlTrueValue;
90  extern const char* xmlFalseValue;
91 
92  enum { defaultDabcPort = 1237 };
93 
94  class ConfigIO;
95 
104  class ConfigBase {
105 
106  friend class ConfigIO;
107 
108  protected:
110 
112  int fVersion; // -1 - error, 0 - xdaq, 1 and more - dabc
113  XMLNodePointer_t fCmdVariables; // node with command variables
114  XMLNodePointer_t fVariables; // node with variables definition
115 
116  // following variables work as 'environment'
117  std::string envDABCSYS;
118  std::string envDABCUSERDIR; // dir with user plugin
119  std::string envDABCWORKDIR; // dir where application is started
120  std::string envDABCNODEID; // current node id (controlled node number)
121  std::string envDABCNUMNODES; // current number of nodes
122  std::string envHost; // host name of current context
123  std::string envContext; // name of current context
124 
127 
129 
131  XMLNodePointer_t node,
132  const char* sub1 = 0,
133  const char* sub2 = 0,
134  const char* sub3 = 0);
135 
137  XMLNodePointer_t node,
138  const char* sub1 = 0,
139  const char* sub2 = 0,
140  const char* sub3 = 0);
141 
142  std::string Find1(XMLNodePointer_t node,
143  const std::string &dflt,
144  const char* sub1,
145  const char* sub2 = 0,
146  const char* sub3 = 0);
147 
148  std::string FindN(XMLNodePointer_t node,
149  XMLNodePointer_t& prev,
150  const char* sub1,
151  const char* sub2 = 0,
152  const char* sub3 = 0);
153 
154  std::string GetEnv(const char* name);
155 
156  static bool IsNodeName(XMLNodePointer_t node, const char* name);
157  const char* GetAttr(XMLNodePointer_t node, const char* attr, const char* defvalue = 0);
158  int GetIntAttr(XMLNodePointer_t node, const char* attr, int defvalue = 0);
159 
160  std::string GetNodeValue(XMLNodePointer_t node);
161  std::string GetAttrValue(XMLNodePointer_t node, const char* name);
162 
163  XMLNodePointer_t FindChild(XMLNodePointer_t node, const char* name);
164  XMLNodePointer_t FindContext(unsigned id);
165 
166  static bool IsWildcard(const char* str);
167 
169  static bool IsContextNode(XMLNodePointer_t node);
170 
171  public:
172  ConfigBase(const char* fname = 0);
173  ~ConfigBase();
174 
175  // following methods implemented for both XDAQ/native xml formats
176 
177  bool IsOk() const { return fVersion>=0; }
178 
179  int GetVersion() const { return fVersion; }
180 
182  unsigned NumNodes();
183 
185  std::string NodeName(unsigned id);
186 
188  int NodePort(unsigned id);
189 
191  bool NodeActive(unsigned id);
192 
194  std::string ContextName(unsigned id);
195 
197  std::string SshArgs(unsigned id = 0, const char* skind = "run", const char* topcfgfile = 0, const char* topworkdir = 0);
198 
200  std::string ResolveEnv(const std::string &arg, int id = -1);
201 
203  void AddCmdVariable(const char* name, const char* value);
204  };
205 
206 }
207 
208 #endif
Base class to read configuration from xml file.
Definition: ConfigBase.h:104
int GetVersion() const
Definition: ConfigBase.h:179
std::string envDABCNUMNODES
Definition: ConfigBase.h:121
XMLNodePointer_t Variables()
Definition: ConfigBase.cxx:131
std::string envHost
Definition: ConfigBase.h:122
void AddCmdVariable(const char *name, const char *value)
Add variable from command line.
Definition: ConfigBase.cxx:151
std::string GetAttrValue(XMLNodePointer_t node, const char *name)
Definition: ConfigBase.cxx:292
std::string SshArgs(unsigned id=0, const char *skind="run", const char *topcfgfile=0, const char *topworkdir=0)
method used by run.sh script to produce command line
Definition: ConfigBase.cxx:529
int GetIntAttr(XMLNodePointer_t node, const char *attr, int defvalue=0)
Definition: ConfigBase.cxx:175
XMLNodePointer_t fCmdVariables
Definition: ConfigBase.h:113
std::string NodeName(unsigned id)
returns nodename of specified context
Definition: ConfigBase.cxx:349
XMLNodePointer_t fVariables
Definition: ConfigBase.h:114
bool NodeMaskMatch(XMLNodePointer_t node, XMLNodePointer_t mask)
Definition: ConfigBase.cxx:218
std::string envDABCUSERDIR
Definition: ConfigBase.h:118
XMLNodePointer_t FindItemMatch(XMLNodePointer_t &lastmatch, XMLNodePointer_t node, const char *sub1=0, const char *sub2=0, const char *sub3=0)
Definition: ConfigBase.cxx:192
XMLNodePointer_t RootNode()
Definition: ConfigBase.cxx:398
bool IsOk() const
Definition: ConfigBase.h:177
std::string GetEnv(const char *name)
Definition: ConfigBase.cxx:523
std::string envDABCSYS
Definition: ConfigBase.h:117
XMLNodePointer_t FindContext(unsigned id)
Definition: ConfigBase.cxx:421
int NodePort(unsigned id)
returns communication port of specified context
Definition: ConfigBase.cxx:358
std::string Find1(XMLNodePointer_t node, const std::string &dflt, const char *sub1, const char *sub2=0, const char *sub3=0)
Search first entry for item sub1/sub2/sub3 in specified node First tries full path,...
Definition: ConfigBase.cxx:304
static bool IsWildcard(const char *str)
Definition: ConfigBase.cxx:391
std::string envContext
Definition: ConfigBase.h:123
std::string FindN(XMLNodePointer_t node, XMLNodePointer_t &prev, const char *sub1, const char *sub2=0, const char *sub3=0)
Definition: ConfigBase.cxx:322
std::string GetNodeValue(XMLNodePointer_t node)
Definition: ConfigBase.cxx:284
XMLNodePointer_t FindChild(XMLNodePointer_t node, const char *name)
Definition: ConfigBase.cxx:181
std::string envDABCNODEID
Definition: ConfigBase.h:120
XMLNodePointer_t FindMatch(XMLNodePointer_t lastmatch, XMLNodePointer_t node, const char *sub1=0, const char *sub2=0, const char *sub3=0)
Definition: ConfigBase.cxx:253
const char * GetAttr(XMLNodePointer_t node, const char *attr, const char *defvalue=0)
Definition: ConfigBase.cxx:169
ConfigBase(const char *fname=0)
Definition: ConfigBase.cxx:94
std::string envDABCWORKDIR
Definition: ConfigBase.h:119
std::string ContextName(unsigned id)
returns name of specified context
Definition: ConfigBase.cxx:379
bool NodeActive(unsigned id)
returns configured (initial) state of the node
Definition: ConfigBase.cxx:371
XMLDocPointer_t fDoc
Definition: ConfigBase.h:111
static bool IsContextNode(XMLNodePointer_t node)
Identifies, if node can be identified as valid context - no any wildcards in names.
Definition: ConfigBase.cxx:404
unsigned NumNodes()
returns number of nodes in xml file
Definition: ConfigBase.cxx:334
static bool IsNodeName(XMLNodePointer_t node, const char *name)
Definition: ConfigBase.cxx:160
std::string ResolveEnv(const std::string &arg, int id=-1)
Replaces entries like ${name} be variable value.
Definition: ConfigBase.cxx:440
Interface class between xml configuration and dabc objects.
Definition: ConfigIO.h:38
Event manipulation API.
Definition: api.h:23
const char * xmlWorkDir
Definition: ConfigBase.cxx:65
const char * xmlDABCNUMNODES
Definition: ConfigBase.cxx:58
const char * xmlThrdStopTime
Definition: ConfigBase.cxx:75
const char * xmlNoDebugPrefix
Definition: ConfigBase.cxx:67
const char * xmlValueAttr
Definition: ConfigBase.cxx:46
const char * xmlDebugger
Definition: ConfigBase.cxx:64
const char * xmlLoglimit
Definition: ConfigBase.cxx:69
const char * xmlInitFunc
Definition: ConfigBase.cxx:82
const char * xmlVersionAttr
Definition: ConfigBase.cxx:28
void * XMLNodePointer_t
Definition: XmlEngine.h:25
const char * xmlTimeoutAttr
Definition: ConfigBase.cxx:42
const char * xmlLDPATH
Definition: ConfigBase.cxx:80
const char * xmlCpuInfo
Definition: ConfigBase.cxx:84
const char * xmlPoolAttr
Definition: ConfigBase.cxx:41
const char * xmlMasterProcess
Definition: ConfigBase.cxx:87
const char * xmlUseacknAttr
Definition: ConfigBase.cxx:39
const char * xmlCopyCfg
Definition: ConfigBase.cxx:60
const char * xmlDeviceAttr
Definition: ConfigBase.cxx:37
const char * xmlSshTimeout
Definition: ConfigBase.cxx:53
const char * xmlUserNode
Definition: ConfigBase.cxx:48
const char * xmlThreadsLayout
Definition: ConfigBase.cxx:78
const char * xmlAppDfltName
Definition: ConfigBase.cxx:31
const char * xmlAutoAttr
Definition: ConfigBase.cxx:43
const char * xmlApplication
Definition: ConfigBase.cxx:30
const char * xmlOptionalAttr
Definition: ConfigBase.cxx:40
const char * xmlNumReconnAttr
Definition: ConfigBase.cxx:45
const char * xmlDebuglevel
Definition: ConfigBase.cxx:66
const char * xmlLogfile
Definition: ConfigBase.cxx:68
const char * xmlSshUser
Definition: ConfigBase.cxx:49
const char * xmlRunTime
Definition: ConfigBase.cxx:73
const char * xmlReconnectAttr
Definition: ConfigBase.cxx:44
const char * xmlRunNode
Definition: ConfigBase.cxx:47
const char * xmlDABCUSERDIR
Definition: ConfigBase.cxx:55
const char * xmlVariablesNode
Definition: ConfigBase.cxx:32
const char * xmlNullOut
Definition: ConfigBase.cxx:63
const char * xmlSshTest
Definition: ConfigBase.cxx:52
const char * xmlHaltTime
Definition: ConfigBase.cxx:74
const char * xmlThreadAttr
Definition: ConfigBase.cxx:38
const char * xmlErrOut
Definition: ConfigBase.cxx:62
const char * xmlLoglevel
Definition: ConfigBase.cxx:70
const char * xmlDABCSYS
Definition: ConfigBase.cxx:54
const char * xmlTrueValue
Definition: ConfigBase.cxx:90
const char * xmlContext
Definition: ConfigBase.cxx:29
const char * xmlRootNode
Definition: ConfigBase.cxx:27
const char * xmlSyslog
Definition: ConfigBase.cxx:72
const char * xmlSocketHost
Definition: ConfigBase.cxx:85
const char * xmlPublisher
Definition: ConfigBase.cxx:88
const char * xmlActive
Definition: ConfigBase.cxx:59
const char * xmlUseControl
Definition: ConfigBase.cxx:86
const char * xmlFalseValue
Definition: ConfigBase.cxx:91
const char * xmlClassAttr
Definition: ConfigBase.cxx:36
const char * xmlAffinity
Definition: ConfigBase.cxx:77
const char * xmlStdOut
Definition: ConfigBase.cxx:61
const char * xmlDABCWORKDIR
Definition: ConfigBase.cxx:56
const char * xmlDABCNODEID
Definition: ConfigBase.cxx:57
const char * xmlNameAttr
Definition: ConfigBase.cxx:33
const char * xmlRunFunc
Definition: ConfigBase.cxx:83
const char * xmlPortAttr
Definition: ConfigBase.cxx:35
const char * xmlTaskset
Definition: ConfigBase.cxx:79
const char * xmlSysloglevel
Definition: ConfigBase.cxx:71
const char * xmlNormalMainThrd
Definition: ConfigBase.cxx:76
const char * xmlSshPort
Definition: ConfigBase.cxx:50
const char * xmlHostAttr
Definition: ConfigBase.cxx:34
@ defaultDabcPort
Definition: ConfigBase.h:92
const char * xmlUserLib
Definition: ConfigBase.cxx:81
void * XMLDocPointer_t
Definition: XmlEngine.h:28
const char * xmlSshInit
Definition: ConfigBase.cxx:51