#include #include #include #include "Jeep/JParser.hh" #include "Jeep/JMessage.hh" #include "JNet/JControlHost.hh" #include "JDAQ/JDAQTags.hh" /** * \file * * Auxiliary program to start (remote) run control client. * * This program makes a connection to a specific port number on the given host with a preset timeout. * The option -H \[:port] correponds to the hostname and the port of the client, respectively. * The option -m \ corresponds to the argument list provided to method enter of the client. * \author mdejong */ int main(int argc, const char *argv[]) { using namespace std; using namespace JPP; JHostname hostname; string message; int timeout_s; int debug; try { JParser<> zap("Auxiliary program to start (remote) run control client."); zap['H'] = make_field(hostname); zap['m'] = make_field(message); zap['t'] = make_field(timeout_s) = 10; // [s] zap['d'] = make_field(debug) = 3; zap(argc, argv); } catch(const exception &error) { FATAL(error.what() << endl); } using namespace KM3NETDAQ; JControlHost::Throw(true); try { JControlHost starter(hostname); string tag; long long int length = 0; bool is_alive = false; for (int i = 0; i != timeout_s; ++i) { is_alive = (starter.CheckHead(tag, length) > 0); if (!is_alive) sleep(1); else break; } if (is_alive) { { char buffer[length]; starter.GetFullData(buffer, length); const string version(buffer, length); DEBUG("Current version " << CHOO_VERSION << endl); DEBUG("Received version " << version << endl); if (version != CHOO_VERSION) { WARNING("Version mis-match: " << version << " " << CHOO_VERSION << endl); } } DEBUG("Send message " << message << endl); starter.PutFullString(RC_STRT, message); { starter.WaitHead(tag, length); char buffer[length]; starter.GetFullData(buffer, length); DEBUG("Got reply " << string(buffer,length) << endl); } } else { ERROR("Timeout at connecting to " << hostname << " after " << timeout_s << " s." << endl); } } catch(const JControlHostException& error) { ERROR(error << endl); } }