blob: 3a6bad53943440bec400f19b96c0b302b5395383 [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 Cain5d66a0a2022-02-09 08:52:10 -060022using PropertyValue = std::variant<uint32_t, bool, double, std::string>;
George Liuf3b75142021-06-10 11:22:50 +080023
24/** @brief Get the bus connection. */
25static auto& getBus()
26{
27 static auto bus = sdbusplus::bus::new_default();
28 return bus;
29}
30
Vishwanatha Subbanna30e329a2017-07-24 23:13:14 +053031/**
George Liuf3b75142021-06-10 11:22:50 +080032 * @brief Get service name by the path and interface of the DBus.
Vishwanatha Subbanna30e329a2017-07-24 23:13:14 +053033 *
George Liuf3b75142021-06-10 11:22:50 +080034 * @param[in] path - D-Bus object path
35 * @param[in] interface - D-Bus Interface
Vishwanatha Subbanna30e329a2017-07-24 23:13:14 +053036 *
George Liuf3b75142021-06-10 11:22:50 +080037 * @return std::string - the D-Bus service name
38 *
Vishwanatha Subbanna30e329a2017-07-24 23:13:14 +053039 */
George Liuf3b75142021-06-10 11:22:50 +080040const std::string getService(const std::string& path,
41 const std::string& interface);
42
43/** @brief Get property(type: variant)
44 *
45 * @param[in] objectPath - D-Bus object path
46 * @param[in] interface - D-Bus interface
47 * @param[in] propertyName - D-Bus property name
48 *
49 * @return The value of the property(type: variant)
50 *
Patrick Williams25613622021-09-02 09:29:54 -050051 * @throw sdbusplus::exception::exception when it fails
George Liuf3b75142021-06-10 11:22:50 +080052 */
53const PropertyValue getProperty(const std::string& objectPath,
54 const std::string& interface,
55 const std::string& propertyName);
56
Chris Cain36f9cde2021-11-22 11:18:21 -060057/**
58 * @brief Sets a given object's property value
59 *
60 * @param[in] object - Name of the object containing the property
61 * @param[in] interface - Interface name containing the property
62 * @param[in] property - Property name
63 * @param[in] value - Property value
64 */
65void setProperty(const std::string& objectPath, const std::string& interface,
Chris Cain5d66a0a2022-02-09 08:52:10 -060066 const std::string& propertyName, PropertyValue&& value);
Chris Cain36f9cde2021-11-22 11:18:21 -060067
Matt Spinler5901abd2021-09-23 13:50:03 -050068/** @brief Get subtree paths
69 *
70 * @param[in] interfaces - D-Bus interfaces
71 * @param[in] path - D-Bus object path
72 *
73 * @return The D-Bus paths from the GetSubTree method
74 *
75 * @throw sdbusplus::exception::exception when it fails
76 */
77std::vector<std::string>
78 getSubtreePaths(const std::vector<std::string>& interfaces,
79 const std::string& path = "/");
80
Chris Cain1be43372021-12-09 19:29:37 -060081/**
82 * @brief Get the D-Bus service and object path for an interface
83 *
84 * @param[in] interface - D-Bus interface name
85 * @param[in,out] path - D-Bus object path
86 *
87 * @return D-Bus service name
88 */
89std::string getServiceUsingSubTree(const std::string& interface,
90 std::string& path);
91
Chris Cainbae4d072022-02-28 09:46:50 -060092/**
93 * @brief Get status of the host
94 *
95 * @return true is the host is running, else false
96 */
97bool isHostRunning();
98
George Liuf3b75142021-06-10 11:22:50 +080099} // namespace utils
Vishwanatha Subbanna30e329a2017-07-24 23:13:14 +0530100} // namespace occ
101} // namespace open_power