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>
27bool 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);
39void ProcessController::clear()
44bool ProcessController::waitReady(
int timeout)
46 if (!m_info.waitReady(timeout)) {
52bool ProcessController::load(
int timeout)
56 m_process.kill(SIGABRT);
57 if (pipe(m_iopipe) < 0) {
66 if (!m_info.waitReady(timeout)) {
70 m_callback->set(m_parname +
".pid", m_process.get_id());
74bool ProcessController::start(
int expno,
int runno)
77 m_info.setExpNumber(expno);
78 m_info.setRunNumber(runno);
79 m_info.setSubNumber(0);
88bool ProcessController::stop()
91 m_info.setExpNumber(0);
92 m_info.setRunNumber(0);
93 m_info.setSubNumber(0);
94 m_info.setInputCount(0);
95 m_info.setInputNBytes(0);
96 m_info.setOutputCount(0);
97 m_info.setOutputNBytes(0);
101bool ProcessController::pause()
104 if (m_info.isRunning()) {
105 m_info.setState(RunInfoBuffer::PAUSED);
107 LogFile::warning(
"Process is not running. Pause request was ignored.");
112bool ProcessController::resume()
115 if (m_info.isPaused()) {
116 m_info.setState(RunInfoBuffer::RUNNING);
118 LogFile::warning(
"Process is not paused. Resume request was ignored.");
123bool ProcessController::abort(
unsigned int timeout)
126 m_process.kill(SIGINT);
128 bool sigintWasSuccessful =
false;
129 for (
unsigned int timer = 0; timer < timeout; ++timer) {
130 if (not m_process.isAlive()) {
131 sigintWasSuccessful =
true;
138 if (sigintWasSuccessful) {
139 LogFile::debug(
"Process successfully killed with SIGINT.");
141 LogFile::warning(
"Process could not be killed with SIGINT, sending SIGABRT.");
142 m_process.kill(SIGABRT);
145 if (m_callback != NULL)
146 m_callback->set(m_parname +
".pid", -1);
149 m_th_process.cancel();
155void ProcessSubmitter::run()
158 dup2(m_iopipe[1], 1);
160 dup2(m_iopipe[1], 2);
163 if (m_con->getExecutable().size() == 0) {
164 m_con->setExecutable(
"basf2");
166 executor.setExecutable(m_con->getExecutable());
167 for (
size_t i = 0; i < m_con->m_arg_v.size(); i++) {
168 executor.addArg(m_con->m_arg_v[i]);
173void ProcessController::addArgument(
const char* format, ...)
176 static char ss[1024];
177 va_start(ap, format);
178 vsprintf(ss, format, ap);
180 m_arg_v.push_back(ss);
Lock Guard for a Mutex instance.
Abstract base class for different kinds of events.