通过一个例子,注册一个新的dbus接口,并向接口内写值。
constexpr auto dbusPath = "/xyz/openbmc_project/control/bmc_type";
constexpr auto dbusName = "xyz.openbmc_project.BMC.type";
int main()
{
boost::asio::io_context io;
auto connection = std::make_shared<sdbusplus::asio::connection>(io);
auto objServer = sdbusplus::asio::object_server(connection);
BMCTypeConfig config = detectAndGetBMCConfig();
// 创建统一接口对象
auto iface = objServer.add_interface(dbusPath, dbusName);
// 注册动态属性值,向dbus上写值
iface->register_property("BmcType", std::string(config.typeValue));
iface->initialize();
// 请求统一服务名称
connection->request_name(dbusName);
io.run();
return 0;
}
效果如下:
路径定义了constexpr auto dbusPath = "/xyz/openbmc_project/control/bmc_type",设备树tree显示时,会自动把上层的目录(也就是/xyz/openbmc_project和/xyz/openbmc_project/control)补全。