Line data Source code
1 : /**
2 : * @file DummyModule.hpp
3 : *
4 : * DummyModule is a simple DAQModule implementation that responds to a "stuff" command with a log message.
5 : *
6 : * This is part of the DUNE DAQ Application Framework, copyright 2020.
7 : * Licensing/copyright details are in the COPYING file that you should have
8 : * received with this code.
9 : */
10 :
11 : #ifndef APPFWK_TEST_PLUGINS_DUMMYMODULE_HPP_
12 : #define APPFWK_TEST_PLUGINS_DUMMYMODULE_HPP_
13 :
14 : #include "appfwk/DAQModule.hpp"
15 : #include "appfwk/opmon/dummymodule.pb.h"
16 :
17 : #include "ers/ers.hpp"
18 : #include "logging/Logging.hpp" // NOTE: if ISSUES ARE DECLARED BEFORE include logging/Logging.hpp, TLOG_DEBUG<<issue wont work.
19 :
20 : #include <memory>
21 : #include <string>
22 : #include <vector>
23 :
24 : namespace dunedaq {
25 :
26 : // Disable coverage collection LCOV_EXCL_START
27 : ERS_DECLARE_ISSUE_BASE(appfwk,
28 : DummyModuleUpdate,
29 : appfwk::GeneralDAQModuleIssue,
30 : message,
31 : ((std::string)name),
32 : ((std::string)message))
33 : // Re-enable coverage collection LCOV_EXCL_STOP
34 :
35 : namespace appfwk {
36 :
37 : /// Showcase DAQModule inheritance, including overriding command implementations in child classes
38 : class DummyParentModule : public DAQModule
39 : {
40 : public:
41 21 : explicit DummyParentModule(const std::string& name)
42 21 : : DAQModule(name)
43 : {
44 21 : register_command("stuff", &DummyParentModule::do_stuff);
45 21 : }
46 :
47 21 : void init(std::shared_ptr<ConfigurationManager>) final {}
48 :
49 : virtual void do_stuff(const CommandData_t& /*data*/) = 0;
50 : };
51 :
52 : class DummyModule : public DummyParentModule
53 : {
54 : public:
55 20 : explicit DummyModule(const std::string& name)
56 20 : : DummyParentModule(name)
57 : {
58 20 : register_command("bad_stuff", &DummyModule::do_bad_stuff);
59 20 : }
60 :
61 4 : void do_bad_stuff(const CommandData_t&) { throw DummyModuleUpdate(ERS_HERE, get_name(), "DummyModule do_bad_stuff"); }
62 :
63 10 : void do_stuff(const CommandData_t& /*data*/) override
64 : {
65 10 : ers::info(DummyModuleUpdate(ERS_HERE, get_name(), "DummyModule do_stuff"));
66 10 : m_stuff_calls++;
67 10 : };
68 :
69 : protected:
70 5 : void generate_opmon_data() override
71 : {
72 5 : opmon::DummyModuleInfo dmi;
73 5 : dmi.set_stuff_calls(m_stuff_calls.exchange(0));
74 :
75 5 : publish(std::move(dmi));
76 5 : }
77 :
78 : private:
79 : std::atomic<uint64_t> m_stuff_calls{ 0 }; // NOLINT(build/unsigned)
80 : };
81 :
82 : class ExtraModule : public DummyParentModule
83 : {
84 : public:
85 1 : explicit ExtraModule(const std::string& name)
86 1 : : DummyParentModule(name)
87 : {
88 1 : }
89 0 : void do_stuff(const CommandData_t& /*data*/) override
90 : {
91 0 : ers::info(DummyModuleUpdate(ERS_HERE, get_name(), "ExtraModule do_stuff"));
92 0 : m_stuff_calls++;
93 0 : }
94 :
95 : protected:
96 1 : void generate_opmon_data() override
97 : {
98 1 : opmon::DummyModuleInfo dmi;
99 1 : dmi.set_stuff_calls(m_stuff_calls.exchange(0));
100 :
101 1 : publish(std::move(dmi));
102 1 : }
103 :
104 : private:
105 : std::atomic<uint64_t> m_stuff_calls{ 0 }; // NOLINT(build/unsigned)
106 : };
107 :
108 : } // namespace appfwk
109 : } // namespace dunedaq
110 :
111 : #endif // APPFWK_TEST_PLUGINS_DUMMYMODULE_HPP_
|