Segmentation fault with dbus

"Charles Hervé Tchoutat Tchabo" t_charles at gmx.de
Sat Aug 18 07:42:41 PDT 2007


Hi,
I am a beginner with DBus, and try to write the following simple ipc programm using instropection 2string.xml . the purpose is 
the client sends a method with 2 strings and the server listens for the method and write the strings to the output. My code look like this

client.c

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

#define COM_EXPL_OUTPUT_TYPE (com_expl_output_get_type ())

typedef struct _ComExplOutput {
	GObject object;
} ComExplOutput;

typedef struct _ComExplOutputClass {
	GObjectClass object_class;
} ComExplOutputClass;

gboolean com_expl_str_out (ComExplOutput *output,
				gchar *str1, gchar *str2,
				GError **error);
	
#include "server-bingings1.h"
#include "client-bingings1.h"

static void
com_expl_output_class_init (ComExplOutputClass *output_class)
{
	dbus_g_object_type_install_info (G_TYPE_FROM_CLASS (output_class),
					 &dbus_glib_com_expl_object_info);
}

static void
com_expl_output_init (ComExplOutput *output)
{
}

G_DEFINE_TYPE(ComExplOutput, com_expl_output, G_TYPE_OBJECT);

gboolean 
com_expl_str_out (ComExplOutput *output,
				gchar *str1, gchar *str2,
				GError **error)
{
	g_print ("output str1 = %s\n", str1);
	g_print ("output str2 = %s\n", str2);
	return TRUE;
}

#define OUTPUT_NAME "com.expl.output"



int
main (int argc, char **argv)
{
	DBusGConnection *connection;
	GError *error = NULL;
	DBusGProxy *proxy;

	connection = dbus_g_bus_get (DBUS_BUS_SESSION, &error);
	if (connection == NULL) {
		return FALSE;
	}


	proxy = dbus_g_proxy_new_for_name (connection,
					   OUTPUT_NAME,
					   "/com/expl/output",
					   "com.expl.output");
	
	if (!com_expl_output_str_out(proxy, "Hello", "World", &error))
	{
	   /* Method failed, the GError is set, let's warn everyone */
	   
	   g_warning ("Woops remote method failed: %s", error->message);
	   g_error_free (error);
	   return FALSE;
	}

	g_object_unref (proxy);
	

	return 0;
}


server.c

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

#define COM_EXPL_OUTPUT_TYPE (com_expl_output_get_type ())

typedef struct _ComExplOutput {
	GObject object;
} ComExplOutput;

typedef struct _ComExplOutputClass {
	GObjectClass object_class;
} ComExplOutputClass;

gboolean com_expl_str_out (ComExplOutput *output,
				gchar *str1, gchar *str2,
				GError **error);
	
#include "server-bingings1.h"

gboolean 
com_expl_str_out (ComExplOutput *output,
				gchar *str1, gchar *str2,
				GError **error)
{
	g_print ("output str1 = %s\n", str1);
	g_print ("output str2 = %s\n", str2);
	return TRUE;
}

static void
com_expl_output_class_init (ComExplOutputClass *output_class)
{
	dbus_g_object_type_install_info (G_TYPE_FROM_CLASS (output_class),
					 &dbus_glib_com_expl_object_info);
}


static void
com_expl_output_init (ComExplOutput *output)
{
}

G_DEFINE_TYPE(ComExplOutput, com_expl_output, G_TYPE_OBJECT);

#define OUTPUT_NAME "com.expl.output"

static gboolean
register_output(void)
{
	DBusGConnection *connection;
	DBusGProxy *proxy;
	GError *error = NULL;
	ComExplOutput *output;
	guint32 request_name_ret;
	
	g_type_init();

	connection = dbus_g_bus_get (DBUS_BUS_SESSION, &error);
	if (connection == NULL) {
		return FALSE;
	}


	proxy = dbus_g_proxy_new_for_name (connection,
					   DBUS_SERVICE_DBUS,
					   DBUS_PATH_DBUS,
					   DBUS_INTERFACE_DBUS);
	if (!org_freedesktop_DBus_request_name (proxy, OUTPUT_NAME,
						0, &request_name_ret, &error)) {
		g_warning("Unable to register service: %s", error->message);
		g_error_free (error);
	}

	output = g_object_new (COM_EXPL_OUTPUT_TYPE, NULL);
	dbus_g_connection_register_g_object (connection, "/com/expl/output", 
					     G_OBJECT (output));
	g_object_unref (proxy);

	return TRUE;
}
int
main (int argc, char **argv)
{
	register_output ();

	return 0;
}



2string.xml

<node name="/com/expl/output">
     <interface name="com.expl.output">
	 <method name="StrOut">
    	     <arg type="s" name="str1" direction="in"/>
	     <arg type="s" name="str2" direction="in"/>
	 </method>
     </interface>
</node>


I can compile the file but when I execute, I receive segmentation fault and error like:
(process:32160): GLib-GObject-CRITICAL **: g_type_set_qdata: assertion `node != NULL' failed
tanks for your answer
Charles 
-- 
Ist Ihr Browser Vista-kompatibel? Jetzt die neuesten 
Browser-Versionen downloaden: http://www.gmx.net/de/go/browser


More information about the dbus mailing list