D-BUS unable to receive few signals.
abhijeet.sinha1 at wipro.com
abhijeet.sinha1 at wipro.com
Wed May 6 00:22:19 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 <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 <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); to
dbus_connection_read_write(conn, 1); and
dbus_connection_read_write(conn, 2);
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 Kumar Sinha
Project Engineer
Wipro Technologies
Bangalore
Please do not print this email unless it is absolutely necessary.
The information contained in this electronic message and any attachments to this message are intended for the exclusive use of the addressee(s) and may contain proprietary, confidential or privileged information. If you are not the intended recipient, you should not disseminate, distribute or copy this e-mail. Please notify the sender immediately and destroy all copies of this message and any attachments.
WARNING: Computer viruses can be transmitted via email. The recipient should check this email and any attachments for the presence of viruses. The company accepts no liability for any damage caused by any virus transmitted by this email.
www.wipro.com
-------------- next part --------------
An HTML attachment was scrubbed...
URL: http://lists.freedesktop.org/archives/dbus/attachments/20090506/f3ba021b/attachment.html
More information about the dbus
mailing list