Deepak Kodihalli | 4de4d00 | 2019-11-11 02:41:43 -0600 | [diff] [blame] | 1 | #pragma once |
| 2 | |
Andrew Jeffery | 2abbce7 | 2023-10-18 10:17:35 +1030 | [diff] [blame] | 3 | #include "common/instance_id.hpp" |
Andrew Jeffery | 7c1dc7e | 2023-04-28 14:52:16 +0930 | [diff] [blame] | 4 | #include "xyz/openbmc_project/Common/error.hpp" |
Deepak Kodihalli | 4de4d00 | 2019-11-11 02:41:43 -0600 | [diff] [blame] | 5 | #include "xyz/openbmc_project/PLDM/Requester/server.hpp" |
| 6 | |
Deepak Kodihalli | 4de4d00 | 2019-11-11 02:41:43 -0600 | [diff] [blame] | 7 | #include <sdbusplus/bus.hpp> |
| 8 | #include <sdbusplus/server/object.hpp> |
| 9 | |
George Liu | 6492f52 | 2020-06-16 10:34:05 +0800 | [diff] [blame] | 10 | #include <map> |
| 11 | |
Deepak Kodihalli | 4de4d00 | 2019-11-11 02:41:43 -0600 | [diff] [blame] | 12 | namespace pldm |
| 13 | { |
| 14 | namespace dbus_api |
| 15 | { |
| 16 | |
Patrick Williams | 84b790c | 2022-07-22 19:26:56 -0500 | [diff] [blame] | 17 | using RequesterIntf = sdbusplus::server::object_t< |
Deepak Kodihalli | 4de4d00 | 2019-11-11 02:41:43 -0600 | [diff] [blame] | 18 | sdbusplus::xyz::openbmc_project::PLDM::server::Requester>; |
| 19 | |
| 20 | /** @class Requester |
| 21 | * @brief OpenBMC PLDM.Requester implementation. |
| 22 | * @details A concrete implementation for the |
| 23 | * xyz.openbmc_project.PLDM.Requester DBus APIs. |
| 24 | */ |
| 25 | class Requester : public RequesterIntf |
| 26 | { |
| 27 | public: |
| 28 | Requester() = delete; |
| 29 | Requester(const Requester&) = delete; |
| 30 | Requester& operator=(const Requester&) = delete; |
| 31 | Requester(Requester&&) = delete; |
| 32 | Requester& operator=(Requester&&) = delete; |
| 33 | virtual ~Requester() = default; |
| 34 | |
| 35 | /** @brief Constructor to put object onto bus at a dbus path. |
| 36 | * @param[in] bus - Bus to attach to. |
| 37 | * @param[in] path - Path to attach at. |
Andrew Jeffery | 7c1dc7e | 2023-04-28 14:52:16 +0930 | [diff] [blame] | 38 | * @param[in] db - The database to use for allocating instance IDs |
| 39 | * @note will throw TooManyResources() if there were no free instance IDs |
| 40 | * Throws std::system_category().default_error_condition if there is |
| 41 | * something wrong with the instance ID database. |
Deepak Kodihalli | 4de4d00 | 2019-11-11 02:41:43 -0600 | [diff] [blame] | 42 | */ |
Andrew Jeffery | 7c1dc7e | 2023-04-28 14:52:16 +0930 | [diff] [blame] | 43 | Requester(sdbusplus::bus_t& bus, const std::string& path, |
| 44 | InstanceIdDb& db) : |
Patrick Williams | 16c2a0a | 2024-08-16 15:20:59 -0400 | [diff] [blame^] | 45 | RequesterIntf(bus, path.c_str()), pldmInstanceIdDb(db) {}; |
Deepak Kodihalli | 4de4d00 | 2019-11-11 02:41:43 -0600 | [diff] [blame] | 46 | |
| 47 | /** @brief Implementation for RequesterIntf.GetInstanceId */ |
Andrew Jeffery | 7c1dc7e | 2023-04-28 14:52:16 +0930 | [diff] [blame] | 48 | uint8_t getInstanceId(uint8_t eid) override |
| 49 | { |
| 50 | int id; |
| 51 | |
| 52 | // Ideally we would be able to look up the TID for a given EID. We don't |
| 53 | // have that infrastructure in place yet. So use the EID value for the |
| 54 | // TID. This is an interim step towards the PLDM requester logic moving |
| 55 | // into libpldm, and eventually this won't be needed. |
| 56 | try |
| 57 | { |
| 58 | id = pldmInstanceIdDb.next(eid); |
| 59 | } |
| 60 | catch (const std::runtime_error& e) |
| 61 | { |
| 62 | throw sdbusplus::xyz::openbmc_project::Common::Error:: |
| 63 | TooManyResources(); |
| 64 | } |
| 65 | |
| 66 | return id; |
| 67 | } |
Deepak Kodihalli | 4de4d00 | 2019-11-11 02:41:43 -0600 | [diff] [blame] | 68 | |
| 69 | /** @brief Mark an instance id as unused |
| 70 | * @param[in] eid - MCTP eid to which this instance id belongs |
| 71 | * @param[in] instanceId - PLDM instance id to be freed |
Andrew Jeffery | 7c1dc7e | 2023-04-28 14:52:16 +0930 | [diff] [blame] | 72 | * @note will throw std::runtime_error if the instance ID was not |
| 73 | * previously allocated. |
| 74 | * Throws std::system_category().default_error_condition if there is |
| 75 | * something wrong with the instance ID database. |
Deepak Kodihalli | 4de4d00 | 2019-11-11 02:41:43 -0600 | [diff] [blame] | 76 | */ |
| 77 | void markFree(uint8_t eid, uint8_t instanceId) |
| 78 | { |
Andrew Jeffery | 7c1dc7e | 2023-04-28 14:52:16 +0930 | [diff] [blame] | 79 | pldmInstanceIdDb.free(eid, instanceId); |
Deepak Kodihalli | 4de4d00 | 2019-11-11 02:41:43 -0600 | [diff] [blame] | 80 | } |
| 81 | |
| 82 | private: |
Andrew Jeffery | 7c1dc7e | 2023-04-28 14:52:16 +0930 | [diff] [blame] | 83 | InstanceIdDb& pldmInstanceIdDb; |
Deepak Kodihalli | 4de4d00 | 2019-11-11 02:41:43 -0600 | [diff] [blame] | 84 | }; |
| 85 | |
| 86 | } // namespace dbus_api |
| 87 | } // namespace pldm |