Issues in passing gshort over dbus using dbus-glib bindings

Mandhare mahesh.dbus at gmail.com
Thu Apr 10 22:19:47 PDT 2008


Hi all,
        I am trying to send gshort using dbus-glib bindings. But in xml file
when i mention type="n" I am getting error that method not found on given
interface. But if I change type="i" and send it will get sent successfully.

        Followed prog. I used to demonstrate the problem. Pls help me. the
mentioned changes are marked in Bold.

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

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

  <interface name="com.example.DBusGlibObject1">
    <annotation name="org.freedesktop.DBus.GLib.CSymbol"
value="dbus_glib_object1"/>
    <method name="Variable_args_method">
      <!-- This is optional, and in this case is redunundant -->
      <annotation name="org.freedesktop.DBus.GLib.CSymbol"
value="dbus_glib_object1_variable_args_method"/>
<arg type="n" name="n" direction="in" />
    </method>
  </interface>
</node>

server .c file::
#include <string.h>
#include <sys/stat.h>
#include <stdio.h>
#include <stdlib.h>
#include "dbus_glib_server1.h"
#include "server-glue.h"
#include <dbus/dbus-glib-bindings.h>
#include <errno.h>

static GObjectClass *parent_class = ((void *)0);
static void dbus_glib_object1_init (DBusGlibObject1 *self);

gboolean dbus_glib_object1_variable_args_method_impl (DBusGlibObject1 *self,
gint16 n,GError **error)
{
	FILE* fp = fopen("/root/dbus-1.0.2/test/log.txt", "w+");
	fprintf(fp, "Function called");
	fclose(fp);
	printf("Function called\n");
	return TRUE;
} 

gboolean dbus_glib_object1_variable_args_method (DBusGlibObject1 *self,
gint16 n,GError **error)
{
	return DBUS_GLIB_OBJECT1_GET_CLASS (self)->method1 (self, n,error);
}

void	dbus_glib_object1_dispose (GObject *self)
{
	static gboolean first_run = TRUE;

	if (first_run)
	{
		first_run = FALSE;
		
		/* Call g_object_unref on any GObjects that we hold, but don't break the
object */

		parent_class-> dispose (self);
	}
}

void	dbus_glib_object1_finalize (GObject *self)
{
	parent_class-> finalize (self);
}

/* Here is where we override any functions. Since we have no properties or
even fields, none of the below are needed. */
void	dbus_glib_object1_class_init		(gpointer g_class, gpointer class_data)
{
	GObjectClass	*object_class	= G_OBJECT_CLASS (g_class);
	DBusGlibObject1Class	*this_class	= DBUS_GLIB_OBJECT1_CLASS (g_class);
	
	//assign value to parent class
	parent_class = g_type_class_peek_parent (g_class);
	
	//assing pointer values to the base class members
	object_class-> dispose = &dbus_glib_object1_dispose;
	object_class-> finalize = &dbus_glib_object1_finalize;
	
	//assign value to derived class members
	this_class->method1 = &dbus_glib_object1_variable_args_method_impl;


dbus_g_object_type_install_info(G_TYPE_FROM_CLASS(this_class),&dbus_glib_DBusGlibObject1_object_info);
}

void dbus_glib_object1_init (DBusGlibObject1 *self)
{
	
}

GType dbus_glib_object1_get_type () 
{
	static GType g_define_type_id = 0; 
	if ((g_define_type_id == 0)) 
	{ 
		static const GTypeInfo g_define_type_info = 
		{ 
			sizeof (DBusGlibObject1Class), 
			(GBaseInitFunc) ((void *)0), 
			(GBaseFinalizeFunc) ((void *)0), 
			(GClassInitFunc) dbus_glib_object1_class_init, 
			(GClassFinalizeFunc) ((void *)0), 
			((void *)0), 
			sizeof (DBusGlibObject1), 
			0, 
			(GInstanceInitFunc) dbus_glib_object1_init, 
		}; 

		g_define_type_id = g_type_register_static 
		(
			G_TYPE_OBJECT, 
			"DBusGlibObject1", 
			&g_define_type_info, 
			(GTypeFlags) 0
		);
	} 

	return g_define_type_id; 
}

