9#include <daq/roisend/RoiSenderCallback.h>
25void* RunRoiSenderLogger(
void*)
27 s_roisender->server();
34RoiSenderCallback::RoiSenderCallback()
37 m_conf =
new RFConf(getenv(
"ROISENDER_CONFFILE"));
48 char* nodename = m_conf->getconf(
"roisender",
"nodename");
50 string execdir = string(m_conf->getconf(
"roisender",
"execdir"));
51 printf(
"execdir = %s\n", execdir.c_str());
53 mkdir(execdir.c_str(), 0755);
54 chdir(execdir.c_str());
60 if (!m_log) m_log =
new RFLogManager(nodename, nodename);
67 char* merger = m_conf->getconf(
"roisender",
"merger");
68 char* mergerport = m_conf->getconf(
"roisender",
"mergerport");
70 char* onsenhost = m_conf->getconf(
"roisender",
"onsenhost");
71 char* onsenport = m_conf->getconf(
"roisender",
"onsenport");
73 string shmname = string(m_conf->getconf(
"system",
"unitname")) +
":" +
74 string(m_conf->getconf(
"roisender",
"nodename"));
77 sprintf(idbuf,
"%2.2d", 0);
80 m_pid_merger = m_proc->
Execute(merger, (
char*)shmname.c_str(), idbuf, onsenhost, onsenport, mergerport);
81 if (m_pid_merger <= 0) {
82 LogFile::error(
"loading %s %s %s %s %s %s failed!", merger, (
char*)shmname.c_str(), idbuf, onsenhost, onsenport, mergerport);
83 setState(RCState::ERROR_ES);
91 pthread_attr_t thread_attr;
92 pthread_attr_init(&thread_attr);
96 pthread_create(&m_logthread, NULL, RunRoiSenderLogger, NULL);
100void RoiSenderCallback::start(
int ,
int )
102 if (m_pid_merger > 0) {
103 int pid = m_pid_merger;
105 LogFile::info(
"Send SIGUSR1 to (pid=%d)", pid);
107 LogFile::error(
"No merger_merge in start!");
108 setState(RCState::ERROR_ES);
112void RoiSenderCallback::stop(
void)
114 if (m_pid_merger > 0) {
115 int pid = m_pid_merger;
117 LogFile::info(
"Send SIGUSR2 to (pid=%d)", pid);
119 LogFile::error(
"No merger_merge in stop!");
120 setState(RCState::ERROR_ES);
124void RoiSenderCallback::abort(
void)
127 if (m_pid_merger > 0) {
128 int pid = m_pid_merger;
130 LogFile::info(
"kill merger (pid=%d) with SIGINT ", pid);
133 for (
int i = 0; m_pid_merger; i++) {
135 int pid = m_pid_merger;
136 if (i == 5 && m_pid_merger > 0) {
138 LogFile::warning(
"kill merger (pid=%d) with SIGKILL", pid);
141 LogFile::error(
"killing merger (pid=%d) did not work", pid);
148void RoiSenderCallback::recover(
const DBObject&,
const std::string&)
156 char* merger = m_conf->getconf(
"roisender",
"merger");
157 char* mergerport = m_conf->getconf(
"roisender",
"mergerport");
159 char* onsenhost = m_conf->getconf(
"roisender",
"onsenhost");
160 char* onsenport = m_conf->getconf(
"roisender",
"onsenport");
162 string shmname = string(m_conf->getconf(
"system",
"unitname")) +
":" +
163 string(m_conf->getconf(
"roisender",
"nodename"));
166 sprintf(idbuf,
"%2.2d", 0);
167 m_pid_merger = m_proc->
Execute(merger, (
char*)shmname.c_str(), idbuf, onsenhost, onsenport, mergerport);
171void RoiSenderCallback::server()
174 pid_t pid = m_proc->CheckProcess();
179 if (pid == m_pid_merger) {
180 if (getNode().getState() == RCState::LOADING_TS
181 || getNode().getState() == RCState::STARTING_TS || getNode().getState() == RCState::STOPPING_TS
182 || getNode().getState() == RCState::READY_S || getNode().getState() == RCState::RUNNING_S) {
184 m_log->Fatal(
"RoiSenderCallback : merger2merge dead. pid = %d\n", pid);
185 setState(RCState::ERROR_ES);
187 m_log->Info(
"RoiSenderCallback : merger2merge dead. pid = %d\n", pid);
192 }
else if (pid < 0) {
193 perror(
"RoiSenderCallback::server");
195 int st = m_proc->CheckOutput();
200 perror(
"RoiSenderCallback::server");
202 m_log->ProcessLog(m_proc->GetFd());
int Execute(char *script, int nargs, char **args)
void load(const DBObject &, const std::string &) override
overloaded functions from base class
Abstract base class for different kinds of events.