Belle II Software development
NSMCallback Class Reference
Inheritance diagram for NSMCallback:
AbstractNSMCallback Callback RCCallback DqmMasterCallback ERecoMasterCallback ERecoRunControlCallback EventServerCallback RFMasterCallback RFRunControlCallback

Public Member Functions

 NSMCallback (int timeout=5)
 
virtual void init (NSMCommunicator &)
 
virtual void term ()
 
virtual void timeout (NSMCommunicator &)
 
bool perform (NSMCommunicator &com) override
 
virtual void ok (const char *, const char *)
 
virtual void fatal (const char *, const char *)
 
virtual void error (const char *, const char *)
 
virtual void logset (const DAQLogMessage &)
 
virtual void vget (const std::string &nodename, const std::string &vname)
 
virtual void vset (NSMCommunicator &com, const NSMVar &var)
 
virtual void vlistget (NSMCommunicator &com)
 
virtual void vlistset (NSMCommunicator &com)
 
virtual void vreply (NSMCommunicator &, const std::string &, bool)
 
void reply (const NSMMessage &msg)
 
void log (LogFile::Priority pri, const char *format,...)
 
void log (LogFile::Priority pri, const std::string &msg)
 
int reset ()
 
NSMDataMap & getDataMap ()
 
NSMData & getData (const std::string &name)
 
NSMData & getData ()
 
void openData (const std::string &name, const std::string &format, int revision=-1)
 
void allocData (const std::string &name, const std::string &format, int revision)
 
const std::string & getCategory () const
 
void setCategory (const std::string &category)
 
int addDB (const DBObject &obj)
 
bool get (const NSMNode &node, const std::string &name, int &val, int timeout=5)
 
bool get (const NSMNode &node, const std::string &name, float &val, int timeout=5)
 
bool get (const NSMNode &node, const std::string &name, std::string &val, int timeout=5)
 
bool get (const NSMNode &node, const std::string &name, std::vector< int > &val, int timeout=5)
 
bool get (const NSMNode &node, const std::string &name, std::vector< float > &val, int timeout=5)
 
bool get (const NSMNode &node, NSMVHandler *handler, int timeout=5)
 
bool get (const DBObject &obj)
 
bool get (const std::string &name, int &val)
 
bool get (const std::string &name, float &val)
 
bool get (const std::string &name, std::string &val)
 
bool get (const std::string &name, std::vector< int > &val)
 
bool get (const std::string &name, std::vector< float > &val)
 
bool get (const std::string &node, const std::string &name, int &val)
 
bool get (const std::string &node, const std::string &name, float &val)
 
bool get (const std::string &node, const std::string &name, std::string &val)
 
bool get (const std::string &node, const std::string &name, std::vector< int > &val)
 
bool get (const std::string &node, const std::string &name, std::vector< float > &val)
 
bool get (const NSMNode &node, NSMVar &var, int timeout=5)
 
bool set (const NSMNode &node, const std::string &name, int val, int timeout=5)
 
bool set (const NSMNode &node, const std::string &name, float val, int timeout=5)
 
bool set (const NSMNode &node, const std::string &name, const std::string &val, int timeout=5)
 
bool set (const NSMNode &node, const std::string &name, const std::vector< int > &val, int timeout=5)
 
bool set (const NSMNode &node, const std::string &name, const std::vector< float > &val, int timeout=5)
 
bool set (const std::string &name, int val)
 
bool set (const std::string &name, float val)
 
bool set (const std::string &name, const std::string &val)
 
bool set (const std::string &name, const std::vector< int > &val)
 
bool set (const std::string &name, const std::vector< float > &val)
 
bool set (const std::string &node, const std::string &name, int val)
 
bool set (const std::string &node, const std::string &name, float val)
 
bool set (const std::string &node, const std::string &name, const std::string &val)
 
bool set (const std::string &node, const std::string &name, const std::vector< int > &val)
 
bool set (const std::string &node, const std::string &name, const std::vector< float > &val)
 
bool set (const NSMNode &node, const NSMVar &var, int timeout=5)
 
int wait (double timeout=5)
 
bool try_wait ()
 
NSMNode & getNode ()
 
const NSMNode & getNode () const
 
void setNode (const NSMNode &node)
 
int getTimeout () const
 
void setTimeout (int timeout)
 
int add (NSMVHandler *handler, bool overwrite=true, bool isdump=true)
 
void remove (const std::string &node, const std::string &name)
 
void remove (const std::string &name)
 
void remove (const DBObject &obj)
 
StringList & getHandlerNames ()
 
NSMVHandlerList & getHandlers ()
 
NSMVHandler & getHandler (const std::string &name)
 
NSMVHandler & getHandler (const std::string &node, const std::string &name)
 
void setUseGet (const std::string &name, bool use)
 
void setUseSet (const std::string &name, bool use)
 
void setRevision (int revision)
 
int getRevision () const
 

Static Public Member Functions

static NSMCommunicator & wait (const NSMNode &node, const NSMCommand &cmd, double timeout=5)
 

Protected Member Functions

void notify (const NSMVar &var) override
 
void reg (const NSMCommand &cmd)
 
void addNode (const NSMNode &node)
 
const NSMNodeMap & getNodes ()
 
void setLogNode (const NSMNode &node)
 
const NSMNode & getLogNode ()
 

Static Protected Member Functions

static void readVar (const NSMMessage &msg, NSMVar &var)
 

Private Types

typedef std::vector< NSMCommand > NSMCommandList
 

Private Member Functions

int addDefaultHandlers ()
 
NSMCommandList & getCommandList ()
 
void alloc_open (NSMCommunicator &com)
 
template<typename T>
bool get_t (const NSMNode &node, const std::string &name, T &val, int timeout, NSMVar::Type type=NSMVar::NONE, int len=0)
 
template<typename T>
bool get_t (const std::string &node, const std::string &name, T &val)
 
template<typename T>
bool set_t (const std::string &node, const std::string &name, const T &val)
 
