Sample program not working on DaVinci 6467 with old Dbus version

Afzal Nadirshah Afzal_Nadirshah at mindtree.com
Wed Apr 1 06:54:50 PDT 2009


Hi,
        I have Dbus 0.22 version on a DaVinci 6467 board. Since it is an old version it doesn't have several API's provided with the new release. I am trying to run the sample dbus-program available from DBus tutorial. I changed several API's which are not present in the earlier version.
I replaced the following API's :
dbus_bus_request_name              with dbus_bus_acquire_service
dbus_message_iter_get_basic      with dbus_message_iter_get_int32

I did not find an API corresponding to dbus_connection_read_write. I tried using dbus_connection_dispatch.
My program compiles properly (with the cross compiling tools provided byMontaVista Linux).

I tried to run the executable. On one terminal I use the executable to receive a signal and on another terminal I use it to send the signal. The "send" seems to be working fine (It doesn't throw any errors) . But at the "receive" end I am not getting any signal. I tried sending multiple signals, but not a single one was received.

Could some one point out where I am going wrong.

Here are the functions I use to send and receive signals :

Send :

/**
 * Connect to the DBUS bus and send a broadcast signal
 */
void sendsignal(char* sigvalue)
{
   DBusMessage* msg;
   DBusMessageIter args;
   DBusConnection* conn;
   DBusError err;
   int ret;
   dbus_uint32_t serial = 0;
   dbus_int32_t v_INT32 = 42;

   char *sig = "AFZAL";

   printf("Sending signal with value %s\n", sigvalue);

   // initialise the error value
   dbus_error_init(&err);

   // connect to the DBUS system bus, and check for errors
   conn = dbus_bus_get(DBUS_BUS_SESSION, &err);
   if (dbus_error_is_set(&err)) {
      fprintf(stderr, "Connection Error (%s)\n", err.message);
      dbus_error_free(&err);
   }
   if (NULL == conn) {
      exit(1);
   }
#if 0
   // register our name on the bus, and check for errors
   ret = dbus_bus_request_name(conn, "test.signal.source", 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);
   }
#endif
   dbus_bus_acquire_service(conn, "test.signal.source", 0, &err);
   // create a signal & check for errors
   msg = dbus_message_new_signal("/test/signal/Object", // object name of the signal
                                    "test.signal.Type", // interface name of the signal
                                 "Test"); // name of the signal
   if (NULL == msg)
   {
      fprintf(stderr, "Message Null\n");
      exit(1);
   }
#if 0
   // append arguments onto signal
   dbus_message_iter_init_append(msg, &args);
   if (!dbus_message_iter_append_basic(&args, DBUS_TYPE_STRING, &sigvalue )) {
      fprintf(stderr, "Out Of Memory!\n");
      exit(1);
   }
#else

   dbus_message_iter_init(msg, &args);
   dbus_message_append_args (msg,
                           DBUS_TYPE_STRING, &sigvalue,
                           DBUS_TYPE_UINT32, &v_INT32,
                           DBUS_TYPE_INVALID);

#endif

   // send the message and flush the connection
   if (!dbus_connection_send(conn, msg, &serial)) {
      fprintf(stderr, "Out Of Memory!\n");
      exit(1);
   }
   dbus_connection_flush(conn);

   printf("Signal Sent\n");

   // free the message
   dbus_message_unref(msg);
}


Receive :

/**
 * Listens for signals on the bus
 */
void receive()
{
   DBusMessage* msg;
   DBusMessageIter args ;
   DBusConnection* conn;
   DBusError err;
   int ret;
   char* sigvalue;
   dbus_int32_t v_INT32;
   char* sigvalue2;
   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_SESSION, &err);
   if (dbus_error_is_set(&err)) {
      fprintf(stderr, "Connection Error (%s)\n", err.message);
      dbus_error_free(&err);
   }
   if (NULL == conn) {
      exit(1);
   }
#if 0
   // 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);
   }
#endif
   dbus_bus_acquire_service(conn, "test.signal.sink", 0, &err);

   // add a rule for which messages we want to see
   dbus_bus_add_match(conn, "type='signal',interface='test.signal.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);
   }
   printf("Match rule sent\n");

   // loop listening for signals being emmitted
   while (true)
   {

      // non blocking read of the next available message
//      dbus_connection_read_write(conn, 0);
      printf ("connection \n");
      dbus_connection_dispatch(conn);
      printf ("Pop \n");
      msg = dbus_connection_pop_message(conn);

      // loop again if we haven't read a message
      if (NULL == msg)
      {
         sleep(1);
         continue;
      }
      printf ("Checkin \n");
      // check if the message is a signal from the correct interface and with the correct name
      if (dbus_message_is_signal(msg, "test.signal.Type", "Test"))
      {
         printf ("receievd \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
            sigvalue = dbus_message_iter_get_int32(&args);
            dbus_message_iter_next (&args);
            printf("Got Signal with value %s \n", sigvalue);
      }
      printf ("Unref \n");
      // free the message
      dbus_message_unref(msg);
      printf ("Done \n");
   }
}


My hunch is that I haven't used a proper API in place of dbus_connection_read_write(conn, 0).
Could somebody please help me.

Thanks in advance.

Regards,
Afzal Nadirshah


________________________________
http://www.mindtree.com/email/disclaimer.html
-------------- next part --------------
An HTML attachment was scrubbed...
URL: http://lists.freedesktop.org/archives/dbus/attachments/20090401/53e2fdd4/attachment-0001.htm 


More information about the dbus mailing list