xref: /openbmc/pldm/platform-mc/manager.hpp (revision a34a64bb)
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         platformManager(terminusManager, termini),
38         sensorManager(event, terminusManager, termini)
39     {}
40 
41     /** @brief Helper function to do the actions before discovering terminus
42      *
43      *  @return coroutine return_value - PLDM completion code
44      */
45     exec::task<int> beforeDiscoverTerminus();
46 
47     /** @brief Helper function to do the actions after discovering terminus
48      *
49      *  @return coroutine return_value - PLDM completion code
50      */
51     exec::task<int> afterDiscoverTerminus();
52 
53     /** @brief Helper function to invoke registered handlers for
54      *         the added MCTP endpoints
55      *
56      *  @param[in] mctpInfos - list information of the MCTP endpoints
57      */
58     void handleMctpEndpoints(const MctpInfos& mctpInfos)
59     {
60         terminusManager.discoverMctpTerminus(mctpInfos);
61     }
62 
63     /** @brief Helper function to invoke registered handlers for
64      *         the removed MCTP endpoints
65      *
66      *  @param[in] mctpInfos - list information of the MCTP endpoints
67      */
68     void handleRemovedMctpEndpoints(const MctpInfos& mctpInfos)
69     {
70         terminusManager.removeMctpTerminus(mctpInfos);
71     }
72 
73     /** @brief Helper function to start sensor polling of the terminus TID
74      */
75     void startSensorPolling(pldm_tid_t tid)
76     {
77         sensorManager.startPolling(tid);
78     }
79 
80     /** @brief Helper function to set available state for pldm request (sensor
81      *         polling and event polling) of the terminus TID. The `false` state
82      *         will trigger stop flow in coroutine of sensor polling/event
83      *         polling task to stop.
84      */
85     void updateAvailableState(pldm_tid_t tid, Availability state)
86     {
87         if (termini.contains(tid))
88         {
89             sensorManager.updateAvailableState(tid, state);
90         }
91     }
92 
93     /** @brief Helper function to stop sensor polling of the terminus TID
94      */
95     void stopSensorPolling(pldm_tid_t tid)
96     {
97         sensorManager.stopPolling(tid);
98     }
99 
100   private:
101     /** @brief List of discovered termini */
102     TerminiMapper termini{};
103 
104     /** @brief Terminus interface for calling the hook functions */
105     TerminusManager terminusManager;
106 
107     /** @brief Platform interface for calling the hook functions */
108     PlatformManager platformManager;
109 
110     /** @brief Store platform manager handler */
111     SensorManager sensorManager;
112 };
113 } // namespace platform_mc
114 } // namespace pldm
115