#include #include #include #include #include #include #include "Jeep/JParser.hh" #include "Jeep/JMessage.hh" #include "Jeep/JArgs.hh" #include "JSystem/JShell.hh" #include "JRuncontrol/JDAQClient.hh" using namespace KM3NETDAQ; /** * \file * Run control demo client class. * * The various action methods could be implemented in this class. * Note that process with extension /- will sleep and kill itself at event ev_configure according the specified inputs. * Note that process with extension /+ will sleep forever during the exit transition. * \author mdejong */ class JDAQDemoClient : public JDAQClient { public: /** * Constructor. * * \param name name of client * \param server name of command message server * \param logger pointer to logger * \param level debug level */ JDAQDemoClient(const std::string& name, const std::string& server, JLogger* logger, const int level) : JDAQClient(name, server, logger, level) {} /** * Constructor. * * \param name name of client * \param logger pointer to logger * \param level debug level */ JDAQDemoClient(const std::string& name, JLogger* logger, const int level) : JDAQClient(name, logger, level) {} /** * Constructor. * * \param name name of client */ JDAQDemoClient(const std::string& name) : JDAQClient(name) {} virtual void actionEnter() { logger.debug("actionEnter()"); } virtual void actionExit() { logger.debug("actionExit()"); if (getName() == "JDAQDemoClient/+") { // sleep forever sleep(std::numeric_limits::max()); } } virtual void actionInit(int length, const char* buffer) { using namespace std; using namespace JPP; JDebugStream(logger) << "actionInit(" << std::string(buffer,length) << ")"; if (string(buffer,length) == ev_error.name()) { ev_error(); } } virtual void actionConfigure(int length, const char* buffer) { using namespace std; using namespace JPP; JDebugStream(logger) << "actionConfigure(" << std::string(buffer,length) << ")"; if (getName() == "JDAQDemoClient/-") { istringstream is(string(buffer,length)); int us1 = 0, us2 = 0; if (is >> us1 >> us2 && us1 > 0 && us2 > 0) { // sleep and terminate process JErrorStream(logger) << "Time to sleep/kill " << us1 << "/" << us2 << " us"; JShell& shell = JShell::getInstance(); shell << "(usleep " << us2 << "; kill -9 " << getpid() << ") &" << endl; usleep(us1); } } } virtual void actionStart(int length, const char* buffer) { JDebugStream(logger) << "actionStart(" << std::string(buffer,length) << ")"; } virtual void actionPause(int length, const char* buffer) { JDebugStream(logger) << "actionPause(" << std::string(buffer,length) << ")"; } virtual void actionContinue(int length, const char* buffer) { JDebugStream(logger) << "actionContinue(" << std::string(buffer,length) << ")"; } virtual void actionStop(int length, const char* buffer) { JDebugStream(logger) << "actionStop(" << std::string(buffer,length) << ")"; } virtual void actionReset(int length, const char* buffer) { JDebugStream(logger) << "actionReset(" << std::string(buffer,length) << ")"; } virtual void actionQuit(int length, const char* buffer) { JDebugStream(logger) << "actionQuit(" << std::string(buffer,length) << ")"; } }; /** * Run control demo client. */ int main(int argc, char* argv[]) { using namespace std; using namespace JPP; using namespace KM3NETDAQ; string server; string logger; string client_name; bool use_cout; int debug; string file_name; int port; try { JParser<> zap("Application for writing real-time data to disk."); zap['H'] = make_field(server) = "localhost"; zap['M'] = make_field(logger) = "localhost"; zap['u'] = make_field(client_name) = "%"; zap['c'] = make_field(use_cout); zap['d'] = make_field(debug) = 3; zap['f'] = make_field(file_name) = ""; zap['P'] = make_field(port) = -1; zap(argc, argv); } catch(const exception &error) { FATAL(error.what() << endl); } if (port == -1) { JLogger* out = NULL; if (use_cout) out = new JStreamLogger(cout); else out = new JControlHostLogger(logger); if (file_name == "") { JDAQDemoClient demo(getProcessName(client_name, argv[0]), server, out, debug); demo.enter(); demo.run(); } else { JDAQDemoClient demo(getProcessName(client_name, argv[0]), out, debug); if (debug >= debug_t && use_cout) { demo.debug(CHSM::machine::D_all); } demo.CHSM::machine::enter(); ifstream in(file_name.c_str()); demo.run(in); in.close(); } } else { JDAQDemoClient demo(getProcessName(client_name, argv[0])); demo.run(port); } }