blob: efbd1cbb5caa4df1366ba65093eb0f777e03ff11 [file] [log] [blame]
Gilbert Chen6c7fed42022-02-22 15:40:17 +00001#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"
Gilbert Cheneac61a42022-02-23 20:56:19 +000010#include "sensor_manager.hpp"
Gilbert Chen6c7fed42022-02-22 15:40:17 +000011#include "terminus_manager.hpp"
12
13namespace pldm
14{
15namespace 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 */
24class 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) :
Thu Nguyen51d66b52024-08-06 09:15:55 +000036 terminusManager(event, handler, instanceIdDb, termini, this,
37 pldm::BmcMctpEid),
Gilbert Cheneac61a42022-02-23 20:56:19 +000038 platformManager(terminusManager, termini),
39 sensorManager(event, terminusManager, termini)
Gilbert Chen6c7fed42022-02-22 15:40:17 +000040 {}
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
Gilbert Cheneac61a42022-02-23 20:56:19 +000074 /** @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
Gilbert Chen6c7fed42022-02-22 15:40:17 +0000101 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;
Gilbert Cheneac61a42022-02-23 20:56:19 +0000110
111 /** @brief Store platform manager handler */
112 SensorManager sensorManager;
Gilbert Chen6c7fed42022-02-22 15:40:17 +0000113};
114} // namespace platform_mc
115} // namespace pldm