Dbus message lost

Pradeep Khannan pradeep.khannan at gmail.com
Fri Mar 12 12:33:24 PST 2010


Hi,

I wrote a sample application, included in this email, to test invoking an
application on a dbus message. I can see that the application launches but
the dbus message that launched the apllication never reaches the filter
method. Could you guys please help me with this.

Thanks,
Pradeep
*
Listener*

#include <stdlib.h>
#include <unistd.h>
#include <glib.h>

#include <dbus/dbus.h>
#include <dbus/dbus-glib-lowlevel.h>

# define TEST_SERVICE "com.tpk.test"
# define TEST_PATH "/com/tpk/test"
# define TEST_INTERFACE "com.tpk.test"

static GMainLoop  *mainloop = 0;

static DBusConnection *server_bus;

static
DBusHandlerResult
server_filter(DBusConnection *conn,
              DBusMessage *msg,
              void *user_data)
{
  DBusHandlerResult   result    = DBUS_HANDLER_RESULT_NOT_YET_HANDLED;
  const char         *interface = dbus_message_get_interface(msg);
  const char         *member    = dbus_message_get_member(msg);
  const char         *object    = dbus_message_get_path(msg);
  int                 type      = dbus_message_get_type(msg);
  DBusMessage        *rsp       = 0;

  g_message ("member %s Object %s", member, object);
  g_message ("=================================================");

  if(dbus_message_is_method_call(msg, TEST_INTERFACE,"Test"))
  {
      g_main_loop_quit(mainloop);
      result = DBUS_HANDLER_RESULT_HANDLED;
  }

  return result;
}

static int
server_init(void)
{

  DBusError err = DBUS_ERROR_INIT;

  if( (server_bus = dbus_bus_get(DBUS_BUS_SESSION, &err)) == 0 )
  {
      g_error("not able to connection session bus");
  }

  if( !dbus_connection_add_filter(server_bus, server_filter, 0, 0) )
  {
      g_error("add filter failed");
  }

  int ret = dbus_bus_request_name(server_bus, TEST_SERVICE,
                                  DBUS_NAME_FLAG_DO_NOT_QUEUE,
                                  //DBUS_NAME_FLAG_REPLACE_EXISTING,
                                  &err);

  if( ret != DBUS_REQUEST_NAME_REPLY_PRIMARY_OWNER )
  {
    if( dbus_error_is_set(&err) )
    {
      g_error("%s: %s: %s\n", "dbus_bus_request_name", err.name,
err.message);
    }
    else
    {
      g_error("%s: %s\n", "dbus_bus_request_name", "not primary owner of
connection\n");
    }
  }

  dbus_connection_setup_with_g_main(server_bus, NULL);
  dbus_connection_set_exit_on_disconnect(server_bus, 0);

  dbus_error_free(&err);
  return 0;
}

int main(int argc, char *argv[] )
{
    mainloop = g_main_loop_new(NULL, FALSE);

    server_init();

    mainloop = g_main_loop_new(NULL, FALSE);
    g_main_loop_run(mainloop);

    return EXIT_SUCCESS;
}

*Sender*

#include <glib.h>
#include <dbus/dbus.h>
#include <dbus/dbus-glib.h>

# define TEST_SERVICE "com.tpk.test"
# define TEST_PATH "/com/tpk/test"
# define TEST_INTERFACE "com.tpk.test"

DBusGProxy* m_TCPCIRProxy;

int main(void) {

    g_type_init();

    GError* error = NULL;
    m_TCPCIRProxy =
dbus_g_proxy_new_for_name(dbus_g_bus_get(DBUS_BUS_SESSION, &error),
                                        TEST_SERVICE,
                                        TEST_PATH,
                                        TEST_INTERFACE);
    if (error)
    {
        g_debug("TCPCIRProxy failed: %s", error->message);
        m_TCPCIRProxy = NULL;
        g_error_free(error);
    }
    error = NULL;


    /*dbus_g_proxy_call(m_TCPCIRProxy,
                                  "Test", &error,
                                  G_TYPE_INVALID,
                                  G_TYPE_INVALID);
*/

       dbus_g_proxy_call_no_reply(m_TCPCIRProxy,
      "Test",
      G_TYPE_INVALID,
      G_TYPE_INVALID);

    g_message ("Success");
}

*Service File* (/usr/share/dbus-1/services/com.tpk.test.service)

[D-BUS Service]
Name=com.tpk.test
Exec=/usr/bin/a.out
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://lists.freedesktop.org/archives/dbus/attachments/20100312/06498603/attachment.html>


More information about the dbus mailing list