int main(int argc,char *argv[])
{
	DBusGlibObject1 *so = NULL;
	DBusGConnection *bus;
	GMainLoop *mainLoop = NULL;
	unsigned int request_ret;
	GError *error = NULL;

	DBusGProxy *proxy = NULL;
	char *x;
	
	g_type_init();

	so = g_object_new(DBUS_GLIB_OBJECT1_TYPE,NULL);

	bus = dbus_g_bus_get(DBUS_BUS_SESSION,NULL);

	proxy =
dbus_g_proxy_new_for_name(bus,DBUS_SERVICE_DBUS,DBUS_PATH_DBUS,DBUS_INTERFACE_DBUS);


dbus_g_connection_register_g_object(bus,"/com/example/DBusGlibObject1",G_OBJECT(so));


if(!org_freedesktop_DBus_request_name(proxy,"com.example.DBusGlibObject1",0,&request_ret,&error))
	{
		g_print("Unable to register service\n");
		return 1;
	}

	mainLoop = g_main_loop_new(NULL,FALSE);
	g_main_loop_run(mainLoop);
	
	return 0;
}

server header file ::
#ifndef __DBUS_GLIB_OBJECT1_H__
#define __DBUS_GLIB_OBJECT1_H__

#include <glib-object.h>

typedef struct _DBusGlibObject1 DBusGlibObject1;
struct _DBusGlibObject1
{
	GObject		parent_obj;
};

typedef struct _DBusGlibObject1Class DBusGlibObject1Class;
struct _DBusGlibObject1Class
{
	GObjectClass	parent_class;

	gboolean (*method1) (DBusGlibObject1 *self, gint16     n, GError **error);
};

GType	dbus_glib_object1_get_type ();

gboolean dbus_glib_object1_variable_args_method (DBusGlibObject1 *self,
gint16 n,GError **error);

/* Handy macros */
#define DBUS_GLIB_OBJECT1_TYPE		(dbus_glib_object1_get_type ())
#define DBUS_GLIB_OBJECT1(obj)		(G_TYPE_CHECK_INSTANCE_CAST ((obj),
DBUS_GLIB_OBJECT1_TYPE, DBusGlibObject1))
#define DBUS_GLIB_OBJECT1_CLASS(c)		(G_TYPE_CHECK_CLASS_CAST ((c),
DBUS_GLIB_OBJECT1_TYPE, DBusGlibObject1Class))
#define DBUS_GLIB_IS_OBJECT(obj)		(G_TYPE_CHECK_TYPE ((obj),
DBUS_GLIB_OBJECT1_TYPE))
#define DBUS_GLIB_IS_OBJECT_CLASS(c)		(G_TYPE_CHECK_CLASS_TYPE ((c),
DBUS_GLIB_OBJECT1_TYPE))
#define DBUS_GLIB_OBJECT1_GET_CLASS(obj)	(G_TYPE_INSTANCE_GET_CLASS ((obj),
DBUS_GLIB_OBJECT1_TYPE, DBusGlibObject1Class))

#endif

client .c file::

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

int main()
{
	DBusGConnection *connection;
	DBusGConnection *connection1;
	GError *error;
	DBusGProxy *proxy;
	gshort         n = -16;
    gint		 ret = 1;
	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);
	}
	
	proxy = dbus_g_proxy_new_for_name (connection,
	                                 "com.example.DBusGlibObject1",
	                                 "/com/example/DBusGlibObject1",
	                                 "com.example.DBusGlibObject1");

	
		if(!com_example_DBusGlibObject1_variable_args_method(proxy, n, &error))
		{
			printf("%s\n",error->message);
			return 1;
		}
	
	return 0;
}








-- 
View this message in context: http://www.nabble.com/Issues-in-passing-gshort-over-dbus-using-dbus-glib-bindings-tp16625152p16625152.html
Sent from the Free Desktop - dbus mailing list archive at Nabble.com.



More information about the dbus mailing list