- gras_cbps_t state,
- xbt_dict_t refs,
- gras_datadesc_type_t type,
- char *data,
- int detect_cycle) {
-
- xbt_ex_t e;
- unsigned int cpt;
- gras_datadesc_type_t sub_type; /* type on which we recurse */
-
- VERB2("Send a %s (%s)",
- type->name, gras_datadesc_cat_names[type->category_code]);
-
- if (!strcmp(type->name,"string"))
- VERB1("value: '%s'",*(char**)data);
-
- if (type->send) {
- type->send(type,state,data);
- DEBUG0("Run the emission callback");
- }
-
- switch (type->category_code) {
- case e_gras_datadesc_type_cat_scalar:
- gras_trp_send(sock, data, type->size[GRAS_THISARCH], 1);
- break;
-
- case e_gras_datadesc_type_cat_struct: {
- gras_dd_cat_struct_t struct_data;
- gras_dd_cat_field_t field;
- char *field_data;
-
- struct_data = type->category.struct_data;
- xbt_assert1(struct_data.closed,
- "Please call gras_datadesc_declare_struct_close on %s before sending it",
- type->name);
- VERB1(">> Send all fields of the structure %s",type->name);
- xbt_dynar_foreach(struct_data.fields, cpt, field) {
- field_data = data;
- field_data += field->offset[GRAS_THISARCH];
-
- sub_type = field->type;
-
- if (field->send) {
- DEBUG1("Run the emission callback of field %s", field->name);
- field->send(type,state,field_data);
- }
-
- VERB1("Send field %s",field->name);
- gras_datadesc_send_rec(sock,state,refs,sub_type, field_data,
- detect_cycle || sub_type->cycle);
-
- }
- VERB1("<< Sent all fields of the structure %s", type->name);
-
- break;
- }
-
- case e_gras_datadesc_type_cat_union: {
- gras_dd_cat_union_t union_data;
- gras_dd_cat_field_t field=NULL;
- unsigned int field_num;
-
- union_data = type->category.union_data;
-
- xbt_assert1(union_data.closed,
- "Please call gras_datadesc_declare_union_close on %s before sending it",
- type->name);
- /* retrieve the field number */
- field_num = union_data.selector(type, state, data);
-
- xbt_assert1(field_num > 0,
- "union field selector of %s gave a negative value",
- type->name);
-
- xbt_assert3(field_num < xbt_dynar_length(union_data.fields),
- "union field selector of %s returned %d but there is only %lu fields",
- type->name, field_num, xbt_dynar_length(union_data.fields));
-
- /* Send the field number */
- gras_dd_send_uint(sock, &field_num, 0 /* not stable */);
-
- /* Send the content */
- field = xbt_dynar_get_as(union_data.fields, field_num, gras_dd_cat_field_t);
- sub_type = field->type;
-
- if (field->send)
- field->send(type,state,data);
-
- gras_datadesc_send_rec(sock,state,refs, sub_type, data,
- detect_cycle || sub_type->cycle);
-
- break;
- }
-
- case e_gras_datadesc_type_cat_ref: {
- gras_dd_cat_ref_t ref_data;
- void **ref=(void**)data;
- int reference_is_to_send;
-
- ref_data = type->category.ref_data;
-
- /* Detect the referenced type and send it to peer if needed */
- sub_type = ref_data.type;
- if (sub_type == NULL) {
- sub_type = (*ref_data.selector)(type,state,data);
- gras_dd_send_uint(sock, &(sub_type->code),1 /*stable*/);
- }
-
- /* Send the actual value of the pointer for cycle handling */
- if (!pointer_type) {
- pointer_type = gras_datadesc_by_name("data pointer");
- xbt_assert(pointer_type);
- }
-
- gras_trp_send(sock, (char*)data,
- pointer_type->size[GRAS_THISARCH], 1 /*stable*/);
-
- /* Send the pointed data only if not already sent */
- if (*(void**)data == NULL) {
- VERB0("Not sending NULL referenced data");
- break;
- }
-
- reference_is_to_send = 0;
- TRY {
- if (detect_cycle)
- /* return ignored. Just checking whether it's known or not */
- xbt_dict_get_ext(refs,(char*)ref, sizeof(char*));
- else
- reference_is_to_send = 1;
- } CATCH(e) {
- if (e.category != not_found_error)
- RETHROW;
- reference_is_to_send = 1;
- xbt_ex_free(e);
- }
-
- if (reference_is_to_send) {
- VERB1("Sending data referenced at %p", (void*)*ref);
- if (detect_cycle)
- xbt_dict_set_ext(refs, (char*)ref, sizeof(void*), ref, NULL);
- gras_datadesc_send_rec(sock,state,refs, sub_type, *ref,
- detect_cycle || sub_type->cycle);
-
- } else {
- VERB1("Not sending data referenced at %p (already done)", (void*)*ref);
- }
-
- break;
- }
-
- case e_gras_datadesc_type_cat_array: {
- gras_dd_cat_array_t array_data;
- unsigned int count;
- char *ptr=data;
- long int elm_size;
-
- array_data = type->category.array_data;
-
- /* determine and send the element count */
- count = array_data.fixed_size;
- if (count == 0) {
- count = array_data.dynamic_size(type,state,data);
- xbt_assert1(count >=0,
- "Invalid (negative) array size for type %s",type->name);
- gras_dd_send_uint(sock, &count, 0/*non-stable*/);
- }
-
- /* send the content */
- sub_type = array_data.type;
- elm_size = sub_type->aligned_size[GRAS_THISARCH];
- if (sub_type->category_code == e_gras_datadesc_type_cat_scalar) {
- VERB1("Array of %d scalars, send it in one shot",count);
- gras_trp_send(sock, data,
- sub_type->aligned_size[GRAS_THISARCH] * count,
- 0 /* not stable */);
- } else if (sub_type->category_code == e_gras_datadesc_type_cat_array &&
- sub_type->category.array_data.fixed_size > 0 &&
- sub_type->category.array_data.type->category_code == e_gras_datadesc_type_cat_scalar) {
-
- VERB1("Array of %d fixed array of scalars, send it in one shot",count);
- gras_trp_send(sock, data,
- sub_type->category.array_data.type->aligned_size[GRAS_THISARCH]
- * count * sub_type->category.array_data.fixed_size,
- 0 /* not stable */);
-
- } else {
- for (cpt=0; cpt<count; cpt++) {
- gras_datadesc_send_rec(sock,state,refs, sub_type, ptr,
- detect_cycle || sub_type->cycle);
- ptr += elm_size;
- }
- }
- break;
- }
-
- default:
- xbt_assert0(0, "Invalid type");
- }
+ gras_cbps_t state,
+ xbt_dict_t refs,
+ gras_datadesc_type_t type,
+ char *data,
+ int detect_cycle) {
+
+ xbt_ex_t e;
+ unsigned int cpt;
+ gras_datadesc_type_t sub_type; /* type on which we recurse */
+
+ VERB2("Send a %s (%s)",
+ type->name, gras_datadesc_cat_names[type->category_code]);
+
+ if (!strcmp(type->name,"string"))
+ VERB1("value: '%s'",*(char**)data);
+
+ if (type->send) {
+ type->send(type,state,data);
+ DEBUG0("Run the emission callback");
+ }
+
+ switch (type->category_code) {
+ case e_gras_datadesc_type_cat_scalar:
+ gras_trp_send(sock, data, type->size[GRAS_THISARCH], 1);
+ break;
+
+ case e_gras_datadesc_type_cat_struct: {
+ gras_dd_cat_struct_t struct_data;
+ gras_dd_cat_field_t field;
+ char *field_data;
+
+ struct_data = type->category.struct_data;
+ xbt_assert1(struct_data.closed,
+ "Please call gras_datadesc_declare_struct_close on %s before sending it",
+ type->name);
+ VERB1(">> Send all fields of the structure %s",type->name);
+ xbt_dynar_foreach(struct_data.fields, cpt, field) {
+ field_data = data;
+ field_data += field->offset[GRAS_THISARCH];
+
+ sub_type = field->type;
+
+ if (field->send) {
+ DEBUG1("Run the emission callback of field %s", field->name);
+ field->send(type,state,field_data);
+ }
+
+ VERB1("Send field %s",field->name);
+ gras_datadesc_send_rec(sock,state,refs,sub_type, field_data,
+ detect_cycle || sub_type->cycle);
+
+ }
+ VERB1("<< Sent all fields of the structure %s", type->name);
+
+ break;
+ }
+
+ case e_gras_datadesc_type_cat_union: {
+ gras_dd_cat_union_t union_data;
+ gras_dd_cat_field_t field=NULL;
+ unsigned int field_num;
+
+ union_data = type->category.union_data;
+
+ xbt_assert1(union_data.closed,
+ "Please call gras_datadesc_declare_union_close on %s before sending it",
+ type->name);
+ /* retrieve the field number */
+ field_num = union_data.selector(type, state, data);
+
+ xbt_assert1(field_num > 0,
+ "union field selector of %s gave a negative value",
+ type->name);
+
+ xbt_assert3(field_num < xbt_dynar_length(union_data.fields),
+ "union field selector of %s returned %d but there is only %lu fields",
+ type->name, field_num, xbt_dynar_length(union_data.fields));
+
+ /* Send the field number */
+ gras_dd_send_uint(sock, &field_num, 0 /* not stable */);
+
+ /* Send the content */
+ field = xbt_dynar_get_as(union_data.fields, field_num, gras_dd_cat_field_t);
+ sub_type = field->type;
+
+ if (field->send)
+ field->send(type,state,data);
+
+ gras_datadesc_send_rec(sock,state,refs, sub_type, data,
+ detect_cycle || sub_type->cycle);
+
+ break;
+ }
+
+ case e_gras_datadesc_type_cat_ref: {
+ gras_dd_cat_ref_t ref_data;
+ void **ref=(void**)data;
+ int reference_is_to_send;
+
+ ref_data = type->category.ref_data;
+
+ /* Detect the referenced type and send it to peer if needed */
+ sub_type = ref_data.type;
+ if (sub_type == NULL) {
+ sub_type = (*ref_data.selector)(type,state,data);
+ gras_dd_send_uint(sock, &(sub_type->code),1 /*stable*/);
+ }
+
+ /* Send the actual value of the pointer for cycle handling */
+ if (!pointer_type) {
+ pointer_type = gras_datadesc_by_name("data pointer");
+ xbt_assert(pointer_type);
+ }
+
+ gras_trp_send(sock, (char*)data,
+ pointer_type->size[GRAS_THISARCH], 1 /*stable*/);
+
+ /* Send the pointed data only if not already sent */
+ if (*(void**)data == NULL) {
+ VERB0("Not sending NULL referenced data");
+ break;
+ }
+
+ reference_is_to_send = 0;
+ TRY {
+ if (detect_cycle)
+ /* return ignored. Just checking whether it's known or not */
+ xbt_dict_get_ext(refs,(char*)ref, sizeof(char*));
+ else
+ reference_is_to_send = 1;
+ } CATCH(e) {
+ if (e.category != not_found_error)
+ RETHROW;
+ reference_is_to_send = 1;
+ xbt_ex_free(e);
+ }
+
+ if (reference_is_to_send) {
+ VERB1("Sending data referenced at %p", (void*)*ref);
+ if (detect_cycle)
+ xbt_dict_set_ext(refs, (char*)ref, sizeof(void*), ref, NULL);
+ gras_datadesc_send_rec(sock,state,refs, sub_type, *ref,
+ detect_cycle || sub_type->cycle);
+
+ } else {
+ VERB1("Not sending data referenced at %p (already done)", (void*)*ref);
+ }
+
+ break;
+ }
+
+ case e_gras_datadesc_type_cat_array: {
+ gras_dd_cat_array_t array_data;
+ unsigned int count;
+ char *ptr=data;
+ long int elm_size;
+
+ array_data = type->category.array_data;
+
+ /* determine and send the element count */
+ count = array_data.fixed_size;
+ if (count == 0) {
+ count = array_data.dynamic_size(type,state,data);
+ xbt_assert1(count >=0,
+ "Invalid (negative) array size for type %s",type->name);
+ gras_dd_send_uint(sock, &count, 0/*non-stable*/);
+ }
+
+ /* send the content */
+ sub_type = array_data.type;
+ elm_size = sub_type->aligned_size[GRAS_THISARCH];
+ if (sub_type->category_code == e_gras_datadesc_type_cat_scalar) {
+ VERB1("Array of %d scalars, send it in one shot",count);
+ gras_trp_send(sock, data,
+ sub_type->aligned_size[GRAS_THISARCH] * count,
+ 0 /* not stable */);
+ } else if (sub_type->category_code == e_gras_datadesc_type_cat_array &&
+ sub_type->category.array_data.fixed_size > 0 &&
+ sub_type->category.array_data.type->category_code == e_gras_datadesc_type_cat_scalar) {
+
+ VERB1("Array of %d fixed array of scalars, send it in one shot",count);
+ gras_trp_send(sock, data,
+ sub_type->category.array_data.type->aligned_size[GRAS_THISARCH]
+ * count * sub_type->category.array_data.fixed_size,
+ 0 /* not stable */);
+
+ } else {
+ for (cpt=0; cpt<count; cpt++) {
+ gras_datadesc_send_rec(sock,state,refs, sub_type, ptr,
+ detect_cycle || sub_type->cycle);
+ ptr += elm_size;
+ }
+ }
+ break;
+ }
+
+ default:
+ xbt_assert0(0, "Invalid type");
+ }