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