1 #pragma once 2 3 #include <optional> 4 #include <sdbusplus/bus.hpp> 5 #include <string> 6 #include <tuple> 7 8 namespace open_power 9 { 10 namespace occ 11 { 12 namespace utils 13 { 14 15 using LABELVALUE = std::tuple<std::string, uint16_t>; 16 17 constexpr auto MAPPER_BUSNAME = "xyz.openbmc_project.ObjectMapper"; 18 constexpr auto MAPPER_OBJ_PATH = "/xyz/openbmc_project/object_mapper"; 19 constexpr auto MAPPER_IFACE = "xyz.openbmc_project.ObjectMapper"; 20 constexpr auto DBUS_PROPERTY_IFACE = "org.freedesktop.DBus.Properties"; 21 22 // The value of the property(type: variant, contains some basic types) 23 using PropertyValue = std::variant<uint32_t, bool>; 24 25 /** @brief Get the bus connection. */ 26 static auto& getBus() 27 { 28 static auto bus = sdbusplus::bus::new_default(); 29 return bus; 30 } 31 32 /** 33 * @brief Get service name by the path and interface of the DBus. 34 * 35 * @param[in] path - D-Bus object path 36 * @param[in] interface - D-Bus Interface 37 * 38 * @return std::string - the D-Bus service name 39 * 40 */ 41 const std::string getService(const std::string& path, 42 const std::string& interface); 43 44 /** @brief Get property(type: variant) 45 * 46 * @param[in] objectPath - D-Bus object path 47 * @param[in] interface - D-Bus interface 48 * @param[in] propertyName - D-Bus property name 49 * 50 * @return The value of the property(type: variant) 51 * 52 * @throw sdbusplus::exception::SdBusError when it fails 53 */ 54 const PropertyValue getProperty(const std::string& objectPath, 55 const std::string& interface, 56 const std::string& propertyName); 57 58 /** 59 * @brief Check the value of the `tempX_label` file 60 * 61 * @param[in] value - the value of the `tempX_label` file 62 * 63 * @return Sensors type and Sensors ID 64 */ 65 std::optional<LABELVALUE> checkLabelValue(const std::string& value); 66 67 } // namespace utils 68 } // namespace occ 69 } // namespace open_power 70