9#include "daq/expreco/ERecoDistributor.h"
20#define RFEVSOUT stdout
25ERecoDistributor::ERecoDistributor(
const string& conffile)
28 m_conf =
new RFConf(conffile.c_str());
29 char* nodename = m_conf->getconf(
"distributor",
"nodename");
34 string execdir = string(m_conf->getconf(
"system",
"execdir_base")) +
"/distributor";
36 mkdir(execdir.c_str(), 0755);
37 chdir(execdir.c_str());
40 string shmname = string(m_conf->getconf(
"system",
"unitname")) +
":" +
41 string(m_conf->getconf(
"distributor",
"nodename"));
42 m_shm =
new RFSharedMem(
const_cast<char*
>(shmname.c_str()));
45 m_proc =
new RFProcessManager(nodename);
49 string ringbuf = string(m_conf->getconf(
"system",
"unitname")) +
":" +
50 string(m_conf->getconf(
"distributor",
"ringbuffer"));
51 int rbufsize = m_conf->getconfi(
"distributor",
"ringbuffersize");
52 m_rbufin =
new RingBuffer(ringbuf.c_str(), rbufsize);
55 m_log =
new RFLogManager(nodename, m_conf->getconf(
"system",
"lognode"));
58 m_flow =
new RFFlowStat(
const_cast<char*
>(shmname.c_str()));
62ERecoDistributor::~ERecoDistributor()
75int ERecoDistributor::Configure(NSMmsg*, NSMcontext*)
79 string ringbuf = string(m_conf->getconf(
"system",
"unitname")) +
":" +
80 string(m_conf->getconf(
"distributor",
"ringbuffer"));
83 string shmname = string(m_conf->getconf(
"system",
"unitname")) +
":" +
84 string(m_conf->getconf(
"distributor",
"nodename"));
88 int maxnodes = m_conf->getconfi(
"processor",
"nnodes");
89 int idbase = m_conf->getconfi(
"processor",
"idbase");
91 char* badlist = m_conf->getconf(
"processor",
"badlist");
93 char* sender = m_conf->getconf(
"distributor",
"sender",
"script");
94 int portbase = m_conf->getconfi(
"distributor",
"sender",
"portbase");
97 char hostname[512], idname[12], shmid[12];
98 for (
int i = 0; i < maxnodes; i++) {
99 snprintf(idname,
sizeof(idname),
"%2.2d", idbase + i);
100 snprintf(shmid,
sizeof(shmid),
"%2.2d", i);
101 if (badlist == NULL ||
102 strstr(badlist, idname) == 0) {
103 int port = (idbase + i) + portbase;
105 sprintf(portchar,
"%d", port);
106 m_pid_sender[m_nnodes] = m_proc->Execute(sender,
const_cast<char*
>(ringbuf.c_str()), portchar,
const_cast<char*
>(shmname.c_str()),
108 printf(
"Running sender to %d\n", port);
116 int maxrecv = m_conf->getconfi(
"distributor",
"receiver",
"nnodes");
117 int ridbase = m_conf->getconfi(
"distributor",
"receiver",
"idbase");
118 const char* rhostbase = m_conf->getconf(
"distributor",
"receiver",
"hostbase");
119 char* rbadlist = m_conf->getconf(
"distributor",
"receiver",
"badlist");
120 char* port = m_conf->getconf(
"distributor",
"receiver",
"port");
121 char* receiver = m_conf->getconf(
"distributor",
"receiver",
"script");
124 for (
int i = 0; i < maxrecv; i++) {
125 sprintf(hostname,
"%s%2.2d", rhostbase, ridbase + i);
126 snprintf(idname,
sizeof(idname),
"%2.2d", ridbase + i);
127 snprintf(shmid,
sizeof(shmid),
"%2.2d", i + 20);
128 if (rbadlist == NULL ||
129 strstr(rbadlist, hostname) == 0) {
130 printf(
"Running receiver for %s\n", hostname);
132 m_pid_recv[m_nrecv] = m_proc->Execute(receiver,
const_cast<char*
>(ringbuf.c_str()), hostname, port,
133 const_cast<char*
>(shmname.c_str()), shmid);
138 printf(
"ERecoDistributor : Configure done\n");
142int ERecoDistributor::UnConfigure(NSMmsg*, NSMcontext*)
147 printf(
"m_nrecv = %d\n", m_nrecv);
148 for (
int i = 0; i < m_nrecv; i++) {
149 if (m_pid_recv[i] != 0) {
150 printf(
"ERecoDistributor : killing receiver pid=%d\n", m_pid_recv[i]);
151 kill(m_pid_recv[i], SIGKILL);
152 waitpid(m_pid_recv[i], &status, 0);
156 printf(
"m_nnodes = %d\n", m_nnodes);
157 for (
int i = 0; i < m_nnodes; i++) {
158 if (m_pid_sender[i] != 0) {
159 printf(
"ERecoDistributor : killing sender pid=%d\n", m_pid_sender[i]);
161 kill(m_pid_sender[i], SIGKILL);
162 waitpid(m_pid_sender[i], &status, 0);
166 m_rbufin->forceClear();
169 m_flow->fillProcessStatus(GetNodeInfo());
171 printf(
"ERecoDistributor : Unconfigure done\n");
175int ERecoDistributor::Start(NSMmsg*, NSMcontext*)
182int ERecoDistributor::Restart(NSMmsg*, NSMcontext*)
184 printf(
"ERecoDistributor : Restarting!!!!!\n");
185 NSMmsg* nsmmsg = NULL;
186 NSMcontext* nsmcontext = NULL;
187 ERecoDistributor::UnConfigure(nsmmsg, nsmcontext);
189 ERecoDistributor::Configure(nsmmsg, nsmcontext);
195void ERecoDistributor::server()
198 m_flow->fillProcessStatus(GetNodeInfo());
201 pid_t pid = m_proc->CheckProcess();
203 printf(
"ERecoDistributor : process dead. pid = %d\n", pid);
204 for (
int i = 0; i < m_nrecv; i++) {
205 if (pid == m_pid_recv[i]) {
206 m_log->Fatal(
"ERecoDistributor : receiver process (%d) dead. pid=%d\n", i, pid);
210 for (
int i = 0; i < m_nnodes; i++) {
211 if (pid == m_pid_sender[i]) {
212 m_log->Fatal(
"ERecoDistributor : sender process (%d) dead. pid=%d\n", i, m_pid_sender[i]);
218 int st = m_proc->CheckOutput();
220 perror(
"ERecoDistributor::server");
223 m_log->ProcessLog(m_proc->GetFd());
Abstract base class for different kinds of events.