Gilbert Chen | 6c7fed4 | 2022-02-22 15:40:17 +0000 | [diff] [blame] | 1 | #pragma once |
| 2 | |
| 3 | #include "libpldm/pldm.h" |
| 4 | |
| 5 | #include "common/instance_id.hpp" |
| 6 | #include "common/types.hpp" |
Gilbert Chen | 77e6fe7 | 2024-08-06 09:23:30 +0000 | [diff] [blame^] | 7 | #include "event_manager.hpp" |
Gilbert Chen | 6c7fed4 | 2022-02-22 15:40:17 +0000 | [diff] [blame] | 8 | #include "platform_manager.hpp" |
| 9 | #include "requester/handler.hpp" |
| 10 | #include "requester/mctp_endpoint_discovery.hpp" |
Gilbert Chen | eac61a4 | 2022-02-23 20:56:19 +0000 | [diff] [blame] | 11 | #include "sensor_manager.hpp" |
Gilbert Chen | 6c7fed4 | 2022-02-22 15:40:17 +0000 | [diff] [blame] | 12 | #include "terminus_manager.hpp" |
| 13 | |
| 14 | namespace pldm |
| 15 | { |
| 16 | namespace platform_mc |
| 17 | { |
| 18 | |
| 19 | /** |
| 20 | * @brief Manager |
| 21 | * |
| 22 | * This class handles all the aspect of the PLDM Platform Monitoring and Control |
| 23 | * specification for the MCTP devices |
| 24 | */ |
| 25 | class Manager : public pldm::MctpDiscoveryHandlerIntf |
| 26 | { |
| 27 | public: |
| 28 | Manager() = delete; |
| 29 | Manager(const Manager&) = delete; |
| 30 | Manager(Manager&&) = delete; |
| 31 | Manager& operator=(const Manager&) = delete; |
| 32 | Manager& operator=(Manager&&) = delete; |
| 33 | ~Manager() = default; |
| 34 | |
| 35 | explicit Manager(sdeventplus::Event& event, RequesterHandler& handler, |
| 36 | pldm::InstanceIdDb& instanceIdDb) : |
Thu Nguyen | 51d66b5 | 2024-08-06 09:15:55 +0000 | [diff] [blame] | 37 | terminusManager(event, handler, instanceIdDb, termini, this, |
| 38 | pldm::BmcMctpEid), |
Gilbert Chen | eac61a4 | 2022-02-23 20:56:19 +0000 | [diff] [blame] | 39 | platformManager(terminusManager, termini), |
Gilbert Chen | 77e6fe7 | 2024-08-06 09:23:30 +0000 | [diff] [blame^] | 40 | sensorManager(event, terminusManager, termini, this), |
| 41 | eventManager(terminusManager, termini) |
Gilbert Chen | 6c7fed4 | 2022-02-22 15:40:17 +0000 | [diff] [blame] | 42 | {} |
| 43 | |
| 44 | /** @brief Helper function to do the actions before discovering terminus |
| 45 | * |
| 46 | * @return coroutine return_value - PLDM completion code |
| 47 | */ |
| 48 | exec::task<int> beforeDiscoverTerminus(); |
| 49 | |
| 50 | /** @brief Helper function to do the actions after discovering terminus |
| 51 | * |
| 52 | * @return coroutine return_value - PLDM completion code |
| 53 | */ |
| 54 | exec::task<int> afterDiscoverTerminus(); |
| 55 | |
| 56 | /** @brief Helper function to invoke registered handlers for |
| 57 | * the added MCTP endpoints |
| 58 | * |
| 59 | * @param[in] mctpInfos - list information of the MCTP endpoints |
| 60 | */ |
| 61 | void handleMctpEndpoints(const MctpInfos& mctpInfos) |
| 62 | { |
| 63 | terminusManager.discoverMctpTerminus(mctpInfos); |
| 64 | } |
| 65 | |
| 66 | /** @brief Helper function to invoke registered handlers for |
| 67 | * the removed MCTP endpoints |
| 68 | * |
| 69 | * @param[in] mctpInfos - list information of the MCTP endpoints |
| 70 | */ |
| 71 | void handleRemovedMctpEndpoints(const MctpInfos& mctpInfos) |
| 72 | { |
| 73 | terminusManager.removeMctpTerminus(mctpInfos); |
| 74 | } |
| 75 | |
Gilbert Chen | eac61a4 | 2022-02-23 20:56:19 +0000 | [diff] [blame] | 76 | /** @brief Helper function to start sensor polling of the terminus TID |
| 77 | */ |
| 78 | void startSensorPolling(pldm_tid_t tid) |
| 79 | { |
| 80 | sensorManager.startPolling(tid); |
| 81 | } |
| 82 | |
| 83 | /** @brief Helper function to set available state for pldm request (sensor |
| 84 | * polling and event polling) of the terminus TID. The `false` state |
| 85 | * will trigger stop flow in coroutine of sensor polling/event |
| 86 | * polling task to stop. |
| 87 | */ |
| 88 | void updateAvailableState(pldm_tid_t tid, Availability state) |
| 89 | { |
| 90 | if (termini.contains(tid)) |
| 91 | { |
| 92 | sensorManager.updateAvailableState(tid, state); |
Gilbert Chen | 77e6fe7 | 2024-08-06 09:23:30 +0000 | [diff] [blame^] | 93 | eventManager.updateAvailableState(tid, state); |
Gilbert Chen | eac61a4 | 2022-02-23 20:56:19 +0000 | [diff] [blame] | 94 | } |
| 95 | } |
| 96 | |
| 97 | /** @brief Helper function to stop sensor polling of the terminus TID |
| 98 | */ |
| 99 | void stopSensorPolling(pldm_tid_t tid) |
| 100 | { |
| 101 | sensorManager.stopPolling(tid); |
| 102 | } |
| 103 | |
Gilbert Chen | 77e6fe7 | 2024-08-06 09:23:30 +0000 | [diff] [blame^] | 104 | /** @brief Sensor event handler funtion |
| 105 | * |
| 106 | * @param[in] request - Event message |
| 107 | * @param[in] payloadLength - Event message payload size |
| 108 | * @param[in] tid - Terminus ID |
| 109 | * @param[in] eventDataOffset - Event data offset |
| 110 | * |
| 111 | * @return PLDM error code: PLDM_SUCCESS when there is no error in handling |
| 112 | * the event |
| 113 | */ |
| 114 | int handleSensorEvent(const pldm_msg* request, size_t payloadLength, |
| 115 | uint8_t /* formatVersion */, uint8_t tid, |
| 116 | size_t eventDataOffset) |
| 117 | { |
| 118 | auto eventData = reinterpret_cast<const uint8_t*>(request->payload) + |
| 119 | eventDataOffset; |
| 120 | auto eventDataSize = payloadLength - eventDataOffset; |
| 121 | eventManager.handlePlatformEvent(tid, 0x00, PLDM_SENSOR_EVENT, |
| 122 | eventData, eventDataSize); |
| 123 | return PLDM_SUCCESS; |
| 124 | } |
| 125 | |
Gilbert Chen | 6c7fed4 | 2022-02-22 15:40:17 +0000 | [diff] [blame] | 126 | private: |
| 127 | /** @brief List of discovered termini */ |
| 128 | TerminiMapper termini{}; |
| 129 | |
| 130 | /** @brief Terminus interface for calling the hook functions */ |
| 131 | TerminusManager terminusManager; |
| 132 | |
| 133 | /** @brief Platform interface for calling the hook functions */ |
| 134 | PlatformManager platformManager; |
Gilbert Chen | eac61a4 | 2022-02-23 20:56:19 +0000 | [diff] [blame] | 135 | |
| 136 | /** @brief Store platform manager handler */ |
| 137 | SensorManager sensorManager; |
Gilbert Chen | 77e6fe7 | 2024-08-06 09:23:30 +0000 | [diff] [blame^] | 138 | |
| 139 | /** @brief Store event manager handler */ |
| 140 | EventManager eventManager; |
Gilbert Chen | 6c7fed4 | 2022-02-22 15:40:17 +0000 | [diff] [blame] | 141 | }; |
| 142 | } // namespace platform_mc |
| 143 | } // namespace pldm |