code source dbus & excuses

"Charles Hervé Tchoutat Tchabo" t_charles at gmx.de
Sat Oct 13 11:41:11 PDT 2007


Hi,
I solved the first part of my problem with structure like "(ddii)" and "a(iibba)". The problem was g_type_init which I initialized at the bad place. But I still have problem with structure like a(aus(uudd)(uiss)). 
I already sent an explanation of my problem. But I think that with the source code may be it would be possible to better understand me.
I excuse myself to still send as much lines of code, it is so that you see the parts which are goods and those which are not.
I send you below my code with an indication on the part which creates faults. 

/*the instropect file*/
<?xml version="1.0" encoding="UTF-8" ?>
<node name="/esd/esdtest/esdmessdata">
   <interface name="esd.esdtest.esdmessdata">
      <!--Remote Methods of the Pruefprogramms from the GUI Application-->
      <method name="StartEsdTest"> 
	  <arg type="a(uss(iddd)(iddd))" name="geometry" direction="in"/>
	  <!--arg type="ad" name="geometry" direction="in"/-->
	  <!--arg type="a(uss)" name="geometry" direction="in"/is OK-->
	  <arg type="(ubui)" name="Level" direction="in"/>
	  <arg type="a(ub)" name="Points" direction="in"/>
	  <!--Output EsdTestStart-->
	  <arg type="b" name="isEsdStart" direction="out"/>
      </method>     
   </interface>
</node>


/*The server File server-guimessdata.c*/

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

typedef struct GuiMessData GuiMessData;
typedef struct GuiMessDataClass GuiMessDataClass;

GType gui_mess_data_get_type (void);

struct GuiMessData
{
  GObject parent;
};

struct GuiMessDataClass
{
  GObjectClass parent;
};

#define GUI_MESS_TYPE_DATA     	      (gui_mess_data_get_type ())
#define GUI_MESS_DATA(object)         (G_TYPE_CHECK_INSTANCE_CAST ((object), GUI_MESS_TYPE_DATA, GuiMessData))
#define GUI_MESS_DATA_CLASS(klass)    (G_TYPE_CHECK_CLASS_CAST ((klass), GUI_MESS_TYPE_DATA, GuiMessDataClass))
#define GUI_MESS_IS_DATA(object)      (G_TYPE_CHECK_INSTANCE_TYPE ((object), GUI_MESS_TYPE_DATA))
#define GUI_MESS_IS_DATA_CLASS(klass) (G_TYPE_CHECK_CLASS_TYPE ((klass), GUI_MESS_TYPE_DATA))
#define GUI_MESS_DATA_GET_CLASS(obj)  (G_TYPE_INSTANCE_GET_CLASS ((obj), GUI_MESS_TYPE_DATA, GuiMessDataClass))

gboolean gui_data_start_esd_test (GuiMessData *obj, GPtrArray* IN_geometry, GValueArray* IN_Level, GPtrArray* IN_Points, gboolean* OUT_isEsdStart, GError **error);

void _printPoints (gpointer data, gpointer userdata);
void _printLevel (GValueArray *Level);
void _printPlugData (gpointer gpdata, gpointer userdata);
void _printVector(GArray* vpt);
void _print_vector(gpointer data);
void _print_one_plug (gpointer gpdata, gpointer userdata);
void _print_plugs (gpointer gpdata, gpointer userdata);
void _print_one_vector(gpointer gpdata, gpointer userdata);
#include "MessDataGlue.h"

/* global variable */
const char *std = NULL;

static void
lose (const char *str, ...)
{
  va_list args;
  va_start (args, str);
  vfprintf (stderr, str, args);
  fputc ('\n', stderr);
  va_end (args);
  exit (1);
}

static void
lose_gerror (const char *prefix, GError *error) 
{
  lose ("%s: %s", prefix, error->message);
}

/* Generate the GObject boilerplate */
G_DEFINE_TYPE(GuiMessData, gui_mess_data, G_TYPE_OBJECT);

/* Class init */
static void
gui_mess_data_class_init (GuiMessDataClass *klass)
{
	dbus_g_object_type_install_info (G_TYPE_FROM_CLASS(klass), &dbus_glib_gui_data_object_info);
}

/* Instance init */
static void
gui_mess_data_init (GuiMessData *obj)
{
}

