dbus允许定义使用map作为参数的method(但是不能使用struct作为参数)。
可以定义一个如下的service:
#include <sdbusplus/asio/connection.hpp>
#include <sdbusplus/asio/object_server.hpp>
#include <sdbusplus/bus.hpp>
#include <nlohmann/json.hpp>
#include <iostream>
#include <string>
#include <map>
#include <variant>
using namespace std;
using json = nlohmann::json;
using variantT = variant<int, string>;
auto doMap(map<string, variantT>& options)
{
for(auto& i : options)
{
cout<<i.first<<" ";
if(i.second.index() == 0)
{
cout<<get<int>(i.second)<<endl;
}
else
{
cout<<get<string>(i.second)<<endl;
}
}
return options;
}
int main()
{
boost::asio::io_context io;
auto conn = std::make_shared<sdbusplus::asio::connecti