Building a server is easy, simply connect to the specified bus, request a name and create an infinite loop where you poll for events. Example:
::Connection connection{};
UDBus::Error error{};
UDBus.bus_get(DBUS_BUS_SESSION, error);
connectionif (error.is_set())
{
("Couldn't connect to the session bus");
LOGreturn 1;
}
auto result = connection.request_name("test.method.server", DBUS_NAME_FLAG_REPLACE_EXISTING, error);
if (result != DBUS_REQUEST_NAME_REPLY_PRIMARY_OWNER)
{
("Not primary owner of the name");
LOGreturn 2;
}
while (true)
{
.read_write(0);
connectionauto message = connection.pop_message();
if (!message.is_valid())
continue;
// Call any mesage parsing code here
.unref();
message}