void
_printLevel (GValueArray *testLevel)
{
	guint n = 0, i;
	GValue *val;	
    for (i = 0; i < testLevel->n_values; i++){
	val = g_value_array_get_nth(testLevel, i);
      switch (i){

      	case 0: 
		if (G_VALUE_HOLDS(val, G_TYPE_UINT)) 
		    if (g_value_type_compatible (G_VALUE_TYPE (val), G_TYPE_UINT)){
		    	printf ("%s", n++ == 0 ? "Testlevel:        " : "                  ");
		    	printf ("[%2d] ", g_value_get_uint(val));
      		    } else g_print("error with g_value_type_compatible \n");
		else g_print("error with G_VALUE_HOLDS \n");
		break;
	case 1: 
		if (G_VALUE_HOLDS(val, G_TYPE_BOOLEAN))
		    if (g_value_type_compatible (G_VALUE_TYPE (val), G_TYPE_BOOLEAN)){
		  	printf ("%s", g_value_get_boolean(val) == FALSE ? "Contact" : "Air    ");
		    } else g_print("error with g_value_type_compatible \n");
		else g_print("error with G_VALUE_HOLDS \n");
		break;
	case 2: 
		if (G_VALUE_HOLDS(val, G_TYPE_UINT))
		   if (g_value_type_compatible (G_VALUE_TYPE (val), G_TYPE_UINT)){
		  	printf (" ; %2dx", g_value_get_uint(val));
      		   } else g_print("error with g_value_type_compatible \n");
		else g_print("error with G_VALUE_HOLDS \n");
		break;
	case 3: 
		if (G_VALUE_HOLDS(val, G_TYPE_INT))
		    if (g_value_type_compatible (G_VALUE_TYPE (val), G_TYPE_INT)){
		    	if (abs(g_value_get_int(g_value_array_get_nth (testLevel, i))) < 1000)
			    printf (" ; %6dV ", abs(g_value_get_int(val)));
		    	else
		            printf (" ; %6gkV", (float) (abs(g_value_get_int(val)) / 1000));
      		    } else g_print("error with g_value_type_compatible \n");
		else g_print("error with G_VALUE_HOLDS \n");
		break;
      }
    }
	printf ("\n");
}

void
_printPoints (gpointer data, gpointer userdata)
{
	GValueArray *point = data;
	guint i;
	GValue *val;
	   for (i = 0; i < point->n_values; i++){
		val = g_value_array_get_nth(point, i);
      		switch (i){

      			case 0: 
				if (G_VALUE_HOLDS(val, G_TYPE_UINT)){
			    	    if (g_value_type_compatible (G_VALUE_TYPE (val), G_TYPE_UINT))
		 	 		printf ("%u --", g_value_get_uint(val));
				    else g_print("error with g_value_type_compatible \n");
      				} else g_print("error with G_VALUE_HOLDS \n");
			break;
			case 1: 
				if (G_VALUE_HOLDS(val, G_TYPE_BOOLEAN)){
				    if (g_value_type_compatible (G_VALUE_TYPE (val), G_TYPE_BOOLEAN))
		  		    	printf ("%s --", g_value_get_boolean(val) == FALSE ? "ERROR" : "OK");
				    else g_print("error with g_value_type_compatible \n");
				} else g_print("error with G_VALUE_HOLDS \n");
			break;
      		} 
		g_print ("\n");    
	  }
}

void
_printVector(GArray* vpt)
{
   gint i;
   for(i=0; i< 3 ; i++){
	g_print ("p.X = %6.1f \n", g_array_index(vpt, double, i));
   }
}

void
_print_vector(gpointer gpdata)
{
	GValueArray *vect = gpdata;
  	guint i;
	GValue *val;
	//double pt;
	
    for (i = 0; i < vect->n_values; i++){
	val = g_value_array_get_nth(vect, i);
      	   if ( i == 0) {
		if (G_VALUE_HOLDS(val, G_TYPE_INT)) 
		    if (g_value_type_compatible (G_VALUE_TYPE (val), G_TYPE_INT)){
		    	printf ("%d -- ", g_value_get_int(val));
      		    } else g_print("error with g_value_type_compatible \n");
		else g_print("error with G_VALUE_HOLDS (val, G_TYPE_INT)\n");
	   } else {
		if (G_VALUE_HOLDS(val, G_TYPE_DOUBLE))
		    if (g_value_type_compatible (G_VALUE_TYPE (val), G_TYPE_DOUBLE)){
		  	printf ("%4.1f -- ", g_value_get_double(val));
		    } else g_print("error with g_value_type_compatible \n");
		else g_print("error with G_VALUE_HOLDS (val, G_TYPE_DOUBLE) \n");
	   }
    }
	printf ("\n");
	//g_value_unset(val);

}

