8 #include "daq/slc/readout/ProcessController.h"
10 #include "daq/slc/readout/ProcessListener.h"
11 #include "daq/slc/readout/LogListener.h"
12 #include "daq/slc/runcontrol/RCHandlerException.h"
14 #include "daq/slc/system/Executor.h"
15 #include "daq/slc/system/PThread.h"
16 #include "daq/slc/system/LogFile.h"
18 #include "daq/slc/base/StringUtil.h"
19 #include <daq/slc/system/LockGuard.h>
27 bool ProcessController::init(
const std::string& parname,
int nodeid)
29 m_name = StringUtil::tolower(m_callback->getNode().getName());
31 LogFile::open(m_name +
"_" + m_parname);
32 if (!m_info.open(m_name +
"_" + m_parname, nodeid,
true)) {
35 m_callback->add(
new NSMVHandlerInt(m_parname +
".pid",
true,
false, 0),
false,
false);
39 void ProcessController::clear()
44 bool ProcessController::waitReady(
int timeout)
46 if (!m_info.waitReady(timeout)) {
52 bool ProcessController::load(
int timeout)
56 m_process.kill(SIGABRT);
57 if (pipe(m_iopipe) < 0) {
66 if (!m_info.waitReady(timeout)) {
71 m_callback->set(m_parname +
".pid", m_process.get_id());
75 bool ProcessController::start(
int expno,
int runno)
78 m_info.setExpNumber(expno);
79 m_info.setRunNumber(runno);
80 m_info.setSubNumber(0);
89 bool ProcessController::stop()
92 m_info.setExpNumber(0);
93 m_info.setRunNumber(0);
94 m_info.setSubNumber(0);
95 m_info.setInputCount(0);
96 m_info.setInputNBytes(0);
97 m_info.setOutputCount(0);
98 m_info.setOutputNBytes(0);
102 bool ProcessController::pause()
105 if (m_info.isRunning()) {
106 m_info.setState(RunInfoBuffer::PAUSED);
108 LogFile::warning(
"Process is not running. Pause request was ignored.");
113 bool ProcessController::resume()
116 if (m_info.isPaused()) {
117 m_info.setState(RunInfoBuffer::RUNNING);
119 LogFile::warning(
"Process is not paused. Resume request was ignored.");
124 bool ProcessController::abort(
unsigned int timeout)
127 m_process.kill(SIGINT);
129 bool sigintWasSuccessful =
false;
130 for (
unsigned int timer = 0; timer < timeout; ++timer) {
131 if (not m_process.isAlive()) {
132 sigintWasSuccessful =
true;
139 if (sigintWasSuccessful) {
140 LogFile::debug(
"Process successfully killed with SIGINT.");
142 LogFile::warning(
"Process could not be killed with SIGINT, sending SIGABRT.");
143 m_process.kill(SIGABRT);
146 if (m_callback != NULL)
147 m_callback->set(m_parname +
".pid", -1);
150 m_th_process.cancel();
156 void ProcessSubmitter::run()
159 dup2(m_iopipe[1], 1);
161 dup2(m_iopipe[1], 2);
164 if (m_con->getExecutable().size() == 0) {
165 m_con->setExecutable(
"basf2");
167 executor.setExecutable(m_con->getExecutable());
168 for (
size_t i = 0; i < m_con->m_arg_v.size(); i++) {
169 executor.addArg(m_con->m_arg_v[i]);
174 void ProcessController::addArgument(
const char* format, ...)
177 static char ss[1024];
178 va_start(ap, format);
179 vsprintf(ss, format, ap);
181 m_arg_v.push_back(ss);
Lock Guard for a Mutex instance.
Abstract base class for different kinds of events.