sdbusplus提供了一个example,可以通过同步方式调用service的method,从而获得当前系统的用户列表:
//list_user.cpp
#include <sdbusplus/bus.hpp>
#include <cstdint>
#include <iostream>
int main()
{
using namespace sdbusplus;
auto b = bus::new_default_system();
auto m = b.new_method_call("org.freedesktop.login1", "/org/freedesktop/login1",
"org.freedesktop.login1.Manager", "ListUsers");
auto reply = b.call(m);
std::vector<std::tuple<uint32_t, std::string, message::object_path>> users;
reply.read(users);
for (auto& user : users)
{
std::cout << std::get<std::string>(user) << "