This is a pretty old post, and the OP has probably resolved the issue by
now. I am going to respond anyway! I should also mention that I don't
know much about DBUS foo. 

* flying match had this to say on [19 Feb 2008, 11:20:21 -0800]:
[snip]
> 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.
> 

I looked at the tutorial at
http://www-128.ibm.com/developerworks/linux/library/l-dbus.html?ca=dgr-lnxw95D-BUS,
and following the tutorial, the attached code works for me.

When I run your code, I get a  runtime warning ("No marshaller for
signature of signal 'ReceivedImMsg'"). I tried adding a marshaller with
dbus_g_object_register_marshaller, but that didn't work either. I don't
really know whether that's the correct way of doing it or not. If you
do find a proper fix, perhaps you could let us know!

[snip]
> 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.

Ticket #3243 (http://developer.pidgin.im/ticket/3243) probably has
something to do with this.

> 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.

I got the above mentioned error message. I think the signal handler is
not being added correctly because there's no marshaller for the signal
(and not because the signature of the signal you create in
 _add_signal may be incorrect).

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

#include <glib.h>
#include <glib-object.h>
#include <dbus/dbus.h>
#include <dbus/dbus-glib.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 */
DBusConnection *bus;

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

static DBusHandlerResult
signal_filter(DBusConnection *connection, DBusMessage *message, void *user_data)
{
	if (dbus_message_is_signal(message, DBUS_INTERFACE_PURPLE, "ReceivedImMsg")) {
		g_print("received IM!!\n");
		return DBUS_HANDLER_RESULT_HANDLED;
	}
	return DBUS_HANDLER_RESULT_NOT_YET_HANDLED;
}

int main(int argc, char **argv)
{
	DBusError error;

	g_type_init();
	dbus_error_init(&error);

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

	loop = g_main_loop_new(NULL, FALSE);
	dbus_connection_setup_with_g_main(bus, NULL);

	/* listening to messages from all objects as no path is specified */
	dbus_bus_add_match(bus, "type='signal',interface='" DBUS_INTERFACE_PURPLE "'", &error);
	dbus_connection_add_filter(bus, signal_filter, NULL, NULL);

	g_main_loop_run(loop);

	return 0;
}

_______________________________________________
Support mailing list
[email protected]
http://pidgin.im/cgi-bin/mailman/listinfo/support

Reply via email to