+2004-07-26 Martin Quinson
+ Version 0.3 (protocol not changed; ABI changed)
+ - Major overhault of the datadesc interface to simplify it:
+ - shorted the function names:
+ s/gras_datadesc_declare_struct/gras_datadesc_struct/ and so on
+ - add a trivial way to push/pop integers into the cbps without malloc.
+ This allows to make really generic sub_type description, which simply
+ pop their size of the stack.
+ - add a function gras_datadesc_ref_pop_arr() which does what users want
+ most of the time: Declare a dynamic array (which pops its size of the
+ stack) and declare a reference to it. Poor name, but anyway.
+ - kill the post-send callback, add a post-receive one
+
2004-07-23 Martin Quinson
- Version 0.2
+ Version 0.2 (protocol changed; ABI changed)
- add some testing for cpbs in the test cases, and fix some more bugs.
This invalidate again the little64 data file, since I cannot regenerate
it myself.
ACLOCAL = aclocal -I acmacro -I /usr/share/aclocal/gnome2-macros
AUTOMAKE_OPTIONS = gnu
+DISTCHECK_CONFIGURE_FLAGS = --enable-gtk-doc
EXTRA_DIST = bootstrap COPYING INSTALL NEWS README README.IEEE TODO AUTHORS ChangeLog\
acmacro/aci.m4 \
This is a shortened version of the changelog.
+0.2 (2004-07-24)
+ - Bug fixes, API and build process polishing, documentation improvement
+ - build shared libs
+
0.1 (2004-07-13)
- No major issue discovered, time to change the versionning schema
#We need a recent ACI
ACI_PREREQ(2003.01.16)
-AC_INIT([GRAS],[0.2],[martin.quinson@ens-lyon.fr])
+AC_INIT([GRAS],[0.3],[martin.quinson@ens-lyon.fr])
AC_CONFIG_SRCDIR([src/include/gras.h])
AC_CONFIG_HEADERS([src/gras_config.h])
GRAS_DEFINE_TYPE
gras_datadesc_by_symbol
-gras_datadesc_declare_array_fixed
-gras_datadesc_declare_array_dyn
-gras_datadesc_declare_ref
-gras_datadesc_declare_ref_generic
-gras_datadesc_declare_struct
-gras_datadesc_declare_struct_append
-gras_datadesc_declare_struct_close
-gras_datadesc_declare_union
-gras_datadesc_declare_union_append
-gras_datadesc_declare_union_close
+gras_datadesc_array_fixed
+gras_datadesc_array_dyn
+gras_datadesc_ref
+gras_datadesc_ref_generic
+gras_datadesc_struct
+gras_datadesc_struct_append
+gras_datadesc_struct_close
+gras_datadesc_union
+gras_datadesc_union_append
+gras_datadesc_union_close
+gras_datadesc_ref_pop_arr
gras_datadesc_cb_set_pre
gras_datadesc_cb_set_post
maintainer-clean-local: clean
cd $(srcdir) && rm -rf xml html $(DOC_MODULE)-decl-list.txt $(DOC_MODULE)-decl.txt
-dist-hook: dist-hook-local
+#
+# Require gtk-doc when making dist
+#
+if ENABLE_GTK_DOC
+dist-check-gtkdoc:
+else
+dist-check-gtkdoc:
+ @echo "*** gtk-doc must be installed and enabled in order to make dist"
+ @false
+endif
+
+dist-hook: dist-check-gtkdoc dist-hook-local
mkdir $(distdir)/tmpl
mkdir $(distdir)/xml
mkdir $(distdir)/html
</para>
@vars:
-@p_type:
@data:
@Returns:
+<!-- # Unused Parameters # -->
+@p_type:
<!-- ##### USER_FUNCTION gras_datadesc_type_cb_void_t ##### -->
</para>
@vars:
-@p_type:
@data:
+<!-- # Unused Parameters # -->
+@p_type:
<!-- ##### FUNCTION gras_datadesc_by_name ##### -->
@name:
-<!-- ##### FUNCTION gras_datadesc_declare_array_fixed ##### -->
+<!-- ##### FUNCTION gras_datadesc_array_fixed ##### -->
<para>
</para>
@Returns:
-<!-- ##### FUNCTION gras_datadesc_declare_array_dyn ##### -->
+<!-- ##### FUNCTION gras_datadesc_array_dyn ##### -->
<para>
</para>
@dynamic_size:
@dst:
@Returns:
-<!-- # Unused Parameters # -->
-@elm_type:
-@code:
-<!-- ##### FUNCTION gras_datadesc_declare_ref ##### -->
+<!-- ##### FUNCTION gras_datadesc_ref ##### -->
<para>
</para>
@referenced_type:
@dst:
@Returns:
-<!-- # Unused Parameters # -->
-@ref_type:
-@code:
-<!-- ##### FUNCTION gras_datadesc_declare_ref_generic ##### -->
+<!-- ##### FUNCTION gras_datadesc_ref_generic ##### -->
<para>
</para>
@Returns:
-<!-- ##### FUNCTION gras_datadesc_declare_struct ##### -->
+<!-- ##### FUNCTION gras_datadesc_struct ##### -->
<para>
</para>
@name:
@dst:
@Returns:
-<!-- # Unused Parameters # -->
-@code:
-<!-- ##### FUNCTION gras_datadesc_declare_struct_append ##### -->
+<!-- ##### FUNCTION gras_datadesc_struct_append ##### -->
<para>
</para>
@Returns:
-<!-- ##### FUNCTION gras_datadesc_declare_struct_close ##### -->
+<!-- ##### FUNCTION gras_datadesc_struct_close ##### -->
<para>
</para>
@struct_type:
-<!-- ##### FUNCTION gras_datadesc_declare_union ##### -->
+<!-- ##### FUNCTION gras_datadesc_union ##### -->
<para>
</para>
@selector:
@dst:
@Returns:
-<!-- # Unused Parameters # -->
-@code:
-<!-- ##### FUNCTION gras_datadesc_declare_union_append ##### -->
+<!-- ##### FUNCTION gras_datadesc_union_append ##### -->
<para>
</para>
@Returns:
-<!-- ##### FUNCTION gras_datadesc_declare_union_close ##### -->
+<!-- ##### FUNCTION gras_datadesc_union_close ##### -->
<para>
</para>
@union_type:
-<!-- ##### FUNCTION gras_datadesc_cb_set_pre ##### -->
-<para>
-
-</para>
-
-@type:
-@pre:
-
-
-<!-- ##### FUNCTION gras_datadesc_cb_set_post ##### -->
-<para>
-
-</para>
-
-@type:
-@post:
-
-
-<!-- ##### FUNCTION gras_dd_cbps_pop ##### -->
+<!-- ##### FUNCTION gras_datadesc_ref_pop_arr ##### -->
<para>
</para>
-@ps:
-@name:
-@ddt:
-
-
-<!-- ##### FUNCTION gras_dd_cbps_push ##### -->
-<para>
-
-</para>
-
-@ps:
-@name:
-@data:
-@ddt:
-
-
-<!-- ##### FUNCTION gras_dd_cbps_set ##### -->
-<para>
-
-</para>
-
-@ps:
-@name:
-@data:
-@ddt:
-
-
-<!-- ##### FUNCTION gras_dd_cbps_get ##### -->
-<para>
-
-</para>
-
-@ps:
-@name:
-@ddt:
-
-
-<!-- ##### FUNCTION gras_dd_cbps_block_begin ##### -->
-<para>
-
-</para>
-
-@ps:
-
-
-<!-- ##### FUNCTION gras_dd_cbps_block_end ##### -->
-<para>
-
-</para>
-
-@ps:
+@element_type:
+@dst:
+@Returns:
<!-- ##### FUNCTION gras_arch_selfid ##### -->
@ud:
+<!-- ##### FUNCTION gras_datadesc_cb_set_post ##### -->
+<para>
+
+</para>
+
+@type:
+@post:
+
+<!-- ##### FUNCTION gras_datadesc_cb_set_pre ##### -->
+<para>
+
+</para>
+
+@type:
+@pre:
+
<!-- ##### FUNCTION gras_datadesc_cmp ##### -->
<para>
@code:
@Returns:
+<!-- ##### FUNCTION gras_datadesc_declare_array_dyn ##### -->
+<para>
+
+</para>
+
+@name:
+@element_type:
+@dynamic_size:
+@dst:
+@Returns:
+@elm_type:
+@code:
+
+<!-- ##### FUNCTION gras_datadesc_declare_array_fixed ##### -->
+<para>
+
+</para>
+
+@name:
+@element_type:
+@fixed_size:
+@dst:
+@Returns:
+
+<!-- ##### FUNCTION gras_datadesc_declare_ref ##### -->
+<para>
+
+</para>
+
+@name:
+@referenced_type:
+@dst:
+@Returns:
+@ref_type:
+@code:
+
<!-- ##### FUNCTION gras_datadesc_declare_ref_cb ##### -->
<para>
@discriminant:
@code:
+<!-- ##### FUNCTION gras_datadesc_declare_ref_generic ##### -->
+<para>
+
+</para>
+
+@name:
+@discriminant:
+@dst:
+@Returns:
+
+<!-- ##### FUNCTION gras_datadesc_declare_struct ##### -->
+<para>
+
+</para>
+
+@name:
+@dst:
+@Returns:
+@code:
+
<!-- ##### MACRO gras_datadesc_declare_struct_add_code ##### -->
<para>
@post_cb:
@Returns:
+<!-- ##### FUNCTION gras_datadesc_declare_struct_append ##### -->
+<para>
+
+</para>
+
+@struct_type:
+@name:
+@field_type:
+@Returns:
+
<!-- ##### FUNCTION gras_datadesc_declare_struct_append_name ##### -->
<para>
@code:
@Returns:
+<!-- ##### FUNCTION gras_datadesc_declare_struct_close ##### -->
+<para>
+
+</para>
+
+@struct_type:
+
+<!-- ##### FUNCTION gras_datadesc_declare_union ##### -->
+<para>
+
+</para>
+
+@name:
+@selector:
+@dst:
+@Returns:
+@code:
+
<!-- ##### MACRO gras_datadesc_declare_union_add_code ##### -->
<para>
@post_cb:
@Returns:
+<!-- ##### FUNCTION gras_datadesc_declare_union_append ##### -->
+<para>
+
+</para>
+
+@union_type:
+@name:
+@field_type:
+@Returns:
+
<!-- ##### FUNCTION gras_datadesc_declare_union_append_name ##### -->
<para>
@code:
@Returns:
+<!-- ##### FUNCTION gras_datadesc_declare_union_close ##### -->
+<para>
+
+</para>
+
+@union_type:
+
<!-- ##### FUNCTION gras_datadesc_from_nws ##### -->
<para>
@code:
@def:
+<!-- ##### FUNCTION gras_dd_cbps_block_begin ##### -->
+<para>
+
+</para>
+
+@ps:
+
+<!-- ##### FUNCTION gras_dd_cbps_block_end ##### -->
+<para>
+
+</para>
+
+@ps:
+
+<!-- ##### FUNCTION gras_dd_cbps_get ##### -->
+<para>
+
+</para>
+
+@ps:
+@name:
+@ddt:
+
+<!-- ##### FUNCTION gras_dd_cbps_pop ##### -->
+<para>
+
+</para>
+
+@ps:
+@name:
+@ddt:
+
+<!-- ##### FUNCTION gras_dd_cbps_push ##### -->
+<para>
+
+</para>
+
+@ps:
+@name:
+@data:
+@ddt:
+
+<!-- ##### FUNCTION gras_dd_cbps_set ##### -->
+<para>
+
+</para>
+
+@ps:
+@name:
+@data:
+@ddt:
+
<!-- ##### FUNCTION gras_ddt_free ##### -->
<para>
#! /bin/sh
-./ping_server 4000&
-./ping_client 127.0.0.1 4000
+./ping_server 4000 $@&
+./ping_client 127.0.0.1 4000 $@
*/
typedef struct s_gras_datadesc_type gras_datadesc_type_t;
+typedef struct s_gras_cbps gras_cbps_t;
+
/* callbacks prototypes */
-typedef void (*gras_datadesc_type_cb_void_t)(void *vars,
- gras_datadesc_type_t *p_type,
- void *data);
-typedef int (*gras_datadesc_type_cb_int_t)(void *vars,
- gras_datadesc_type_t *p_type,
- void *data);
+typedef void (*gras_datadesc_type_cb_void_t)(gras_cbps_t *vars, void *data);
+typedef int (*gras_datadesc_type_cb_int_t)(gras_cbps_t *vars, void *data);
/***********************************************
**** Search and retrieve declared datatype ****
******************************************/
gras_error_t
-gras_datadesc_declare_struct(const char *name,
+gras_datadesc_struct(const char *name,
gras_datadesc_type_t **dst);
gras_error_t
-gras_datadesc_declare_struct_append(gras_datadesc_type_t *struct_type,
+gras_datadesc_struct_append(gras_datadesc_type_t *struct_type,
const char *name,
gras_datadesc_type_t *field_type);
void
-gras_datadesc_declare_struct_close(gras_datadesc_type_t *struct_type);
+gras_datadesc_struct_close(gras_datadesc_type_t *struct_type);
gras_error_t
-gras_datadesc_declare_union(const char *name,
+gras_datadesc_union(const char *name,
gras_datadesc_type_cb_int_t selector,
gras_datadesc_type_t **dst);
gras_error_t
-gras_datadesc_declare_union_append(gras_datadesc_type_t *union_type,
+gras_datadesc_union_append(gras_datadesc_type_t *union_type,
const char *name,
gras_datadesc_type_t *field_type);
void
-gras_datadesc_declare_union_close(gras_datadesc_type_t *union_type);
+gras_datadesc_union_close(gras_datadesc_type_t *union_type);
gras_error_t
-gras_datadesc_declare_ref(const char *name,
+gras_datadesc_ref(const char *name,
gras_datadesc_type_t *referenced_type,
gras_datadesc_type_t **dst);
gras_error_t
-gras_datadesc_declare_ref_generic(const char *name,
+gras_datadesc_ref_generic(const char *name,
gras_datadesc_type_cb_int_t discriminant,
gras_datadesc_type_t **dst);
gras_error_t
-gras_datadesc_declare_array_fixed(const char *name,
+gras_datadesc_array_fixed(const char *name,
gras_datadesc_type_t *element_type,
long int fixed_size,
gras_datadesc_type_t **dst);
gras_error_t
-gras_datadesc_declare_array_dyn(const char *name,
+gras_datadesc_array_dyn(const char *name,
gras_datadesc_type_t *element_type,
gras_datadesc_type_cb_int_t dynamic_size,
gras_datadesc_type_t **dst);
+gras_error_t
+gras_datadesc_ref_pop_arr(gras_datadesc_type_t *element_type,
+ gras_datadesc_type_t **dst);
/*********************************
* Change stuff within datadescs *
*********************************/
-typedef struct s_gras_dd_cbps gras_dd_cbps_t;
-void gras_datadesc_cb_set_pre (gras_datadesc_type_t *type,
- gras_datadesc_type_cb_void_t pre);
-void gras_datadesc_cb_set_post(gras_datadesc_type_t *type,
- gras_datadesc_type_cb_void_t post);
+void gras_datadesc_cb_send (gras_datadesc_type_t *type,
+ gras_datadesc_type_cb_void_t pre);
+void gras_datadesc_cb_recv(gras_datadesc_type_t *type,
+ gras_datadesc_type_cb_void_t post);
/******************************
* Get stuff within datadescs *
/********************************************************
* Advanced data describing: callback persistent states *
********************************************************/
+/* simple one: push/pop sizes of arrays */
+void
+gras_cbps_i_push(gras_cbps_t *ps, int val);
+int
+gras_cbps_i_pop(gras_cbps_t *ps);
+int gras_datadesc_cb_pop(gras_cbps_t *vars, void *data);
+/* complex one: complete variable environment support */
gras_error_t
-gras_dd_cbps_pop (gras_dd_cbps_t *ps,
- const char *name,
- gras_datadesc_type_t **ddt,
+gras_cbps_v_pop (gras_cbps_t *ps,
+ const char *name,
+ gras_datadesc_type_t **ddt,
void **res);
gras_error_t
-gras_dd_cbps_push(gras_dd_cbps_t *ps,
- const char *name,
- void *data,
- gras_datadesc_type_t *ddt);
+gras_cbps_v_push(gras_cbps_t *ps,
+ const char *name,
+ void *data,
+ gras_datadesc_type_t *ddt);
void
-gras_dd_cbps_set (gras_dd_cbps_t *ps,
- const char *name,
- void *data,
- gras_datadesc_type_t *ddt);
+gras_cbps_v_set (gras_cbps_t *ps,
+ const char *name,
+ void *data,
+ gras_datadesc_type_t *ddt);
void *
-gras_dd_cbps_get (gras_dd_cbps_t *ps,
- const char *name,
- gras_datadesc_type_t **ddt);
+gras_cbps_v_get (gras_cbps_t *ps,
+ const char *name,
+ gras_datadesc_type_t **ddt);
void
-gras_dd_cbps_block_begin(gras_dd_cbps_t *ps);
+gras_cbps_block_begin(gras_cbps_t *ps);
void
-gras_dd_cbps_block_end(gras_dd_cbps_t *ps);
+gras_cbps_block_end(gras_cbps_t *ps);
typedef struct {
gras_datadesc_type_t *type;
void *data;
-} gras_dd_cbps_elm_t;
+} gras_cbps_elm_t;
-struct s_gras_dd_cbps {
- gras_dict_t *space; /* varname x dynar of gras_dd_cbps_elm_t */
+struct s_gras_cbps {
+ gras_dynar_t *lints; /* simple stack of long integers (easy interface) */
+
+ gras_dict_t *space; /* varname x dynar of gras_cbps_elm_t */
gras_dynar_t *frames; /* of dynar of names defined within this frame
(and to pop when we leave it) */
gras_dynar_t *globals;
}
gras_error_t
-gras_dd_cbps_new(gras_dd_cbps_t **dst) {
+gras_cbps_new(gras_cbps_t **dst) {
gras_error_t errcode;
- gras_dd_cbps_t *res;
+ gras_cbps_t *res;
- if (!(res=malloc(sizeof(gras_dd_cbps_t))))
+ if (!(res=malloc(sizeof(gras_cbps_t))))
RAISE_MALLOC;
+ TRY(gras_dynar_new(&(res->lints), sizeof(int), NULL));
+
TRY(gras_dict_new(&(res->space)));
/* no leak, the content is freed manually on block_end */
TRY(gras_dynar_new(&(res->frames), sizeof(gras_dynar_t*), NULL));
TRY(gras_dynar_new(&(res->globals), sizeof(char*), NULL));
- gras_dd_cbps_block_begin(res);
+ gras_cbps_block_begin(res);
*dst = res;
return no_error;
}
void
-gras_dd_cbps_free(gras_dd_cbps_t **state) {
+gras_cbps_free(gras_cbps_t **state) {
+
+ gras_dynar_free( (*state)->lints );
- gras_dd_cbps_block_end(*state);
+ gras_cbps_block_end(*state);
gras_dict_free ( &( (*state)->space ) );
gras_dynar_free( (*state)->frames );
gras_dynar_free( (*state)->globals );
}
/**
- * gras_dd_cbps_push:
+ * gras_cbps_v_push:
*
* Declare a new element in the PS, and give it a value. If an element of that
* name already exists, it is masked by the one given here, and will be
* seeable again only after a pop to remove the value this push adds.
*/
gras_error_t
-gras_dd_cbps_push(gras_dd_cbps_t *ps,
- const char *name,
- void *data,
- gras_datadesc_type_t *ddt) {
+gras_cbps_v_push(gras_cbps_t *ps,
+ const char *name,
+ void *data,
+ gras_datadesc_type_t *ddt) {
gras_dynar_t *varstack,*frame;
- gras_dd_cbps_elm_t *p_var;
+ gras_cbps_elm_t *p_var;
gras_error_t errcode;
char *varname = strdup(name);
if (errcode == mismatch_error) {
DEBUG1("Create a new variable stack for '%s' into the space",name);
- gras_dynar_new(&varstack, sizeof (gras_dd_cbps_elm_t *), NULL);
+ gras_dynar_new(&varstack, sizeof (gras_cbps_elm_t *), NULL);
gras_dict_set(ps->space, varname, (void **)varstack, NULL);
/* leaking, you think? only if you do not close all the openned blocks ;)*/
} else if (errcode != no_error) {
return errcode;
}
- p_var = calloc(1, sizeof(gras_dd_cbps_elm_t));
+ p_var = calloc(1, sizeof(gras_cbps_elm_t));
p_var->type = ddt;
p_var->data = data;
}
/**
- * gras_dd_cbps_pop:
+ * gras_cbps_v_pop:
*
* Retrieve an element from the PS, and remove it from the PS. If it's not
* present in the current block, it will fail (with abort) and not search
* in upper blocks since this denotes a programmation error.
*/
gras_error_t
-gras_dd_cbps_pop (gras_dd_cbps_t *ps,
- const char *name,
- gras_datadesc_type_t **ddt,
- void **res) {
+gras_cbps_v_pop (gras_cbps_t *ps,
+ const char *name,
+ gras_datadesc_type_t **ddt,
+ void **res) {
gras_dynar_t *varstack,*frame;
- gras_dd_cbps_elm_t *var = NULL;
+ gras_cbps_elm_t *var = NULL;
void *data = NULL;
gras_error_t errcode;
}
/**
- * gras_dd_cbps_set:
+ * gras_cbps_v_set:
*
* Change the value of an element in the PS.
* If it's not present in the current block, look in the upper ones.
* its value is changed.
*/
void
-gras_dd_cbps_set (gras_dd_cbps_t *ps,
- const char *name,
- void *data,
- gras_datadesc_type_t *ddt) {
+gras_cbps_v_set (gras_cbps_t *ps,
+ const char *name,
+ void *data,
+ gras_datadesc_type_t *ddt) {
gras_dynar_t *p_dynar = NULL;
- gras_dd_cbps_elm_t *p_elm = NULL;
+ gras_cbps_elm_t *p_elm = NULL;
gras_error_t errcode;
DEBUG1("set(%s)",name);
errcode = gras_dict_get(ps->space, name, (void **)&p_dynar);
if (errcode == mismatch_error) {
- gras_dynar_new(&p_dynar, sizeof (gras_dd_cbps_elm_t *), NULL);
+ gras_dynar_new(&p_dynar, sizeof (gras_cbps_elm_t *), NULL);
gras_dict_set(ps->space, name, (void **)p_dynar, NULL);
- p_elm = calloc(1, sizeof(gras_dd_cbps_elm_t));
+ p_elm = calloc(1, sizeof(gras_cbps_elm_t));
gras_dynar_push(ps->globals, &name);
} else {
gras_dynar_pop(p_dynar, &p_elm);
}
/**
- * gras_dd_cbps_get:
+ * gras_cbps_v_get:
*
* Get the value of an element in the PS without modifying it.
* (note that you get the content of the data struct and not a copy to it)
* If not present there neither, the code may segfault (Oli?).
*/
void *
-gras_dd_cbps_get (gras_dd_cbps_t *ps,
- const char *name,
- gras_datadesc_type_t **ddt) {
+gras_cbps_v_get (gras_cbps_t *ps,
+ const char *name,
+ gras_datadesc_type_t **ddt) {
gras_dynar_t *p_dynar = NULL;
- gras_dd_cbps_elm_t *p_elm = NULL;
+ gras_cbps_elm_t *p_elm = NULL;
DEBUG1("get(%s)",name);
/* FIXME: Error handling */
}
/**
- * gras_dd_cbps_block_begin:
+ * gras_cbps_block_begin:
*
* Begins a new block.
*
*/
void
-gras_dd_cbps_block_begin(gras_dd_cbps_t *ps) {
+gras_cbps_block_begin(gras_cbps_t *ps) {
gras_dynar_t *p_dynar = NULL;
}
/**
- * gras_dd_cbps_block_begin:
+ * gras_cbps_block_begin:
*
* End the current block, and go back to the upper one.
*/
void
-gras_dd_cbps_block_end(gras_dd_cbps_t *ps) {
+gras_cbps_block_end(gras_cbps_t *ps) {
gras_dynar_t *frame = NULL;
int cursor = 0;
gras_dynar_foreach(frame, cursor, name) {
gras_dynar_t *varstack = NULL;
- gras_dd_cbps_elm_t *var = NULL;
+ gras_cbps_elm_t *var = NULL;
DEBUG2("Get ride of %s (%p)",name,name);
gras_dict_get(ps->space, name, (void **)&varstack);
}
+/**
+ * gras_cbps_i_push:
+ *
+ * Push a new long integer value into the cbps.
+ */
+void
+gras_cbps_i_push(gras_cbps_t *ps,
+ int val) {
+ gras_error_t errcode;
+ TRYFAIL(gras_dynar_push(ps->lints,&val));
+}
+/**
+ * gras_cbps_i_pop:
+ *
+ * Pop the lastly pushed long integer value from the cbps.
+ */
+int
+gras_cbps_i_pop(gras_cbps_t *ps) {
+ int ret;
+
+ gras_assert0(gras_dynar_length(ps->lints) > 0,
+ "gras_cbps_i_pop: no value to pop");
+ gras_dynar_pop(ps->lints, &ret);
+ return ret;
+}
+/**
+ * gras_dd_cb_pop:
+ *
+ * Generic cb returning the lastly pushed value
+ */
+int gras_datadesc_cb_pop(gras_cbps_t *vars, void *data) {
+ return gras_cbps_i_pop(vars);
+}
/* callback for array size when sending strings */
static int
-_strlen_cb(void *vars,
- gras_datadesc_type_t *type,
- void *data) {
+_strlen_cb(gras_cbps_t *vars, void *data) {
return 1+(long int)strlen(data);
}
TRYFAIL(gras_set_new(&gras_datadesc_set_local));
- TRYFAIL(gras_datadesc_declare_scalar("signed char",
- gras_ddt_scalar_char,
- e_gras_dd_scalar_encoding_sint,
- NULL, &ddt));
- TRYFAIL(gras_datadesc_declare_scalar("char",
- gras_ddt_scalar_char,
- e_gras_dd_scalar_encoding_sint,
- NULL, &ddt));
- TRYFAIL(gras_datadesc_declare_scalar("unsigned char",
- gras_ddt_scalar_char,
- e_gras_dd_scalar_encoding_uint,
- NULL, &ddt));
+ TRYFAIL(gras_datadesc_scalar("signed char",
+ gras_ddt_scalar_char,
+ e_gras_dd_scalar_encoding_sint,
+ &ddt));
+ TRYFAIL(gras_datadesc_scalar("char",
+ gras_ddt_scalar_char,
+ e_gras_dd_scalar_encoding_sint,
+ &ddt));
+ TRYFAIL(gras_datadesc_scalar("unsigned char",
+ gras_ddt_scalar_char,
+ e_gras_dd_scalar_encoding_uint,
+ &ddt));
- TRYFAIL(gras_datadesc_declare_scalar("signed short int",
- gras_ddt_scalar_short,
- e_gras_dd_scalar_encoding_sint,
- NULL, &ddt));
- TRYFAIL(gras_datadesc_declare_scalar("short int",
- gras_ddt_scalar_short,
- e_gras_dd_scalar_encoding_sint,
- NULL, &ddt));
- TRYFAIL(gras_datadesc_declare_scalar("unsigned short int",
- gras_ddt_scalar_short,
- e_gras_dd_scalar_encoding_uint,
- NULL, &ddt));
+ TRYFAIL(gras_datadesc_scalar("signed short int",
+ gras_ddt_scalar_short,
+ e_gras_dd_scalar_encoding_sint,
+ &ddt));
+ TRYFAIL(gras_datadesc_scalar("short int",
+ gras_ddt_scalar_short,
+ e_gras_dd_scalar_encoding_sint,
+ &ddt));
+ TRYFAIL(gras_datadesc_scalar("unsigned short int",
+ gras_ddt_scalar_short,
+ e_gras_dd_scalar_encoding_uint,
+ &ddt));
- TRYFAIL(gras_datadesc_declare_scalar("signed int",
- gras_ddt_scalar_int,
- e_gras_dd_scalar_encoding_sint,
- NULL, &ddt));
- TRYFAIL(gras_datadesc_declare_scalar("int",
- gras_ddt_scalar_int,
- e_gras_dd_scalar_encoding_sint,
- NULL, &ddt));
- TRYFAIL(gras_datadesc_declare_scalar("unsigned int",
- gras_ddt_scalar_int,
- e_gras_dd_scalar_encoding_uint,
- NULL, &ddt));
+ TRYFAIL(gras_datadesc_scalar("signed int",
+ gras_ddt_scalar_int,
+ e_gras_dd_scalar_encoding_sint,
+ &ddt));
+ TRYFAIL(gras_datadesc_scalar("int",
+ gras_ddt_scalar_int,
+ e_gras_dd_scalar_encoding_sint,
+ &ddt));
+ TRYFAIL(gras_datadesc_scalar("unsigned int",
+ gras_ddt_scalar_int,
+ e_gras_dd_scalar_encoding_uint,
+ &ddt));
- TRYFAIL(gras_datadesc_declare_scalar("signed long int",
- gras_ddt_scalar_long,
- e_gras_dd_scalar_encoding_sint,
- NULL, &ddt));
- TRYFAIL(gras_datadesc_declare_scalar("long int",
- gras_ddt_scalar_long,
- e_gras_dd_scalar_encoding_sint,
- NULL, &ddt));
- TRYFAIL(gras_datadesc_declare_scalar("unsigned long int",
- gras_ddt_scalar_long,
- e_gras_dd_scalar_encoding_uint,
- NULL, &ddt));
+ TRYFAIL(gras_datadesc_scalar("signed long int",
+ gras_ddt_scalar_long,
+ e_gras_dd_scalar_encoding_sint,
+ &ddt));
+ TRYFAIL(gras_datadesc_scalar("long int",
+ gras_ddt_scalar_long,
+ e_gras_dd_scalar_encoding_sint,
+ &ddt));
+ TRYFAIL(gras_datadesc_scalar("unsigned long int",
+ gras_ddt_scalar_long,
+ e_gras_dd_scalar_encoding_uint,
+ &ddt));
- TRYFAIL(gras_datadesc_declare_scalar("signed long long int",
- gras_ddt_scalar_long_long,
- e_gras_dd_scalar_encoding_sint,
- NULL, &ddt));
- TRYFAIL(gras_datadesc_declare_scalar("long long int",
- gras_ddt_scalar_long_long,
- e_gras_dd_scalar_encoding_sint,
- NULL, &ddt));
- TRYFAIL(gras_datadesc_declare_scalar("unsigned long long int",
- gras_ddt_scalar_long_long,
- e_gras_dd_scalar_encoding_uint,
- NULL, &ddt));
+ TRYFAIL(gras_datadesc_scalar("signed long long int",
+ gras_ddt_scalar_long_long,
+ e_gras_dd_scalar_encoding_sint,
+ &ddt));
+ TRYFAIL(gras_datadesc_scalar("long long int",
+ gras_ddt_scalar_long_long,
+ e_gras_dd_scalar_encoding_sint,
+ &ddt));
+ TRYFAIL(gras_datadesc_scalar("unsigned long long int",
+ gras_ddt_scalar_long_long,
+ e_gras_dd_scalar_encoding_uint,
+ &ddt));
- TRYFAIL(gras_datadesc_declare_scalar("data pointer",
- gras_ddt_scalar_pdata,
- e_gras_dd_scalar_encoding_uint,
- NULL, &ddt));
- TRYFAIL(gras_datadesc_declare_scalar("function pointer",
- gras_ddt_scalar_pfunc,
- e_gras_dd_scalar_encoding_uint,
- NULL, &ddt));
+ TRYFAIL(gras_datadesc_scalar("data pointer",
+ gras_ddt_scalar_pdata,
+ e_gras_dd_scalar_encoding_uint,
+ &ddt));
+ TRYFAIL(gras_datadesc_scalar("function pointer",
+ gras_ddt_scalar_pfunc,
+ e_gras_dd_scalar_encoding_uint,
+ &ddt));
- TRYFAIL(gras_datadesc_declare_scalar("float",
- gras_ddt_scalar_float,
- e_gras_dd_scalar_encoding_float,
- NULL, &ddt));
- TRYFAIL(gras_datadesc_declare_scalar("double",
- gras_ddt_scalar_double,
- e_gras_dd_scalar_encoding_float,
- NULL,&ddt));
-
- TRYFAIL(gras_datadesc_declare_array_dyn("char[]",
- gras_datadesc_by_name("char"),
- _strlen_cb,&ddt));
- TRYFAIL(gras_datadesc_declare_ref("string",
- gras_datadesc_by_name("char[]"),
- &ddt));
+ TRYFAIL(gras_datadesc_scalar("float",
+ gras_ddt_scalar_float,
+ e_gras_dd_scalar_encoding_float,
+ &ddt));
+ TRYFAIL(gras_datadesc_scalar("double",
+ gras_ddt_scalar_double,
+ e_gras_dd_scalar_encoding_float,
+ &ddt));
+
+ TRYFAIL(gras_datadesc_array_dyn("char[]",
+ gras_datadesc_by_name("char"),
+ _strlen_cb,&ddt));
+ TRYFAIL(gras_datadesc_ref("string",
+ gras_datadesc_by_name("char[]"),
+ &ddt));
}
int r_arch, void *dst);
/* Indicate (lack of) interest in datatype */
-void gras_datadesc_ref(gras_datadesc_type_t *type);
+void gras_datadesc_addref(gras_datadesc_type_t *type);
void gras_datadesc_unref(gras_datadesc_type_t *type);
#endif /* GRAS_DATADESC_INTERFACE_H */
enum e_gras_datadesc_type_category category_code;
union u_gras_datadesc_category category;
- gras_datadesc_type_cb_void_t pre;
- gras_datadesc_type_cb_void_t post;
+ gras_datadesc_type_cb_void_t send;
+ gras_datadesc_type_cb_void_t recv;
};
/***************************
* Type creation functions *
***************************/
gras_error_t
-gras_datadesc_declare_scalar(const char *name,
- gras_ddt_scalar_type_t type,
- enum e_gras_dd_scalar_encoding encoding,
- gras_datadesc_type_cb_void_t cb,
- gras_datadesc_type_t **dst);
+gras_datadesc_scalar(const char *name,
+ gras_ddt_scalar_type_t type,
+ enum e_gras_dd_scalar_encoding encoding,
+ gras_datadesc_type_t **dst);
/****************************************************
* Callback persistant state constructor/destructor *
****************************************************/
gras_error_t
-gras_dd_cbps_new(gras_dd_cbps_t **dst);
+gras_cbps_new(gras_cbps_t **dst);
void
-gras_dd_cbps_free(gras_dd_cbps_t **state);
+gras_cbps_free(gras_cbps_t **state);
/***************
* Convertions *
}
/**
- * gras_datadesc_declare_scalar:
+ * gras_datadesc_scalar:
*
* Create a new scalar and give a pointer to it
*/
gras_error_t
-gras_datadesc_declare_scalar(const char *name,
- gras_ddt_scalar_type_t type,
- enum e_gras_dd_scalar_encoding encoding,
- gras_datadesc_type_cb_void_t cb,
- gras_datadesc_type_t **dst) {
+gras_datadesc_scalar(const char *name,
+ gras_ddt_scalar_type_t type,
+ enum e_gras_dd_scalar_encoding encoding,
+ gras_datadesc_type_t **dst) {
gras_error_t errcode;
gras_datadesc_type_t *res;
res->category_code = e_gras_datadesc_type_cat_scalar;
res->category.scalar_data.encoding = encoding;
- res->pre = cb;
return no_error;
}
}
/**
- * gras_datadesc_declare_struct:
+ * gras_datadesc_struct:
*
* Create a new struct and give a pointer to it
*/
gras_error_t
-gras_datadesc_declare_struct(const char *name,
- gras_datadesc_type_t **dst) {
+gras_datadesc_struct(const char *name,
+ gras_datadesc_type_t **dst) {
gras_error_t errcode;
gras_datadesc_type_t *res;
}
/**
- * gras_datadesc_declare_struct_append:
+ * gras_datadesc_struct_append:
*
* Append a field to the struct
*/
gras_error_t
-gras_datadesc_declare_struct_append(gras_datadesc_type_t *struct_type,
- const char *name,
- gras_datadesc_type_t *field_type) {
+gras_datadesc_struct_append(gras_datadesc_type_t *struct_type,
+ const char *name,
+ gras_datadesc_type_t *field_type) {
gras_error_t errcode;
gras_dd_cat_field_t *field;
return no_error;
}
void
-gras_datadesc_declare_struct_close(gras_datadesc_type_t *struct_type) {
+gras_datadesc_struct_close(gras_datadesc_type_t *struct_type) {
struct_type->category.struct_data.closed = 1;
- // INFO0("FIXME: Do something in gras_datadesc_declare_struct_close");
+ // INFO0("FIXME: Do something in gras_datadesc_struct_close");
}
/**
- * gras_datadesc_declare_union:
+ * gras_datadesc_union:
*
* Create a new union and give a pointer to it
*/
gras_error_t
-gras_datadesc_declare_union(const char *name,
- gras_datadesc_type_cb_int_t selector,
- gras_datadesc_type_t **dst) {
+gras_datadesc_union(const char *name,
+ gras_datadesc_type_cb_int_t selector,
+ gras_datadesc_type_t **dst) {
gras_error_t errcode;
gras_datadesc_type_t *res;
}
/**
- * gras_datadesc_declare_union_append:
+ * gras_datadesc_union_append:
*
* Append a field to the union
*/
gras_error_t
-gras_datadesc_declare_union_append(gras_datadesc_type_t *union_type,
- const char *name,
- gras_datadesc_type_t *field_type) {
+gras_datadesc_union_append(gras_datadesc_type_t *union_type,
+ const char *name,
+ gras_datadesc_type_t *field_type) {
gras_error_t errcode;
gras_dd_cat_field_t *field;
}
void
-gras_datadesc_declare_union_close(gras_datadesc_type_t *union_type) {
+gras_datadesc_union_close(gras_datadesc_type_t *union_type) {
union_type->category.union_data.closed = 1;
- // INFO0("FIXME: Do something in gras_datadesc_declare_union_close");
+ // INFO0("FIXME: Do something in gras_datadesc_union_close");
}
/**
- * gras_datadesc_declare_ref:
+ * gras_datadesc_ref:
*
* Create a new ref to a fixed type and give a pointer to it
*/
gras_error_t
-gras_datadesc_declare_ref(const char *name,
- gras_datadesc_type_t *referenced_type,
- gras_datadesc_type_t **dst) {
+gras_datadesc_ref(const char *name,
+ gras_datadesc_type_t *referenced_type,
+ gras_datadesc_type_t **dst) {
gras_error_t errcode;
gras_datadesc_type_t *res;
return no_error;
}
/**
- * gras_datadesc_declare_ref_generic:
+ * gras_datadesc_ref_generic:
*
* Create a new ref to a type given at use time, and give a pointer to it
*/
gras_error_t
-gras_datadesc_declare_ref_generic(const char *name,
- gras_datadesc_type_cb_int_t selector,
- gras_datadesc_type_t **dst) {
+gras_datadesc_ref_generic(const char *name,
+ gras_datadesc_type_cb_int_t selector,
+ gras_datadesc_type_t **dst) {
gras_error_t errcode;
gras_datadesc_type_t *res;
}
/**
- * gras_datadesc_declare_array_fixed:
+ * gras_datadesc_array_fixed:
*
* Create a new array and give a pointer to it
*/
gras_error_t
-gras_datadesc_declare_array_fixed(const char *name,
- gras_datadesc_type_t *element_type,
- long int fixed_size,
- gras_datadesc_type_t **dst) {
+gras_datadesc_array_fixed(const char *name,
+ gras_datadesc_type_t *element_type,
+ long int fixed_size,
+ gras_datadesc_type_t **dst) {
gras_error_t errcode;
gras_datadesc_type_t *res;
return no_error;
}
/**
- * gras_datadesc_declare_array_dyn:
+ * gras_datadesc_array_dyn:
*
* Create a new array and give a pointer to it
*/
gras_error_t
-gras_datadesc_declare_array_dyn(const char *name,
- gras_datadesc_type_t *element_type,
- gras_datadesc_type_cb_int_t dynamic_size,
- gras_datadesc_type_t **dst) {
+gras_datadesc_array_dyn(const char *name,
+ gras_datadesc_type_t *element_type,
+ gras_datadesc_type_cb_int_t dynamic_size,
+ gras_datadesc_type_t **dst) {
gras_error_t errcode;
gras_datadesc_type_t *res;
return no_error;
}
+/**
+ * gras_datadesc_ref_pop_arr:
+ *
+ * Most of the time, you want to include a reference in your structure which
+ * is a pointer to a dynamic array whose size is fixed by another field of
+ * your structure.
+ *
+ * This case pops up so often that this function was created to take care of
+ * this case. It creates a dynamic array type whose size is poped from the
+ * current cbps, and then create a reference to it.
+ *
+ * The name of the created datatype will be the name of the element type, with
+ * '[]*' appended to it.
+ *
+ * Then to use it, you just have to make sure that your structure pre-callback
+ * does push the size of the array in the cbps (using #gras_cbps_i_push), and
+ * you are set.
+ *
+ * But be remember that this is a stack. If you have two different pop_arr, you
+ * should push the second one first, so that the first one is on the top of the
+ * list when the first field gets transfered.
+ *
+ */
+gras_error_t
+gras_datadesc_ref_pop_arr(gras_datadesc_type_t *element_type,
+ gras_datadesc_type_t **dst) {
+ gras_error_t errcode;
+ char *name=malloc(strlen(element_type->name) + 4);
+
+ sprintf(name,"%s[]",element_type->name);
+
+ TRY(gras_datadesc_array_dyn(name,element_type,
+ gras_datadesc_cb_pop, dst));
+
+ sprintf(name,"%s[]*",element_type->name);
+ TRY(gras_datadesc_ref(name,*dst,dst));
+
+ free(name);
+
+ return no_error;
+}
gras_error_t
gras_datadesc_import_nws(const char *name,
const DataDescriptor *desc,
}
/**
- * gras_datadesc_cb_set_pre:
+ * gras_datadesc_cb_send:
*
- * Add a pre-send callback to this datadexc
+ * Add a pre-send callback to this datadexc.
+ * (useful to push the sizes of the upcoming arrays, for example)
*/
-void gras_datadesc_cb_set_pre (gras_datadesc_type_t *type,
- gras_datadesc_type_cb_void_t pre) {
- type->pre = pre;
+void gras_datadesc_cb_send (gras_datadesc_type_t *type,
+ gras_datadesc_type_cb_void_t send) {
+ type->send = send;
}
/**
- * gras_datadesc_cb_set_post:
+ * gras_datadesc_cb_recv:
*
- * Add a post-send callback to this datadexc
+ * Add a post-receive callback to this datadesc.
+ * (useful to put the function pointers to the rigth value, for example)
*/
-void gras_datadesc_cb_set_post(gras_datadesc_type_t *type,
- gras_datadesc_type_cb_void_t post) {
- type->post = post;
+void gras_datadesc_cb_recv(gras_datadesc_type_t *type,
+ gras_datadesc_type_cb_void_t recv) {
+ type->recv = recv;
}
/**
- * gras_datadesc_ref:
+ * gras_datadesc_addref:
*
* Adds a reference to the datastruct.
* ddt will be freed only when the refcount becomes 0.
*/
-void gras_datadesc_ref(gras_datadesc_type_t *type) {
+void gras_datadesc_addref(gras_datadesc_type_t *type) {
type->refcounter ++;
}
/**
* gras_datadesc_unref:
*
- * Adds a reference to the datastruct.
+ * Removes a reference to the datastruct.
* ddt will be freed only when the refcount becomes 0.
*/
void gras_datadesc_unref(gras_datadesc_type_t *type) {
static gras_error_t
gras_datadesc_send_rec(gras_socket_t *sock,
- gras_dd_cbps_t *state,
+ gras_cbps_t *state,
gras_dict_t *refs,
gras_datadesc_type_t *type,
char *data);
static gras_error_t
gras_datadesc_recv_rec(gras_socket_t *sock,
- gras_dd_cbps_t *state,
+ gras_cbps_t *state,
gras_dict_t *refs,
gras_datadesc_type_t *type,
int r_arch,
return d1->category_code > d2->category_code ? 1 : -1;
}
- if (d1->pre != d2->pre) {
- DEBUG4("ddt_cmp: %s->pre=%p != %s->pre=%p",
- d1->name,d1->pre, d2->name,d2->pre);
- return d1->pre > d2->pre ? 1 : -1;
+ if (d1->send != d2->send) {
+ DEBUG4("ddt_cmp: %s->send=%p != %s->send=%p",
+ d1->name,d1->send, d2->name,d2->send);
+ return d1->send > d2->send ? 1 : -1;
}
- if (d1->post != d2->post) {
- DEBUG4("ddt_cmp: %s->post=%p != %s->post=%p",
- d1->name,d1->post, d2->name,d2->post);
- return d1->post > d2->post ? 1 : -1;
+ if (d1->recv != d2->recv) {
+ DEBUG4("ddt_cmp: %s->recv=%p != %s->recv=%p",
+ d1->name,d1->recv, d2->name,d2->recv);
+ return d1->recv > d2->recv ? 1 : -1;
}
switch (d1->category_code) {
static gras_error_t
gras_datadesc_send_rec(gras_socket_t *sock,
- gras_dd_cbps_t *state,
+ gras_cbps_t *state,
gras_dict_t *refs,
gras_datadesc_type_t *type,
char *data) {
VERB2("Send a %s (%s)",
type->name, gras_datadesc_cat_names[type->category_code]);
- if (type->pre) {
- type->pre(state,type,data);
+ if (type->send) {
+ type->send(state,data);
}
switch (type->category_code) {
gras_error_name(errcode),field->code,cpt,type->name);
if (field->pre)
- field->pre(state,sub_type,field_data);
+ field->pre(state,field_data);
VERB1("Send field %s",field->name);
TRY(gras_datadesc_send_rec(sock,state,refs,sub_type, field_data));
if (field->post)
- field->post(state,sub_type,field_data);
+ field->post(state,field_data);
}
VERB1("<< Sent all fields of the structure %s", type->name);
"Please call gras_datadesc_declare_union_close on %s before sending it",
type->name);
/* retrieve the field number */
- field_num = union_data.selector(state, type, data);
+ field_num = union_data.selector(state, data);
gras_assert1(field_num > 0,
"union field selector of %s gave a negative value",
TRY(gras_datadesc_by_id(field->code, &sub_type));
if (field->pre)
- field->pre(state,sub_type,data);
+ field->pre(state,data);
TRY(gras_datadesc_send_rec(sock,state,refs, sub_type, data));
if (field->post)
- field->post(state,sub_type,data);
+ field->post(state,data);
break;
}
/* Detect the referenced type and send it to peer if needed */
ref_code = ref_data.code;
if (ref_code < 0) {
- ref_code = ref_data.selector(state,type,data);
+ ref_code = ref_data.selector(state,data);
TRY(gras_dd_send_int(sock, ref_code));
}
/* determine and send the element count */
count = array_data.fixed_size;
if (count <= 0) {
- count = array_data.dynamic_size(state,type,data);
+ count = array_data.dynamic_size(state,data);
gras_assert1(count >=0,
"Invalid (negative) array size for type %s",type->name);
TRY(gras_dd_send_int(sock, count));
gras_assert0(0, "Invalid type");
}
- if (type->post) {
- type->post(state,type,data);
- }
-
return no_error;
}
void *src) {
gras_error_t errcode;
- gras_dd_cbps_t *state = NULL;
+ gras_cbps_t *state = NULL;
gras_dict_t *refs; /* all references already sent */
TRY(gras_dict_new(&refs));
- TRY(gras_dd_cbps_new(&state));
+ TRY(gras_cbps_new(&state));
errcode = gras_datadesc_send_rec(sock,state,refs,type,(char*)src);
gras_dict_free(&refs);
- gras_dd_cbps_free(&state);
+ gras_cbps_free(&state);
return errcode;
}
*/
gras_error_t
gras_datadesc_recv_rec(gras_socket_t *sock,
- gras_dd_cbps_t *state,
+ gras_cbps_t *state,
gras_dict_t *refs,
gras_datadesc_type_t *type,
int r_arch,
gras_assert0(0, "Invalid type");
}
+ if (type->recv)
+ type->recv(state,l_data);
+
return no_error;
}
void *dst) {
gras_error_t errcode;
- gras_dd_cbps_t *state = NULL; /* callback persistent state */
+ gras_cbps_t *state = NULL; /* callback persistent state */
gras_dict_t *refs; /* all references already sent */
TRY(gras_dict_new(&refs));
- TRY(gras_dd_cbps_new(&state));
+ TRY(gras_cbps_new(&state));
errcode = gras_datadesc_recv_rec(sock, state, refs, type,
r_arch, NULL, 0,
(char *) dst,-1);
gras_dict_free(&refs);
- gras_dd_cbps_free(&state);
+ gras_cbps_free(&state);
return errcode;
}
sprintf(buffname,"struct %s",identifier.type_name);
identifier.type = gras_datadesc_by_name(buffname);
if (!identifier.type) {
- TRY(gras_datadesc_declare_struct(buffname,&identifier.type));
+ TRY(gras_datadesc_struct(buffname,&identifier.type));
}
} else if (tm.is_unsigned) {
free(identifier.type_name);
array.type = gras_datadesc_by_name(array.type_name);
if (array.type==NULL) {
- TRY(gras_datadesc_declare_array_fixed(array.type_name,
- identifier.type,
- size, &array.type));
+ TRY(gras_datadesc_array_fixed(array.type_name, identifier.type,
+ size, &array.type));
}
array.name = identifier.name;
TRY(gras_dynar_push(*dynar,&array));
/* Create the struct descriptor */
if (gras_ddt_parse_tok_num == GRAS_DDT_PARSE_TOKEN_WORD) {
- TRYFAIL(gras_datadesc_declare_struct(gras_ddt_parse_text,&struct_type));
+ TRYFAIL(gras_datadesc_struct(gras_ddt_parse_text,&struct_type));
DEBUG1("Parse the struct '%s'", gras_ddt_parse_text);
gras_ddt_parse_tok_num = gras_ddt_parse_lex_n_dump();
} else {
sprintf(buffname,"anonymous struct %d",anonymous_struct++);
DEBUG1("Parse the anonymous struct nb %d", anonymous_struct);
- TRYFAIL(gras_datadesc_declare_struct(buffname,&struct_type));
+ TRYFAIL(gras_datadesc_struct(buffname,&struct_type));
}
if (gras_ddt_parse_tok_num != GRAS_DDT_PARSE_TOKEN_LP) {
DEBUG1("This statement contained %d fields",gras_dynar_length(fields));
gras_dynar_foreach(fields,i, field) {
DEBUG1("Append field %s",field.name);
- TRYFAIL(gras_datadesc_declare_struct_append(struct_type,field.name,
- field.type));
+ TRYFAIL(gras_datadesc_struct_append(struct_type, field.name, field.type));
free(field.name);
free(field.type_name);
}
}
- gras_datadesc_declare_struct_close(struct_type);
+ gras_datadesc_struct_close(struct_type);
if (errcode != mismatch_error)
return NULL; /* FIXME: LEAK! */
/**
- * gras_datadesc_declare_parse:
+ * gras_datadesc_parse:
*
* Create a datadescription from the result of parsing the C type description
*/
msgtype->name_len = strlen(namev);
msgtype->version = version;
msgtype->ctn_type = payload;
- gras_datadesc_ref(payload);
+ gras_datadesc_addref(payload);
TRY(gras_set_add(_gras_msgtype_set, (gras_set_elm_t*)msgtype,
&gras_msgtype_free));
gras_assert(string_type);
}
- DEBUG3("send %s to %s:%d", msgtype->name,
+ DEBUG3("send '%s' to %s:%d", msgtype->name,
gras_socket_peer_name(sock),gras_socket_peer_port(sock));
TRY(gras_trp_chunk_send(sock, GRAS_header, 6));
INFO0("---- Test on fixed array ----");
- TRY(gras_datadesc_declare_array_fixed("fixed int array",
- gras_datadesc_by_name("int"),
- SIZE, &my_type));
+ TRY(gras_datadesc_array_fixed("fixed int array",
+ gras_datadesc_by_name("int"),
+ SIZE, &my_type));
TRY(write_read(my_type, &i,&j, sock,direction));
if (direction == READ || direction == RW) {
INFO1("---- Test on a reference to an integer (%p) ----",i);
- TRY(gras_datadesc_declare_ref("int*",gras_datadesc_by_name("int"),&my_type));
+ TRY(gras_datadesc_ref("int*",gras_datadesc_by_name("int"),&my_type));
TRY(write_read(my_type, &i,&j, sock,direction));
if (direction == READ || direction == RW) {
INFO0("---- Test on homogeneous structure ----");
/* create descriptor */
- TRY(gras_datadesc_declare_struct("homostruct",&my_type));
- TRY(gras_datadesc_declare_struct_append(my_type,"a",
- gras_datadesc_by_name("signed int")));
- TRY(gras_datadesc_declare_struct_append(my_type,"b",
- gras_datadesc_by_name("int")));
- TRY(gras_datadesc_declare_struct_append(my_type,"c",
- gras_datadesc_by_name("int")));
- TRY(gras_datadesc_declare_struct_append(my_type,"d",
- gras_datadesc_by_name("int")));
- gras_datadesc_declare_struct_close(my_type);
- TRY(gras_datadesc_declare_ref("homostruct*",
- gras_datadesc_by_name("homostruct"),
- &my_type));
+ TRY(gras_datadesc_struct("homostruct",&my_type));
+ TRY(gras_datadesc_struct_append(my_type,"a",
+ gras_datadesc_by_name("signed int")));
+ TRY(gras_datadesc_struct_append(my_type,"b",
+ gras_datadesc_by_name("int")));
+ TRY(gras_datadesc_struct_append(my_type,"c",
+ gras_datadesc_by_name("int")));
+ TRY(gras_datadesc_struct_append(my_type,"d",
+ gras_datadesc_by_name("int")));
+ gras_datadesc_struct_close(my_type);
+ TRY(gras_datadesc_ref("homostruct*",
+ gras_datadesc_by_name("homostruct"),
+ &my_type));
/* init a value, exchange it and check its validity*/
if (! (i=malloc(sizeof(homostruct))) )
INFO0("---- Test on heterogeneous structure ----");
/* create descriptor */
- TRY(gras_datadesc_declare_struct("hetestruct",&my_type));
- TRY(gras_datadesc_declare_struct_append(my_type,"c1",
- gras_datadesc_by_name("unsigned char")));
- TRY(gras_datadesc_declare_struct_append(my_type,"l1",
- gras_datadesc_by_name("unsigned long int")));
- TRY(gras_datadesc_declare_struct_append(my_type,"c2",
- gras_datadesc_by_name("unsigned char")));
- TRY(gras_datadesc_declare_struct_append(my_type,"l2",
- gras_datadesc_by_name("unsigned long int")));
- gras_datadesc_declare_struct_close(my_type);
- TRY(gras_datadesc_declare_ref("hetestruct*",
- gras_datadesc_by_name("hetestruct"),
- &my_type));
+ TRY(gras_datadesc_struct("hetestruct",&my_type));
+ TRY(gras_datadesc_struct_append(my_type,"c1",
+ gras_datadesc_by_name("unsigned char")));
+ TRY(gras_datadesc_struct_append(my_type,"l1",
+ gras_datadesc_by_name("unsigned long int")));
+ TRY(gras_datadesc_struct_append(my_type,"c2",
+ gras_datadesc_by_name("unsigned char")));
+ TRY(gras_datadesc_struct_append(my_type,"l2",
+ gras_datadesc_by_name("unsigned long int")));
+ gras_datadesc_struct_close(my_type);
+ TRY(gras_datadesc_ref("hetestruct*", gras_datadesc_by_name("hetestruct"),
+ &my_type));
/* init a value, exchange it and check its validity*/
if (! (i=malloc(sizeof(hetestruct))) )
INFO0("---- Test on nested structures ----");
/* create descriptor */
- TRY(gras_datadesc_declare_struct("nestedstruct",&my_type));
+ TRY(gras_datadesc_struct("nestedstruct",&my_type));
- TRY(gras_datadesc_declare_struct_append(my_type,"hete",
- gras_datadesc_by_name("hetestruct")));
- TRY(gras_datadesc_declare_struct_append(my_type,"homo",
- gras_datadesc_by_name("homostruct")));
- gras_datadesc_declare_struct_close(my_type);
- TRY(gras_datadesc_declare_ref("nestedstruct*",
- gras_datadesc_by_name("nestedstruct"),
- &my_type));
+ TRY(gras_datadesc_struct_append(my_type,"hete",
+ gras_datadesc_by_name("hetestruct")));
+ TRY(gras_datadesc_struct_append(my_type,"homo",
+ gras_datadesc_by_name("homostruct")));
+ gras_datadesc_struct_close(my_type);
+ TRY(gras_datadesc_ref("nestedstruct*", gras_datadesc_by_name("nestedstruct"),
+ &my_type));
/* init a value, exchange it and check its validity*/
if (! (i=malloc(sizeof(nestedstruct))) )
gras_error_t errcode;
gras_datadesc_type_t *my_type,*ref_my_type;
- TRY(gras_datadesc_declare_struct("chained_list_t",&my_type));
- TRY(gras_datadesc_declare_ref("chained_list_t*",my_type,&ref_my_type));
+ TRY(gras_datadesc_struct("chained_list_t",&my_type));
+ TRY(gras_datadesc_ref("chained_list_t*",my_type,&ref_my_type));
- TRY(gras_datadesc_declare_struct_append(my_type,"v",
- gras_datadesc_by_name("int")));
- TRY(gras_datadesc_declare_struct_append(my_type,"l",ref_my_type));
- gras_datadesc_declare_struct_close(my_type);
+ TRY(gras_datadesc_struct_append(my_type,"v", gras_datadesc_by_name("int")));
+ TRY(gras_datadesc_struct_append(my_type,"l", ref_my_type));
+ gras_datadesc_struct_close(my_type);
return no_error;
}
int* literals;
} Clause;
-void Clause_pre_cb (void *vars,gras_datadesc_type_t *p_type,void *data);
-int Clause_num_lits(void *vars,gras_datadesc_type_t *p_type,void *data);
+void Clause_pre_cb (gras_cbps_t *vars,void *data);
-void Clause_pre_cb(void *vars,
- gras_datadesc_type_t *p_type,
- void *data) {
- Clause c=*(Clause*)data;
- int *count=malloc(sizeof(int));
- *count=c.num_lits;
-
- gras_dd_cbps_push(vars,"num_lits",count,
- gras_datadesc_by_name("int"));
- DEBUG2("writen data=%p (got %p)",count,data);
- DEBUG1("writen count=%d",*count);
-}
-
-int Clause_num_lits(void *vars,
- gras_datadesc_type_t *p_type,
- void *data) {
- // int *res;
- gras_datadesc_type_t *ddt;
- void *d = gras_dd_cbps_get (vars,"num_lits",&ddt);
- DEBUG1("read data=%p",d);
- DEBUG1("read count=%d",*(int*)d);
- return *(int*)d;
+void Clause_pre_cb(gras_cbps_t *vars, void *data) {
+ gras_cbps_i_push(vars, (long int) ((Clause*)data)->num_lits);
}
gras_error_t test_clause(gras_socket_t *sock, int direction) {
DEBUG1("created count=%d",i->num_lits);
/* create the damn type descriptor */
- TRYFAIL(gras_datadesc_declare_struct("Clause",&ddt));
- gras_datadesc_cb_set_pre(ddt,Clause_pre_cb);
+ TRYFAIL(gras_datadesc_struct("Clause",&ddt));
+
+ gras_datadesc_cb_send(ddt,Clause_pre_cb); /* push the size of the arrray */
- TRYFAIL(gras_datadesc_declare_struct_append(ddt,"num_lits",
- gras_datadesc_by_name("int")));
-
- TRYFAIL(gras_datadesc_declare_array_dyn("Clause{int[]}",
- gras_datadesc_by_name("int"),
- Clause_num_lits,
- &array_t));
- TRYFAIL(gras_datadesc_declare_ref("Clause{int[]}*",array_t,&array_t));
- TRYFAIL(gras_datadesc_declare_struct_append(ddt,"literals",array_t));
- gras_datadesc_declare_struct_close(ddt);
- TRYFAIL(gras_datadesc_declare_ref("Clause*",ddt,&ddt));
+ TRYFAIL(gras_datadesc_struct_append(ddt,"num_lits",
+ gras_datadesc_by_name("int")));
+
+ TRYFAIL(gras_datadesc_ref_pop_arr(gras_datadesc_by_name("int"), &array_t));
+ TRYFAIL(gras_datadesc_struct_append(ddt,"literals",array_t));
+ gras_datadesc_struct_close(ddt);
+ TRYFAIL(gras_datadesc_ref("Clause*",ddt,&ddt));
TRY(write_read(ddt, &i,&j, sock,direction));
if (direction == READ || direction == RW) {