NSMVHandler * getHandler_p (const std::string &node, const std::string &name)
 

Private Attributes

NSMCommandList m_cmd_v
 
NSMNodeMap m_nodes
 
NSMData m_data
 
NSMDataMap m_datas
 
NSMNode m_lognode
 
std::string m_category
 
NSMNode m_node
 
int m_timeout
 
NSMNodeMapMap m_node_v_m
 
int m_revision
 
NSMVHandlerList m_handler
 
StringList m_hnames
 

Friends

class NSMCommunicator
 
class NSMNodeDaemon
 

Detailed Description

Definition at line 31 of file NSMCallback.h.

Member Typedef Documentation

◆ NSMCommandList

typedef std::vector<NSMCommand> NSMCommandList
private

Definition at line 83 of file NSMCallback.h.

Constructor & Destructor Documentation

◆ NSMCallback()

NSMCallback ( int timeout = 5)
explicit

Definition at line 24 of file NSMCallback.cc.

25 : AbstractNSMCallback(timeout)
26{
27 reg(NSMCommand::OK);
28 reg(NSMCommand::ERROR);
29 reg(NSMCommand::LOG);
30 reg(NSMCommand::VGET);
31 reg(NSMCommand::VSET);
32 reg(NSMCommand::VREPLY);
33 reg(NSMCommand::VLISTGET);
34 reg(NSMCommand::VLISTSET);
35
36 addDefaultHandlers();
37}

◆ ~NSMCallback()

virtual ~NSMCallback ( )
inlineoverridevirtual

Definition at line 38 of file NSMCallback.h.

38{}

Member Function Documentation

◆ add()

int add ( NSMVHandler * handler,
bool overwrite = true,
bool isdump = true )
inherited

Definition at line 25 of file Callback.cc.

26{
27 if (handler) {
28 std::string hname = handler->getNode() + "@" + handler->getName();
29 if (m_handler.find(hname) != m_handler.end()) {
30 NSMVHandler* handler_old = m_handler.find(hname)->second;
31 if (handler->useSet() && overwrite) {
32 handler->set(handler_old->get());
33 }
34 delete handler_old;
35 m_handler.erase(hname);
36 }
37 handler->setDumped(isdump);
38 m_handler.insert(std::pair<std::string, NSMVHandler*>(hname, handler));
39 m_hnames.push_back(hname);
40 return m_handler.size();
41 }
42 return 0;
43}

◆ addDB()

int addDB ( const DBObject & obj)
inherited

Definition at line 26 of file AbstractNSMCallback.cc.

27{
28 DBObject::NameValueList list;
29 obj.search(list, "", true);
30 int id = 0;
31 for (DBObject::NameValueList::iterator it = list.begin();
32 it != list.end(); ++it) {
33 const std::string& name(it->name);
34 if (name.size() == 0 || name.at(0) == '$') continue;
35 switch (it->type) {
36 case DBField::BOOL:
37 id = Callback::add(new NSMVHandlerInt(name, true, true, (int) * (static_cast<bool*>(it->buf))));
38 set(name, (int) * (static_cast<bool*>(it->buf)));
39 break;
40 case DBField::CHAR:
41 id = Callback::add(new NSMVHandlerInt(name, true, true, (int) * (static_cast<char*>(it->buf))));
42 set(name, (int) * (static_cast<char*>(it->buf)));
43 break;
44 case DBField::SHORT:
45 id = Callback::add(new NSMVHandlerInt(name, true, true, (int) * (static_cast<short*>(it->buf))));
46 set(name, (int) * (static_cast<short*>(it->buf)));
47 break;
48 case DBField::INT:
49 id = Callback::add(new NSMVHandlerInt(name, true, true, *(static_cast<int*>(it->buf))));
50 set(name, (int) * (static_cast<int*>(it->buf)));
51 break;
52 case DBField::LONG:
53 id = Callback::add(new NSMVHandlerInt(name, true, true, (int) * (static_cast<long long*>(it->buf))));
54 set(name, (int) * (static_cast<long long*>(it->buf)));
55 break;
56 case DBField::FLOAT:
57 id = Callback::add(new NSMVHandlerFloat(name, true, true, *(static_cast<float*>(it->buf))));
58 set(name, * (static_cast<float*>(it->buf)));
59 break;
60 case DBField::DOUBLE:
61 id = Callback::add(new NSMVHandlerFloat(name, true, true, (float) * (static_cast<double*>(it->buf))));
62 set(name, (float) * (static_cast<double*>(it->buf)));
63 break;
64 case DBField::TEXT:
65 id = Callback::add(new NSMVHandlerText(name, true, true, *(static_cast<std::string*>(it->buf))));
66 set(name, *(static_cast<std::string*>(it->buf)));
67 break;
68 default:
69 break;
70 }
71 }
72 return id;
73}

◆ addDefaultHandlers()

int addDefaultHandlers ( )
private

Definition at line 50 of file NSMCallback.cc.

51{
52 return add(new NSMVHandlerText("version", true, false, DAQ_SLC_VERSION::DAQ_SLC_VERSION), false, true);
53}

◆ addNode()

void addNode ( const NSMNode & node)
protected

Definition at line 55 of file NSMCallback.cc.

56{
57 std::string name = node.getName();
58 if (m_nodes.find(name) == m_nodes.end()) {
59 m_nodes.insert(NSMNodeMap::value_type(name, node));
60 }
61}

◆ alloc_open()

void alloc_open ( NSMCommunicator & com)
private

Definition at line 303 of file NSMCallback.cc.

304{
305 try {
306 if (!m_data.isAvailable() && m_data.getName().size() > 0 &&
307 m_data.getFormat().size() > 0 && m_data.getRevision() > 0) {
308 m_data.allocate(com);
309 }
310 } catch (const NSMHandlerException& e) {
311 LogFile::warning(e.what());
312 }
313 for (NSMDataMap::iterator it = m_datas.begin();
314 it != m_datas.end(); ++it) {
315 try {
316 NSMData& data(it->second);
317 if (!data.isAvailable() && data.getName().size() > 0 &&
318 data.getFormat().size() > 0) {
319 data.open(com);
320 }
321 } catch (const NSMHandlerException& e) {
322 }
323 }
324}

