Gunnar Mills | 01a323b | 2017-01-18 09:48:13 -0600 | [diff] [blame] | 1 | #pragma once |
| 2 | #include <tuple> |
| 3 | #include <systemd/sd-bus.h> |
| 4 | #include <sdbusplus/server.hpp> |
| 5 | |
| 6 | namespace sdbusplus |
| 7 | { |
| 8 | namespace xyz |
| 9 | { |
| 10 | namespace openbmc_project |
| 11 | { |
| 12 | namespace Software |
| 13 | { |
| 14 | namespace server |
| 15 | { |
| 16 | |
| 17 | class Version |
| 18 | { |
| 19 | public: |
| 20 | /* Define all of the basic class operations: |
| 21 | * Not allowed: |
| 22 | * - Default constructor to avoid nullptrs. |
| 23 | * - Copy operations due to internal unique_ptr. |
| 24 | * - Move operations due to 'this' being registered as the |
| 25 | * 'context' with sdbus. |
| 26 | * Allowed: |
| 27 | * - Destructor. |
| 28 | */ |
| 29 | Version() = delete; |
| 30 | Version(const Version&) = delete; |
| 31 | Version& operator=(const Version&) = delete; |
| 32 | Version(Version&&) = delete; |
| 33 | Version& operator=(Version&&) = delete; |
| 34 | virtual ~Version() = default; |
| 35 | |
| 36 | /** @brief Constructor to put object onto bus at a dbus path. |
| 37 | * @param[in] bus - Bus to attach to. |
| 38 | * @param[in] path - Path to attach at. |
| 39 | */ |
| 40 | Version(bus::bus& bus, const char* path); |
| 41 | |
| 42 | enum class VersionPurpose |
| 43 | { |
| 44 | Unknown, |
| 45 | Other, |
| 46 | System, |
| 47 | BMC, |
| 48 | Host, |
| 49 | }; |
| 50 | |
| 51 | |
| 52 | |
| 53 | /** Get value of Version */ |
| 54 | virtual std::string version() const; |
| 55 | /** Set value of Version */ |
| 56 | virtual std::string version(std::string value); |
| 57 | /** Get value of Purpose */ |
| 58 | virtual VersionPurpose purpose() const; |
| 59 | /** Set value of Purpose */ |
| 60 | virtual VersionPurpose purpose(VersionPurpose value); |
| 61 | |
| 62 | /** @brief Convert a string to an appropriate enum value. |
| 63 | * @param[in] s - The string to convert in the form of |
| 64 | * "xyz.openbmc_project.Software.Version.<value name>" |
| 65 | * @return - The enum value. |
| 66 | */ |
| 67 | static VersionPurpose convertVersionPurposeFromString(std::string& s); |
| 68 | |
| 69 | private: |
| 70 | |
| 71 | /** @brief sd-bus callback for get-property 'Version' */ |
| 72 | static int _callback_get_Version( |
| 73 | sd_bus*, const char*, const char*, const char*, |
| 74 | sd_bus_message*, void*, sd_bus_error*); |
| 75 | /** @brief sd-bus callback for set-property 'Version' */ |
| 76 | static int _callback_set_Version( |
| 77 | sd_bus*, const char*, const char*, const char*, |
| 78 | sd_bus_message*, void*, sd_bus_error*); |
| 79 | |
| 80 | /** @brief sd-bus callback for get-property 'Purpose' */ |
| 81 | static int _callback_get_Purpose( |
| 82 | sd_bus*, const char*, const char*, const char*, |
| 83 | sd_bus_message*, void*, sd_bus_error*); |
| 84 | /** @brief sd-bus callback for set-property 'Purpose' */ |
| 85 | static int _callback_set_Purpose( |
| 86 | sd_bus*, const char*, const char*, const char*, |
| 87 | sd_bus_message*, void*, sd_bus_error*); |
| 88 | |
| 89 | |
| 90 | static constexpr auto _interface = "xyz.openbmc_project.Software.Version"; |
| 91 | static const vtable::vtable_t _vtable[]; |
| 92 | sdbusplus::server::interface::interface |
| 93 | _xyz_openbmc_project_Software_Version_interface; |
| 94 | |
| 95 | std::string _version{}; |
| 96 | VersionPurpose _purpose{}; |
| 97 | |
| 98 | }; |
| 99 | |
| 100 | /* Specialization of sdbusplus::server::bindings::details::convertForMessage |
| 101 | * for enum-type Version::VersionPurpose. |
| 102 | * |
| 103 | * This converts from the enum to a constant c-string representing the enum. |
| 104 | * |
| 105 | * @param[in] e - Enum value to convert. |
| 106 | * @return C-string representing the name for the enum value. |
| 107 | */ |
| 108 | std::string convertForMessage(Version::VersionPurpose e); |
| 109 | |
| 110 | } // namespace server |
| 111 | } // namespace Software |
| 112 | } // namespace openbmc_project |
| 113 | } // namespace xyz |
| 114 | } // namespace sdbusplus |
| 115 | |