Friday, November 9, 2012

D-Bus


to connect to D-bus,
conn = g_dbus_setup_bus(DBUS_BUS_SYSTEM, BLUEZ_NAME, &err);
check in      ./external/bluetooth/android-obex-obexd/src/manager.c

Connection failure could be checked in "err".
This will be giving service.

To invoke message in remote object, which must be connected to D-bus,

DBusMessage * dbus_message_new_method_call (const char *destination, const char *path, const char *interface, const char *method)
  Constructs a new message to invoke a method on a remote object.




Check this program:
int main(int argc, char *argv[])
{
struct sigaction sa;
DBusConnection *conn;
DBusError err;

dbus_error_init(&err);
debug("obex-client start to run");
conn = g_dbus_setup_bus(DBUS_BUS_SYSTEM, CLIENT_SERVICE, &err);
if (conn == NULL) {
if (dbus_error_is_set(&err) == TRUE) {
fprintf(stderr, "%s\n", err.message);
dbus_error_free(&err);
} else
fprintf(stderr, "Can't register with session bus\n");
exit(EXIT_FAILURE);
}

if (g_dbus_register_interface(conn, CLIENT_PATH, CLIENT_INTERFACE,
client_methods, NULL, NULL,
NULL, NULL) == FALSE) {
fprintf(stderr, "Can't register client interface\n");
dbus_connection_unref(conn);
exit(EXIT_FAILURE);
}

event_loop = g_main_loop_new(NULL, FALSE);

memset(&sa, 0, sizeof(sa));
sa.sa_handler = sig_term;
sigaction(SIGINT, &sa, NULL);
sigaction(SIGTERM, &sa, NULL);

g_main_loop_run(event_loop);

g_dbus_unregister_interface(conn, CLIENT_PATH, CLIENT_INTERFACE);

dbus_connection_unref(conn);

g_main_loop_unref(event_loop);

return 0;
}

No comments:

Post a Comment