◆ error()

virtual void error ( const char * ,
const char *  )
inlinevirtual

Definition at line 47 of file NSMCallback.h.

47{}

◆ fatal()

virtual void fatal ( const char * ,
const char *  )
inlinevirtual

Definition at line 46 of file NSMCallback.h.

46{}

◆ get() [1/18]

bool get ( const DBObject & obj)
inherited

Definition at line 300 of file AbstractNSMCallback.cc.

301{
302 DBObject::NameValueList list;
303 obj.search(list);
304 for (DBObject::NameValueList::iterator it = list.begin();
305 it != list.end(); ++it) {
306 const std::string& name(it->name);
307 if (name.size() == 0 || name.at(0) == '$') continue;
308 int vi = 0;
309 float vf = 0;
310 std::string vs;
311 switch (it->type) {
312 case DBField::BOOL:
313 if (get(name, vi)) *(static_cast<bool*>(it->buf)) = (bool)vi;
314 break;
315 case DBField::CHAR:
316 if (get(name, vi)) *(static_cast<char*>(it->buf)) = (char)vi;
317 break;
318 case DBField::SHORT:
319 if (get(name, vi)) *(static_cast<short*>(it->buf)) = (short)vi;
320 break;
321 case DBField::INT:
322 if (get(name, vi)) *(static_cast<int*>(it->buf)) = (int)vi;
323 break;
324 case DBField::LONG:
325 if (get(name, vi)) *(static_cast<long long*>(it->buf)) = vi;
326 break;
327 case DBField::FLOAT:
328 if (get(name, vf)) *(static_cast<float*>(it->buf)) = vf;
329 break;
330 case DBField::DOUBLE:
331 if (get(name, vf)) *(static_cast<double*>(it->buf)) = vf;
332 break;
333 case DBField::TEXT:
334 if (get(name, vs)) *(static_cast<std::string*>(it->buf)) = vs;
335 break;
336 default:
337 break;
338 }
339 }
340 return true;
341}

◆ get() [2/18]

bool get ( const NSMNode & node,
const std::string & name,
float & val,
int timeout = 5 )
inherited

Definition at line 246 of file AbstractNSMCallback.cc.

248{
249 return get_t(node, name, val, timeout, NSMVar::FLOAT, 0);
250}

◆ get() [3/18]

bool get ( const NSMNode & node,
const std::string & name,
int & val,
int timeout = 5 )
inherited

Definition at line 240 of file AbstractNSMCallback.cc.

242{
243 return get_t(node, name, val, timeout, NSMVar::INT, 0);
244}

◆ get() [4/18]

bool get ( const NSMNode & node,
const std::string & name,
std::string & val,
int timeout = 5 )
inherited

Definition at line 252 of file AbstractNSMCallback.cc.

254{
255 return get_t(node, name, val, timeout, NSMVar::TEXT, 1);
256}

◆ get() [5/18]

bool get ( const NSMNode & node,
const std::string & name,
std::vector< float > & val,
int timeout = 5 )
inherited

Definition at line 264 of file AbstractNSMCallback.cc.

266{
267 return get_t(node, name, val, timeout, NSMVar::FLOAT, 1);
268}

◆ get() [6/18]

bool get ( const NSMNode & node,
const std::string & name,
std::vector< int > & val,
int timeout = 5 )
inherited

Definition at line 258 of file AbstractNSMCallback.cc.

260{
261 return get_t(node, name, val, timeout, NSMVar::INT, 1);
262}

◆ get() [7/18]

bool get ( const NSMNode & node,
NSMVar & var,
int timeout = 5 )
inherited

Definition at line 176 of file AbstractNSMCallback.cc.

178{
179 if (node.getName().size() > 0) {
180 const std::string name = var.getName();
181 NSMCommunicator::send(NSMMessage(node, NSMCommand::VGET, name));
182 if (timeout < 0) return true;
183 double t0 = Time().get();
184 double t = t0;
185 double tout = timeout;
186 while (true) {
187 double t1 = (tout - (t - t0) > 0 ? tout - (t - t0) : 0);
188 NSMCommunicator& com(wait(NSMNode(), NSMCommand::UNKNOWN, t1));
189 NSMMessage msg = com.getMessage();
190 NSMCommand cmd(msg.getRequestName());
191 if (cmd == NSMCommand::VSET) {
192 if (msg.getLength() > 0 && msg.getData() != NULL &&
193 node.getName() == msg.getData() &&
194 var.getName() == (msg.getData() + msg.getParam(2) + 1)) {
195 readVar(msg, var);
196 return true;
197 }
198 } else if (cmd == NSMCommand::VGET || cmd == NSMCommand::VLISTGET ||
199 cmd == NSMCommand::OK || cmd == NSMCommand::ERROR || cmd == NSMCommand::FATAL) {
200 perform(com);
201 } else {
202 com.pushQueue(msg);
203 }
204 t = Time().get();
205 }
206 }
207 return false;
208}

◆ get() [8/18]

bool get ( const NSMNode & node,
NSMVHandler * handler,
int timeout = 5 )
inherited

Definition at line 141 of file AbstractNSMCallback.cc.