void
_print_one_vector(gpointer gpdata, gpointer userdata)
{
	GValueArray *vect = gpdata;
  	guint i;
	GValue *val;
	//double pt;
	
    for (i = 0; i < vect->n_values; i++){
	val = g_value_array_get_nth(vect, i);
      	   if ( i == 0) {
		if (G_VALUE_HOLDS(val, G_TYPE_INT)) 
		    if (g_value_type_compatible (G_VALUE_TYPE (val), G_TYPE_INT)){
		    	printf ("%d -- ", g_value_get_int(val));
      		    } else g_print("error with g_value_type_compatible \n");
		else g_print("error with G_VALUE_HOLDS \n");
	   } else {
		if (G_VALUE_HOLDS(val, G_TYPE_DOUBLE))
		    if (g_value_type_compatible (G_VALUE_TYPE (val), G_TYPE_DOUBLE)){
		  	printf ("%4.1f -- ", g_value_get_double(val));
		    } else g_print("error with g_value_type_compatible \n");
		else g_print("error with G_VALUE_HOLDS \n");
	   }
    }
	printf ("\n");
}

void 
_print_one_plug (gpointer gpdata, gpointer userdata)
{
	GValueArray *point = gpdata;
	guint i;
	GValue *val;
	  for (i = 0; i < point->n_values; i++){
		val = g_value_array_get_nth(point, i);
      		switch (i){

      			case 0: 
				if (G_VALUE_HOLDS(val, G_TYPE_UINT)){
			    	    if (g_value_type_compatible (G_VALUE_TYPE (val), G_TYPE_UINT))
		 	 		printf ("%u --", g_value_get_uint(val));
				    else g_print("error with g_value_type_compatible \n");
      				} else g_print("error with G_VALUE_HOLDS \n");
			break;
			case 1: 
				if (G_VALUE_HOLDS(val, G_TYPE_STRING)){
				    if (g_value_type_compatible (G_VALUE_TYPE (val), G_TYPE_STRING))
		  		    	printf ("%s --", g_value_get_string(val));
				    else g_print("error with g_value_type_compatible \n");
				} else g_print("error with G_VALUE_HOLDS \n");
			break;
			case 2: 
				if (G_VALUE_HOLDS(val, G_TYPE_STRING)){
				    if (g_value_type_compatible (G_VALUE_TYPE (val), G_TYPE_STRING))
		  		    	printf ("%s --", g_value_get_string(val));
				    else g_print("error with g_value_type_compatible \n");
				} else g_print("error with G_VALUE_HOLDS \n");
			break;
/* this part which makes problem */
			default: if (!G_IS_VALUE(val)) 
					g_print ("dont have a value \n"); 
				 else{ g_print ("have value \n");
				    if (g_value_type_compatible (G_VALUE_TYPE (val), G_TYPE_POINTER))
					if (G_VALUE_HOLDS_POINTER(val)){
					       _print_vector(g_value_get_pointer(val));
					}else g_print ("error G_VALUE_HOLDS_POINTER \n");				    
				    else g_print("error with g_value_type_compatible G_TYPE_POINTER \n");
				 }
/* end of the part which makes problem */			
      		} 
		g_print ("\n");    
	  }
}

gboolean 
gui_data_start_esd_test (GuiMessData *obj, GPtrArray* _geometry, GValueArray* _Level, GPtrArray* _Points, gboolean* _isEsdStart, GError **error)
{
     if (_geometry != NULL)
     	g_ptr_array_foreach(_geometry, (GFunc)_print_one_plug, NULL);
     else{
	 *_isEsdStart = FALSE;
     }
    if (_Level != NULL)
     	_printLevel (_Level);
     else{
	 *_isEsdStart = FALSE;
     }
     if (_Points != NULL)
     	g_ptr_array_foreach(_Points, (GFunc)_printPoints, NULL);
     else{
	 *_isEsdStart = FALSE;
     }
    *_isEsdStart = TRUE;
     return TRUE;
}

