blob: 1d173a3f0f99e40ba24e829bb83afff9c206776f [file] [log] [blame]
Vishwanatha Subbanna30e329a2017-07-24 23:13:14 +05301#pragma once
2
3#include <sdbusplus/bus.hpp>
4#include <string>
5namespace open_power
6{
7namespace occ
8{
George Liuf3b75142021-06-10 11:22:50 +08009namespace utils
10{
11constexpr auto MAPPER_BUSNAME = "xyz.openbmc_project.ObjectMapper";
12constexpr auto MAPPER_OBJ_PATH = "/xyz/openbmc_project/object_mapper";
13constexpr auto MAPPER_IFACE = "xyz.openbmc_project.ObjectMapper";
14constexpr auto DBUS_PROPERTY_IFACE = "org.freedesktop.DBus.Properties";
15
16// The value of the property(type: variant, contains some basic types)
17using PropertyValue = std::variant<uint32_t, bool>;
18
19/** @brief Get the bus connection. */
20static auto& getBus()
21{
22 static auto bus = sdbusplus::bus::new_default();
23 return bus;
24}
25
Vishwanatha Subbanna30e329a2017-07-24 23:13:14 +053026/**
George Liuf3b75142021-06-10 11:22:50 +080027 * @brief Get service name by the path and interface of the DBus.
Vishwanatha Subbanna30e329a2017-07-24 23:13:14 +053028 *
George Liuf3b75142021-06-10 11:22:50 +080029 * @param[in] path - D-Bus object path
30 * @param[in] interface - D-Bus Interface
Vishwanatha Subbanna30e329a2017-07-24 23:13:14 +053031 *
George Liuf3b75142021-06-10 11:22:50 +080032 * @return std::string - the D-Bus service name
33 *
Vishwanatha Subbanna30e329a2017-07-24 23:13:14 +053034 */
George Liuf3b75142021-06-10 11:22:50 +080035const std::string getService(const std::string& path,
36 const std::string& interface);
37
38/** @brief Get property(type: variant)
39 *
40 * @param[in] objectPath - D-Bus object path
41 * @param[in] interface - D-Bus interface
42 * @param[in] propertyName - D-Bus property name
43 *
44 * @return The value of the property(type: variant)
45 *
46 * @throw sdbusplus::exception::SdBusError when it fails
47 */
48const PropertyValue getProperty(const std::string& objectPath,
49 const std::string& interface,
50 const std::string& propertyName);
51
52} // namespace utils
Vishwanatha Subbanna30e329a2017-07-24 23:13:14 +053053} // namespace occ
54} // namespace open_power