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),
108 CommandRegistrationFailedMessage,
110 "Command registration
failed: " << message,
111 ((
std::
string)cmd)((
std::
string)name),
112 ((
std::
string)message))
120 "Command is not recognised",
121 ((
std::
string)cmd)((
std::
string)name),
130 "Command Failed. Reason " << reason,
131 ((
std::
string)cmd)((
std::
string)name),
132 ((
std::
string)reason))
140 "Required Connection Not Found. Type: " << type << ", direction: " << direction,
142 ((
std::
string)type)((
std::
string)direction))
163 using data_t = nlohmann::json;
165 explicit DAQModule(std::string name)
170 virtual ~DAQModule()
noexcept =
default;
178 virtual void init(std::shared_ptr<ConfigurationManager> mcfg) = 0;
188 void execute_command(
const std::string& name,
const data_t& data = {});
190 std::vector<std::string> get_commands()
const;
192 bool has_command(
const std::string& name)
const;
194 void set_command_registration_allowed(
bool allowed) { m_command_registration_allowed = allowed; }
204 template<
typename Child>
205 void register_command(
const std::string& name,
void (Child::*f)(
const data_t&));
207 DAQModule(DAQModule
const&) =
delete;
208 DAQModule(DAQModule&&) =
delete;
209 DAQModule& operator=(DAQModule
const&) =
delete;
210 DAQModule& operator=(DAQModule&&) =
delete;
213 using CommandMap_t = std::map<std::string, std::function<void(
const data_t&)>>;
214 CommandMap_t m_commands;
215 std::atomic<bool> m_command_registration_allowed{
true };
218std::shared_ptr<DAQModule>
219make_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