int
main (int argc, char **argv)
{
  DBusGConnection *bus;
  DBusGProxy *bus_proxy;
  GError *error = NULL;
  GuiMessData *obj;
  GMainLoop *mainloop;
  guint request_name_result;

  g_type_init ();

  mainloop = g_main_loop_new (NULL, FALSE);
  g_print ("Launching receiveGuiMessData ...\n"); 

  /* Obtain a connection to the session bus */
  bus = dbus_g_bus_get (DBUS_BUS_SESSION, &error);
  if (!bus)
    lose_gerror ("Couldn't connect to session bus", error);

  obj = g_object_new (GUI_MESS_TYPE_DATA, NULL);
  dbus_g_connection_register_g_object (bus, "/esd/esdtest/esdmessdata", G_OBJECT (obj));

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

  if (!org_freedesktop_DBus_request_name (bus_proxy, "esd.esdtest.esdmessdata", 0, &request_name_result, &error))
      lose_gerror ("Failed to acquire esd.esdtest.esdmessdata", error);

  if (request_name_result != DBUS_REQUEST_NAME_REPLY_PRIMARY_OWNER){
	g_error ("Got result code %u from requesting name", request_name_result);
	exit (1); 
  }
  g_main_loop_run (mainloop);
  exit (0);
}

/*the client File client-guimessdata.c*/

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

static void lose (const char *fmt, ...) G_GNUC_NORETURN G_GNUC_PRINTF (1, 2);
static void lose_gerror (const char *prefix, GError *error) G_GNUC_NORETURN;

static void
lose (const char *str, ...)
{
  va_list args;
  va_start (args, str);
  vfprintf (stderr, str, args);
  fputc ('\n', stderr);
  va_end (args);
  exit (1);
}

static void
lose_gerror (const char *prefix, GError *error) 
{
  lose ("%s: %s", prefix, error->message);
}
#include "MessDataBindings.h"

static void _gvalue_array_append_int(GValueArray *g_val_array, gint v_int);
static void _gvalue_array_append_bool(GValueArray *g_val_array, const gboolean v_bool);
static void _gvalue_array_append_uint(GValueArray *g_val_array, guint v_uint);
static void _gvalue_array_append_string(GValueArray *g_val_array, const gchar *v_string);
static void _gvalue_array_append_double(GValueArray *g_val_array, gdouble v_double);
static void _gvalue_array_append_pointer (GValueArray *g_val_array, gpointer v_pointer);
void _gvalue_array_double (double x, double y, double z);
void _vector_coord (GArray *garray, double x, double y, double z);


static void
_gvalue_array_append_int(GValueArray *g_val_array, gint v_int)
{
  GValue val ={0};
  g_value_init(&val, G_TYPE_INT);
  g_value_set_int(&val, v_int);
  g_value_array_append(g_val_array, &val);
  g_value_unset(&val);
}

static void
_gvalue_array_append_bool(GValueArray *g_val_array, const gboolean v_bool)
{
  GValue val ={0};
  g_value_init(&val, G_TYPE_BOOLEAN);
  g_value_set_boolean(&val, v_bool);
  g_value_array_append(g_val_array, &val);
  g_value_unset(&val);
}

static void
_gvalue_array_append_uint(GValueArray *g_val_array, guint v_uint)
{
  GValue val ={0};
  g_value_init(&val, G_TYPE_UINT);
  g_value_set_uint(&val, v_uint);
  g_value_array_append(g_val_array, &val);
  g_value_unset(&val);
}

static void
_gvalue_array_append_string(GValueArray *g_val_array, const gchar *v_string)
{
  GValue val ={0};
  g_value_init(&val, G_TYPE_STRING);
  g_value_set_string(&val, v_string);
  g_value_array_append(g_val_array, &val);
  g_value_unset(&val);
}

static void
_gvalue_array_append_double(GValueArray *g_val_array, gdouble v_double)
{
  GValue val ={0};
  g_value_init(&val, G_TYPE_DOUBLE);
  g_value_set_double(&val, v_double);
  g_value_array_append(g_val_array, &val);
  g_value_unset(&val);
}

static void
_gvalue_array_append_pointer (GValueArray *g_val_array, gpointer v_pointer)
{
  GValue val ={0};
  g_value_init(&val, G_TYPE_POINTER);
  g_value_set_pointer(&val, v_pointer);
  g_value_array_append(g_val_array, &val);
  g_value_unset(&val);
}

