6 #pragma GCC diagnostic push
7 #pragma GCC diagnostic ignored "-Wdeprecated-declarations"
8 #define _LIBCPP_ENABLE_CXX17_REMOVED_FEATURES 1
10 #include <xmlrpc-c/base.hpp>
11 #include <xmlrpc-c/client_simple.hpp>
12 #include <xmlrpc-c/girerr.hpp>
13 #include <xmlrpc-c/registry.hpp>
14 #include <xmlrpc-c/server_abyss.hpp>
15 #undef _LIBCPP_ENABLE_CXX17_REMOVED_FEATURES
16 #pragma GCC diagnostic pop
18 #include "TRACE/tracemf.h"
19 #include "artdaq/DAQdata/Globals.hh"
20 #define TRACE_NAME (app_name + "_xmlrpc_commander").c_str()
22 #include "artdaq/ExternalComms/CommanderInterface.hh"
24 #include "artdaq-core/Utilities/ExceptionHandler.hh"
26 #include <netinet/in.h>
27 #include <sys/socket.h>
88 std::string
send_init(fhicl::ParameterSet
const& ps, uint64_t timeout, uint64_t timestamp)
override;
100 std::string
send_soft_init(fhicl::ParameterSet
const& ps, uint64_t timeout, uint64_t timestamp)
override;
112 std::string
send_reinit(fhicl::ParameterSet
const& ps, uint64_t timeout, uint64_t timestamp)
override;
124 std::string
send_start(art::RunID runNumber, uint64_t timeout, uint64_t timestamp)
override;
135 std::string
send_pause(uint64_t timeout, uint64_t timestamp)
override;
146 std::string
send_resume(uint64_t timeout, uint64_t timestamp)
override;
157 std::string
send_stop(uint64_t timeout, uint64_t timestamp)
override;
184 std::string
send_report(std::string
const& what)
override;
217 std::string
send_trace_set(std::string
const& name, std::string
const& type, std::string
const& mask)
override;
227 std::string
send_meta_command(std::string
const& command, std::string
const& argument)
override;
248 std::string serverUrl_;
250 std::string send_command_(
const std::string& command);
251 std::string send_command_(
const std::string& command,
const std::string& arg);
252 std::string send_command_(
const std::string& command,
const fhicl::ParameterSet& pset, uint64_t timestamp, uint64_t timeout);
253 std::string send_command_(
const std::string& command, uint64_t a, uint64_t b);
254 std::string send_command_(
const std::string& command, uint64_t a, uint32_t b);
255 std::string send_command_(
const std::string& command, art::RunID r, uint64_t a, uint64_t b);
256 std::string send_command_(
const std::string&, uint64_t);
257 std::string send_command_(
const std::string&,
const std::string&,
const std::string&);
258 std::string send_command_(
const std::string&,
const std::string&,
const std::string&,
const std::string&);
262 std::unique_ptr<xmlrpc_c::serverAbyss>
server;
274 env_wrap() { xmlrpc_env_init(&this->env_c); };
284 static xmlrpc_c::paramList
285 pListFromXmlrpcArray(xmlrpc_value*
const arrayP)
288 XMLRPC_ASSERT_ARRAY_OK(arrayP);
289 unsigned int const arraySize = xmlrpc_array_size(&env.env_c, arrayP);
290 assert(!env.env_c.fault_occurred);
291 xmlrpc_c::paramList paramList(arraySize);
292 for (
unsigned int i = 0; i < arraySize; ++i)
294 xmlrpc_value* arrayItemP;
295 xmlrpc_array_read_item(&env.env_c, arrayP, i, &arrayItemP);
296 assert(!env.env_c.fault_occurred);
297 paramList.add(xmlrpc_c::value(arrayItemP));
298 xmlrpc_DECREF(arrayItemP);
303 c_executeMethod(xmlrpc_env*
const envP,
304 xmlrpc_value*
const paramArrayP,
305 void*
const methodPtr,
306 void*
const callInfoPtr)
308 auto*
const methodP(static_cast<xmlrpc_c::method*>(methodPtr));
309 xmlrpc_c::paramList
const paramList(pListFromXmlrpcArray(paramArrayP));
310 auto*
const callInfoP(static_cast<xmlrpc_c::callInfo*>(callInfoPtr));
311 xmlrpc_value* retval;
315 xmlrpc_c::value result;
318 auto*
const method2P(dynamic_cast<xmlrpc_c::method2*>(methodP));
319 if (method2P !=
nullptr)
321 method2P->execute(paramList, callInfoP, &result);
325 methodP->execute(paramList, &result);
328 catch (xmlrpc_c::fault
const& fault)
330 xmlrpc_env_set_fault(envP, fault.getCode(),
331 fault.getDescription().c_str());
333 if (envP->fault_occurred == 0)
335 if (result.isInstantiated())
337 retval = result.cValue();
342 "Xmlrpc-c user's xmlrpc_c::method object's "
343 "'execute method' failed to set the RPC result "
348 catch (std::exception
const& e)
351 "Unexpected error executing code for "
352 "particular method, detected by Xmlrpc-c "
353 "method registry code. Method did not "
354 "fail; rather, it did not complete at all. %s",
359 xmlrpc_env_set_fault(envP, XMLRPC_INTERNAL_ERROR,
360 "Unexpected error executing code for "
361 "particular method, detected by Xmlrpc-c "
362 "method registry code. Method did not "
363 "fail; rather, it did not complete at all.");
376 const std::string& helpText =
"execute request")
378 std::string msg(
"Exception when trying to ");
379 msg.append(helpText);
381 msg.append(er.what());
382 if (msg[msg.size() - 1] ==
'\n')
384 msg.erase(msg.size() - 1);
396 const std::string& helpText)
398 std::string msg(
"Exception when trying to ");
399 msg.append(helpText);
401 msg.append(er.what());
402 if (msg[msg.size() - 1] ==
'\n')
404 msg.erase(msg.size() - 1);
416 const std::string& helpText)
418 std::string msg(
"Exception when trying to ");
419 msg.append(helpText);
421 msg.append(er.what());
422 if (msg[msg.size() - 1] ==
'\n')
424 msg.erase(msg.size() - 1);
436 const std::string& helpText)
438 std::string msg(
"Exception when trying to ");
439 msg.append(helpText);
441 msg.append(boost::diagnostic_information(er));
442 if (msg[msg.size() - 1] ==
'\n') msg.erase(msg.size() - 1);
452 const std::string& helpText)
454 std::string msg(
"Exception when trying to ");
455 msg.append(helpText);
457 msg.append(er.what());
458 if (msg[msg.size() - 1] ==
'\n') msg.erase(msg.size() - 1);
469 const std::string& helpText)
471 std::string msg(
"Exception when trying to ");
472 msg.append(helpText);
475 if (msg[msg.size() - 1] ==
'\n')
477 msg.erase(msg.size() - 1);
499 class cmd_ :
public xmlrpc_c::method
512 _signature = signature;
521 void execute(
const xmlrpc_c::paramList& paramList, xmlrpc_c::value* retvalP)
final;
531 virtual bool execute_(
const xmlrpc_c::paramList&, xmlrpc_c::value* retvalP) = 0;
543 T
getParam(
const xmlrpc_c::paramList& paramList,
int index);
569 T
getParam(
const xmlrpc_c::paramList& paramList,
int index, T default_value);
578 throw cet::exception(
"cmd_") <<
"Error in cmd_::getParam(): value type not supported" << std::endl;
590 uint64_t cmd_::getParam<uint64_t>(
const xmlrpc_c::paramList& paramList,
int index)
592 TLOG(TLVL_DEBUG + 33) <<
"Getting parameter " << index <<
" from list as uint64_t.";
595 TLOG(TLVL_DEBUG + 33) <<
"Param value: " << paramList.getI8(index);
596 return static_cast<uint64_t
>(paramList.getI8(index));
600 TLOG(TLVL_DEBUG + 33) <<
"Param value (int): " << paramList.getInt(index);
601 return static_cast<uint64_t
>(paramList.getInt(index));
614 uint32_t cmd_::getParam<uint32_t>(
const xmlrpc_c::paramList& paramList,
int index)
616 TLOG(TLVL_DEBUG + 33) <<
"Getting parameter " << index <<
" from list as uint32_t.";
617 TLOG(TLVL_DEBUG + 33) <<
"Param value: " << paramList.getInt(index);
618 return static_cast<uint32_t
>(paramList.getInt(index));
630 std::string cmd_::getParam<std::string>(
const xmlrpc_c::paramList& paramList,
int index)
632 TLOG(TLVL_DEBUG + 33) <<
"Getting parameter " << index <<
" from list as string.";
633 TLOG(TLVL_DEBUG + 33) <<
"Param value: " << paramList.getString(index);
634 return static_cast<std::string
>(paramList.getString(index));
646 art::RunID cmd_::getParam<art::RunID>(
const xmlrpc_c::paramList& paramList,
int index)
648 TLOG(TLVL_DEBUG + 33) <<
"Getting parameter " << index <<
" from list as Run Number.";
649 art::RunNumber_t run_number;
652 TLOG(TLVL_DEBUG + 33) <<
"Param value: " << paramList.getInt(index);
653 run_number = art::RunNumber_t(paramList.getInt(index));
657 TLOG(TLVL_DEBUG + 33) <<
"Parameter is not an int. Trying string...";
659 auto runNumber = paramList.getString(index);
660 TLOG(TLVL_DEBUG + 33) <<
"Got run number string " << runNumber;
661 run_number = art::RunNumber_t(std::stoi(runNumber));
664 art::RunID run_id(run_number);
677 fhicl::ParameterSet cmd_::getParam<fhicl::ParameterSet>(
const xmlrpc_c::paramList& paramList,
int index)
679 TLOG(TLVL_DEBUG + 33) <<
"Getting parameter " << index <<
" from list as ParameterSet.";
680 TLOG(TLVL_DEBUG + 33) <<
"Param value: " << paramList.getString(index);
681 std::string configString = std::string(paramList.getString(index));
682 TLOG(TLVL_DEBUG + 32) <<
"Loading Parameter Set from string: " << configString << std::endl;
683 fhicl::ParameterSet pset;
687 pset = fhicl::ParameterSet::make(configString);
689 catch (
const fhicl::exception& e)
691 if (getenv(
"FHICL_FILE_PATH") ==
nullptr)
693 TLOG(TLVL_ERROR) <<
"INFO: environment variable FHICL_FILE_PATH was not set. Using \".\"";
694 std::cerr <<
"INFO: environment variable FHICL_FILE_PATH was not set. Using \".\"" << std::endl;
695 setenv(
"FHICL_FILE_PATH",
".", 0);
697 cet::filepath_lookup_after1 lookup_policy(
"FHICL_FILE_PATH");
698 pset = fhicl::ParameterSet::make(configString, lookup_policy);
701 TLOG(TLVL_INFO) <<
"Parameter Set Loaded." << std::endl;
709 T val = default_value;
711 if (static_cast<unsigned>(index) < paramList.size())
713 val = getParam<T>(paramList, index);
718 void cmd_::execute(
const xmlrpc_c::paramList& paramList, xmlrpc_c::value*
const retvalP)
720 TLOG(TLVL_DEBUG + 33) <<
"Received Request to " << _help <<
", attempting to get lock";
721 std::unique_lock<std::timed_mutex> lk(
_c.
mutex_, std::defer_lock);
722 lk.try_lock_for(std::chrono::milliseconds(250));
740 if (!retvalP->isInstantiated())
742 *retvalP = xmlrpc_c::value_string(
"Success");
748 *retvalP = xmlrpc_c::value_string(problemReport);
751 catch (std::runtime_error& er)
754 *retvalP = xmlrpc_c::value_string(msg);
755 TLOG(TLVL_ERROR) << msg;
757 catch (art::Exception& er)
760 *retvalP = xmlrpc_c::value_string(msg);
761 TLOG(TLVL_ERROR) << msg;
763 catch (cet::exception& er)
766 *retvalP = xmlrpc_c::value_string(msg);
767 TLOG(TLVL_ERROR) << msg;
769 catch (boost::exception& er)
772 *retvalP = xmlrpc_c::value_string(msg);
773 TLOG(TLVL_ERROR) << msg;
775 catch (std::exception& er)
778 *retvalP = xmlrpc_c::value_string(msg);
779 TLOG(TLVL_ERROR) << msg;
783 std::string msg =
exception_msg(
"Unknown exception (not from std, boost, cet, or art)", _help);
784 *retvalP = xmlrpc_c::value_string(msg);
785 TLOG(TLVL_ERROR) << msg;
792 TLOG(TLVL_ERROR) <<
"Unable to get lock while trying to " << _help <<
", returning busy";
793 *retvalP = xmlrpc_c::value_string(
"busy");
805 #define GENERATE_INIT_TRANSITION(NAME, CALL, DESCRIPTION) \
807 class NAME##_ : public cmd_ \
813 explicit NAME##_(xmlrpc_commander& c) : cmd_(c, "s:sII", DESCRIPTION) {} \
816 static const uint64_t defaultTimeout = 45; \
818 static const uint64_t defaultTimestamp = std::numeric_limits<const uint64_t>::max(); \
821 bool execute_(const xmlrpc_c::paramList& paramList, xmlrpc_c::value* const retvalP) \
823 fhicl::ParameterSet ps; \
826 ps = getParam<fhicl::ParameterSet>(paramList, 0); \
830 *retvalP = xmlrpc_c::value_string("Error: The " #NAME " message requires a single argument that is a string containing the initialization ParameterSet"); \
834 return _c._commandable.CALL(ps, \
835 getParam<uint64_t>(paramList, 1, defaultTimeout), \
836 getParam<uint64_t>(paramList, 2, defaultTimestamp)); \
840 GENERATE_INIT_TRANSITION(init, initialize,
"initialize the program")
842 GENERATE_INIT_TRANSITION(soft_init, soft_initialize, "initialize software components in the program")
844 GENERATE_INIT_TRANSITION(reinit, reinitialize, "re-initialize the program")
846 #undef GENERATE_INIT_TRANSITION
861 :
cmd_(c,
"s:iII",
"start the run")
870 bool execute_(xmlrpc_c::paramList
const& paramList, xmlrpc_c::value*
const retvalP)
override
874 getParam<art::RunID>(paramList, 0);
878 *retvalP = xmlrpc_c::value_string(
"Error: The start message requires the run number as an argument.");
896 #define GENERATE_TIMEOUT_TIMESTAMP_TRANSITION(NAME, CALL, DESCRIPTION, TIMEOUT) \
898 class NAME##_ : public cmd_ \
903 NAME##_(xmlrpc_commander& c) : cmd_(c, "s:II", DESCRIPTION) {} \
906 static const uint64_t defaultTimeout = TIMEOUT; \
908 static const uint64_t defaultTimestamp = std::numeric_limits<const uint64_t>::max(); \
911 bool execute_(const xmlrpc_c::paramList& paramList, xmlrpc_c::value* const) \
913 return _c._commandable.CALL(getParam<uint64_t>(paramList, 0, defaultTimeout), \
914 getParam<uint64_t>(paramList, 1, defaultTimestamp)); \
918 GENERATE_TIMEOUT_TIMESTAMP_TRANSITION(pause, pause,
"pause the program", 45)
920 GENERATE_TIMEOUT_TIMESTAMP_TRANSITION(resume, resume, "resume the program", 45)
922 GENERATE_TIMEOUT_TIMESTAMP_TRANSITION(stop, stop, "stop the program", 45)
924 #undef GENERATE_TIMEOUT_TIMESTAMP_TRANSITION
937 :
cmd_(c,
"s:i",
"shutdown the program")
944 bool execute_(
const xmlrpc_c::paramList& paramList, xmlrpc_c::value*
const )
override
970 :
cmd_(c,
"s:n",
"report the current state")
974 bool execute_(xmlrpc_c::paramList
const& , xmlrpc_c::value*
const retvalP)
override
992 :
cmd_(c,
"s:s",
"report statistics")
996 bool execute_(xmlrpc_c::paramList
const& paramList, xmlrpc_c::value*
const retvalP)
override
1000 getParam<std::string>(paramList, 0);
1004 *retvalP = xmlrpc_c::value_string(
"Error: The report message requires a single argument that selects the type of statistics to be reported.");
1008 *retvalP = xmlrpc_c::value_string(
_c.
_commandable.
report(getParam<std::string>(paramList, 0)));
1024 :
cmd_(c,
"s:n",
"return the currently legal commands")
1028 bool execute_(xmlrpc_c::paramList
const& , xmlrpc_c::value*
const retvalP)
override
1031 std::string resultString;
1033 for (
auto& cmd : cmdList)
1035 resultString.append(cmd +
" ");
1036 if (cmd ==
"shutdown")
1038 resultString.append(
" reset");
1041 *retvalP = xmlrpc_c::value_string(resultString);
1058 :
cmd_(c,
"s:s",
"Get notified of a new monitor")
1062 bool execute_(xmlrpc_c::paramList
const& paramList, xmlrpc_c::value*
const retvalP)
override
1066 getParam<fhicl::ParameterSet>(paramList, 0);
1070 *retvalP = xmlrpc_c::value_string(
"Error: The register_monitor command expects a string representing the FHiCL definition of a Transfer plugin");
1090 :
cmd_(c,
"s:s",
"Remove a monitor")
1094 bool execute_(xmlrpc_c::paramList
const& paramList, xmlrpc_c::value*
const retvalP)
override
1098 getParam<std::string>(paramList, 0);
1102 *retvalP = xmlrpc_c::value_string(
"Error: The unregister_monitor command expects a string representing the label of the monitor to be removed");
1122 :
cmd_(c,
"s:ssI",
"Set TRACE mask")
1126 bool execute_(xmlrpc_c::paramList
const& paramList, xmlrpc_c::value*
const retvalP)
override
1130 getParam<std::string>(paramList, 0);
1131 getParam<std::string>(paramList, 1);
1132 getParam<std::string>(paramList, 2);
1136 *retvalP = xmlrpc_c::value_string(
"Error: The trace_set command expects a name (ALL for all), a mask type (M, S , or T), and a mask");
1140 return _c.
_commandable.
do_trace_set(getParam<std::string>(paramList, 0), getParam<std::string>(paramList, 1), getParam<std::string>(paramList, 2));
1155 :
cmd_(c,
"s:s",
"Get TRACE mask")
1159 bool execute_(xmlrpc_c::paramList
const& paramList, xmlrpc_c::value*
const retvalP)
override
1163 getParam<std::string>(paramList, 0);
1167 *retvalP = xmlrpc_c::value_string(
"Error: The trace_get command expects a name (ALL for all)");
1187 :
cmd_(c,
"s:ss",
"Run custom command")
1191 bool execute_(xmlrpc_c::paramList
const& paramList, xmlrpc_c::value*
const retvalP)
override
1195 getParam<std::string>(paramList, 0);
1196 getParam<std::string>(paramList, 1);
1200 *retvalP = xmlrpc_c::value_string(
"Error: The meta_command command expects a string command and a string argument");
1219 :
cmd_(c,
"s:Ii",
"create a new subrun")
1226 bool execute_(
const xmlrpc_c::paramList& paramList, xmlrpc_c::value*
const )
override
1244 :
cmd_(c,
"s:ss",
"Add an entry to the configuration archive list")
1248 bool execute_(xmlrpc_c::paramList
const& paramList, xmlrpc_c::value*
const retvalP)
override
1252 getParam<std::string>(paramList, 0);
1253 getParam<std::string>(paramList, 1);
1257 *retvalP = xmlrpc_c::value_string(
"Error: The add_config_archive_entry command expects a string key and a string value");
1276 :
cmd_(c,
"s:n",
"Clear the configuration archive list")
1280 bool execute_(xmlrpc_c::paramList
const& , xmlrpc_c::value*
const )
override
1292 class shutdown_ :
public xmlrpc_c::registry::shutdown
1295 shutdown_(xmlrpc_c::serverAbyss *server) : _server(server) {}
1297 virtual void doit(
const std::string& paramString,
void*)
const
1299 TLOG(TLVL_INFO) <<
"A shutdown command was sent "
1300 <<
"with parameter "
1301 << paramString <<
"\"";
1302 _server->terminate();
1305 xmlrpc_c::serverAbyss *_server;
1311 , port_(ps.get<int>(
"id", 0))
1312 , serverUrl_(ps.get<std::string>(
"server_url",
""))
1315 if (serverUrl_.empty())
1317 char hostname[HOST_NAME_MAX];
1318 gethostname(hostname, HOST_NAME_MAX);
1319 serverUrl_ = std::string(hostname);
1321 if (serverUrl_.find(
"http") == std::string::npos)
1323 serverUrl_ =
"http://" + serverUrl_;
1325 if (serverUrl_.find(std::to_string(port_)) == std::string::npos && serverUrl_.find(
':', 7) == std::string::npos)
1327 serverUrl_ = serverUrl_ +
":" + std::to_string(port_);
1329 if (serverUrl_.find(
"RPC2") == std::string::npos)
1331 serverUrl_ = serverUrl_ +
"/RPC2";
1333 TLOG(TLVL_INFO) <<
"XMLRPC COMMANDER CONSTRUCTOR: Port: " << port_ <<
", Server Url: " << serverUrl_;
1340 xmlrpc_c::registry registry;
1341 struct xmlrpc_method_info3 methodInfo;
1342 memset(&methodInfo, 0,
sizeof(methodInfo));
1347 #define register_method(m) register_method2(m, 0x400000)
1350 xmlrpc_registry*** c_registryPPP;
1351 c_registryPPP =
reinterpret_cast<xmlrpc_registry***
>(
reinterpret_cast<char*
>(®istry) +
sizeof(girmem::autoObject));
1353 #define register_method2(m, ss) \
1354 xmlrpc_c::method* ptr_##m(dynamic_cast<xmlrpc_c::method*>(new m##_(*this))); \
1355 std::string m##signature = ptr_##m->signature(), m##help = ptr_##m->help(); \
1356 methodInfo.methodName = "daq." #m; \
1357 methodInfo.methodFunction = &c_executeMethod; \
1358 methodInfo.serverInfo = ptr_##m; \
1359 methodInfo.stackSize = ss; \
1360 methodInfo.signatureString = &m##signature[0]; \
1361 methodInfo.help = &m##help[0]; \
1362 xmlrpc_env_init(&env); \
1363 xmlrpc_registry_add_method3(&env, **c_registryPPP, &methodInfo); \
1364 if (env.fault_occurred) throw(girerr::error(env.fault_string)); \
1365 xmlrpc_env_clean(&env)
1367 #define unregister_method(m) delete ptr_##m;
1369 register_method2(init, 0x200000);
1370 register_method(soft_init);
1371 register_method(reinit);
1372 register_method(start);
1373 register_method(status);
1374 register_method(report);
1375 register_method(stop);
1376 register_method(pause);
1377 register_method(resume);
1378 register_method(register_monitor);
1379 register_method(unregister_monitor);
1380 register_method(legal_commands);
1381 register_method(trace_set);
1382 register_method(trace_get);
1383 register_method(meta_command);
1384 register_method(rollover_subrun);
1388 register_method(shutdown);
1391 xmlrpc_c::methodPtr
const ptr_reset(
new shutdown_(*
this));
1392 registry.addMethod(
"daq.reset", ptr_reset);
1394 #undef register_method
1411 XMLRPC_SOCKET socket_file_descriptor = socket(PF_INET, SOCK_STREAM, 0);
1413 if (socket_file_descriptor < 0)
1415 throw cet::exception(
"xmlrpc_commander::run") <<
"Problem with the socket() call; C-style errno == " << errno <<
" (" << strerror(errno) <<
")";
1419 int retval = setsockopt(socket_file_descriptor,
1420 SOL_SOCKET, SO_REUSEADDR,
1421 &enable,
sizeof(
int));
1425 throw cet::exception(
"xmlrpc_commander::run") <<
"Problem with the call to setsockopt(); C-style errno == " << errno <<
" (" << strerror(errno) <<
")";
1428 struct sockaddr_in sockAddr;
1430 sockAddr.sin_family = AF_INET;
1431 sockAddr.sin_port = htons(port_);
1432 sockAddr.sin_addr.s_addr = 0;
1434 retval = bind(socket_file_descriptor,
1435 reinterpret_cast<struct sockaddr*>(&sockAddr),
1440 close(socket_file_descriptor);
1441 throw cet::exception(
"xmlrpc_commander::run") <<
"Problem with the bind() call; C-style errno == " << errno <<
" (" << strerror(errno) <<
")";
1444 server = std::make_unique<xmlrpc_c::serverAbyss>(xmlrpc_c::serverAbyss::constrOpt().registryP(®istry).socketFd(socket_file_descriptor));
1447 xmlrpc_c::serverAbyss::shutdown shutdown_obj(&
server);
1448 registry.setShutdown(&shutdown_obj);
1451 TLOG(TLVL_DEBUG + 32) <<
"running server";
1467 TLOG(TLVL_WARNING) <<
"server threw an exception; closing the socket and rethrowing";
1469 close(socket_file_descriptor);
1473 close(socket_file_descriptor);
1475 unregister_method(init);
1476 unregister_method(soft_init);
1477 unregister_method(reinit);
1478 unregister_method(start);
1479 unregister_method(status);
1480 unregister_method(report);
1481 unregister_method(stop);
1482 unregister_method(pause);
1483 unregister_method(resume);
1484 unregister_method(register_monitor);
1485 unregister_method(unregister_monitor);
1486 unregister_method(legal_commands);
1487 unregister_method(trace_set);
1488 unregister_method(trace_get);
1489 unregister_method(meta_command);
1490 unregister_method(rollover_subrun);
1494 unregister_method(shutdown);
1496 TLOG(TLVL_DEBUG + 32) <<
"server terminated";
1503 std::string xmlrpc_commander::send_command_(
const std::string& command)
1505 if (serverUrl_.empty())
1507 std::stringstream errmsg;
1508 errmsg <<
"Problem attempting " << command <<
" XML-RPC call: No server URL set!";
1509 ExceptionHandler(ExceptionHandlerRethrow::yes, errmsg.str());
1511 xmlrpc_c::clientSimple myClient;
1512 xmlrpc_c::value result;
1516 myClient.call(serverUrl_,
"daq." + command,
"", &result);
1520 std::stringstream errmsg;
1521 errmsg <<
"Problem attempting " << command <<
" XML-RPC call on host " << serverUrl_
1522 <<
"; possible causes are malformed FHiCL or nonexistent process at requested port";
1523 ExceptionHandler(ExceptionHandlerRethrow::yes, errmsg.str());
1526 return xmlrpc_c::value_string(result);
1529 std::string xmlrpc_commander::send_command_(
const std::string& command,
const std::string& arg)
1531 if (serverUrl_.empty())
1533 std::stringstream errmsg;
1534 errmsg <<
"Problem attempting " << command <<
" XML-RPC call: No server URL set!";
1535 ExceptionHandler(ExceptionHandlerRethrow::yes, errmsg.str());
1537 xmlrpc_c::clientSimple myClient;
1538 xmlrpc_c::value result;
1542 myClient.call(serverUrl_,
"daq." + command,
"s", &result, arg.c_str());
1546 std::stringstream errmsg;
1547 errmsg <<
"Problem attempting " << command <<
" XML-RPC call on host " << serverUrl_
1548 <<
"; possible causes are malformed FHiCL or nonexistent process at requested port";
1549 ExceptionHandler(ExceptionHandlerRethrow::yes, errmsg.str());
1552 return xmlrpc_c::value_string(result);
1555 std::string xmlrpc_commander::send_command_(
const std::string& command,
const fhicl::ParameterSet& pset, uint64_t timestamp, uint64_t timeout)
1557 if (serverUrl_.empty())
1559 std::stringstream errmsg;
1560 errmsg <<
"Problem attempting " << command <<
" XML-RPC call: No server URL set!";
1561 ExceptionHandler(ExceptionHandlerRethrow::yes, errmsg.str());
1563 xmlrpc_c::clientSimple myClient;
1564 xmlrpc_c::value result;
1568 myClient.call(serverUrl_,
"daq." + command,
"sII", &result, pset.to_string().c_str(), timestamp, timeout);
1572 std::stringstream errmsg;
1573 errmsg <<
"Problem attempting " << command <<
" XML-RPC call on host " << serverUrl_
1574 <<
"; possible causes are malformed FHiCL or nonexistent process at requested port";
1575 ExceptionHandler(ExceptionHandlerRethrow::yes, errmsg.str());
1578 return xmlrpc_c::value_string(result);
1581 std::string artdaq::xmlrpc_commander::send_command_(
const std::string& command, uint64_t a, uint64_t b)
1583 if (serverUrl_.empty())
1585 std::stringstream errmsg;
1586 errmsg <<
"Problem attempting " << command <<
" XML-RPC call: No server URL set!";
1587 ExceptionHandler(ExceptionHandlerRethrow::yes, errmsg.str());
1589 xmlrpc_c::clientSimple myClient;
1590 xmlrpc_c::value result;
1594 myClient.call(serverUrl_,
"daq." + command,
"II", &result, a, b);
1598 std::stringstream errmsg;
1599 errmsg <<
"Problem attempting " << command <<
" XML-RPC call on host " << serverUrl_
1600 <<
"; possible causes are malformed FHiCL or nonexistent process at requested port";
1601 ExceptionHandler(ExceptionHandlerRethrow::yes, errmsg.str());
1604 return xmlrpc_c::value_string(result);
1607 std::string artdaq::xmlrpc_commander::send_command_(
const std::string& command, uint64_t a, uint32_t b)
1609 if (serverUrl_.empty())
1611 std::stringstream errmsg;
1612 errmsg <<
"Problem attempting " << command <<
" XML-RPC call: No server URL set!";
1613 ExceptionHandler(ExceptionHandlerRethrow::yes, errmsg.str());
1615 xmlrpc_c::clientSimple myClient;
1616 xmlrpc_c::value result;
1620 myClient.call(serverUrl_,
"daq." + command,
"Ii", &result, a, b);
1624 std::stringstream errmsg;
1625 errmsg <<
"Problem attempting " << command <<
" XML-RPC call on host " << serverUrl_
1626 <<
"; possible causes are malformed FHiCL or nonexistent process at requested port";
1627 ExceptionHandler(ExceptionHandlerRethrow::yes, errmsg.str());
1630 return xmlrpc_c::value_string(result);
1633 std::string artdaq::xmlrpc_commander::send_command_(
const std::string& command, art::RunID r, uint64_t a, uint64_t b)
1635 if (serverUrl_.empty())
1637 std::stringstream errmsg;
1638 errmsg <<
"Problem attempting " << command <<
" XML-RPC call: No server URL set!";
1639 ExceptionHandler(ExceptionHandlerRethrow::yes, errmsg.str());
1641 xmlrpc_c::clientSimple myClient;
1642 xmlrpc_c::value result;
1646 myClient.call(serverUrl_,
"daq." + command,
"iII", &result, r.run(), a, b);
1650 std::stringstream errmsg;
1651 errmsg <<
"Problem attempting " << command <<
" XML-RPC call on host " << serverUrl_
1652 <<
"; possible causes are malformed FHiCL or nonexistent process at requested port";
1653 ExceptionHandler(ExceptionHandlerRethrow::yes, errmsg.str());
1656 return xmlrpc_c::value_string(result);
1659 std::string artdaq::xmlrpc_commander::send_command_(
const std::string& command, uint64_t arg1)
1661 if (serverUrl_.empty())
1663 std::stringstream errmsg;
1664 errmsg <<
"Problem attempting " << command <<
" XML-RPC call: No server URL set!";
1665 ExceptionHandler(ExceptionHandlerRethrow::yes, errmsg.str());
1667 xmlrpc_c::clientSimple myClient;
1668 xmlrpc_c::value result;
1672 myClient.call(serverUrl_,
"daq." + command,
"I", &result, arg1);
1676 std::stringstream errmsg;
1677 errmsg <<
"Problem attempting " << command <<
" XML-RPC call on host " << serverUrl_
1678 <<
"; possible causes are malformed FHiCL or nonexistent process at requested port";
1679 ExceptionHandler(ExceptionHandlerRethrow::yes, errmsg.str());
1682 return xmlrpc_c::value_string(result);
1685 std::string artdaq::xmlrpc_commander::send_command_(
const std::string& command,
const std::string& arg1,
const std::string& arg2)
1687 if (serverUrl_.empty())
1689 std::stringstream errmsg;
1690 errmsg <<
"Problem attempting " << command <<
" XML-RPC call: No server URL set!";
1691 ExceptionHandler(ExceptionHandlerRethrow::yes, errmsg.str());
1693 xmlrpc_c::clientSimple myClient;
1694 xmlrpc_c::value result;
1698 myClient.call(serverUrl_,
"daq." + command,
"ss", &result, arg1.c_str(), arg2.c_str());
1702 std::stringstream errmsg;
1703 errmsg <<
"Problem attempting " << command <<
" XML-RPC call on host " << serverUrl_
1704 <<
"; possible causes are malformed FHiCL or nonexistent process at requested port";
1705 ExceptionHandler(ExceptionHandlerRethrow::yes, errmsg.str());
1708 return xmlrpc_c::value_string(result);
1711 std::string artdaq::xmlrpc_commander::send_command_(
const std::string& command,
const std::string& arg1,
const std::string& arg2,
const std::string& arg3)
1713 if (serverUrl_.empty())
1715 std::stringstream errmsg;
1716 errmsg <<
"Problem attempting " << command <<
" XML-RPC call: No server URL set!";
1717 ExceptionHandler(ExceptionHandlerRethrow::yes, errmsg.str());
1719 xmlrpc_c::clientSimple myClient;
1720 xmlrpc_c::value result;
1724 myClient.call(serverUrl_,
"daq." + command,
"sss", &result, arg1.c_str(), arg2.c_str(), arg3.c_str());
1728 std::stringstream errmsg;
1729 errmsg <<
"Problem attempting " << command <<
" XML-RPC call on host " << serverUrl_
1730 <<
"; possible causes are bad arguments or nonexistent process at requested port";
1731 ExceptionHandler(ExceptionHandlerRethrow::yes, errmsg.str());
1734 return xmlrpc_c::value_string(result);
1739 return send_command_(
"register_monitor", monitor_fhicl);
1743 return send_command_(
"unregister_monitor", monitor_label);
1747 return send_command_(
"init", ps, timeout, timestamp);
1751 return send_command_(
"soft_init", ps, timeout, timestamp);
1755 return send_command_(
"reinit", ps, timeout, timestamp);
1759 return send_command_(
"start", run, timeout, timestamp);
1763 return send_command_(
"pause", timeout, timestamp);
1767 return send_command_(
"resume", timeout, timestamp);
1771 return send_command_(
"stop", timeout, timestamp);
1775 return send_command_(
"shutdown", timeout);
1779 return send_command_(
"status");
1783 return send_command_(
"report", what);
1787 return send_command_(
"legal_commands");
1791 return send_command_(
"trace_get", name);
1795 return send_command_(
"trace_set", name, type, mask);
1799 return send_command_(
"meta_command", command, arg);
1803 return send_command_(
"rollover_subrun", when, sr);
virtual bool do_add_config_archive_entry(std::string const &, std::string const &)
Add the specified key-value pair to the configuration archive list.
This interface defines the functions used to transfer data between artdaq applications.
cmd_(xmlrpc_commander &c, const std::string &signature, const std::string &description)
cmd_ Constructor
static const uint64_t defaultTimeout
virtual std::string report(std::string const &) const
Default report implementation returns current report_string.
Commandable is the base class for all artdaq components which implement the artdaq state machine...
legal_commands_(xmlrpc_commander &c)
legal_commands_ Constructor
virtual bool do_clear_config_archive()
Clears the configuration archive list.
Command class representing a start transition.
rollover_subrun_(xmlrpc_commander &c)
shutdown_ Constructor
xmlrpc_commander(const fhicl::ParameterSet &ps, artdaq::Commandable &commandable)
xmlrpc_commander Constructor
std::string send_trace_set(std::string const &name, std::string const &type, std::string const &mask) override
Send an send_trace_msgfacility_set command over XMLRPC
std::string send_register_monitor(std::string const &monitor_fhicl) override
Send a register_monitor command over XMLRPC
std::string send_init(fhicl::ParameterSet const &ps, uint64_t timeout, uint64_t timestamp) override
Send an init command over XMLRPC
std::string send_meta_command(std::string const &command, std::string const &argument) override
Send an send_meta_command command over XMLRPC
std::string send_stop(uint64_t timeout, uint64_t timestamp) override
Send a stop command over XMLRPC
virtual std::string clear_config_archive()
Using the transport mechanism, send a clear_config_archive command
virtual std::string unregister_monitor(std::string const &)
Perform the unregister_monitor action.
std::string send_status() override
Send a status command over XMLRPC
std::string send_legal_commands() override
Send a legal_commands command over XMLRPC
The xmlrpc_commander class serves as the XMLRPC server run in each artdaq application.
static const uint64_t defaultTimestamp
static const uint32_t defaultSubrunNumber
Default subrun number for command.
The "cmd_" class serves as the base class for all artdaq's XML-RPC commands.
trace_set_(xmlrpc_commander &c)
unregister_monitor_ Constructor
void run_server() override
Run the XMLRPC server.
std::unique_ptr< xmlrpc_c::serverAbyss > server
XMLRPC server.
std::string status() const
Returns the current state of the Commandable.
std::string send_shutdown(uint64_t timeout) override
Send a shutdown command over XMLRPC
std::string send_reinit(fhicl::ParameterSet const &ps, uint64_t timeout, uint64_t timestamp) override
Send a reinit command over XMLRPC
std::string exception_msg(const std::runtime_error &er, const std::string &helpText="execute request")
Write an exception message.
static const uint64_t defaultSequenceID
Default Sequence ID for command.
add_config_archive_entry_(xmlrpc_commander &c)
add_config_archive_entry_ Constructor
std::string send_trace_get(std::string const &name) override
Send an send_trace_get command over XMLRPC
virtual std::string register_monitor(fhicl::ParameterSet const &)
Perform the register_monitor action.
virtual bool do_trace_set(std::string const &name, std::string const &type, std::string const &mask_in_string_form)
Set the given TRACE mask for the given TRACE name.
register_monitor_ Command class
add_config_archive_entry_ Command class
legal_commands_ Command class
std::string send_pause(uint64_t timeout, uint64_t timestamp) override
Send a pause command over XMLRPC
artdaq::Commandable & _commandable
Reference to the Commandable that this Commander Commands.
xmlrpc_commander & _c
The xmlrpc_commander instance that the command will be sent to.
std::string send_start(art::RunID runNumber, uint64_t timeout, uint64_t timestamp) override
Send a start command over XMLRPC
clear_config_archive_ Command class
virtual std::string add_config_archive_entry(std::string const &key, std::string const &value)
Using the transport mechanism, send an add_config_archive_entry command
void execute(const xmlrpc_c::paramList ¶mList, xmlrpc_c::value *retvalP) final
Execute trhe command with the given parameters.
status_(xmlrpc_commander &c)
status_ Constructor
clear_config_archive_(xmlrpc_commander &c)
clear_config_archive_ Constructor
Wrapper for XMLRPC environment construction/destruction
std::timed_mutex mutex_
XMLRPC mutex.
register_monitor_(xmlrpc_commander &c)
register_monitor_ Constructor
static const uint64_t defaultTimeout
std::string send_rollover_subrun(uint64_t when, uint32_t sr) override
Send a send_rollover_subrun command over XMLRPC
unregister_monitor_(xmlrpc_commander &c)
unregister_monitor_ Constructor
virtual bool execute_(const xmlrpc_c::paramList &, xmlrpc_c::value *retvalP)=0
"execute_" is a wrapper function around the call to the commandable object's function ...
shutdown_(xmlrpc_commander &c)
shutdown_ Constructor
std::vector< std::string > legal_commands() const
Get the legal transition commands from the current state.
std::string send_soft_init(fhicl::ParameterSet const &ps, uint64_t timeout, uint64_t timestamp) override
Send a soft_init command over XMLRPC
rollover_subrun_ Command class
std::string send_resume(uint64_t timeout, uint64_t timestamp) override
Send a resume command over XMLRPC
std::string send_unregister_monitor(std::string const &monitor_label) override
Send an unregister_monitor command over XMLRPC
std::string send_report(std::string const &what) override
Send a report command over XMLRPC
bool start(art::RunID id, uint64_t timeout, uint64_t timestamp)
Processes the start transition.
report_(xmlrpc_commander &c)
report_ Constructor
start_(xmlrpc_commander &c)
start_ Command (cmd_ derived class) Constructor
virtual std::string do_trace_get(std::string const &name)
Get the TRACE mask for the given TRACE name If name is "ALL", then all TRACE masks will be printed...
virtual bool do_meta_command(std::string const &cmd, std::string const &args)
Run a module-defined command with the given parameter string.
trace_get_(xmlrpc_commander &c)
trace_msgfacility_set_ Constructor
std::atomic< bool > running_
Whether the server is running and able to respond to requests.
virtual bool do_rollover_subrun(uint64_t eventNum, uint32_t subrunNum)
Perform the rollover_subrun transition.
unregister_monitor_ Command class
T getParam(const xmlrpc_c::paramList ¶mList, int index)
Get a parameter from the parameter list.
bool shutdown(uint64_t timeout)
Processes the shutdown transition.