diff options
author | Brad Bishop <bradleyb@fuzziesquirrel.com> | 2017-07-30 13:32:23 -0400 |
---|---|---|
committer | Patrick Williams <patrick@stwcx.xyz> | 2017-08-03 01:52:48 +0000 |
commit | f2238ae65801eaf0795f483afd8e1fc5eb6f85a4 (patch) | |
tree | 4acced7707e4ce12cea281d250b2acf19e49bad6 | |
parent | e67b41bc46f7b801eec3d0c40f451cb2c35d7e66 (diff) | |
download | phosphor-fan-presence-f2238ae65801eaf0795f483afd8e1fc5eb6f85a4.tar.gz phosphor-fan-presence-f2238ae65801eaf0795f483afd8e1fc5eb6f85a4.zip |
Allow existing bus connections
Overload the wrapper methods in sdbusplus.hpp for clients
that already have a bus connection.
Change-Id: I662385e6afe52179293ccbd41212d208e34bfbc5
Signed-off-by: Brad Bishop <bradleyb@fuzziesquirrel.com>
-rw-r--r-- | sdbusplus.hpp | 135 |
1 files changed, 129 insertions, 6 deletions
diff --git a/sdbusplus.hpp b/sdbusplus.hpp index 0b842e6..1efe54d 100644 --- a/sdbusplus.hpp +++ b/sdbusplus.hpp @@ -40,19 +40,20 @@ class SDBusPlus /** @brief Invoke a method. */ template <typename ...Args> static auto callMethod( + sdbusplus::bus::bus& bus, const std::string& busName, const std::string& path, const std::string& interface, const std::string& method, Args&& ... args) { - auto reqMsg = getBus().new_method_call( + auto reqMsg = bus.new_method_call( busName.c_str(), path.c_str(), interface.c_str(), method.c_str()); reqMsg.append(std::forward<Args>(args)...); - auto respMsg = getBus().call(reqMsg); + auto respMsg = bus.call(reqMsg); if (respMsg.is_method_error()) { @@ -68,9 +69,28 @@ class SDBusPlus return respMsg; } + /** @brief Invoke a method. */ + template <typename ...Args> + static auto callMethod( + const std::string& busName, + const std::string& path, + const std::string& interface, + const std::string& method, + Args&& ... args) + { + return callMethod( + getBus(), + busName, + path, + interface, + method, + std::forward<Args>(args)...); + } + /** @brief Invoke a method and read the response. */ template <typename Ret, typename ...Args> static auto callMethodAndRead( + sdbusplus::bus::bus& bus, const std::string& busName, const std::string& path, const std::string& interface, @@ -79,6 +99,7 @@ class SDBusPlus { sdbusplus::message::message respMsg = callMethod<Args...>( + bus, busName, path, interface, @@ -89,8 +110,28 @@ class SDBusPlus return resp; } + /** @brief Invoke a method and read the response. */ + template <typename Ret, typename ...Args> + static auto callMethodAndRead( + const std::string& busName, + const std::string& path, + const std::string& interface, + const std::string& method, + Args&& ... args) + { + return callMethodAndRead<Ret>( + getBus(), + busName, + path, + interface, + method, + std::forward<Args>(args)...); + } + + /** @brief Get service from the mapper. */ static auto getService( + sdbusplus::bus::bus& bus, const std::string& path, const std::string& interface) { @@ -98,6 +139,7 @@ class SDBusPlus using GetObject = std::map<std::string, std::vector<std::string>>; auto mapperResp = callMethodAndRead<GetObject>( + bus, "xyz.openbmc_project.ObjectMapper"s, "/xyz/openbmc_project/object_mapper"s, "xyz.openbmc_project.ObjectMapper"s, @@ -117,9 +159,21 @@ class SDBusPlus return mapperResp.begin()->first; } + /** @brief Get service from the mapper. */ + static auto getService( + const std::string& path, + const std::string& interface) + { + return getService( + getBus(), + path, + interface); + } + /** @brief Get a property with mapper lookup. */ template <typename Property> static auto getProperty( + sdbusplus::bus::bus& bus, const std::string& path, const std::string& interface, const std::string& property) @@ -127,7 +181,8 @@ class SDBusPlus using namespace std::literals::string_literals; auto msg = callMethod( - getService(path, interface), + bus, + getService(bus, path, interface), path, "org.freedesktop.DBus.Properties"s, "Get"s, @@ -138,9 +193,24 @@ class SDBusPlus return value.template get<Property>(); } + /** @brief Get a property with mapper lookup. */ + template <typename Property> + static auto getProperty( + const std::string& path, + const std::string& interface, + const std::string& property) + { + return getProperty<Property>( + getBus(), + path, + interface, + property); + } + /** @brief Set a property with mapper lookup. */ template <typename Property> static void setProperty( + sdbusplus::bus::bus& bus, const std::string& path, const std::string& interface, const std::string& property, @@ -152,7 +222,8 @@ class SDBusPlus std::forward<Property>(value)); callMethod( - getService(path, interface), + bus, + getService(bus, path, interface), path, "org.freedesktop.DBus.Properties"s, "Set"s, @@ -161,16 +232,50 @@ class SDBusPlus varValue); } + /** @brief Set a property with mapper lookup. */ + template <typename Property> + static void setProperty( + const std::string& path, + const std::string& interface, + const std::string& property, + Property&& value) + { + return setProperty( + getBus(), + path, + interface, + property, + std::forward<Property>(value)); + } + /** @brief Invoke method with mapper lookup. */ template <typename ...Args> static auto lookupAndCallMethod( + sdbusplus::bus::bus& bus, const std::string& path, const std::string& interface, const std::string& method, Args&& ... args) { return callMethod( - getService(path, interface), + bus, + getService(bus, path, interface), + path, + interface, + method, + std::forward<Args>(args)...); + } + + /** @brief Invoke method with mapper lookup. */ + template <typename ...Args> + static auto lookupAndCallMethod( + const std::string& path, + const std::string& interface, + const std::string& method, + Args&& ... args) + { + return lookupAndCallMethod( + getBus(), path, interface, method, @@ -180,13 +285,31 @@ class SDBusPlus /** @brief Invoke method and read with mapper lookup. */ template <typename Ret, typename ...Args> static auto lookupCallMethodAndRead( + sdbusplus::bus::bus& bus, const std::string& path, const std::string& interface, const std::string& method, Args&& ... args) { return callMethodAndRead( - getService(path, interface), + bus, + getService(bus, path, interface), + path, + interface, + method, + std::forward<Args>(args)...); + } + + /** @brief Invoke method and read with mapper lookup. */ + template <typename Ret, typename ...Args> + static auto lookupCallMethodAndRead( + const std::string& path, + const std::string& interface, + const std::string& method, + Args&& ... args) + { + return lookupCallMethodAndRead<Ret>( + getBus(), path, interface, method, |