Cannot get D-BUS working
Pier Luigi Fiorini
plfiorini@users.sf.net
Wed Mar 10 18:28:54 PST 2004
--Boundary-00=_m51TAc5NqnKjolM
Content-Type: text/plain;
charset="us-ascii"
Content-Transfer-Encoding: 7bit
Content-Disposition: inline
Hi,
I played a bit with D-BUS in these days and I made a simple program that send
a signal to the system bus (see the attachment).
With dbus-monitor --system "member='TestSignal'" or
dbus-monitor --system "type='signal',interface='org.test.simple'" or
dbus-monitor --system "sender='org.test.example'"
I don't see any message. :-/
What's wrong with my simple app?
--
BeFree lead developer
http://befree.berlios.de
--Boundary-00=_m51TAc5NqnKjolM
Content-Type: text/x-csrc;
charset="us-ascii";
name="send.c"
Content-Transfer-Encoding: 7bit
Content-Disposition: attachment;
filename="send.c"
#include <stdio.h>
#include <stdlib.h>
#define DBUS_API_SUBJECT_TO_CHANGE
#include <dbus/dbus.h>
int
main (void)
{
DBusError err;
DBusConnection *conn;
DBusMessage *mess;
DBusMessageIter iter;
dbus_error_init (&err);
conn = dbus_bus_get (DBUS_BUS_SYSTEM, &err);
if (!conn)
{
printf ("Couldn't connect to system bus: %s\n", err.message);
dbus_error_free (&err);
return 1;
}
dbus_bus_add_match (conn, "sender='org.test.example'", &err);
if (dbus_error_is_set (&err))
{
printf ("Couldn't set match: %s\n", err.message);
dbus_connection_disconnect (conn);
dbus_error_free (&err);
return 1;
}
mess = dbus_message_new_signal ("/org/test/simple", "org.test.simple", "TestSignal");
if (!mess)
{
printf ("Couldn't create signal!\n");
dbus_connection_disconnect (conn);
dbus_error_free (&err);
return 1;
}
#if 0
if (!dbus_message_set_sender (mess, "org.test.sender"))
{
printf ("Couldn't set sender!\n");
dbus_connection_disconnect (conn);
dbus_error_free (&err);
return 1;
}
#endif
if (!dbus_message_set_member (mess, "TestSignal"))
{
printf ("Couldn't set member!\n");
dbus_connection_disconnect (conn);
dbus_error_free (&err);
return 1;
}
dbus_message_iter_init (mess, &iter);
if (!dbus_message_iter_append_int32 (&iter, 42))
{
printf ("Couldn't append int32!\n");
dbus_connection_disconnect (conn);
dbus_error_free (&err);
return 1;
}
if (!dbus_connection_send (conn, mess, NULL))
{
printf ("Couldn't send!\n");
dbus_connection_disconnect (conn);
dbus_error_free (&err);
return 1;
}
dbus_connection_flush (conn);
return 0;
}
--Boundary-00=_m51TAc5NqnKjolM--
More information about the dbus
mailing list