dbus
Aashish Raina
aashish_raina at persistent.co.in
Sat Oct 27 06:06:03 PDT 2007
The problem is solved now.
There are few doubts regarding this small application
1:i have a sender_signal application (which sends a signal)
2: one rec_signal application (which will rec it)
Problem is that the receiver when comparing the interface from which
the signal is coming ,,after providing the right interface it is not going
into the if condition
in rec _signal application when i am comparing
whether the signal has come from the same interface it does not go
into the loop.
if (dbus_message_is_signal(msg, "org.pirate.parrot.Type", "Feathers"))
//interface and signal
{
}
else
{
}
goes in the else part
3: This function is not working says undefined refrence in my
receiver_signal application :-> dbus_message_iter_get_basic(&args,
&sigvalue);
is there any other function which helps me to get the signal
4: when we send signal what does it actually mean ,does it mean just a
string being passed from server to client (it is not a function )
This is sender_signal in one file
main()
{
DBusError error,error2;
DBusConnection *conn;
//dbus_uint32_t serial = 0; // unique number to associate replies with
requests
DBusMessage* msg;
DBusMessageIter args;
dbus_error_init (&error);
conn = dbus_bus_get (DBUS_BUS_SYSTEM, &error);
if (!conn)
{
fprintf (stderr, "%s: %s\n",
error.name, error.message);
return 1;
}
else
printf("%p",conn);
//now sending a message but from a well known address :lets accuire a
service
//Connecting to the system bus is a nice first step, but we want to be able
to send messages from a well-known address. Let's acquire a service:
dbus_bus_acquire_service (conn, "org.pirate.parrot",0, &error2);
//dbus_bus_acquire_service (conn, "org.freedesktop.DBus",0, &error2);
if (dbus_error_is_set (&error2))
{
fprintf (stderr, "%s: %s\n",
error2.name, error2.message);
printf("\nentred into the error\n");
//dbus_connection_disconnect (conn);
//return;
}
//DBusMessage *msg;
DBusMessageIter iter;
/* create a new message of type signal */
msg = dbus_message_new_signal(
"org/pirate/parrot/Object",
"org.pirate.parrot.Type", "Feathers");
if (NULL == msg)
{
fprintf(stderr, "Message Null\n");
exit(1);
}
else
printf("created");
//let us not give ant parameter to signal
/* build the signal's payload up */
dbus_message_iter_init (msg, &iter);
dbus_message_iter_append_string (&iter, "Shiny");
dbus_message_iter_append_string (&iter,
"Well Groomed");
/* send the message */
if (!dbus_connection_send (conn, msg, NULL))
fprintf (stderr, "error sending message\n");
else
printf("message send");
/* drop the reference count on the message */
//dbus_message_unref (msg);
/* flush the connection buffer */
dbus_connection_flush (conn);
///////////////////////////////////////////////////////////////////////////////////////////////////////
this is receiver waiting for signal in another file
main()
{
DBusMessage* msg;
DBusMessageIter args;
DBusConnection* conn;
DBusError err,error2;
int ret;
char* sigvalue;
printf("Listening for signals\n");
// initialise the errors
dbus_error_init(&err);
// connect to the bus and check for errors
conn = dbus_bus_get(DBUS_BUS_SYSTEM, &err);
printf("%p",conn);
if (dbus_error_is_set(&err)) {
fprintf(stderr, "Connection Error (%s)\n", err.message);
dbus_error_free(&err);
}
if (NULL == conn) {
exit(1);
}
/*
// request our name on the bus and check for errors
ret = dbus_bus_request_name(conn, "test.signal.sink",
DBUS_NAME_FLAG_REPLACE_EXISTING , &err);
if (dbus_error_is_set(&err)) {
fprintf(stderr, "Name Error (%s)\n", err.message);
dbus_error_free(&err);
}
if (DBUS_REQUEST_NAME_REPLY_PRIMARY_OWNER != ret) {
exit(1);
}
*/
//create a object for communication
dbus_bus_acquire_service (conn, "org.pirate.parrot_rec",0, &error2);
// add a rule for which messages we want to see
dbus_bus_add_match(conn,
"type='signal',interface='org.pirate.parrot.Type'", &err); // see signals
from the given interface
//dbus_connection_flush(conn);
if (dbus_error_is_set(&err)) {
fprintf(stderr, "Match Error (%s)\n", err.message);
exit(1);
}
else
printf("Match rule sent\n");
// loop listening for signals being emmitted
while (true) {
printf("\nwelcome\n");
// non blocking read of the next available message
// dbus_connection_read_write(conn, 0); this is not working
msg = dbus_connection_pop_message(conn); //gets the first mesage from
the queue
// loop again if we haven't read a message
if (NULL == msg) {
sleep(1);
continue;
}
else
printf("\n message aaya\n");
// check if the message is a signal from the correct interface and with
the correct name
if (dbus_message_is_signal(msg, "org.pirate.parrot.Type", "Feathers"))
//interface and signal (feathers)
{
printf("\nfound the interface\n");
// read the parameters
if (!dbus_message_iter_init(msg, &args))
fprintf(stderr, "Message Has No Parameters\n");
else if (DBUS_TYPE_STRING != dbus_message_iter_get_arg_type(&args))
fprintf(stderr, "Argument is not string!\n");
else
{
printf("\nentered else\n ");
}
printf("\n(args)%p\n",args);
dbus_message_iter_get_basic(&args, &sigvalue);
//printf("Got Signal with value %s\n", sigvalue);
}
/*else
{
printf("\nprob with the interface\n");
}*/
// free the message
dbus_message_unref(msg);
}
}
DISCLAIMER
==========
This e-mail may contain privileged and confidential information which is the property of Persistent Systems Ltd. It is intended only for the use of the individual or entity to which it is addressed. If you are not the intended recipient, you are not authorized to read, retain, copy, print, distribute or use this message. If you have received this communication in error, please notify the sender and delete all copies of this message. Persistent Systems Ltd. does not accept any liability for virus infected mails.
More information about the dbus
mailing list