<html>
<head>
<meta http-equiv="content-type" content="text/html; charset=utf-8">
</head>
<body bgcolor="#FFFFFF" text="#000000">
Hello, <br>
<br>
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.<br>
<div class="moz-signature">The function I may used shall be
"dbus_connection_register_object_path". I tried it but it not
worked.<br>
Does someone have any example of use?<br>
<br>
I use qdbusviewer to verify each try.<br>
My actual code is the following: <br>
<font size="-1"><br>
DBusMessage* msg;<br>
DBusMessage* reply;<br>
DBusMessageIter args;<br>
DBusConnection* conn;<br>
DBusError err;<br>
int ret;<br>
char* param;<br>
<br>
printf("Listening for method calls\n");<br>
<br>
// initialise the error<br>
dbus_error_init(&err);<br>
<br>
// connect to the bus and check for errors<br>
conn = dbus_bus_get(DBUS_BUS_SESSION, &err);<br>
if (dbus_error_is_set(&err)) { <br>
fprintf(stderr, "Connection Error (%s)\n", err.message); <br>
dbus_error_free(&err); <br>
}<br>
if (NULL == conn) {<br>
fprintf(stderr, "Connection Null\n"); <br>
exit(1); <br>
}<br>
<br>
// request our name on the bus and check for errors<br>
ret = dbus_bus_request_name(conn, "test.method.server",
DBUS_NAME_FLAG_REPLACE_EXISTING , &err);<br>
if (dbus_error_is_set(&err)) { <br>
fprintf(stderr, "Name Error (%s)\n", err.message); <br>
dbus_error_free(&err);<br>
}<br>
<br>
if (DBUS_REQUEST_NAME_REPLY_PRIMARY_OWNER != ret) { <br>
fprintf(stderr, "Not Primary Owner (%d)\n", ret);<br>
exit(1); <br>
}<br>
<br>
DBusObjectPathVTable table = {<br>
.unregister_function = reply_to_method_call,<br>
};<br>
<br>
dbus_connection_register_object_path(conn, "/test", &table,
NULL);<br>
<br>
<br>
// loop, testing for new messages<br>
while (true) {<br>
// non blocking read of the next available message<br>
dbus_connection_read_write(conn, 0);<br>
msg = dbus_connection_pop_message(conn);<br>
<br>
// loop again if we haven't got a message<br>
if (NULL == msg) { <br>
sleep(1); <br>
continue; <br>
}<br>
<br>
// check this is a method call for the right interface
& method<br>
if (dbus_message_is_method_call(msg, "test.method.Type",
"Method")) <br>
reply_to_method_call(msg, conn);<br>
<br>
<br>
// free the message<br>
dbus_message_unref(msg);<br>
}<br>
<br>
// close the connection<br>
dbus_connection_close(conn);<br>
}<br>
</font><br>
Thank you by advance, <br>
<br>
Loïc.<font size="-1"><br>
</font></div>
</body>
</html>