143{
144 if (handler && node.getName().size() > 0) {
145 NSMVar var(handler->get());
146 add(handler);
147 const std::string name = handler->getName();//var.getName();
148 NSMCommunicator::send(NSMMessage(node, NSMCommand::VGET, name));
149 if (timeout < 0) return true;
150 double t0 = Time().get();
151 double t = t0;
152 double tout = timeout;
153 while (true) {
154 double t1 = (tout - (t - t0) > 0 ? tout - (t - t0) : 0);
155 NSMCommunicator& com(wait(NSMNode(), NSMCommand::UNKNOWN, t1));
156 NSMMessage msg = com.getMessage();
157 NSMCommand cmd(msg.getRequestName());
158 if (cmd == NSMCommand::VSET) {
159 if (node.getName() == msg.getData() &&
160 var.getName() == (msg.getData() + msg.getParam(2) + 1)) {
161 readVar(msg, var);
162 return handler->handleSet(var);
163 }
164 } else if (cmd == NSMCommand::VGET || cmd == NSMCommand::VLISTGET ||
165 cmd == NSMCommand::OK || cmd == NSMCommand::ERROR || cmd == NSMCommand::FATAL) {
166 perform(com);
167 } else {
168 com.pushQueue(msg);
169 }
170 t = Time().get();
171 }
172 }
173 return false;
174}

◆ get() [9/18]

bool get ( const std::string & name,
float & val )
inlineinherited

Definition at line 52 of file AbstractNSMCallback.h.

52{ return get("", name, val); }

◆ get() [10/18]

bool get ( const std::string & name,
int & val )
inlineinherited

Definition at line 51 of file AbstractNSMCallback.h.

51{ return get("", name, val); }

◆ get() [11/18]

bool get ( const std::string & name,
std::string & val )
inlineinherited

Definition at line 53 of file AbstractNSMCallback.h.

53{ return get("", name, val); }

◆ get() [12/18]

bool get ( const std::string & name,
std::vector< float > & val )
inlineinherited

Definition at line 55 of file AbstractNSMCallback.h.

55{ return get("", name, val); }

◆ get() [13/18]

bool get ( const std::string & name,
std::vector< int > & val )
inlineinherited

Definition at line 54 of file AbstractNSMCallback.h.

54{ return get("", name, val); }

◆ get() [14/18]

bool get ( const std::string & node,
const std::string & name,
float & val )
inlineinherited

Definition at line 62 of file AbstractNSMCallback.h.

62{ return get_t(node, name, val); }

◆ get() [15/18]

bool get ( const std::string & node,
const std::string & name,
int & val )
inlineinherited

Definition at line 61 of file AbstractNSMCallback.h.

61{ return get_t(node, name, val); }

◆ get() [16/18]

bool get ( const std::string & node,
const std::string & name,
std::string & val )
inlineinherited

Definition at line 63 of file AbstractNSMCallback.h.

63{ return get_t(node, name, val); }

◆ get() [17/18]

bool get ( const std::string & node,
const std::string & name,
std::vector< float > & val )
inlineinherited

Definition at line 65 of file AbstractNSMCallback.h.

65{ return get_t(node, name, val); }

◆ get() [18/18]

bool get ( const std::string & node,
const std::string & name,
std::vector< int > & val )
inlineinherited

Definition at line 64 of file AbstractNSMCallback.h.

64{ return get_t(node, name, val); }

◆ get_t() [1/2]

template<typename T>
bool get_t ( const NSMNode & node,
const std::string & name,
T & val,
int timeout,
NSMVar::Type type = NSMVar::NONE,
int len = 0 )
inlineprivateinherited

Definition at line 100 of file AbstractNSMCallback.h.

102 {
103 NSMVar var(name);
104 var.setNode(node.getName());
105 if (get(node, var, timeout)) {
106 if (type == NSMVar::NONE ||
107 (type == var.getType() &&
108 ((len == 0 && var.getLength() == 0) ||
109 (len > 0 && var.getLength() > 0)))) {
110 var >> val;
111 return true;
112 }
113 }
114 return false;
115 }

◆ get_t() [2/2]

template<typename T>
bool get_t ( const std::string & node,
const std::string & name,
T & val )
inlineprivateinherited

Definition at line 117 of file AbstractNSMCallback.h.

118 {
119 NSMVHandler* handler = getHandler_p(node, name);
120 if (handler) {
121 NSMVar var;
122 handler->handleGet(var);
123 var >> val;
124 return true;
125 }
126 return false;
127 }

◆ getCategory()

const std::string & getCategory ( ) const
inline

Definition at line 71 of file NSMCallback.h.

71{ return m_category; }

◆ getCommandList()

NSMCommandList & getCommandList ( )
inlineprivate

Definition at line 88 of file NSMCallback.h.

88{ return m_cmd_v; }

◆ getData()

NSMData & getData ( )
inline

Definition at line 66 of file NSMCallback.h.

66{ return m_data; }

◆ getDataMap()

NSMDataMap & getDataMap ( )
inline

Definition at line 64 of file NSMCallback.h.

64{ return m_datas; }

◆ getHandler() [1/2]

NSMVHandler & getHandler ( const std::string & name)
inlineinherited

Definition at line 42 of file Callback.h.

43 {
44 return getHandler("", name);
45 }

◆ getHandler() [2/2]

NSMVHandler & getHandler ( const std::string & node,
const std::string & name )
inherited

Definition at line 56 of file Callback.cc.

58{
59 NSMVHandler* p = getHandler_p(node, name);
60 if (p != NULL) return *p;
61 throw (std::out_of_range(StringUtil::form("no handler for %s:%s",
62 node.c_str(), name.c_str())));
63}

◆ getHandler_p()

NSMVHandler * getHandler_p ( const std::string & node,
const std::string & name )
privateinherited

Definition at line 65 of file Callback.cc.

66{
67 std::string hname = node + "@" + name;
68 if (m_handler.find(hname) != m_handler.end()) {
69 return m_handler.find(hname)->second;
70 }
71 hname = "@" + name;
72 if (m_handler.find(hname) != m_handler.end()) {
73 return m_handler.find(hname)->second;
74 }
75 return NULL;
76}

◆ getHandlerNames()

StringList & getHandlerNames ( )
inlineinherited

Definition at line 40 of file Callback.h.

40{ return m_hnames; }

◆ getHandlers()

