a question about NameOwnerChanged

Zheng, Huan huan.zheng at intel.com
Sun Jan 18 00:33:46 PST 2009


Hi, Dear developers
I'm new to DBUS world, and I'm trying to get the NameOwnerChanged Signal from org.freedesktop.Dbus
But It seems I can't get my callback be invoked.
Could you please help? Below is the code that I'm using.
Thanks a lot!!!!!

#include <memory.h>
#include <stdio.h>
#include <stdlib.h>
#include <stdio.h>
#include <unistd.h>

#include <glib.h>
#include <dbus/dbus.h>
#include <dbus/dbus-glib.h>


GError *error;

DBusGConnection *fdb_connection;
DBusGProxy *fdb_proxy = NULL;
/* Connect to am dbus server
 * return 0 means failed
 * return 1 means succeeded
 * */
gint dbus_init() {
    char *fdb_name = "org.freedesktop.Dbus";
    char *fdb_path = "/org/freedesktop/Dbus";
    char *fdb_interface = "org.freedesktop.Dbus";

    fdb_connection = dbus_g_bus_get(DBUS_BUS_SESSION, &error);
    if (fdb_connection == NULL) {
        g_printerr("Failed to open connection to bus: %s\n",
                    error->message);
        g_error_free(error);
        return 0;
    }

    fdb_proxy = dbus_g_proxy_new_for_name(fdb_connection, fdb_name,
                                   fdb_path, fdb_interface);
    if (fdb_proxy == NULL) {
        g_print("connect to freedesktop dbus server failed\n");
        return 0;
    }
    else {
        g_print("connect to freedesktop dbus server succeeded\n");
    }
    return 1;
}

static void fdb_signal_handler (DBusGProxy* p, const gchar* str, const gchar* str1, const gchar* str2, gpointer userData) {
    g_print("fdb_signal_handler\n");
    g_print("Got signal %s\n", str);
    g_print("Got signal %s\n", str1);
    g_print("Got signal %s\n", str2);
}

/* Signal connection initialization
 * */
void connect_signals() {
    dbus_g_proxy_add_signal(fdb_proxy, "NameOwnerChanged", G_TYPE_STRING, G_TYPE_STRING, G_TYPE_STRING, G_TYPE_INVALID);
    dbus_g_proxy_connect_signal(fdb_proxy, "NameOwnerChanged", G_CALLBACK(fdb_signal_handler), NULL, NULL);
}

int main(int argc, char* argv[]) {

    g_type_init();
    if (dbus_init() == 0)
        return -1;
    connect_signals();

    static GMainLoop *loop = NULL;
    loop = g_main_loop_new(NULL, FALSE);
    g_main_loop_run(loop);
}


Best Regards, Zheng, Huan(ZBT)

OTC/SSD/SSG

Intel Aisa-Pacific Research & Developement Ltd

Tel: 021-6116 6435

Inet: 8821 6435

Cub: 3W035

-------------- next part --------------
An HTML attachment was scrubbed...
URL: http://lists.freedesktop.org/archives/dbus/attachments/20090118/f3ea47d9/attachment.htm 


More information about the dbus mailing list