Line data Source code
1 : /**
2 : * @file Application.hpp Loads and distributes commands to DAQModules
3 : *
4 : * This is part of the DUNE DAQ Application Framework, copyright 2020.
5 : * Licensing/copyright details are in the COPYING file that you should have
6 : * received with this code.
7 : */
8 :
9 : #ifndef APPFWK_SRC_APPLICATION_HPP_
10 : #define APPFWK_SRC_APPLICATION_HPP_
11 :
12 : // appfwk Includes
13 : #include "ConfigurationManagerOwner.hpp"
14 : #include "DAQModuleManager.hpp"
15 : #include "appfwk/cmd/Structs.hpp"
16 :
17 : // DUNE-DAQ includes
18 : #include "cmdlib/CommandFacility.hpp"
19 : #include "cmdlib/CommandedObject.hpp"
20 : #include "logging/Logging.hpp" // NOTE: if ISSUES ARE DECLARED BEFORE include logging/Logging.hpp, TLOG_DEBUG<<issue wont work.
21 : #include "opmonlib/OpMonManager.hpp"
22 : #include "rcif/opmon/run_info.pb.h"
23 : #include "utilities/NamedObject.hpp"
24 :
25 : // External libraries
26 : #include "nlohmann/json.hpp"
27 :
28 : // C++ includes
29 : #include <atomic>
30 : #include <chrono>
31 : #include <memory>
32 : #include <mutex>
33 : #include <string>
34 :
35 : namespace dunedaq {
36 :
37 : // Disable coverage collection LCOV_EXCL_START
38 :
39 : ERS_DECLARE_ISSUE(appfwk,
40 : ApplicationNotInitialized,
41 : "Application " << name << " has not been initialized yet.",
42 : ((std::string)name))
43 :
44 : ERS_DECLARE_ISSUE(appfwk,
45 : InvalidStateForCommand,
46 : "Command " << cmdid << " not allowed at this time. state: " << state << ", error: " << err
47 : << ", busy: " << busy,
48 : ((std::string)cmdid)((std::string)state)((bool)err)((bool)busy)) // NOLINT
49 :
50 : ERS_DECLARE_ISSUE(appfwk,
51 : ApplicationFailure,
52 : "Application " << application << " in session " << session << " failed",
53 : ((std::string)session)((std::string)application))
54 :
55 : // Re-enable coverage collection LCOV_EXCL_STOP
56 :
57 : namespace appfwk {
58 :
59 : class Application
60 : : public ConfigurationManagerOwner
61 : , public cmdlib::CommandedObject
62 : , public opmonlib::OpMonManager
63 : , public utilities::NamedObject
64 : {
65 : public:
66 : using dataobj_t = nlohmann::json;
67 :
68 : Application(std::string app_name,
69 : std::string session_name,
70 : std::string cmdlibimpl,
71 : std::string confimpl,
72 : std::string configuration_id);
73 :
74 : void init();
75 :
76 : void run(std::atomic<bool>& end_marker);
77 :
78 : void execute(const dataobj_t& cmd_data) override;
79 :
80 : bool check_state_for_cmd(const dataobj_t& cmd_data) const;
81 :
82 : void generate_opmon_data() override;
83 :
84 10 : void set_state(std::string s)
85 : {
86 10 : const std::lock_guard<std::mutex> lock(m_mutex);
87 10 : m_state = s;
88 10 : }
89 10 : std::string get_state() const
90 : {
91 10 : const std::lock_guard<std::mutex> lock(m_mutex);
92 20 : return m_state;
93 10 : }
94 :
95 : protected:
96 : void publish_app_info();
97 :
98 : private:
99 : DAQModuleManager m_mod_mgr;
100 : mutable std::mutex m_mutex;
101 : std::string m_state;
102 : std::atomic<bool> m_busy;
103 : std::atomic<bool> m_error;
104 : bool m_initialized;
105 : std::chrono::time_point<std::chrono::steady_clock> m_run_start_time;
106 : dunedaq::rcif::opmon::RunInfo m_runinfo;
107 : std::shared_ptr<cmdlib::CommandFacility> m_cmd_fac;
108 : };
109 :
110 : } // namespace appfwk
111 : } // namespace dunedaq
112 :
113 : #endif // APPFWK_SRC_APPLICATION_HPP_
|