blob: eb38c0379fb4710740576c02ec29196e40afe836 [file] [log] [blame]
Vishwanatha Subbanna30e329a2017-07-24 23:13:14 +05301#pragma once
2
3#include <sdbusplus/bus.hpp>
George Liub5ca1012021-09-10 12:53:11 +08004
5#include <optional>
Vishwanatha Subbanna30e329a2017-07-24 23:13:14 +05306#include <string>
George Liu13901592021-06-03 14:13:21 +08007#include <tuple>
8
Vishwanatha Subbanna30e329a2017-07-24 23:13:14 +05309namespace open_power
10{
11namespace occ
12{
George Liuf3b75142021-06-10 11:22:50 +080013namespace utils
14{
George Liu13901592021-06-03 14:13:21 +080015
George Liuf3b75142021-06-10 11:22:50 +080016constexpr auto MAPPER_BUSNAME = "xyz.openbmc_project.ObjectMapper";
17constexpr auto MAPPER_OBJ_PATH = "/xyz/openbmc_project/object_mapper";
18constexpr auto MAPPER_IFACE = "xyz.openbmc_project.ObjectMapper";
19constexpr auto DBUS_PROPERTY_IFACE = "org.freedesktop.DBus.Properties";
20
21// The value of the property(type: variant, contains some basic types)
Chris Cainc86d80f2023-05-04 15:49:18 -050022using PropertyValue =
23 std::variant<uint32_t, bool, double, std::string, std::vector<std::string>>;
George Liuf3b75142021-06-10 11:22:50 +080024
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 *
Patrick Williamsaf408082022-07-22 19:26:54 -050052 * @throw sdbusplus::exception_t when it fails
George Liuf3b75142021-06-10 11:22:50 +080053 */
54const PropertyValue getProperty(const std::string& objectPath,
55 const std::string& interface,
56 const std::string& propertyName);
57
Chris Cain36f9cde2021-11-22 11:18:21 -060058/**
59 * @brief Sets a given object's property value
60 *
61 * @param[in] object - Name of the object containing the property
62 * @param[in] interface - Interface name containing the property
63 * @param[in] property - Property name
64 * @param[in] value - Property value
65 */
66void setProperty(const std::string& objectPath, const std::string& interface,
Chris Cain5d66a0a2022-02-09 08:52:10 -060067 const std::string& propertyName, PropertyValue&& value);
Chris Cain36f9cde2021-11-22 11:18:21 -060068
Matt Spinler5901abd2021-09-23 13:50:03 -050069/** @brief Get subtree paths
70 *
71 * @param[in] interfaces - D-Bus interfaces
72 * @param[in] path - D-Bus object path
73 *
74 * @return The D-Bus paths from the GetSubTree method
75 *
Patrick Williamsaf408082022-07-22 19:26:54 -050076 * @throw sdbusplus::exception_t when it fails
Matt Spinler5901abd2021-09-23 13:50:03 -050077 */
78std::vector<std::string>
79 getSubtreePaths(const std::vector<std::string>& interfaces,
80 const std::string& path = "/");
81
Chris Cain1be43372021-12-09 19:29:37 -060082/**
83 * @brief Get the D-Bus service and object path for an interface
84 *
85 * @param[in] interface - D-Bus interface name
86 * @param[in,out] path - D-Bus object path
87 *
88 * @return D-Bus service name
89 */
90std::string getServiceUsingSubTree(const std::string& interface,
91 std::string& path);
92
Chris Cainbae4d072022-02-28 09:46:50 -060093/**
94 * @brief Get status of the host
95 *
96 * @return true is the host is running, else false
97 */
98bool isHostRunning();
99
George Liuf3b75142021-06-10 11:22:50 +0800100} // namespace utils
Vishwanatha Subbanna30e329a2017-07-24 23:13:14 +0530101} // namespace occ
102} // namespace open_power