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

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 ()
 
NSMDatagetData (const std::string &name)
 
NSMDatagetData ()
 
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)
 
NSMCommunicatorwait (const NSMNode &node, const NSMCommand &cmd, double timeout=5)
 
bool try_wait ()
 
NSMNodegetNode ()
 
const NSMNodegetNode () 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 ()
 
NSMVHandlergetHandler (const std::string &name)
 
NSMVHandlergetHandler (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
 

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 NSMNodegetLogNode ()
 
void readVar (const NSMMessage &msg, NSMVar &var)
 

Private Types

typedef std::vector< NSMCommandNSMCommandList
 

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)
 
NSMVHandlergetHandler_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 82 of file NSMCallback.h.

Constructor & Destructor Documentation

◆ NSMCallback()

NSMCallback ( int  timeout = 5)

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 ( )
inlinevirtual

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) * ((bool*)it->buf)));
38 set(name, (int) * ((bool*)it->buf));
39 break;
40 case DBField::CHAR:
41 id = Callback::add(new NSMVHandlerInt(name, true, true, (int) * ((char*)it->buf)));
42 set(name, (int) * ((char*)it->buf));
43 break;
44 case DBField::SHORT:
45 id = Callback::add(new NSMVHandlerInt(name, true, true, (int) * ((short*)it->buf)));
46 set(name, (int) * ((short*)it->buf));
47 break;
48 case DBField::INT:
49 id = Callback::add(new NSMVHandlerInt(name, true, true, *((int*)it->buf)));
50 set(name, (int) * ((int*)it->buf));
51 break;
52 case DBField::LONG:
53 id = Callback::add(new NSMVHandlerInt(name, true, true, (int) * ((long long*)it->buf)));
54 set(name, (int) * ((long long*)it->buf));
55 break;
56 case DBField::FLOAT:
57 id = Callback::add(new NSMVHandlerFloat(name, true, true, *((float*)it->buf)));
58 set(name, * ((float*)it->buf));
59 break;
60 case DBField::DOUBLE:
61 id = Callback::add(new NSMVHandlerFloat(name, true, true, (float) * ((double*)it->buf)));
62 set(name, (float) * ((double*)it->buf));
63 break;
64 case DBField::TEXT:
65 id = Callback::add(new NSMVHandlerText(name, true, true, *((std::string*)it->buf)));
66 set(name, *((std::string*)it->buf));
67 break;
68 default:
69 break;
70 }
71 }
72 return id;
73}

◆ addDefaultHandlers()

int addDefaultHandlers ( )
private

Definition at line 49 of file NSMCallback.cc.

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

◆ addNode()

void addNode ( const NSMNode node)
protected

Definition at line 54 of file NSMCallback.cc.

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

◆ alloc_open()

void alloc_open ( NSMCommunicator com)
private

Definition at line 300 of file NSMCallback.cc.

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