NSMVHandlerList & getHandlers ( )
inlineinherited

Definition at line 41 of file Callback.h.

41{ return m_handler; }

◆ getLogNode()

const NSMNode & getLogNode ( )
inlineprotected

Definition at line 80 of file NSMCallback.h.

80{ return m_lognode; }

◆ getNode() [1/2]

NSMNode & getNode ( )
inlineinherited

Definition at line 79 of file AbstractNSMCallback.h.

79{ return m_node; }

◆ getNode() [2/2]

const NSMNode & getNode ( ) const
inlineinherited

Definition at line 80 of file AbstractNSMCallback.h.

80{ return m_node; }

◆ getNodes()

const NSMNodeMap & getNodes ( )
inlineprotected

Definition at line 78 of file NSMCallback.h.

78{ return m_nodes; }

◆ getRevision()

int getRevision ( ) const
inlineinherited

Definition at line 59 of file Callback.h.

59{ return m_revision; }

◆ getTimeout()

int getTimeout ( ) const
inlineinherited

Definition at line 82 of file AbstractNSMCallback.h.

82{ return m_timeout; }

◆ init()

virtual void init ( NSMCommunicator & )
inlinevirtual

Definition at line 41 of file NSMCallback.h.

41{}

◆ log() [1/2]

void log ( LogFile::Priority pri,
const char * format,
... )

Definition at line 78 of file NSMCallback.cc.

79{
80 va_list ap;
81 char ss[1024 * 10];
82 va_start(ap, format);
83 vsnprintf(ss, sizeof(ss), format, ap);
84 va_end(ap);
85 log(pri, std::string(ss));
86}

◆ log() [2/2]

void log ( LogFile::Priority pri,
const std::string & msg )

Definition at line 88 of file NSMCallback.cc.

