problem with the sample code written for using DBUS

amol gajewar amol_gajewar at yahoo.co.in
Tue Mar 6 20:17:00 PST 2007


hi all
follwing is the sample code written using dbus, where there is one server
which has got method ManyArgs which i want to invoke from client.
Following is the code snippet,

MyServer.xml

<?xml version="1.0" encoding="UTF-8" ?>

<node name="/com/example/MyServer">

  <interface name="com.example.MyServer">
    <annotation name="org.freedesktop.DBus.GLib.CSymbol" value="my_server"/>
    <method name="ManyArgs">
      <!-- This is optional, and in this case is redunundant -->
      <annotation name="org.freedesktop.DBus.GLib.CSymbol" value="my_server_many_args"/>
    </method>
  </interface>
</node>


MyServer.c
#include <stdio.h>
#include <glib-object.h>
#include <glib/gi18n.h>
#include <dbus/dbus-glib.h>

#include "server.h"

static gboolean my_server_many_args()
{
    if(1)
    {
        printf("\nmy_server_many_args\n");     
        return TRUE;        
    }
    return FALSE;
}

#include "my-server-glue.h"



static GMainLoop *loop;
DBusGConnection *connection;
static MyServer *server;

G_DEFINE_TYPE(MyServer, my_server, G_TYPE_OBJECT);

/* Class init */
static void
my_server_class_init (MyServerClass *my_server_class)
{
  //g_type_class_add_private (e_data_book_factory_class, sizeof (EDataBookFactoryPrivate));
  printf("\ni am class init\n");
  dbus_g_object_type_install_info (G_TYPE_FROM_CLASS (my_server_class), &dbus_glib__object_info);
}

/* Instance init */
static void
my_server_init (MyServer *server)
{
}



int
main (int argc, char **argv)
{
  GError *error = NULL;
  guint32 request_name_ret;

  g_type_init ();

  loop = g_main_loop_new (NULL, FALSE);

  /* Obtain a connection to the session bus */
  connection = dbus_g_bus_get (DBUS_BUS_SESSION, &error);

  if (connection == NULL)
  {
      printf("\nFailed to open connection to bus\n");
  }    

  server = g_object_new (TYPE_MY_SERVER, NULL);
  dbus_g_connection_register_g_object (connection,
                                       "/com/example/MyServer",
                                       G_OBJECT (server));

  g_main_loop_run (loop);        
  dbus_g_connection_unref (connection);
  return 0;
}


MyClient.c
//#define DBUS_API_SUBJECT_TO_CHANGE

#include <dbus-1.0/dbus/dbus.h>
#include <dbus-1.0/dbus/dbus-glib.h>
#include "my-server-bindings.h"


int main (int argc, char **argv)
{
  DBusGConnection *connection;
  DBusGProxy *proxy;    
  DBusMessage *message;    


  GError *error;
  char **name_list;
  char **name_list_ptr;

  guint32 request_name_ret;

  g_type_init ();


  error = NULL;
  connection = dbus_g_bus_get (DBUS_BUS_SESSION,
                               &error);
 
  if (connection == NULL)
    {
      g_printerr ("Failed to open connection to bus: %s\n",
                  error->message);
      g_error_free (error);
      exit (1);
    }


  /* Create a proxy object for the "bus driver" (name "org.freedesktop.DBus") */
 
  proxy = dbus_g_proxy_new_for_name (connection,
                                     DBUS_SERVICE_DBUS,
                                     "/com/example/MyServer",//DBUS_PATH_DBUS,
                                     "com.example.MyServer");

  
 // com_example_MyServer_many_args (DBusGProxy *proxy, GError **error)    
 if(!com_example_MyServer_many_args (proxy,&error))
     //printf("i am failed");
    {
      /* Just do demonstrate remote exceptions versus regular GError */
      if (error->domain == DBUS_GERROR && error->code == DBUS_GERROR_REMOTE_EXCEPTION)
        g_printerr ("Caught remote method exception %s: %s",
                dbus_g_error_get_name (error),
                error->message);
      else
        g_printerr ("Error: %s\n", error->message);
      g_error_free (error);
      exit (1);
    }

  g_object_unref (proxy);
  return 0;
}

Steps I do,
I run first server program which according to me registers object to dbus (object which has method ManyArgs)
Then I run client which establish connection with dbus and gives call
to ManyArgs,

Output I am getting is error:
Error: org.freedesktop.DBus does not understand message ManyArgs

Can anybody tell me what is wrong.
Any Pointers on it will be helpful.















 				
---------------------------------
 Here’s a new way to find what you're looking for - Yahoo! Answers 
-------------- next part --------------
An HTML attachment was scrubbed...
URL: http://lists.freedesktop.org/archives/dbus/attachments/20070307/f77f7dfe/attachment-0001.html


More information about the dbus mailing list