Belle II Software development
NSMNodeDaemon Class Reference

Public Member Functions

 NSMNodeDaemon (NSMCallback *callback1, const std::string &host1, int port1, NSMCallback *callback2=NULL, const std::string &host2="", int port2=0)
 
void add (NSMCallback *callback, const std::string &host, int port)
 
void run ()
 

Private Attributes

int m_timeout
 
std::vector< NSMCallback * > m_callback
 

Detailed Description

Definition at line 19 of file NSMNodeDaemon.h.

Constructor & Destructor Documentation

◆ NSMNodeDaemon() [1/2]

NSMNodeDaemon ( )
inline

Definition at line 22 of file NSMNodeDaemon.h.

22: m_timeout(0) {}

◆ NSMNodeDaemon() [2/2]

NSMNodeDaemon ( NSMCallback callback1,
const std::string &  host1,
int  port1,
NSMCallback callback2 = NULL,
const std::string &  host2 = "",
int  port2 = 0 
)
inline

Definition at line 23 of file NSMNodeDaemon.h.

27 : m_timeout(0)
28 {
29 add(callback1, host1, port1);
30 add(callback2, host2, port2);
31 }

◆ ~NSMNodeDaemon()

virtual ~NSMNodeDaemon ( )
inlinevirtual

Definition at line 32 of file NSMNodeDaemon.h.

32{}

Member Function Documentation

◆ add()

void add ( NSMCallback callback,
const std::string &  host,
int  port 
)

Definition at line 25 of file NSMNodeDaemon.cc.

27{
28 try {
29 if (callback != NULL && host.size() > 0 && port > 0) {
31 NSMNode& node(callback->getNode());
32 com->init(node, host, port);
33 com->setCallback(callback);
34 callback->init(*com);
35 callback->alloc_open(*com);
36 m_timeout = callback->getTimeout();
37 if (callback->getLogNode().getName().size() == 0) {
38 ConfigFile file("slowcontrol");
39 callback->setLogNode(NSMNode(file.get("log.collector")));
40 }
41 m_callback.push_back(callback);
42 }
43 } catch (const std::exception& e) {
44 LogFile::fatal(e.what());
45 exit(1);
46 }
47}

◆ run()

void run ( )

Definition at line 49 of file NSMNodeDaemon.cc.

50{
51 NSMCommunicatorList& com_v(NSMCommunicator::get());
52 try {
53 {
54 std::string nodename = com_v[0]->getCallback().getNode().getName();
55 std::string filename = ("/tmp/nsmvget." + StringUtil::tolower(nodename));
56 std::ifstream fin(filename.c_str());
57 std::vector<std::string> nodes, vnames;
58 std::string node, vname;
59 while (fin >> node >> vname) {
60 nodes.push_back(node);
61 vnames.push_back(vname);
62 }
63 ::remove(filename.c_str());
64 for (size_t i = 0; i < com_v.size(); i++) {
65 NSMCommunicator& com(*com_v[i]);
66 for (size_t j = 0; j < nodes.size(); j++) {
67 com.getCallback().vget(nodes[j], vnames[j]);
68 }
69 }
70 }
71 double t0 = Time().get();
72 while (true) {
73 try {
74 NSMCommunicator& com(NSMCommunicator::select(m_timeout));
75 com.getCallback().perform(com);
76 } catch (const TimeoutException& e) {}
77 for (size_t i = 0; i < com_v.size(); i++) {
78 NSMCommunicator& com(*com_v[i]);
79 while (com.hasQueue()) {
80 com.setMessage(com.popQueue());
81 com.getCallback().perform(com);
82 }
83 }
84 double t = Time().get();
85 if (t - t0 >= m_timeout) {
86 for (size_t i = 0; i < com_v.size(); i++) {
87 NSMCommunicator& com(*com_v[i]);
88 com.getCallback().timeout(com);
89 com.getCallback().alloc_open(com);
90 }
91 t0 = t;
92 }
93 }
94 } catch (const std::exception& e) {
95 LogFile::fatal("NSM node brdge : Caught exception %s\n"
96 "Terminate process...", e.what());
97 }
98 for (size_t i = 0; i < com_v.size(); i++) {
99 NSMCommunicator& com(*com_v[i]);
100 com.getCallback().term();
101 }
102}

Member Data Documentation

◆ m_callback

std::vector<NSMCallback*> m_callback
private

Definition at line 42 of file NSMNodeDaemon.h.

◆ m_timeout

int m_timeout
private

Definition at line 41 of file NSMNodeDaemon.h.


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