DBUS glibc simple code problem

flying match flyingmatch at gmail.com
Tue Feb 19 14:20:21 EST 2008

Dear Pidgin gurus,

I'm a newbie of Pidgin developer. And I'm trying to write a simple DBUS
glibc based application for Pidgin.

I know there are bunch of Python based eamples in Pidgin source code, such
as purple-notifications-example and purple-remote. What I want to achieve in
my first step is very simple, implement a glibc based
purple-notifications-example, and upload to the Pidgin web page to share
with everybody.

The code is complied, but just cannot get any received-im-msg notification
no matter how hard I try.  I wonder if anyone could spend some time helping
me find the reason (guess could be very stupid anyway)? If I managed to get
the code run as smoothly as that purple-notifications-example, I'll submit
to the web page to share with the community.

Your help is really appreciated!

Ok, now let's get to my stupid code, quite short anyway.

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

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

/* access point of Pidgin dbus */
#define DBUS_SERVICE_PURPLE      "im.pidgin.purple.PurpleService"
#define DBUS_PATH_PURPLE         "/im/pidgin/purple/PurpleObject"
#define DBUS_INTERFACE_PURPLE    "im.pidgin.purple.PurpleInterface"

/* dbus globle instance */
DBusGConnection *bus;
DBusGProxy *purple_proxy;

 /* Main event loop */
GMainLoop *loop = NULL;

void received_im_msg_cb (DBusGProxy *purple_proxy, int account_id, const
char *name,
                                          const char *message, int conv_id,
unsigned int flags,
                                          gpointer user_data)
    g_print("%s says %s\n", name, message);

int main (int argc, char **argv)
    GError *error = NULL;

    g_type_init ();

    bus = dbus_g_bus_get (DBUS_BUS_SESSION, &error);
    if (bus == NULL) {
        g_printerr("Failed to open connection to bus: %s", error->message);
        return -1;

    /* Create a proxy object for the bus driver */
    purple_proxy = dbus_g_proxy_new_for_name (bus,

    if (!purple_proxy) {
        g_printerr("Couldn't connect to the Purple Service: %s",
        return -1;

     loop = g_main_loop_new (NULL, FALSE);

     dbus_g_proxy_add_signal(purple_proxy, "ReceivedImMsg",
                            G_TYPE_NONE, G_TYPE_INT, G_TYPE_STRING,
                            G_TYPE_INT, G_TYPE_INT, G_TYPE_INVALID);

    dbus_g_proxy_connect_signal(purple_proxy, "ReceivedImMsg",
                                G_CALLBACK(received_im_msg_cb), bus, NULL);

    g_main_loop_run (loop);

   return 0;

I compiled the code above with following command:
$gcc -MMD -Wall -ggdb -O `pkg-config --cflags dbus-1 glib-2.0 dbus-glib-1`
`pkg-config --libs dbus-1 glib-2.0 dbus-glib-1` main.c -o dbus_test

And run it

But this dbus_test does not print any message no matter how many IM messages
I receive from my buddies on the Pidgin 2.3.1, which runs on my Ubuntu Linux

Couple of questions if you are still reading:
1. Unlike Pidgin dbus methods which can be viewed by dbus-viewer, dbus
signals don't have any definitions. As a result, I have no way to know the
parameters associated with each signal. I.e., I'm just guessing what
parameters associated with signal ReceviedImMsg above.

2. The dbus_g_proxy_add_signal() and dbus_g_proxy_connect_signal() do not
return any failure, so I don't know if my signal handler is added
successfully or not. I tried to change different parameters associated with
the ReceivedImMsg signal, given any parameter, the code can compile and run,
but just don't actually work.

Again, your help is appreciated!

-------------- next part --------------
An HTML attachment was scrubbed...
URL: http://pidgin.im/pipermail/support/attachments/20080219/b8b486b6/attachment.htm 

More information about the Support mailing list