◆ 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)) *((bool*)it->buf) = (bool)vi;
314 break;
315 case DBField::CHAR:
316 if (get(name, vi)) *((char*)it->buf) = (char)vi;
317 break;
318 case DBField::SHORT:
319 if (get(name, vi)) *((short*)it->buf) = (short)vi;
320 break;
321 case DBField::INT:
322 if (get(name, vi)) *((int*)it->buf) = (int)vi;
323 break;
324 case DBField::LONG:
325 if (get(name, vi)) *((long long*)it->buf) = vi;
326 break;
327 case DBField::FLOAT:
328 if (get(name, vf)) *((float*)it->buf) = vf;
329 break;
330 case DBField::DOUBLE:
331 if (get(name, vf)) *((double*)it->buf) = vf;
332 break;
333 case DBField::TEXT:
334 if (get(name, vs)) *((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]

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 99 of file AbstractNSMCallback.h.

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

◆ get_t() [2/2]

bool get_t ( const std::string &  node,
const std::string &  name,
T &  val 
)
inlineprivateinherited

Definition at line 116 of file AbstractNSMCallback.h.

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

◆ getCategory()

const std::string & getCategory ( ) const
inline

Definition at line 70 of file NSMCallback.h.

70{ return m_category; }

◆ getCommandList()

NSMCommandList & getCommandList ( )
inlineprivate

Definition at line 87 of file NSMCallback.h.

87{ return m_cmd_v; }

◆ getData()

NSMData & getData ( )
inline

Definition at line 65 of file NSMCallback.h.

65{ return m_data; }

◆ getDataMap()

NSMDataMap & getDataMap ( )
inline

Definition at line 63 of file NSMCallback.h.

63{ 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 79 of file NSMCallback.h.

79{ return m_lognode; }

◆ getNode() [1/2]

NSMNode & getNode ( )
inlineinherited

Definition at line 78 of file AbstractNSMCallback.h.

78{ return m_node; }

◆ getNode() [2/2]

const NSMNode & getNode ( ) const
inlineinherited

Definition at line 79 of file AbstractNSMCallback.h.

79{ return m_node; }

◆ getNodes()

const NSMNodeMap & getNodes ( )
inlineprotected

Definition at line 77 of file NSMCallback.h.

77{ 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 81 of file AbstractNSMCallback.h.

81{ 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 77 of file NSMCallback.cc.

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

◆ log() [2/2]

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

Definition at line 87 of file NSMCallback.cc.

88{
89 LogFile::put(pri, msg);
90 try {
91 if (getLogNode().getName().size() > 0) {
92 NSMCommunicator::send(NSMMessage(getLogNode().getName(),
93 DAQLogMessage(getNode().getName(),
94 pri, getCategory(), msg)));
95 }
96 } catch (const NSMHandlerException& e) {
97 LogFile::error(e.what());
98 }
99}
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 155 of file NSMCallback.cc.

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

◆ 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 101 of file NSMCallback.cc.

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

◆ readVar()

void readVar ( const NSMMessage msg,
NSMVar var 
)
protectedinherited

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 75 of file NSMCallback.h.

75{ 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 62 of file NSMCallback.cc.

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

◆ reset()

int reset ( )

Definition at line 40 of file NSMCallback.cc.

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

◆ 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()

bool set_t ( const std::string &  node,
const std::string &  name,
const T &  val 
)
inlineprivateinherited

Definition at line 128 of file AbstractNSMCallback.h.

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

◆ setCategory()

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

Definition at line 71 of file NSMCallback.h.

71{ m_category = category; }

◆ setLogNode()

void setLogNode ( const NSMNode node)
inlineprotected

Definition at line 78 of file NSMCallback.h.

78{ m_lognode = node; }

◆ setNode()

void setNode ( const NSMNode node)
inlineinherited

Definition at line 80 of file AbstractNSMCallback.h.

80{ 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 82 of file AbstractNSMCallback.h.

82{ 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 181 of file NSMCallback.cc.

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

◆ vlistget()

void vlistget ( NSMCommunicator com)
virtual

Definition at line 240 of file NSMCallback.cc.

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

◆ vlistset()

void vlistset ( NSMCommunicator com)
virtual

Definition at line 275 of file NSMCallback.cc.

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

◆ 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 211 of file NSMCallback.cc.

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

◆ wait() [1/2]

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

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 double t = t0;
99 int count = 0;
100 try {
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 Function 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 96 of file NSMCallback.h.

◆ m_cmd_v

NSMCommandList m_cmd_v
private

Definition at line 91 of file NSMCallback.h.

◆ m_data

NSMData m_data
private

Definition at line 93 of file NSMCallback.h.

◆ m_datas

NSMDataMap m_datas
private

Definition at line 94 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 95 of file NSMCallback.h.

◆ m_node

NSMNode m_node
privateinherited

Definition at line 89 of file AbstractNSMCallback.h.

◆ m_node_v_m

NSMNodeMapMap m_node_v_m
privateinherited

Definition at line 91 of file AbstractNSMCallback.h.

◆ m_nodes

NSMNodeMap m_nodes
private

Definition at line 92 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 90 of file AbstractNSMCallback.h.


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