HLCC Documentation 2.2.0
Loading...
Searching...
No Matches
monCmdsImpl.hpp
Go to the documentation of this file.
1// SPDX-FileCopyrightText: 2020-2025 European Southern Observatory (ESO)
2//
3// SPDX-License-Identifier: LGPL-3.0-only
4
13#ifndef HLCC_TELIF_TELMON_MONCMDSIMPL_HPP
14#define HLCC_TELIF_TELMON_MONCMDSIMPL_HPP
15
16#include <rad/exceptions.hpp>
17#include <rad/smAdapter.hpp>
18#include "Telmonif.hpp"
19
20#include "telmon/monCmds.rad.hpp"
21#include "telmon/logger.hpp"
22
23namespace hlcc::telmon {
24
25class MonCmdsImpl : public telmonif::AsyncMonCmds {
26public:
27 explicit MonCmdsImpl(rad::SMAdapter& sm) : m_sm(sm) {
28 /* GCH
29 * I do the registration of the RejectionHandler
30 * in the definition of each command handler method
31 * by adding the line:
32 * m_sm.RegisterDefaultRequestRejectHandler<StdCmds::Exit>();
33 * This has the advantage of putting the registration one by one
34 * together with the code of each handler, making it easy to keep the
35 * code aligned and to handle special cases, for example with
36 * specific handlers for commands returning something different form
37 * a string or not setting an handler for commands that are always available,
38 * in any state and will never be rejected.
39 * The drawback is a small performance penalty, since it will try to
40 * insert the registration in the std::map every time.
41 * Nothing will happen, since std::map will not insert a duplicate and will
42 * simply ignore the additional insertion.
43 * If that is a problem, we might do the registration here in the constructor,
44 * but it will be error prone when keeping the code aligned when
45 * adding or removing commands
46 */
47 RAD_TRACE(GetLogger());
48 }
49
50 virtual ~MonCmdsImpl() {
51 RAD_TRACE(GetLogger());
52 }
53
54 virtual elt::mal::future<std::string> Reload() override {
55 RAD_TRACE(GetLogger());
56 LOG4CPLUS_INFO(GetLogger(), "Received Reload");
57
58 auto ev = std::make_shared<MonCmds::Reload>();
59 m_sm.RegisterDefaultRequestRejectHandler<MonCmds::Reload>();
60 m_sm.PostEvent(ev);
61 return ev->GetPayload().GetReplyFuture();
62 }
63
64 virtual elt::mal::future<std::string> GetModulesLoaded() override {
65 RAD_TRACE(GetLogger());
66 LOG4CPLUS_INFO(GetLogger(), "Received GetModulesLoaded");
67
68 auto ev = std::make_shared<MonCmds::GetModulesLoaded>();
69 m_sm.RegisterDefaultRequestRejectHandler<MonCmds::GetModulesLoaded>();
70 m_sm.PostEvent(ev);
71 return ev->GetPayload().GetReplyFuture();
72 }
73
74 virtual elt::mal::future<std::string> SetAppIgnore(const std::shared_ptr<telmonif::AppIgnoreData>& ignore_args) override {
75 RAD_TRACE(GetLogger());
76 LOG4CPLUS_INFO(GetLogger(), "Received SetAppIgnore with: Appname " << ignore_args->getApp_name()
77 << ", Ignore " << ignore_args->getIgnore());
78
79 auto ev = std::make_shared<MonCmds::SetAppIgnore>(ignore_args->clone());
80 m_sm.RegisterDefaultRequestRejectHandler<MonCmds::SetAppIgnore>();
81 m_sm.PostEvent(ev);
82 return ev->GetPayload().GetReplyFuture();
83 }
84
85 virtual elt::mal::future<std::string> SetSubsystemIgnore(const std::shared_ptr<telmonif::SubsystemIgnoreData>& ignore_args) override {
86 RAD_TRACE(GetLogger());
87 LOG4CPLUS_INFO(GetLogger(), "Received SetSubsystemIgnore with: Subsystem " << ignore_args->getSubsystem_name()
88 << ", Ignore " << ignore_args->getIgnore());
89
90 auto ev = std::make_shared<MonCmds::SetSubsystemIgnore>(ignore_args->clone());
91 m_sm.RegisterDefaultRequestRejectHandler<MonCmds::SetSubsystemIgnore>();
92 m_sm.PostEvent(ev);
93 return ev->GetPayload().GetReplyFuture();
94 }
95
96private:
97 rad::SMAdapter& m_sm;
98};
99
100} // namespace hlcc::telmon
101
102#endif // HLCC_TELIF_TELMON_MONCMDSIMPL_HPP
Default logger name.
Definition monCmdsImpl.hpp:25
virtual elt::mal::future< std::string > SetAppIgnore(const std::shared_ptr< telmonif::AppIgnoreData > &ignore_args) override
Definition monCmdsImpl.hpp:74
virtual elt::mal::future< std::string > Reload() override
Definition monCmdsImpl.hpp:54
virtual elt::mal::future< std::string > SetSubsystemIgnore(const std::shared_ptr< telmonif::SubsystemIgnoreData > &ignore_args) override
Definition monCmdsImpl.hpp:85
MonCmdsImpl(rad::SMAdapter &sm)
Definition monCmdsImpl.hpp:27
virtual elt::mal::future< std::string > GetModulesLoaded() override
Definition monCmdsImpl.hpp:64
virtual ~MonCmdsImpl()
Definition monCmdsImpl.hpp:50
Definition actionMgr.cpp:31
log4cplus::Logger & GetLogger()
Definition logger.cpp:21