16#ifndef APPFWK_INCLUDE_APPFWK_DAQMODULE_HPP_
17#define APPFWK_INCLUDE_APPFWK_DAQMODULE_HPP_
25#include "cetlib/BasicPluginFactory.h"
26#include "cetlib/compiler_macros.h"
28#include "nlohmann/json.hpp"
38#ifndef EXTERN_C_FUNC_DECLARE_START
40#define EXTERN_C_FUNC_DECLARE_START \
50#define DEFINE_DUNE_DAQ_MODULE(klass) \
51 EXTERN_C_FUNC_DECLARE_START \
52 std::shared_ptr<dunedaq::appfwk::DAQModule> make(std::string n) \
54 return std::shared_ptr<dunedaq::appfwk::DAQModule>(new klass(n)); \
65 DAQModuleCreationFailed,
66 "Failed to create DAQModule " << instance_name <<
" of type " << plugin_name,
67 ((std::string)plugin_name)((std::string)instance_name))
98 CommandRegistrationFailed,
100 "Command registration
failed.",
101 ((
std::
string)cmd)((
std::
string)name),
110 "Command is not recognised",
111 ((
std::
string)cmd)((
std::
string)name),
120 "Command Failed. Reason " << reason,
121 ((
std::
string)cmd)((
std::
string)name),
122 ((
std::
string)reason))
130 "Required Connection Not Found. Type: " << type << ", direction: " << direction,
132 ((
std::
string)type)((
std::
string)direction))
153 using data_t = nlohmann::json;
155 explicit DAQModule(std::string name)
160 virtual ~DAQModule()
noexcept =
default;
168 virtual void init(std::shared_ptr<ConfigurationManager> mcfg) = 0;
178 void execute_command(
const std::string& name,
const data_t& data = {});
180 std::vector<std::string> get_commands()
const;
182 bool has_command(
const std::string& name)
const;
192 template<
typename Child>
193 void register_command(
const std::string& name,
void (Child::*f)(
const data_t&));
195 DAQModule(DAQModule
const&) =
delete;
196 DAQModule(DAQModule&&) =
delete;
197 DAQModule& operator=(DAQModule
const&) =
delete;
198 DAQModule& operator=(DAQModule&&) =
delete;
201 using CommandMap_t = std::map<std::string, std::function<void(
const data_t&)>>;
202 CommandMap_t m_commands;
205std::shared_ptr<DAQModule>
206make_module(std::string
const& plugin_name, std::string
const& instance_name);
#define ERS_DECLARE_ISSUE_BASE(namespace_name, class_name, base_class_name, message, base_attributes, attributes)
#define ERS_DECLARE_ISSUE(namespace_name, class_name, message, attributes)
Implements the Named interface.
void init(unordered_map< std::string, std::string > params)
Unsupported std::string uri Execution of command failed
DAQModule std::string name CommandIssue