130e329adSVishwanatha Subbanna #pragma once
230e329adSVishwanatha Subbanna
330e329adSVishwanatha Subbanna #include <sdbusplus/bus.hpp>
4b5ca1015SGeorge Liu
5b5ca1015SGeorge Liu #include <optional>
630e329adSVishwanatha Subbanna #include <string>
713901597SGeorge Liu #include <tuple>
813901597SGeorge Liu
930e329adSVishwanatha Subbanna namespace open_power
1030e329adSVishwanatha Subbanna {
1130e329adSVishwanatha Subbanna namespace occ
1230e329adSVishwanatha Subbanna {
13f3b7514eSGeorge Liu namespace utils
14f3b7514eSGeorge Liu {
1513901597SGeorge Liu
16f3b7514eSGeorge Liu constexpr auto MAPPER_BUSNAME = "xyz.openbmc_project.ObjectMapper";
17f3b7514eSGeorge Liu constexpr auto MAPPER_OBJ_PATH = "/xyz/openbmc_project/object_mapper";
18f3b7514eSGeorge Liu constexpr auto MAPPER_IFACE = "xyz.openbmc_project.ObjectMapper";
19f3b7514eSGeorge Liu constexpr auto DBUS_PROPERTY_IFACE = "org.freedesktop.DBus.Properties";
20f3b7514eSGeorge Liu
21f3b7514eSGeorge Liu // The value of the property(type: variant, contains some basic types)
22c86d80faSChris Cain using PropertyValue =
23c86d80faSChris Cain std::variant<uint32_t, bool, double, std::string, std::vector<std::string>>;
24f3b7514eSGeorge Liu
25f3b7514eSGeorge Liu /** @brief Get the bus connection. */
getBus()26f3b7514eSGeorge Liu static auto& getBus()
27f3b7514eSGeorge Liu {
28f3b7514eSGeorge Liu static auto bus = sdbusplus::bus::new_default();
29f3b7514eSGeorge Liu return bus;
30f3b7514eSGeorge Liu }
31f3b7514eSGeorge Liu
3230e329adSVishwanatha Subbanna /**
33f3b7514eSGeorge Liu * @brief Get service name by the path and interface of the DBus.
3430e329adSVishwanatha Subbanna *
35f3b7514eSGeorge Liu * @param[in] path - D-Bus object path
36f3b7514eSGeorge Liu * @param[in] interface - D-Bus Interface
3730e329adSVishwanatha Subbanna *
38f3b7514eSGeorge Liu * @return std::string - the D-Bus service name
39f3b7514eSGeorge Liu *
4030e329adSVishwanatha Subbanna */
41f3b7514eSGeorge Liu const std::string getService(const std::string& path,
42f3b7514eSGeorge Liu const std::string& interface);
43f3b7514eSGeorge Liu
44f3b7514eSGeorge Liu /** @brief Get property(type: variant)
45f3b7514eSGeorge Liu *
46f3b7514eSGeorge Liu * @param[in] objectPath - D-Bus object path
47f3b7514eSGeorge Liu * @param[in] interface - D-Bus interface
48f3b7514eSGeorge Liu * @param[in] propertyName - D-Bus property name
49f3b7514eSGeorge Liu *
50f3b7514eSGeorge Liu * @return The value of the property(type: variant)
51f3b7514eSGeorge Liu *
52af40808fSPatrick Williams * @throw sdbusplus::exception_t when it fails
53f3b7514eSGeorge Liu */
54f3b7514eSGeorge Liu const PropertyValue getProperty(const std::string& objectPath,
55f3b7514eSGeorge Liu const std::string& interface,
56f3b7514eSGeorge Liu const std::string& propertyName);
57f3b7514eSGeorge Liu
5836f9cdedSChris Cain /**
5936f9cdedSChris Cain * @brief Sets a given object's property value
6036f9cdedSChris Cain *
6136f9cdedSChris Cain * @param[in] object - Name of the object containing the property
6236f9cdedSChris Cain * @param[in] interface - Interface name containing the property
6336f9cdedSChris Cain * @param[in] property - Property name
6436f9cdedSChris Cain * @param[in] value - Property value
6536f9cdedSChris Cain */
6636f9cdedSChris Cain void setProperty(const std::string& objectPath, const std::string& interface,
675d66a0aaSChris Cain const std::string& propertyName, PropertyValue&& value);
6836f9cdedSChris Cain
695901abdaSMatt Spinler /** @brief Get subtree paths
705901abdaSMatt Spinler *
715901abdaSMatt Spinler * @param[in] interfaces - D-Bus interfaces
725901abdaSMatt Spinler * @param[in] path - D-Bus object path
735901abdaSMatt Spinler *
745901abdaSMatt Spinler * @return The D-Bus paths from the GetSubTree method
755901abdaSMatt Spinler *
76af40808fSPatrick Williams * @throw sdbusplus::exception_t when it fails
775901abdaSMatt Spinler */
78*d7542c83SPatrick Williams std::vector<std::string> getSubtreePaths(
79*d7542c83SPatrick Williams const std::vector<std::string>& interfaces, const std::string& path = "/");
805901abdaSMatt Spinler
811be4337bSChris Cain /**
821be4337bSChris Cain * @brief Get the D-Bus service and object path for an interface
831be4337bSChris Cain *
841be4337bSChris Cain * @param[in] interface - D-Bus interface name
851be4337bSChris Cain * @param[in,out] path - D-Bus object path
861be4337bSChris Cain *
871be4337bSChris Cain * @return D-Bus service name
881be4337bSChris Cain */
891be4337bSChris Cain std::string getServiceUsingSubTree(const std::string& interface,
901be4337bSChris Cain std::string& path);
911be4337bSChris Cain
92bae4d07eSChris Cain /**
93bae4d07eSChris Cain * @brief Get status of the host
94bae4d07eSChris Cain *
95bae4d07eSChris Cain * @return true is the host is running, else false
96bae4d07eSChris Cain */
97bae4d07eSChris Cain bool isHostRunning();
98bae4d07eSChris Cain
99f3b7514eSGeorge Liu } // namespace utils
10030e329adSVishwanatha Subbanna } // namespace occ
10130e329adSVishwanatha Subbanna } // namespace open_power
102