Dbus sample program does not work

Ho Chi Bun Philip cbho at astri.org
Thu Dec 11 04:16:28 EST 2008


i.e. when I compiled the following program under scratchbox (the
development platform for N810). How to debug it? Dbus-monitor works and
can capture the Received message.

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

#include "marshal.h"  /* The file generated from marshal.list via tool
glib-genmarshal */

/* pidgin dbus station name */
#define DBUS_SERVICE_PURPLE      "im.pidgin.purple.PurpleService"
#define DBUS_PATH_PURPLE         "/im/pidgin/purple/PurpleObject"
#define DBUS_INTERFACE_PURPLE    "im.pidgin.purple.PurpleInterface"

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


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

/* Signal callback handling routing */
void received_im_msg_cb (DBusGProxy *purple_proxy, unsigned int
account_id, 
                         const char *sender, const char *message, 
                         unsigned int conv_id, unsigned int flags,
                         gpointer user_data)
{
    g_print("Account %d receives msg \"%s\" from %s\n",   
            account_id, message, sender);
}

/*
 * The main process, loop waiting for any signals
 */
int main (int argc, char **argv)
{
    GError *error = NULL;
    
    g_type_init ();

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

    /* Create a proxy object for the bus driver */
    purple_proxy = dbus_g_proxy_new_for_name (bus,
                                              DBUS_SERVICE_PURPLE,
                                              DBUS_PATH_PURPLE,
                                              DBUS_INTERFACE_PURPLE);
    
    if (!purple_proxy) {
        g_printerr("Couldn't connect to the Purple Service: %s",
error->message);
        g_error_free(error);
        return -1;
    }

    /* Create the main loop instance */
    loop = g_main_loop_new (NULL, FALSE);

    /* Register dbus signal marshaller */
 
dbus_g_object_register_marshaller(marshal_VOID__UINT_STRING_STRING_UINT_
UINT, 
                                      G_TYPE_NONE, G_TYPE_UINT,
G_TYPE_STRING, 
                                      G_TYPE_STRING, G_TYPE_UINT,
G_TYPE_UINT, 
                                      G_TYPE_INVALID);
        
    /* Add the signal to the proxy */
    dbus_g_proxy_add_signal(purple_proxy, "ReceivedImMsg", 
                            G_TYPE_UINT, G_TYPE_STRING, G_TYPE_STRING, 
                            G_TYPE_UINT, G_TYPE_UINT, G_TYPE_INVALID);

    /* Connect the signal handler to the proxy */
    dbus_g_proxy_connect_signal(purple_proxy, "ReceivedImMsg",
                                G_CALLBACK(received_im_msg_cb), bus,
NULL);

    /* Main loop */
    g_main_loop_run (loop);

    return 0;
}


-----Original Message-----
From: devel-bounces at pidgin.im [mailto:devel-bounces at pidgin.im] On Behalf
Of Ho Chi Bun Philip
Sent: Thursday, December 11, 2008 11:18 AM
To: devel at pidgin.im
Subject: Dbus sample program does not work


Hi

I am new to Dbus and Pidgin. I am trying the test program in Dbus
How-to. But the program does not work somehow.

http://developer.pidgin.im/wiki/DbusHowto

I have already defined marshaller functions for the signal handler and
able to compile it with the dbus simple C program to listen to signal
ReceivedImMsg.

When a buddy send a message through a Bonjour network, pidgin can show
the message. But there is no printout in the test program.

I have also tried changing the signal name to DisplayedImMsg but also no
response.

I doubt that different DBUS_SESSION_BUS_PID s is being used.

I mostly use N810 platform but I also tried Linux but to no avail.

Regards,
Philip



This message (including any attachments) is for the named addressee(s)'s
use only. It may contain sensitive, confidential, private proprietary or
legally privileged information intended for a specific individual and
purpose, and is protected by law. If you are not the intended recipient,
please immediately delete it and all copies of it from your system,
destroy any hard copies of it and notify the sender. Any use,
disclosure, copying, or distribution of this message and/or any
attachments is strictly prohibited. 



~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
This message (including any attachments) is for the named
addressee(s)'s use only. It may contain sensitive, confidential,
private proprietary or legally privileged information intended for a
specific individual and purpose, and is protected by law. If you are
not the intended recipient, please immediately delete it and all copies
of it from your system, destroy any hard copies of it
and notify the sender. Any use, disclosure, copying, or distribution of
this message and/or any attachments is strictly prohibited.
~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~




More information about the Devel mailing list