8#ifndef CMDLIB_INCLUDE_CMDLIB_COMMANDFACILITY_HPP_
9#define CMDLIB_INCLUDE_CMDLIB_COMMANDFACILITY_HPP_
15#include <cetlib/BasicPluginFactory.h>
16#include <cetlib/compiler_macros.h>
18#include <tbb/concurrent_queue.h>
26#ifndef EXTERN_C_FUNC_DECLARE_START
27#define EXTERN_C_FUNC_DECLARE_START \
36#define DEFINE_DUNE_COMMAND_FACILITY(klass) \
37 EXTERN_C_FUNC_DECLARE_START \
38 std::unique_ptr<dunedaq::cmdlib::CommandFacility> make() \
40 return std::unique_ptr<dunedaq::cmdlib::CommandFacility>(new klass()); \
67 virtual void run(std::atomic<bool>& end_marker) = 0;
104template <
typename...
ARGS>
105std::shared_ptr<CommandFacility>
107 std::string
const&
uri,
110 auto sep =
uri.find(
"://");
112 if (sep == std::string::npos) {
115 scheme =
uri.substr(0, sep);
117 std::string plugin_name = scheme +
"CommandFacility";
118 static cet::BasicPluginFactory bpf(
"duneCommandFacility",
"make");
119 std::shared_ptr<CommandFacility> cf_ptr;
121 cf_ptr = bpf.makePlugin<std::shared_ptr<CommandFacility>>(
124 std::forward<ARGS>(args)...
126 }
catch (
const cet::exception &cexpt) {
Interface needed by DAQ apps and services for command handling.
void handle_command(const cmdobj_t &cmd, cmd::CommandReply meta)
The glue between commanded and completion callback.
virtual void completion_callback(const cmdobj_t &cmd, cmd::CommandReply &meta)=0
Must be implemented to handling the results of the commands.
virtual ~CommandFacility()
CommandFacility(std::string)
CommandedObject * m_commanded_object
Commanded Object to run execute with received commands as parameters.
CommandFacility & operator=(CommandFacility &&)=delete
CommandFacility is not move-assignable.
CompletionQueue m_completion_queue
virtual void run(std::atomic< bool > &end_marker)=0
Meant to be called once from main (implementation specific)
std::string m_name
name of the commanded object
CommandFacility & operator=(const CommandFacility &)=delete
CommandFacility is not copy-assignable.
CommandFacility(CommandFacility &&)=delete
CommandFacility is not move-constructible.
std::atomic< bool > m_active
Single thrad is responsible to trigger tasks.
CommandCallback m_command_callback
tbb::concurrent_queue< std::future< void > > CompletionQueue
Completion queue for reqistered tasks.
std::function< void(const cmdobj_t &, cmd::CommandReply)> CommandCallback
Request callback function signature.
void set_commanded(CommandedObject &commanded, std::string name)
Meant to be called once from main.
CommandFacility(const CommandFacility &)=delete
CommandFacility is not copy-constructible.
void execute_command(const cmdobj_t &cmd, cmd::CommandReply meta)
Feed commands from the implementation.
Interface needed by commanded objects in the DAQ.
Base class for any user define issue.
std::shared_ptr< CommandFacility > make_command_facility(std::string const &uri, ARGS &&... args)
Unsupported std::string uri Execution of command std::string error Failed to create CommandFacility uri
Unsupported std::string uri Execution of command std::string error CommandFacilityCreationFailed