9#include "daq/rfarm/manager/RFEventServer.h"
20#define RFEVSOUT stdout
28RFEventServer::RFEventServer(
const string& conffile)
31 m_conf =
new RFConf(conffile.c_str());
32 char* nodename = m_conf->getconf(
"distributor",
"nodename");
37 string execdir = string(m_conf->getconf(
"system",
"execdir_base")) +
"/distributor";
39 mkdir(execdir.c_str(), 0755);
40 chdir(execdir.c_str());
43 string shmname = string(m_conf->getconf(
"system",
"unitname")) +
":" +
44 string(m_conf->getconf(
"distributor",
"nodename"));
45 m_shm =
new RFSharedMem(
const_cast<char*
>(shmname.c_str()));
48 m_proc =
new RFProcessManager(nodename);
52 string ringbuf = string(m_conf->getconf(
"system",
"unitname")) +
":" +
53 string(m_conf->getconf(
"distributor",
"ringbuffer"));
54 int rbufsize = m_conf->getconfi(
"distributor",
"ringbuffersize");
55 m_rbufin =
new RingBuffer(ringbuf.c_str(), rbufsize);
58 m_log =
new RFLogManager(nodename, m_conf->getconf(
"system",
"lognode"));
61 m_flow =
new RFFlowStat(
const_cast<char*
>(shmname.c_str()));
65 for (
int i = 0; i < m_nnodes; i++)
70RFEventServer::~RFEventServer()
84 s_instance =
new RFEventServer(conffile);
97int RFEventServer::Configure(NSMmsg*, NSMcontext*)
101 string ringbuf = string(m_conf->getconf(
"system",
"unitname")) +
":" +
102 string(m_conf->getconf(
"distributor",
"ringbuffer"));
105 string shmname = string(m_conf->getconf(
"system",
"unitname")) +
":" +
106 string(m_conf->getconf(
"distributor",
"nodename"));
110 int maxnodes = m_conf->getconfi(
"processor",
"nnodes");
111 int idbase = m_conf->getconfi(
"processor",
"idbase");
113 char* badlist = m_conf->getconf(
"processor",
"badlist");
115 char* sender = m_conf->getconf(
"distributor",
"sender",
"script");
116 int portbase = m_conf->getconfi(
"distributor",
"sender",
"portbase");
118 char idname[12], shmid[12];
119 for (
int i = 0; i < maxnodes; i++) {
120 snprintf(idname,
sizeof(idname),
"%2.2d", idbase + i);
121 snprintf(shmid,
sizeof(shmid),
"%2.2d", i);
122 if (badlist == NULL ||
123 strstr(badlist, idname) == 0) {
124 int port = (idbase + i) + portbase;
126 sprintf(portchar,
"%d", port);
127 m_pid_sender[m_nnodes] = m_proc->Execute(sender,
const_cast<char*
>(ringbuf.c_str()), portchar,
const_cast<char*
>(shmname.c_str()),
135 char* srcG = m_conf->getconf(
"distributor",
"source");
136 if (strstr(srcG,
"net") != 0) {
138 char* receiver = m_conf->getconf(
"distributor",
"receiver",
"script");
139 char* src = m_conf->getconf(
"distributor",
"receiver",
"host");
140 char* port = m_conf->getconf(
"distributor",
"receiver",
"port");
143 sprintf(idbuf,
"%2.2d", RF_INPUT_ID);
144 m_pid_recv = m_proc->Execute(receiver,
const_cast<char*
>(ringbuf.c_str()), src, port,
const_cast<char*
>(shmname.c_str()), idbuf);
145 m_flow->clear(RF_INPUT_ID);
146 }
else if (strstr(srcG,
"file") != 0) {
148 char* filein = m_conf->getconf(
"distributor",
"fileinput",
"script");
149 char* file = m_conf->getconf(
"distributor",
"fileinput",
"filename");
151 char* nnodechr = m_conf->getconf(
"distributor",
"nnodes");
152 m_pid_recv = m_proc->Execute(filein,
const_cast<char*
>(ringbuf.c_str()), file, nnodechr);
155 m_rbufin->forceClear();
161int RFEventServer::UnConfigure(NSMmsg*, NSMcontext*)
165 if (m_pid_recv != 0) {
166 kill(m_pid_recv, SIGINT);
167 waitpid(m_pid_recv, &status, 0);
169 for (
int i = 0; i < m_nnodes; i++) {
170 if (m_pid_sender[i] != 0) {
171 printf(
"RFEventServer:: killing sender pid=%d\n", m_pid_sender[i]);
173 kill(m_pid_sender[i], SIGINT);
174 waitpid(m_pid_sender[i], &status, 0);
178 m_rbufin->forceClear();
181 m_flow->fillProcessStatus(GetNodeInfo());
183 printf(
"Unconfigure : done\n");
187int RFEventServer::Start(NSMmsg*, NSMcontext*)
194int RFEventServer::Stop(NSMmsg*, NSMcontext*)
201int RFEventServer::Restart(NSMmsg*, NSMcontext*)
203 printf(
"RFEventServer : Restarting!!!!!\n");
218 NSMmsg* nsmmsg = NULL;
219 NSMcontext* nsmcontext = NULL;
220 RFEventServer::UnConfigure(nsmmsg, nsmcontext);
222 RFEventServer::Configure(nsmmsg, nsmcontext);
228void RFEventServer::server()
231 m_flow->fillProcessStatus(GetNodeInfo());
235 pid_t pid = m_proc->CheckProcess();
237 printf(
"RFEventServer : process dead. pid = %d\n", pid);
238 if (pid == m_pid_recv) {
239 m_log->Fatal(
"RFEventServer : receiver process dead. pid=%d\n", pid);
242 for (
int i = 0; i < m_nnodes; i++) {
243 if (pid == m_pid_sender[i]) {
244 m_log->Fatal(
"RFEventServer : sender process (%d) dead. pid=%d\n", i, m_pid_sender[i]);
251 int st = m_proc->CheckOutput();
253 perror(
"RFEventServer::server");
256 m_log->ProcessLog(m_proc->GetFd());
258 m_flow->fillNodeInfo(RF_INPUT_ID, GetNodeInfo(),
false);
259 m_flow->fillProcessStatus(GetNodeInfo(), m_pid_recv, m_pid_sender[sender_id]);
269void RFEventServer::cleanup()
271 printf(
"RFEventServer : cleaning up\n");
272 UnConfigure(NULL, NULL);
284 printf(
"RFEventServer: Done. Exitting\n");
Abstract base class for different kinds of events.