blob: 84e861b68fd4303c671596634bbd9349a9e7bcf2 [file] [log] [blame]
Deepak Kodihalli4de4d002019-11-11 02:41:43 -06001#pragma once
2
Andrew Jeffery2abbce72023-10-18 10:17:35 +10303#include "common/instance_id.hpp"
Andrew Jeffery7c1dc7e2023-04-28 14:52:16 +09304#include "xyz/openbmc_project/Common/error.hpp"
Deepak Kodihalli4de4d002019-11-11 02:41:43 -06005#include "xyz/openbmc_project/PLDM/Requester/server.hpp"
6
Deepak Kodihalli4de4d002019-11-11 02:41:43 -06007#include <sdbusplus/bus.hpp>
8#include <sdbusplus/server/object.hpp>
9
George Liu6492f522020-06-16 10:34:05 +080010#include <map>
11
Deepak Kodihalli4de4d002019-11-11 02:41:43 -060012namespace pldm
13{
14namespace dbus_api
15{
16
Patrick Williams84b790c2022-07-22 19:26:56 -050017using RequesterIntf = sdbusplus::server::object_t<
Deepak Kodihalli4de4d002019-11-11 02:41:43 -060018 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 */
25class 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 Jeffery7c1dc7e2023-04-28 14:52:16 +093038 * @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 Kodihalli4de4d002019-11-11 02:41:43 -060042 */
Andrew Jeffery7c1dc7e2023-04-28 14:52:16 +093043 Requester(sdbusplus::bus_t& bus, const std::string& path,
44 InstanceIdDb& db) :
45 RequesterIntf(bus, path.c_str()),
46 pldmInstanceIdDb(db){};
Deepak Kodihalli4de4d002019-11-11 02:41:43 -060047
48 /** @brief Implementation for RequesterIntf.GetInstanceId */
Andrew Jeffery7c1dc7e2023-04-28 14:52:16 +093049 uint8_t getInstanceId(uint8_t eid) override
50 {
51 int id;
52
53 // Ideally we would be able to look up the TID for a given EID. We don't
54 // have that infrastructure in place yet. So use the EID value for the
55 // TID. This is an interim step towards the PLDM requester logic moving
56 // into libpldm, and eventually this won't be needed.
57 try
58 {
59 id = pldmInstanceIdDb.next(eid);
60 }
61 catch (const std::runtime_error& e)
62 {
63 throw sdbusplus::xyz::openbmc_project::Common::Error::
64 TooManyResources();
65 }
66
67 return id;
68 }
Deepak Kodihalli4de4d002019-11-11 02:41:43 -060069
70 /** @brief Mark an instance id as unused
71 * @param[in] eid - MCTP eid to which this instance id belongs
72 * @param[in] instanceId - PLDM instance id to be freed
Andrew Jeffery7c1dc7e2023-04-28 14:52:16 +093073 * @note will throw std::runtime_error if the instance ID was not
74 * previously allocated.
75 * Throws std::system_category().default_error_condition if there is
76 * something wrong with the instance ID database.
Deepak Kodihalli4de4d002019-11-11 02:41:43 -060077 */
78 void markFree(uint8_t eid, uint8_t instanceId)
79 {
Andrew Jeffery7c1dc7e2023-04-28 14:52:16 +093080 pldmInstanceIdDb.free(eid, instanceId);
Deepak Kodihalli4de4d002019-11-11 02:41:43 -060081 }
82
83 private:
Andrew Jeffery7c1dc7e2023-04-28 14:52:16 +093084 InstanceIdDb& pldmInstanceIdDb;
Deepak Kodihalli4de4d002019-11-11 02:41:43 -060085};
86
87} // namespace dbus_api
88} // namespace pldm