xref: /openbmc/pldm/platform-mc/manager.hpp (revision b3b84b49)
1 #pragma once
2 
3 #include "libpldm/pldm.h"
4 
5 #include "common/instance_id.hpp"
6 #include "common/types.hpp"
7 #include "platform_manager.hpp"
8 #include "requester/handler.hpp"
9 #include "requester/mctp_endpoint_discovery.hpp"
10 #include "sensor_manager.hpp"
11 #include "terminus_manager.hpp"
12 
13 namespace pldm
14 {
15 namespace platform_mc
16 {
17 
18 /**
19  * @brief Manager
20  *
21  * This class handles all the aspect of the PLDM Platform Monitoring and Control
22  * specification for the MCTP devices
23  */
24 class Manager : public pldm::MctpDiscoveryHandlerIntf
25 {
26   public:
27     Manager() = delete;
28     Manager(const Manager&) = delete;
29     Manager(Manager&&) = delete;
30     Manager& operator=(const Manager&) = delete;
31     Manager& operator=(Manager&&) = delete;
32     ~Manager() = default;
33 
34     explicit Manager(sdeventplus::Event& event, RequesterHandler& handler,
35                      pldm::InstanceIdDb& instanceIdDb) :
36         terminusManager(event, handler, instanceIdDb, termini, this,
37                         pldm::BmcMctpEid),
38         platformManager(terminusManager, termini),
39         sensorManager(event, terminusManager, termini)
40     {}
41 
42     /** @brief Helper function to do the actions before discovering terminus
43      *
44      *  @return coroutine return_value - PLDM completion code
45      */
46     exec::task<int> beforeDiscoverTerminus();
47 
48     /** @brief Helper function to do the actions after discovering terminus
49      *
50      *  @return coroutine return_value - PLDM completion code
51      */
52     exec::task<int> afterDiscoverTerminus();
53 
54     /** @brief Helper function to invoke registered handlers for
55      *         the added MCTP endpoints
56      *
57      *  @param[in] mctpInfos - list information of the MCTP endpoints
58      */
59     void handleMctpEndpoints(const MctpInfos& mctpInfos)
60     {
61         terminusManager.discoverMctpTerminus(mctpInfos);
62     }
63 
64     /** @brief Helper function to invoke registered handlers for
65      *         the removed MCTP endpoints
66      *
67      *  @param[in] mctpInfos - list information of the MCTP endpoints
68      */
69     void handleRemovedMctpEndpoints(const MctpInfos& mctpInfos)
70     {
71         terminusManager.removeMctpTerminus(mctpInfos);
72     }
73 
74     /** @brief Helper function to start sensor polling of the terminus TID
75      */
76     void startSensorPolling(pldm_tid_t tid)
77     {
78         sensorManager.startPolling(tid);
79     }
80 
81     /** @brief Helper function to set available state for pldm request (sensor
82      *         polling and event polling) of the terminus TID. The `false` state
83      *         will trigger stop flow in coroutine of sensor polling/event
84      *         polling task to stop.
85      */
86     void updateAvailableState(pldm_tid_t tid, Availability state)
87     {
88         if (termini.contains(tid))
89         {
90             sensorManager.updateAvailableState(tid, state);
91         }
92     }
93 
94     /** @brief Helper function to stop sensor polling of the terminus TID
95      */
96     void stopSensorPolling(pldm_tid_t tid)
97     {
98         sensorManager.stopPolling(tid);
99     }
100 
101   private:
102     /** @brief List of discovered termini */
103     TerminiMapper termini{};
104 
105     /** @brief Terminus interface for calling the hook functions */
106     TerminusManager terminusManager;
107 
108     /** @brief Platform interface for calling the hook functions */
109     PlatformManager platformManager;
110 
111     /** @brief Store platform manager handler */
112     SensorManager sensorManager;
113 };
114 } // namespace platform_mc
115 } // namespace pldm
116