void 
_gvalue_array_vector (GValueArray *g_val_array, gint v_int, double x, double y, double z)
{
	_gvalue_array_append_int (g_val_array, v_int);
	_gvalue_array_append_double(g_val_array, x);
	_gvalue_array_append_double(g_val_array, y);
	_gvalue_array_append_double(g_val_array, z);
}

void 
_vector_coord (GArray *garray, double x, double y, double z)
{
    	g_array_append_val (garray, x);
   	g_array_append_val (garray, y);
	g_array_append_val (garray, z);
}

int
main (int argc, char **argv)
{
  DBusGConnection *bus;
  DBusGProxy *remote_object;

  GError *error = NULL;
  gboolean is_esd_start = FALSE;

  g_type_init ();

  GValueArray *level;  // (ubui)
  level = g_value_array_new (4);
  _gvalue_array_append_uint(level, 1);
  _gvalue_array_append_bool(level, TRUE);
  _gvalue_array_append_uint(level, 3);
  _gvalue_array_append_int(level, 2);

  GValueArray *point_a;  // (ub)
  point_a = g_value_array_new (2);
  _gvalue_array_append_uint(point_a, 1);
  _gvalue_array_append_bool(point_a, FALSE);

  GValueArray *point_b;  // (ub)
  point_b = g_value_array_new (2);
  _gvalue_array_append_uint(point_b, 3);
  _gvalue_array_append_bool(point_b, TRUE);

  GPtrArray* gp_points;  // a(ub)
  gp_points = g_ptr_array_new();
  g_ptr_array_add(gp_points, (gpointer)point_a);
  g_ptr_array_add(gp_points, (gpointer)point_b);

  GPtrArray* gp_plugs;    //a(uss(iddd)(iddd))
  gp_plugs = g_ptr_array_new();
  GValueArray *plug_a, *plug_b;
  GValueArray *vector_a, *vector_b, *vector_c, *vector_d;

  plug_a = g_value_array_new (3);
  _gvalue_array_append_uint (plug_a, 1);
  _gvalue_array_append_string(plug_a, "SKN");
  _gvalue_array_append_string(plug_a, "info plug 1");

  vector_a = g_value_array_new (4);
  _gvalue_array_vector (vector_a, 1, 0.0, 0.0, 0.0);
  _gvalue_array_append_pointer(plug_a, vector_a);

  vector_b = g_value_array_new (4);
  _gvalue_array_vector (vector_b, 2, 0.0, -100.0, -150.0);
  _gvalue_array_append_pointer(plug_a, vector_b);

  g_ptr_array_add(gp_plugs, (gpointer)plug_a); // add plug

  plug_b = g_value_array_new (3);
  _gvalue_array_append_uint (plug_b, 2);
  _gvalue_array_append_string(plug_b, "AMSK");
  _gvalue_array_append_string(plug_b, "info plug 2");

  vector_c = g_value_array_new (4);
  _gvalue_array_vector (vector_c, 3, 40.0, 0.0, 0.0);
  _gvalue_array_append_pointer(plug_b, vector_c);

  vector_d = g_value_array_new (4);
  _gvalue_array_vector (vector_d, 4, 40.0, -100.0, -150.0);
  _gvalue_array_append_pointer(plug_b, vector_d);

  g_ptr_array_add(gp_plugs, (gpointer)plug_b);  // add plug

  bus = dbus_g_bus_get (DBUS_BUS_SESSION, &error);
  if (!bus)
    lose_gerror ("Couldn't connect to session bus", error);
  
  remote_object = dbus_g_proxy_new_for_name (bus,
					     "esd.esdtest.esdmessdata",
					     "/esd/esdtest/esdmessdata",
					     "esd.esdtest.esdmessdata");

  if (!esd_esdtest_esdmessdata_start_esd_test (remote_object, gp_plugs, level, gp_points, &is_esd_start, &error))
  //if (!esd_esdtest_esdmessdata_start_esd_test (remote_object, level, gp_points, &is_esd_start, &error))
    lose_gerror ("Failed to complete start_esd_test ", error);

  if (is_esd_start)
  	printf ("The ESD Test has started \n");
    g_object_unref (G_OBJECT (remote_object));
  exit(0);
}


 regards,


-- 
Psssst! Schon vom neuen GMX MultiMessenger gehört?
Der kanns mit allen: http://www.gmx.net/de/go/multimessenger

-- 
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