D-BUS unable to receive few signals.
Abhijeet Kumar Sinha
abhijeet.aks at gmail.com
Mon May 11 09:46:42 PDT 2009
Hello,
I was trying to trigger some task when DHCP does an DHCPACK on an IP. This I
thought of achieving by using dbus signals.
I picked up the code from the following page --
http://dbus.freedesktop.org/doc/dbus/libdbus-tutorial.html<https://webmail.wipro.com/exchweb/bin/redir.asp?URL=http://dbus.freedesktop.org/doc/dbus/libdbus-tutorial.html>Read
the "Receiving a Signal" section and modified it to my own
requirements.
As for sending the signal I used the dbus-send command from DHCP server (
Inserting few statements in ISC DHCP's dhcpd.conf file by which on commit or
on release the dbus-send command in triggered )
I am facing a problem, where some Signals do not reach the dbus server
program. It happens once in 40-50 signals. But my application would not want
to lose the Signals.
Part of my Code
dbus-server.c
#include <dbus/dbus.h>
#include <stdbool.h>
#include <unistd.h>
#include <stdio.h>
#include <stdlib.h>
#include<string.h> void receive()
{
DBusMessage* msg;
DBusMessageIter args;
DBusConnection* conn;
DBusError err;
int ret, ipcheck;
char *sigvalue1, *message;
dbus_bool_t sigvalue2;
bool request_type;
static int sequence_number = 0;
dbus_error_init(&err);
conn = dbus_bus_get(DBUS_BUS_SYSTEM, &err);
ret = dbus_bus_request_name(conn, "com.example.app.Sink",
DBUS_NAME_FLAG_REPLACE_EXISTING , &err);
dbus_bus_add_match(conn,
"type='signal',interface='com.example.app.Signal'", &err);
dbus_connection_flush(conn);
// All the checks were made to see if the connection is
established. while
(true)
{
dbus_connection_read_write(conn, 0);
msg = dbus_connection_pop_message(conn);
if (NULL == msg) {
sleep(1);
continue;
}
if (dbus_message_is_signal(msg, "com.example.app.Signal", "Test"))
{
fprintf(stdout,"\n#####################################################\n");
sequence_number++;
fprintf(stdout,"\nSignal Sequence Number: %d\n",sequence_number);
fflush(stdout);
if (dbus_message_iter_init(msg, &args))
{
dbus_message_iter_get_basic(&args,&sigvalue1);
dbus_message_iter_next(&args);
dbus_message_iter_get_basic(&args,&sigvalue2);
fflush(stdout);
if( sigvalue2 )
request_type=true;
else
request_type=false;
if ( request_type )
{
// DO SOMETHING
dbus_message_unref(msg);
continue;
}
else
{
// DO SOMETHING ELSE
dbus_message_unref(msg);
continue;
}
}
}
dbus_message_unref(msg);
} // end of while loop
}
A dbus-send command is sent using --
dbus-send --system --dest='com.example.app.Sink' --type=signal
/com/example/app/Signal com.example.app.Signal.Test string:"192.168.47.100"
boolean:true or
dbus-send --system --dest='com.example.app.Sink' --type=signal
/com/example/app/Signal com.example.app.Signal.Test string:"192.168.47.100"
boolean:false
I have an xml conf file in /etc/dbus-1/system.d/app.conf
<!DOCTYPE busconfig PUBLIC "-//freedesktop//DTD D-BUS Bus Configuration
1.0//EN"
"http://www.freedesktop.org/standards/dbus/1.0/busconfig.dtd<https://webmail.wipro.com/exchweb/bin/redir.asp?URL=http://www.freedesktop.org/standards/dbus/1.0/busconfig.dtd>
">
<busconfig>
<policy user="root">
<allow own="com.example.app.Source"/>
<allow send_interface="com.example.app.Signal"/>
<allow send_destination="com.example.app.Sink"/>
</policy>
<policy user="root">
<allow own="com.example.app.Sink"/>
</policy>
<policy context="default">
<deny own="com.example.app.Source"/>
<deny send_destination="com.example.app.Sink"/>
<deny send_interface="com.example.app.Signal"/>
</policy>
</busconfig>
I modified the dbus-server.c code to change the following
*dbus_connection_read_write(conn, 0); *
*dbus_connection_read_write(conn, 1); *
*dbus_connection_read_write(conn, 2);*
Apart from that I also tried
*if (NULL == msg) {
usleep(1000);
continue;
}*
But none had the required effect. Is there any glitch which is left which
makes it lose the Signal ? I have picked most part of the code from the
example provided on the tutorial, so I assume it should work. Please provide
any leads as to what is making the Signal to be lost.
--
Regards,
Abhijeet
-------------- next part --------------
An HTML attachment was scrubbed...
URL: http://lists.freedesktop.org/archives/dbus/attachments/20090511/3222b063/attachment.html
More information about the dbus
mailing list