1 #pragma once
2 
3 #include "libpldm/platform.h"
4 #include "libpldm/pldm.h"
5 
6 #include "terminus.hpp"
7 #include "terminus_manager.hpp"
8 
9 #include <vector>
10 
11 namespace pldm
12 {
13 
14 namespace platform_mc
15 {
16 
17 /**
18  * @brief PlatformManager
19  *
20  * PlatformManager class manages the actions outlined in the platform spec.
21  */
22 class PlatformManager
23 {
24   public:
25     PlatformManager() = delete;
26     PlatformManager(const PlatformManager&) = delete;
27     PlatformManager(PlatformManager&&) = delete;
28     PlatformManager& operator=(const PlatformManager&) = delete;
29     PlatformManager& operator=(PlatformManager&&) = delete;
30     ~PlatformManager() = default;
31 
32     explicit PlatformManager(TerminusManager& terminusManager,
33                              TerminiMapper& termini) :
34         terminusManager(terminusManager), termini(termini)
35     {}
36 
37     /** @brief Initialize terminus which supports PLDM Type 2
38      *
39      *  @return coroutine return_value - PLDM completion code
40      */
41     exec::task<int> initTerminus();
42 
43   private:
44     /** @brief Fetch all PDRs from terminus.
45      *
46      *  @param[in] terminus - The terminus object to store fetched PDRs
47      *  @return coroutine return_value - PLDM completion code
48      */
49     exec::task<int> getPDRs(std::shared_ptr<Terminus> terminus);
50 
51     /** @brief Fetch PDR from terminus
52      *
53      *  @param[in] tid - Destination TID
54      *  @param[in] recordHndl - Record handle
55      *  @param[in] dataTransferHndl - Data transfer handle
56      *  @param[in] transferOpFlag - Transfer Operation Flag
57      *  @param[in] requstCnt - Request Count of data
58      *  @param[in] recordChgNum - Record change number
59      *  @param[out] nextRecordHndl - Next record handle
60      *  @param[out] nextDataTransferHndl - Next data transfer handle
61      *  @param[out] transferFlag - Transfer flag
62      *  @param[out] responseCnt - Response count of record data
63      *  @param[out] recordData - Returned record data
64      *  @param[out] transferCrc - CRC value when record data is last part of PDR
65      *  @return coroutine return_value - PLDM completion code
66      */
67     exec::task<int>
68         getPDR(const pldm_tid_t tid, const uint32_t recordHndl,
69                const uint32_t dataTransferHndl, const uint8_t transferOpFlag,
70                const uint16_t requestCnt, const uint16_t recordChgNum,
71                uint32_t& nextRecordHndl, uint32_t& nextDataTransferHndl,
72                uint8_t& transferFlag, uint16_t& responseCnt,
73                std::vector<uint8_t>& recordData, uint8_t& transferCrc);
74 
75     /** @brief get PDR repository information.
76      *
77      *  @param[in] tid - Destination TID
78      *  @param[out] repositoryState - the state of repository
79      *  @param[out] recordCount - number of records
80      *  @param[out] repositorySize - repository size
81      *  @param[out] largestRecordSize - largest record size
82      * *
83      *  @return coroutine return_value - PLDM completion code
84      */
85     exec::task<int> getPDRRepositoryInfo(
86         const pldm_tid_t tid, uint8_t& repositoryState, uint32_t& recordCount,
87         uint32_t& repositorySize, uint32_t& largestRecordSize);
88 
89     /** reference of TerminusManager for sending PLDM request to terminus*/
90     TerminusManager& terminusManager;
91 
92     /** @brief Managed termini list */
93     TerminiMapper& termini;
94 };
95 } // namespace platform_mc
96 } // namespace pldm
97