Line data Source code
1 : /**
2 : * @file SNBTransferBookkeeper.cpp SNBTransferBookkeeper Bookkeeper module retriving transfers informations from
3 : * SNBFileTransfer clients.
4 : *
5 : * This is part of the DUNE DAQ , copyright 2020.
6 : * Licensing/copyright details are in the COPYING file that you should have
7 : * received with this code.
8 : */
9 :
10 : #include "SNBTransferBookkeeper.hpp"
11 : #include "appfwk/cmd/Nljs.hpp"
12 :
13 : #include <memory>
14 : #include <set>
15 : #include <string>
16 :
17 : namespace dunedaq::snbmodules {
18 :
19 0 : SNBTransferBookkeeper::SNBTransferBookkeeper(const std::string& name)
20 0 : : DAQModule(name)
21 : {
22 0 : register_command("conf", &SNBTransferBookkeeper::do_conf);
23 0 : register_command("scrap", &SNBTransferBookkeeper::do_scrap);
24 0 : register_command("start", &SNBTransferBookkeeper::do_start);
25 0 : register_command("stop", &SNBTransferBookkeeper::do_stop);
26 : // register_command("info", &SNBTransferBookkeeper::do_info);
27 :
28 0 : m_name = name;
29 0 : }
30 :
31 : // void
32 : // SNBTransferBookkeeper::do_info(const nlohmann::json &args)
33 : //{
34 : // (void)args;
35 : // m_bookkeeper->request_update_metadata(true);
36 : // }
37 :
38 : void
39 0 : SNBTransferBookkeeper::init(std::shared_ptr<dunedaq::appfwk::ConfigurationManager> mcfg)
40 : {
41 0 : auto mdal = mcfg->get_dal<appmodel::SNBTransferBookkeeper>(get_name());
42 0 : if (!mdal) {
43 0 : throw appfwk::CommandFailed(ERS_HERE, "init", get_name(), "Unable to retrieve configuration object");
44 : }
45 :
46 0 : m_snbbk_conf = mdal->get_configuration();
47 0 : }
48 :
49 : void
50 0 : SNBTransferBookkeeper::do_conf(const CommandData_t& /*payload*/)
51 : {
52 0 : m_bookkeeper = std::make_shared<Bookkeeper>(IPFormat(m_snbbk_conf->get_bookkeeper_ip()),
53 0 : m_name,
54 0 : m_snbbk_conf->get_bookkeeper_log_path(),
55 0 : m_snbbk_conf->get_refresh_rate(),
56 0 : m_snbbk_conf->get_connection_prefix(),
57 0 : m_snbbk_conf->get_timeout_send(),
58 0 : m_snbbk_conf->get_timeout_receive());
59 0 : m_thread = std::make_unique<dunedaq::utilities::WorkerThread>(
60 0 : [&](std::atomic<bool>& running) { m_bookkeeper->do_work(running); });
61 0 : }
62 :
63 : void
64 0 : SNBTransferBookkeeper::do_scrap(const CommandData_t& /*payload*/)
65 : {
66 0 : m_bookkeeper.reset();
67 0 : m_thread.reset();
68 0 : }
69 :
70 : void
71 0 : SNBTransferBookkeeper::do_start(const CommandData_t& /*payload*/)
72 : {
73 0 : m_bookkeeper->lookups_connections();
74 0 : m_thread->start_working_thread();
75 0 : }
76 :
77 : void
78 0 : SNBTransferBookkeeper::do_stop(const CommandData_t& /*payload*/)
79 : {
80 0 : m_thread->stop_working_thread();
81 0 : }
82 :
83 : } // namespace dunedaq::snbmodules
84 :
85 0 : DEFINE_DUNE_DAQ_MODULE(dunedaq::snbmodules::SNBTransferBookkeeper)
|