Create an object

Loïc Claudet loic.claudet at clearsy.com
Thu Apr 20 13:50:18 UTC 2017


Hello,

I am trying to create a new objet under a defined service. I made lot of 
researches on google but did find any concrete example.
The function I may used shall be "dbus_connection_register_object_path". 
I tried it but it not worked.
Does someone have any example of use?

I use qdbusviewer to verify each try.
My actual code is the following:

  DBusMessage* msg;
    DBusMessage* reply;
    DBusMessageIter args;
    DBusConnection* conn;
    DBusError err;
    int ret;
    char* param;

    printf("Listening for method calls\n");

    // initialise the error
    dbus_error_init(&err);

    // connect to the bus and check for errors
    conn = dbus_bus_get(DBUS_BUS_SESSION, &err);
    if (dbus_error_is_set(&err)) {
       fprintf(stderr, "Connection Error (%s)\n", err.message);
       dbus_error_free(&err);
    }
    if (NULL == conn) {
       fprintf(stderr, "Connection Null\n");
       exit(1);
    }

    // request our name on the bus and check for errors
    ret = dbus_bus_request_name(conn, "test.method.server", 
DBUS_NAME_FLAG_REPLACE_EXISTING , &err);
    if (dbus_error_is_set(&err)) {
       fprintf(stderr, "Name Error (%s)\n", err.message);
       dbus_error_free(&err);
    }

    if (DBUS_REQUEST_NAME_REPLY_PRIMARY_OWNER != ret) {
       fprintf(stderr, "Not Primary Owner (%d)\n", ret);
       exit(1);
    }

DBusObjectPathVTable table  = {
     .unregister_function = reply_to_method_call,
};

dbus_connection_register_object_path(conn, "/test", &table, NULL);


    // loop, testing for new messages
    while (true) {
       // non blocking read of the next available message
       dbus_connection_read_write(conn, 0);
       msg = dbus_connection_pop_message(conn);

       // loop again if we haven't got a message
       if (NULL == msg) {
          sleep(1);
          continue;
       }

       // check this is a method call for the right interface & method
       if (dbus_message_is_method_call(msg, "test.method.Type", "Method"))
          reply_to_method_call(msg, conn);


       // free the message
       dbus_message_unref(msg);
    }

    // close the connection
    dbus_connection_close(conn);
}

Thank you by advance,

Loïc.
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <https://lists.freedesktop.org/archives/dbus/attachments/20170420/26c91404/attachment.html>


More information about the dbus mailing list