blob: 6254ed75fb1aa4329a384b52a11a09388356a121 [file] [log] [blame]
Vishwanatha Subbanna30e329a2017-07-24 23:13:14 +05301#pragma once
2
George Liu13901592021-06-03 14:13:21 +08003#include <optional>
Vishwanatha Subbanna30e329a2017-07-24 23:13:14 +05304#include <sdbusplus/bus.hpp>
5#include <string>
George Liu13901592021-06-03 14:13:21 +08006#include <tuple>
7
Vishwanatha Subbanna30e329a2017-07-24 23:13:14 +05308namespace open_power
9{
10namespace occ
11{
George Liuf3b75142021-06-10 11:22:50 +080012namespace utils
13{
George Liu13901592021-06-03 14:13:21 +080014
15using LABELVALUE = std::tuple<std::string, uint16_t>;
16
George Liuf3b75142021-06-10 11:22:50 +080017constexpr auto MAPPER_BUSNAME = "xyz.openbmc_project.ObjectMapper";
18constexpr auto MAPPER_OBJ_PATH = "/xyz/openbmc_project/object_mapper";
19constexpr auto MAPPER_IFACE = "xyz.openbmc_project.ObjectMapper";
20constexpr auto DBUS_PROPERTY_IFACE = "org.freedesktop.DBus.Properties";
21
22// The value of the property(type: variant, contains some basic types)
23using PropertyValue = std::variant<uint32_t, bool>;
24
25/** @brief Get the bus connection. */
26static auto& getBus()
27{
28 static auto bus = sdbusplus::bus::new_default();
29 return bus;
30}
31
Vishwanatha Subbanna30e329a2017-07-24 23:13:14 +053032/**
George Liuf3b75142021-06-10 11:22:50 +080033 * @brief Get service name by the path and interface of the DBus.
Vishwanatha Subbanna30e329a2017-07-24 23:13:14 +053034 *
George Liuf3b75142021-06-10 11:22:50 +080035 * @param[in] path - D-Bus object path
36 * @param[in] interface - D-Bus Interface
Vishwanatha Subbanna30e329a2017-07-24 23:13:14 +053037 *
George Liuf3b75142021-06-10 11:22:50 +080038 * @return std::string - the D-Bus service name
39 *
Vishwanatha Subbanna30e329a2017-07-24 23:13:14 +053040 */
George Liuf3b75142021-06-10 11:22:50 +080041const 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 */
54const PropertyValue getProperty(const std::string& objectPath,
55 const std::string& interface,
56 const std::string& propertyName);
57
George Liu13901592021-06-03 14:13:21 +080058/**
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 */
65std::optional<LABELVALUE> checkLabelValue(const std::string& value);
66
George Liuf3b75142021-06-10 11:22:50 +080067} // namespace utils
Vishwanatha Subbanna30e329a2017-07-24 23:13:14 +053068} // namespace occ
69} // namespace open_power