89{
90 LogFile::put(pri, msg);
91 try {
92 if (getLogNode().getName().size() > 0) {
93 NSMCommunicator::send(NSMMessage(getLogNode().getName(),
94 DAQLogMessage(getNode().getName(),
95 pri, getCategory(), msg)));
96 }
97 } catch (const NSMHandlerException& e) {
98 LogFile::error(e.what());
99 }
100}
TString getName(const TObject *obj)
human-readable name (e.g.
Definition ObjectInfo.cc:45

◆ logset()

virtual void logset ( const DAQLogMessage & )
inlinevirtual

Definition at line 48 of file NSMCallback.h.

48{}

◆ notify()

void notify ( const NSMVar & var)
overrideprotectedvirtual

Implements AbstractNSMCallback.

Definition at line 156 of file NSMCallback.cc.

157{
158 std::string vname = var.getName();
159 NSMVar var_out = var;
160 if (var_out.getNode().size() == 0) {
161 var_out.setNode(getNode().getName());
162 }
163
164 if (m_node_v_m.find(vname) != m_node_v_m.end()) {
165 try {
166 NSMNodeMap& node_v(m_node_v_m[vname]);
167 for (NSMNodeMap::iterator inode = node_v.begin();
168 inode != node_v.end();) {
169 NSMNode& node(inode->second);
170 if (NSMCommunicator::send(NSMMessage(node, var_out))) {
171 ++inode;
172 } else {
173 node_v.erase(inode++);
174 }
175 }
176 } catch (const IOException& e) {
177 LogFile::error(e.what());
178 }
179 }
180}

◆ ok()

virtual void ok ( const char * ,
const char *  )
inlinevirtual

Definition at line 45 of file NSMCallback.h.

45{}

◆ perform()

bool perform ( NSMCommunicator & com)
overridevirtual

Implements AbstractNSMCallback.

Definition at line 102 of file NSMCallback.cc.

103{
104 const NSMMessage& msg(com.getMessage());
105 const NSMCommand cmd = msg.getRequestName();
106 if (cmd == NSMCommand::OK || cmd == NSMCommand::ERROR ||
107 cmd == NSMCommand::FATAL) {
108 if (msg.getLength() > 0) {
109 if (cmd == NSMCommand::OK) {
110 ok(msg.getNodeName(), msg.getData());
111 } else if (cmd == NSMCommand::ERROR) {
112 error(msg.getNodeName(), msg.getData());
113 } else if (cmd == NSMCommand::FATAL) {
114 fatal(msg.getNodeName(), msg.getData());
115 }
116 }
117 return true;
118 } else if (cmd == NSMCommand::LOG) {
119 int id = com.getNodeIdByName(msg.getNodeName());
120 DAQLogMessage lmsg;
121 lmsg.setId(id);
122 lmsg.setNodeName(msg.getNodeName());
123 if (msg.getNParams() > 0) {
124 lmsg.setPriority((LogFile::Priority)msg.getParam(0));
125 }
126 if (msg.getNParams() > 1) lmsg.setDate(msg.getParam(1));
127 if (msg.getNParams() > 2) lmsg.setCategory(msg.getParam(2));
128 lmsg.setMessage(msg.getLength() > 0 ? msg.getData() : "");
129 logset(lmsg);
130 return true;
131 } else if (cmd == NSMCommand::VGET) {
132 if (msg.getLength() > 0) {
133 vget(msg.getNodeName(), msg.getData());
134 }
135 return true;
136 } else if (cmd == NSMCommand::VSET) {
137 if (msg.getLength() > 0) {
138 NSMVar var;
139 readVar(msg, var);
140 vset(com, var);
141 }
142 return true;
143 } else if (cmd == NSMCommand::VREPLY) {
144 vreply(com, msg.getData(), msg.getParam(0));
145 return true;
146 } else if (cmd == NSMCommand::VLISTGET) {
147 vlistget(com);
148 return true;
149 } else if (cmd == NSMCommand::VLISTSET) {
150 vlistset(com);
151 return true;
152 }
153 return false;
154}

◆ readVar()

void readVar ( const NSMMessage & msg,
NSMVar & var )
staticprotectedinherited

Definition at line 129 of file AbstractNSMCallback.cc.

130{
131 const int* pars = msg.getParams();
132 const char* node = msg.getData();
133 const char* name = (msg.getData() + pars[2] + 1);
134 const char* value = (msg.getData() + pars[2] + 1 + pars[3] + 1);
135 var = NSMVar(name, (NSMVar::Type)pars[0], pars[1], value);
136 var.setNode(node);
137 var.setId(pars[4]);
138 var.setDate(pars[5]);
139}

◆ reg()

void reg ( const NSMCommand & cmd)
inlineprotected

Definition at line 76 of file NSMCallback.h.

76{ m_cmd_v.push_back(cmd); }

◆ remove() [1/3]

void remove ( const DBObject & obj)
inherited

Definition at line 78 of file Callback.cc.

79{
80 DBObject::NameValueList list;
81 obj.search(list, "", true);
82 for (DBObject::NameValueList::iterator it = list.begin();
83 it != list.end(); ++it) {
84 const std::string& name(it->name);
85 if (name.size() == 0 || name.at(0) == '$') continue;
86 switch (it->type) {
87 case DBField::OBJECT:
88 break;
89 default:
90 remove(name);
91 break;
92 }
93 }
94}

◆ remove() [2/3]

void remove ( const std::string & name)
inlineinherited

Definition at line 38 of file Callback.h.

38{ remove("", name); }

◆ remove() [3/3]

void remove ( const std::string & node,
const std::string & name )
inherited

Definition at line 45 of file Callback.cc.

46{
47 std::string hname = node + "@" + node;
48 if (m_handler.find(hname) != m_handler.end()) {
49 NSMVHandler* handler_old = m_handler.find(hname)->second;
50 delete handler_old;
51 m_handler.erase(hname);
52 return;
53 }
54}

◆ reply()

void reply ( const NSMMessage & msg)

Definition at line 63 of file NSMCallback.cc.

64{
65 NSMMessage msg_out = msg;
66 for (NSMNodeMap::iterator it = m_nodes.begin();
67 it != m_nodes.end();) {
68 const NSMNode& node(it->second);
69 msg_out.setNodeName(node.getName());
70 if (NSMCommunicator::send(msg_out)) {
71 ++it;
72 } else {
73 m_nodes.erase(it++);
74 }
75 }
76}

◆ reset()

int reset ( )

Definition at line 41 of file NSMCallback.cc.

42{
43 int revision = Callback::reset();
44
45 addDefaultHandlers();
46
47 return revision;
48}

◆ set() [1/16]

bool set ( const NSMNode & node,
const NSMVar & var,
int timeout = 5 )
inherited

Definition at line 210 of file AbstractNSMCallback.cc.

212{
213 if (node.getName().size() > 0) {
214 NSMCommunicator::send(NSMMessage(node, var));
215 if (timeout < 0) return true;
216 double t0 = Time().get();
217 double t = t0;
218 double tout = timeout;
219 while (true) {
220 double t1 = (tout - (t - t0) > 0 ? tout - (t - t0) : 0);
221 NSMCommunicator& com(wait(node, NSMCommand::VREPLY, t1));
222 NSMMessage msg(com.getMessage());
223 NSMCommand cmd(msg.getRequestName());
224 if (cmd == NSMCommand::VREPLY && var.getName() == msg.getData()) {
225 bool ret = msg.getParam(0) > 0;
226 perform(com);
227 return ret;
228 } else if (cmd == NSMCommand::VGET || cmd == NSMCommand::VLISTGET ||
229 cmd == NSMCommand::OK || cmd == NSMCommand::ERROR || cmd == NSMCommand::FATAL) {
230 perform(com);
231 } else {
232 com.pushQueue(msg);
233 }
234 t = Time().get();
235 }
236 }
237 return false;
238}

◆ set() [2/16]

bool set ( const NSMNode & node,
const std::string & name,
const std::string & val,
int timeout = 5 )
inherited

Definition at line 282 of file AbstractNSMCallback.cc.

284{
285 return set(node, NSMVar(name, val), timeout);
286}

◆ set() [3/16]

bool set ( const NSMNode & node,
const std::string & name,
const std::vector< float > & val,
int timeout = 5 )
inherited

Definition at line 294 of file AbstractNSMCallback.cc.

296{
297 return set(node, NSMVar(name, val), timeout);
298}

◆ set() [4/16]

bool set ( const NSMNode & node,
const std::string & name,
const std::vector< int > & val,
int timeout = 5 )
inherited

Definition at line 288 of file AbstractNSMCallback.cc.

290{
291 return set(node, NSMVar(name, val), timeout);
292}

◆ set() [5/16]

bool set ( const NSMNode & node,
const std::string & name,
float val,
int timeout = 5 )
inherited

Definition at line 276 of file AbstractNSMCallback.cc.

278{
279 return set(node, NSMVar(name, val), timeout);
280}

◆ set() [6/16]

bool set ( const NSMNode & node,
const std::string & name,
int val,
int timeout = 5 )
inherited

Definition at line 270 of file AbstractNSMCallback.cc.

272{
273 return set(node, NSMVar(name, val), timeout);
274}

◆ set() [7/16]

bool set ( const std::string & name,
const std::string & val )
inlineinherited

Definition at line 58 of file AbstractNSMCallback.h.

58{ return set("", name, val); }

◆ set() [8/16]

bool set ( const std::string & name,
const std::vector< float > & val )
inlineinherited

Definition at line 60 of file AbstractNSMCallback.h.

60{ return set("", name, val); }

◆ set() [9/16]

bool set ( const std::string & name,
const std::vector< int > & val )
inlineinherited

Definition at line 59 of file AbstractNSMCallback.h.

59{ return set("", name, val); }

◆ set() [10/16]

bool set ( const std::string & name,
float val )
inlineinherited

Definition at line 57 of file AbstractNSMCallback.h.

57{ return set("", name, val); }

◆ set() [11/16]

bool set ( const std::string & name,
int val )
inlineinherited

Definition at line 56 of file AbstractNSMCallback.h.

56{ return set("", name, val); }

◆ set() [12/16]

bool set ( const std::string & node,
const std::string & name,
const std::string & val )
inlineinherited

Definition at line 68 of file AbstractNSMCallback.h.

68{ return set_t(node, name, val); }

◆ set() [13/16]

bool set ( const std::string & node,
const std::string & name,
const std::vector< float > & val )
inlineinherited

Definition at line 70 of file AbstractNSMCallback.h.

70{ return set_t(node, name, val); }

◆ set() [14/16]

bool set ( const std::string & node,
const std::string & name,
const std::vector< int > & val )
inlineinherited

Definition at line 69 of file AbstractNSMCallback.h.

69{ return set_t(node, name, val); }

◆ set() [15/16]

bool set ( const std::string & node,
const std::string & name,
float val )
inlineinherited

Definition at line 67 of file AbstractNSMCallback.h.

67{ return set_t(node, name, val); }

◆ set() [16/16]

bool set ( const std::string & node,
const std::string & name,
int val )
inlineinherited

Definition at line 66 of file AbstractNSMCallback.h.

66{ return set_t(node, name, val); }

◆ set_t()

template<typename T>
bool set_t ( const std::string & node,
const std::string & name,
const T & val )
inlineprivateinherited

Definition at line 129 of file AbstractNSMCallback.h.

130 {
131 NSMVHandler* handler = getHandler_p(node, name);
132 if (handler) {
133 handler->set(val);
134 if (node.size() == 0) {
135 notify(handler->get());
136 }
137 return true;
138 }
139 return false;
140 }

◆ setCategory()

void setCategory ( const std::string & category)
inline

Definition at line 72 of file NSMCallback.h.

72{ m_category = category; }

◆ setLogNode()

void setLogNode ( const NSMNode & node)
inlineprotected

Definition at line 79 of file NSMCallback.h.

79{ m_lognode = node; }

◆ setNode()

void setNode ( const NSMNode & node)
inlineinherited

Definition at line 81 of file AbstractNSMCallback.h.

81{ m_node = node; }

◆ setRevision()

void setRevision ( int revision)
inlineinherited

Definition at line 58 of file Callback.h.

58{ m_revision = revision; }

◆ setTimeout()

void setTimeout ( int timeout)
inlineinherited

Definition at line 83 of file AbstractNSMCallback.h.

83{ m_timeout = timeout; }

◆ setUseGet()

void setUseGet ( const std::string & name,
bool use )
inlineinherited

Definition at line 48 of file Callback.h.

49 {
50 getHandler(name).setUseGet(use);
51 }

◆ setUseSet()

void setUseSet ( const std::string & name,
bool use )
inlineinherited

Definition at line 52 of file Callback.h.

53 {
54 getHandler(name).setUseSet(use);
55 }

◆ term()

virtual void term ( )
inlinevirtual

Definition at line 42 of file NSMCallback.h.

42{}

◆ timeout()

virtual void timeout ( NSMCommunicator & )
inlinevirtual

Definition at line 43 of file NSMCallback.h.

43{}

◆ try_wait()

bool try_wait ( )
inherited

Definition at line 119 of file AbstractNSMCallback.cc.

120{
121 try {
122 perform(wait(NSMNode(), NSMCommand::UNKNOWN, 0));
123 } catch (const std::exception& e) {
124 return false;
125 }
126 return true;
127}

◆ vget()

void vget ( const std::string & nodename,
const std::string & vname )
virtual

Definition at line 182 of file NSMCallback.cc.

183{
184 NSMNode node(nodename);
185 NSMVar var(vname);
186 try {
187 // cppcheck-suppress constVariablePointer ; the handler is used mutably below
188 NSMVHandler* handler_p = getHandler_p(nodename, vname);
189 if (handler_p) {
190 NSMVHandler& handler(*handler_p);
191 handler.handleGet(var);
192 var.setNode(getNode().getName());
193 var.setName(vname);
194 //var.setId(i + 1);
195 var.setDate(Date());
196 NSMCommunicator::send(NSMMessage(node, var));
197 if (m_node_v_m.find(vname) == m_node_v_m.end()) {
198 m_node_v_m.insert(NSMNodeMapMap::value_type(vname, NSMNodeMap()));
199 }
200 NSMNodeMap& node_v(m_node_v_m[vname]);
201 if (node_v.find(nodename) == node_v.end()) {
202 node_v.insert(NSMNodeMap::value_type(nodename, NSMNode(nodename)));
203 std::string filename = ("/tmp/nsmvget." + StringUtil::tolower(getNode().getName()));
204 std::ofstream fout(filename.c_str(), std::ios::app);
205 fout << nodename << " " << vname << std::endl;
206 }
207 }
208 } catch (const NSMHandlerException& e) {
209 LogFile::error(e.what());
210 }
211}

◆ vlistget()

void vlistget ( NSMCommunicator & com)
virtual

Definition at line 243 of file NSMCallback.cc.

244{
245 std::stringstream ss;
246 int i = 0;
247 int count = 0;
248 for (NSMVHandlerList::iterator it = m_handler.begin();
249 it != m_handler.end(); ++it) {
250 NSMVHandler& handler(*it->second);
251 if (handler.getNode().size() == 0) {
252 ss << handler.getName() << ":"
253 << handler.get().getTypeLabel() << ":"
254 << (int)handler.useGet() << ":"
255 << (int)handler.useSet() << ":"
256 << i << "\n";
257 count++;
258 }
259 i++;
260 }
261 std::string nodename = com.getMessage().getNodeName();
262 NSMNode node(nodename);
263 try {
264 NSMCommunicator::send(NSMMessage(node, NSMCommand::VLISTSET,
265 count, ss.str()));
266 } catch (const NSMHandlerException& e) {
267 LogFile::error(e.what());
268 }
269}

◆ vlistset()

void vlistset ( NSMCommunicator & com)
virtual

Definition at line 278 of file NSMCallback.cc.

279{
280 std::string data = com.getMessage().getData();
281 StringList s = StringUtil::split(data, '\n');
282 std::vector<vlistentry_t> vlist;
283 size_t length = 0;
284 for (size_t i = 0; i < s.size(); i++) {
285 StringList ss = StringUtil::split(s[i], ':');
286 if (ss.size() > 4) {
287 vlistentry_t en = { ss[0],
288 ss[1], ss[2] == "1", ss[3] == "1"
289 };
290 vlist.push_back(en);
291 if (length < ss[0].size()) length = ss[0].size();
292 }
293 }
294 for (size_t i = 0; i < vlist.size(); i++) {
295 const vlistentry_t& en(vlist[i]);
296 std::cout << StringUtil::form(StringUtil::form("%%-%ds ", length), en.name.c_str())
297 << " : " << en.type << " "
298 << (en.useGet ? "get " : "")
299 << (en.useSet ? "set " : "") << std::endl;
300 }
301}

◆ vreply()

virtual void vreply ( NSMCommunicator & ,
const std::string & ,
bool  )
inlinevirtual

Definition at line 54 of file NSMCallback.h.

54{}

◆ vset()

void vset ( NSMCommunicator & com,
const NSMVar & var )
virtual

Definition at line 213 of file NSMCallback.cc.

214{
215 try {
216 NSMMessage msg(com.getMessage());
217 // cppcheck-suppress constVariablePointer ; the handler is used mutably below
218 NSMVHandler* handler_p = getHandler_p(var.getNode(), var.getName());
219 if (handler_p) {
220 NSMVHandler& handler(*handler_p);
221 if (var.getName() == handler.getName() &&
222 (var.getNode() == handler.getNode() ||
223 (var.getNode().size() == 0 && handler.getNode() == getNode().getName()) ||
224 (handler.getNode().size() == 0 && var.getNode() == getNode().getName())) &&
225 handler.useSet()) {
226 NSMNode node(msg.getNodeName());
227 bool result = false;
228 if ((result = handler.handleSet(var)) &&
229 (var.getNode().size() == 0 || var.getNode() == getNode().getName())) {
230 notify(var);
231 }
232 if (var.getNode().size() == 0) {
233 NSMCommunicator::send(NSMMessage(node, NSMCommand::VREPLY,
234 result, var.getName()));
235 }
236 }
237 }
238 } catch (const NSMHandlerException& e) {
239 LogFile::error(e.what());
240 }
241}

◆ wait() [1/2]

NSMCommunicator & wait ( const NSMNode & node,
const NSMCommand & cmd,
double timeout = 5 )
staticinherited

Definition at line 75 of file AbstractNSMCallback.cc.

78{
79 double t0 = Time().get();
80 double t = t0;
81 while (true) {
82 double t1 = (timeout - (t - t0) > 0 ? timeout - (t - t0) : 0);
83 NSMCommunicator& com(NSMCommunicator::select(t1));
84 NSMMessage msg = com.getMessage();
85 const std::string reqname = msg.getRequestName();
86 if ((cmd == NSMCommand::UNKNOWN || cmd == reqname) &&
87 (node.getName().size() == 0 || msg.getNodeName() == node.getName())) {
88 return com;
89 }
90 com.pushQueue(msg);
91 t = Time().get();
92 }
93}

◆ wait() [2/2]

int wait ( double timeout = 5)
inherited

Definition at line 95 of file AbstractNSMCallback.cc.

96{
97 double t0 = Time().get();
98 int count = 0;
99 try {
100 double t = t0;
101 while (true) {
102 double t1 = (timeout - (t - t0) > 0 ? timeout - (t - t0) : 0);
103 if (t1 == 0) break;
104 NSMCommunicator& com(NSMCommunicator::select(t1));
105 NSMMessage msg = com.getMessage();
106 NSMCommand cmd(msg.getRequestName());
107 if (cmd == NSMCommand::VGET || cmd == NSMCommand::VLISTGET) {
108 perform(com);
109 } else {
110 com.pushQueue(msg);
111 }
112 t = Time().get();
113 }
114 } catch (const TimeoutException& e) {
115 }
116 return count;
117}

Friends And Related Symbol Documentation

◆ NSMCommunicator

friend class NSMCommunicator
friend

Definition at line 33 of file NSMCallback.h.

◆ NSMNodeDaemon

friend class NSMNodeDaemon
friend

Definition at line 34 of file NSMCallback.h.

Member Data Documentation

◆ m_category

std::string m_category
private

Definition at line 97 of file NSMCallback.h.

◆ m_cmd_v

NSMCommandList m_cmd_v
private

Definition at line 92 of file NSMCallback.h.

◆ m_data

NSMData m_data
private

Definition at line 94 of file NSMCallback.h.

◆ m_datas

NSMDataMap m_datas
private

Definition at line 95 of file NSMCallback.h.

◆ m_handler

NSMVHandlerList m_handler
privateinherited

Definition at line 66 of file Callback.h.

◆ m_hnames

StringList m_hnames
privateinherited

Definition at line 67 of file Callback.h.

◆ m_lognode

NSMNode m_lognode
private

Definition at line 96 of file NSMCallback.h.

◆ m_node

NSMNode m_node
privateinherited

Definition at line 90 of file AbstractNSMCallback.h.

◆ m_node_v_m

NSMNodeMapMap m_node_v_m
privateinherited

Definition at line 92 of file AbstractNSMCallback.h.

◆ m_nodes

NSMNodeMap m_nodes
private

Definition at line 93 of file NSMCallback.h.

◆ m_revision

int m_revision
privateinherited

Definition at line 65 of file Callback.h.

◆ m_timeout

int m_timeout
privateinherited

Definition at line 91 of file AbstractNSMCallback.h.


The documentation for this class was generated from the following files: