8#include "daq/slc/nsm/NSMNodeDaemon.h"
10#include "daq/slc/nsm/NSMCommunicator.h"
11#include "daq/slc/base/TimeoutException.h"
13#include <daq/slc/system/LogFile.h>
14#include <daq/slc/system/Time.h>
16#include <daq/slc/base/StringUtil.h>
17#include <daq/slc/base/ConfigFile.h>
26 const std::string& host,
int port)
29 if (callback != NULL && host.size() > 0 && port > 0) {
31 NSMNode& node(callback->getNode());
32 com->init(node, host, port);
33 com->setCallback(callback);
35 callback->alloc_open(*com);
36 m_timeout = callback->getTimeout();
37 if (callback->getLogNode().getName().size() == 0) {
39 callback->setLogNode(
NSMNode(file.get(
"log.collector")));
41 m_callback.push_back(callback);
43 }
catch (
const std::exception& e) {
44 LogFile::fatal(e.what());
49void NSMNodeDaemon::run()
51 NSMCommunicatorList& com_v(NSMCommunicator::get());
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);
63 ::remove(filename.c_str());
64 for (
size_t i = 0; i < com_v.size(); i++) {
66 for (
size_t j = 0; j < nodes.size(); j++) {
67 com.getCallback().vget(nodes[j], vnames[j]);
71 double t0 =
Time().get();
75 com.getCallback().perform(com);
77 for (
size_t i = 0; i < com_v.size(); i++) {
79 while (com.hasQueue()) {
80 com.setMessage(com.popQueue());
81 com.getCallback().perform(com);
84 double t =
Time().get();
85 if (t - t0 >= m_timeout) {
86 for (
size_t i = 0; i < com_v.size(); i++) {
88 com.getCallback().timeout(com);
89 com.getCallback().alloc_open(com);
94 }
catch (
const std::exception& e) {
95 LogFile::fatal(
"NSM node brdge : Caught exception %s\n"
96 "Terminate process...", e.what());
98 for (
size_t i = 0; i < com_v.size(); i++) {
100 com.getCallback().term();
Abstract base class for different kinds of events.