blob: 5e49f83834161059b7d3b20e9233bf64be974229 [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
George Liuf3b75142021-06-10 11:22:50 +080015constexpr auto MAPPER_BUSNAME = "xyz.openbmc_project.ObjectMapper";
16constexpr auto MAPPER_OBJ_PATH = "/xyz/openbmc_project/object_mapper";
17constexpr auto MAPPER_IFACE = "xyz.openbmc_project.ObjectMapper";
18constexpr auto DBUS_PROPERTY_IFACE = "org.freedesktop.DBus.Properties";
19
20// The value of the property(type: variant, contains some basic types)
21using PropertyValue = std::variant<uint32_t, bool>;
22
23/** @brief Get the bus connection. */
24static auto& getBus()
25{
26 static auto bus = sdbusplus::bus::new_default();
27 return bus;
28}
29
Vishwanatha Subbanna30e329a2017-07-24 23:13:14 +053030/**
George Liuf3b75142021-06-10 11:22:50 +080031 * @brief Get service name by the path and interface of the DBus.
Vishwanatha Subbanna30e329a2017-07-24 23:13:14 +053032 *
George Liuf3b75142021-06-10 11:22:50 +080033 * @param[in] path - D-Bus object path
34 * @param[in] interface - D-Bus Interface
Vishwanatha Subbanna30e329a2017-07-24 23:13:14 +053035 *
George Liuf3b75142021-06-10 11:22:50 +080036 * @return std::string - the D-Bus service name
37 *
Vishwanatha Subbanna30e329a2017-07-24 23:13:14 +053038 */
George Liuf3b75142021-06-10 11:22:50 +080039const std::string getService(const std::string& path,
40 const std::string& interface);
41
42/** @brief Get property(type: variant)
43 *
44 * @param[in] objectPath - D-Bus object path
45 * @param[in] interface - D-Bus interface
46 * @param[in] propertyName - D-Bus property name
47 *
48 * @return The value of the property(type: variant)
49 *
Patrick Williams25613622021-09-02 09:29:54 -050050 * @throw sdbusplus::exception::exception when it fails
George Liuf3b75142021-06-10 11:22:50 +080051 */
52const PropertyValue getProperty(const std::string& objectPath,
53 const std::string& interface,
54 const std::string& propertyName);
55
56} // namespace utils
Vishwanatha Subbanna30e329a2017-07-24 23:13:14 +053057} // namespace occ
58} // namespace open_power