属性的读写,其实函数形式很像,只是参数类型有所不同,可以把这部分抽象出来:
//dbus_prop.hpp
#pragma once#include <utility>
#include <boost/asio.hpp>
#include <sdbusplus/asio/connection.hpp>
#include <sdbusplus/bus.hpp>
#include <sdbusplus/message/native_types.hpp>
#include <string>
#include <tuple>
#include <variant>using namespace sdbusplus;template <class T>
std::tuple<int, std::string> dbusGetProp(const std::string& service, const std::string& obj,const std::string& interFace, const std::string& propName,T& propValue)
{std::string errMsg = "ok";int ret = 0;boost::asio::io_context io;auto conn = make_shared<sdbusplus::asio::connection>(io);auto methodCall = conn->new_method_call(service.c_str(), obj.c_str(), "org.freedesktop.DBus.Properties", "Get");