Used erased type to reduce binary for getProperty
Introduced erased type patern to reduce amount of templates which
reduces binary size for bmcweb.
Tested:
- Examples which use getProperty helper function are working as before.
https://gerrit.openbmc-project.xyz/c/openbmc/bmcweb/+/44019
Signed-off-by: Krzysztof Grobelny <krzysztof.grobelny@intel.com>
Change-Id: I6b089412edb31f1124a9e2364008cf170b17beff
diff --git a/include/sdbusplus/asio/property.hpp b/include/sdbusplus/asio/property.hpp
index 148bf15..bbbd991 100644
--- a/include/sdbusplus/asio/property.hpp
+++ b/include/sdbusplus/asio/property.hpp
@@ -16,16 +16,18 @@
interface);
}
-template <typename T, typename Handler>
-inline void getProperty(sdbusplus::asio::connection& bus,
- const std::string& service, const std::string& path,
- const std::string& interface,
- const std::string& propertyName, Handler&& handler)
+template <typename T>
+inline void
+ getProperty(sdbusplus::asio::connection& bus, const std::string& service,
+ const std::string& path, const std::string& interface,
+ const std::string& propertyName,
+ std::function<void(boost::system::error_code, T)>&& handler)
{
+ static_assert(std::is_same_v<T, std::decay_t<T>>);
+
bus.async_method_call(
- [handler = std::forward<Handler>(handler)](
- boost::system::error_code ec,
- std::variant<std::monostate, T>& ret) {
+ [handler = std::move(handler)](boost::system::error_code ec,
+ std::variant<std::monostate, T>& ret) {
if (ec)
{
handler(ec, {});
@@ -34,7 +36,7 @@
if (T* value = std::get_if<T>(&ret))
{
- handler(ec, *value);
+ handler(ec, std::move(*value));
return;
}