3 /* ddt_exchange - send/recv data described */
5 /* Copyright (c) 2003-2009 The SimGrid Team. All rights reserved. */
7 /* This program is free software; you can redistribute it and/or modify it
8 * under the terms of the license (GNU LGPL) which comes with this package. */
11 #include "gras/DataDesc/datadesc_private.h"
12 #include "gras/Transport/transport_interface.h" /* gras_trp_send/recv */
14 XBT_LOG_NEW_DEFAULT_SUBCATEGORY(gras_ddt_exchange,gras_ddt,
15 "Sending data over the network");
16 const char *gras_datadesc_cat_names[9] = {
18 "scalar", "struct", "union", "ref", "array", "ignored",
21 static gras_datadesc_type_t int_type = NULL;
22 static gras_datadesc_type_t pointer_type = NULL;
24 static XBT_INLINE void
25 gras_dd_send_int(gras_socket_t sock, int *i, int stable) {
28 int_type = gras_datadesc_by_name("int");
32 DEBUG1("send_int(%u)",*i);
33 gras_trp_send(sock, (char*)i, int_type->size[GRAS_THISARCH], stable);
36 static XBT_INLINE void
37 gras_dd_recv_int(gras_socket_t sock, int r_arch, int *i) {
40 int_type = gras_datadesc_by_name("int");
44 if (int_type->size[GRAS_THISARCH] >= int_type->size[r_arch]) {
45 gras_trp_recv(sock, (char*)i, int_type->size[r_arch]);
46 if (r_arch != GRAS_THISARCH)
47 gras_dd_convert_elm(int_type,1,r_arch, i,i);
49 void *ptr = xbt_malloc(int_type->size[r_arch]);
51 gras_trp_recv(sock, (char*)ptr, int_type->size[r_arch]);
52 if (r_arch != GRAS_THISARCH)
53 gras_dd_convert_elm(int_type,1,r_arch, ptr,i);
56 DEBUG1("recv_int(%u)",*i);
60 * Note: here we suppose that the remote NULL is a sequence
61 * of 'length' bytes set to 0.
62 * FIXME: Check in configure?
65 gras_dd_is_r_null(char **r_ptr, long int length) {
68 for (i=0; i<length; i++) {
69 if ( ((unsigned char*)r_ptr) [i]) {
77 static XBT_INLINE void
78 gras_dd_alloc_ref(xbt_dict_t refs,
81 long int r_len, /* pointer_type->size[r_arch] */
86 xbt_assert1(size>0,"Cannot allocate %ld bytes!", size);
87 l_data = xbt_malloc((size_t)size);
90 DEBUG5("alloc_ref: l_data=%p, &l_data=%p; r_ref=%p; *r_ref=%p, r_len=%ld",
91 (void*)l_data,(void*)&l_data,
92 (void*)r_ref, (void*)(r_ref?*r_ref:NULL), r_len);
93 if (detect_cycle && r_ref && !gras_dd_is_r_null( r_ref, r_len)) {
94 void *ptr = xbt_malloc(sizeof(void *));
96 memcpy(ptr,l_ref, sizeof(void *));
98 DEBUG2("Insert l_ref=%p under r_ref=%p",*(void**)ptr, *(void**)r_ref);
101 xbt_dict_set_ext(refs,(const char *) r_ref, r_len, ptr, xbt_free_f);
106 gras_datadesc_memcpy_rec(gras_cbps_t state,
108 gras_datadesc_type_t type,
117 gras_datadesc_type_t sub_type; /* type on which we recurse */
120 VERB5("Copy a %s (%s) from %p to %p (local sizeof=%ld)",
121 type->name, gras_datadesc_cat_names[type->category_code],
122 src,dst,type->size[GRAS_THISARCH]);
125 type->send(type,state,src);
128 switch (type->category_code) {
129 case e_gras_datadesc_type_cat_scalar:
130 memcpy(dst,src,type->size[GRAS_THISARCH]);
131 count += type->size[GRAS_THISARCH];
134 case e_gras_datadesc_type_cat_struct: {
135 gras_dd_cat_struct_t struct_data;
136 gras_dd_cat_field_t field;
140 struct_data = type->category.struct_data;
141 xbt_assert1(struct_data.closed,
142 "Please call gras_datadesc_declare_struct_close on %s before copying it",
144 VERB1(">> Copy all fields of the structure %s",type->name);
145 xbt_dynar_foreach(struct_data.fields, cpt, field) {
146 field_src = src + field->offset[GRAS_THISARCH];
147 field_dst = dst + field->offset[GRAS_THISARCH];
149 sub_type = field->type;
152 field->send(type,state,field_src);
154 DEBUG1("Copy field %s",field->name);
155 count += gras_datadesc_memcpy_rec(state,refs,sub_type, field_src, field_dst, 0,
156 detect_cycle || sub_type->cycle);
158 if (XBT_LOG_ISENABLED(gras_ddt_exchange,xbt_log_priority_verbose)) {
159 if (sub_type == gras_datadesc_by_name("unsigned int")) {
160 VERB2("Copied value for field '%s': %d (type: unsigned int)",field->name, *(unsigned int*)field_dst);
161 } else if (sub_type == gras_datadesc_by_name("int")) {
162 VERB2("Copied value for field '%s': %d (type: int)",field->name, *(int*)field_dst);
164 } else if (sub_type == gras_datadesc_by_name("unsigned long int")) {
165 VERB2("Copied value for field '%s': %ld (type: unsigned long int)",field->name, *(unsigned long int*)field_dst);
166 } else if (sub_type == gras_datadesc_by_name("long int")) {
167 VERB2("Copied value for field '%s': %ld (type: long int)",field->name, *(long int*)field_dst);
169 } else if (sub_type == gras_datadesc_by_name("string")) {
170 VERB2("Copied value for field '%s': '%s' (type: string)", field->name, *(char**)field_dst);
172 VERB1("Copied a value for field '%s' (type not scalar?)", field->name);
177 VERB1("<< Copied all fields of the structure %s", type->name);
182 case e_gras_datadesc_type_cat_union: {
183 gras_dd_cat_union_t union_data;
184 gras_dd_cat_field_t field=NULL;
185 unsigned int field_num;
187 union_data = type->category.union_data;
189 xbt_assert1(union_data.closed,
190 "Please call gras_datadesc_declare_union_close on %s before copying it",
192 /* retrieve the field number */
193 field_num = union_data.selector(type, state, src);
195 xbt_assert1(field_num > 0,
196 "union field selector of %s gave a negative value",
199 xbt_assert3(field_num < xbt_dynar_length(union_data.fields),
200 "union field selector of %s returned %d but there is only %lu fields",
201 type->name, field_num, xbt_dynar_length(union_data.fields));
203 /* Copy the content */
204 field = xbt_dynar_get_as(union_data.fields, field_num, gras_dd_cat_field_t);
205 sub_type = field->type;
208 field->send(type,state,src);
210 count += gras_datadesc_memcpy_rec(state,refs, sub_type, src, dst,0,
211 detect_cycle || sub_type->cycle);
216 case e_gras_datadesc_type_cat_ref: {
217 gras_dd_cat_ref_t ref_data;
220 int reference_is_to_cpy;
222 ref_data = type->category.ref_data;
224 /* Detect the referenced type */
225 sub_type = ref_data.type;
226 if (sub_type == NULL) {
227 sub_type = (*ref_data.selector)(type,state,src);
230 /* Send the pointed data only if not already sent */
231 if (*(void**)src == NULL) {
232 VERB0("Not copying NULL referenced data");
238 reference_is_to_cpy = 0;
241 /* return ignored. Just checking whether it's known or not */
242 n_ref=xbt_dict_get_ext(refs,(char*)o_ref, sizeof(char*));
244 reference_is_to_cpy = 1;
247 if (e.category != not_found_error)
249 reference_is_to_cpy = 1;
253 if (reference_is_to_cpy) {
254 int subsubcount = -1;
255 void *l_referenced=NULL;
256 VERB2("Copy a ref to '%s' referenced at %p",sub_type->name, (void*)*o_ref);
259 pointer_type = gras_datadesc_by_name("data pointer");
260 xbt_assert(pointer_type);
263 if (sub_type->category_code == e_gras_datadesc_type_cat_array) {
264 /* Damn. Reference to a dynamic array. Allocating the space for it is more complicated */
265 gras_dd_cat_array_t array_data = sub_type->category.array_data;
266 gras_datadesc_type_t subsub_type;
268 subsub_type = array_data.type;
269 subsubcount = array_data.fixed_size;
270 if (subsubcount == -1)
271 subsubcount = array_data.dynamic_size(subsub_type,state,*o_ref);
273 if (subsubcount != 0)
274 gras_dd_alloc_ref(refs,
275 subsub_type->size[GRAS_THISARCH] * subsubcount,
276 o_ref,pointer_type->size[GRAS_THISARCH],
277 (char**)&l_referenced,
280 gras_dd_alloc_ref(refs,sub_type->size[GRAS_THISARCH],
281 o_ref,pointer_type->size[GRAS_THISARCH],
282 (char**)&l_referenced,
286 count += gras_datadesc_memcpy_rec(state,refs, sub_type,
287 *o_ref,(char*)l_referenced, subsubcount,
288 detect_cycle || sub_type->cycle);
290 *(void**)dst=l_referenced;
291 VERB3("'%s' previously referenced at %p now at %p",
292 sub_type->name, *(void**)o_ref, l_referenced);
295 VERB2("NOT copying data previously referenced @%p (already done, @%p now)",
296 *(void**)o_ref, *(void**)n_ref);
304 case e_gras_datadesc_type_cat_array: {
305 gras_dd_cat_array_t array_data;
306 unsigned long int array_count;
311 array_data = type->category.array_data;
313 /* determine and send the element count */
314 array_count = array_data.fixed_size;
315 if (array_count == -1)
316 array_count = subsize;
317 if (array_count == -1) {
318 array_count = array_data.dynamic_size(type,state,src);
319 xbt_assert1(array_count >=0,
320 "Invalid (negative) array size for type %s",type->name);
323 /* send the content */
324 sub_type = array_data.type;
325 elm_size = sub_type->aligned_size[GRAS_THISARCH];
326 if (sub_type->category_code == e_gras_datadesc_type_cat_scalar) {
327 VERB1("Array of %ld scalars, copy it in one shot",array_count);
328 memcpy(dst, src, sub_type->aligned_size[GRAS_THISARCH] * array_count);
329 count += sub_type->aligned_size[GRAS_THISARCH] * array_count;
330 } else if (sub_type->category_code == e_gras_datadesc_type_cat_array &&
331 sub_type->category.array_data.fixed_size > 0 &&
332 sub_type->category.array_data.type->category_code == e_gras_datadesc_type_cat_scalar) {
334 VERB1("Array of %ld fixed array of scalars, copy it in one shot",
336 memcpy(dst,src,sub_type->category.array_data.type->aligned_size[GRAS_THISARCH]
337 * array_count * sub_type->category.array_data.fixed_size);
338 count += sub_type->category.array_data.type->aligned_size[GRAS_THISARCH]
339 * array_count * sub_type->category.array_data.fixed_size;
342 VERB1("Array of %ld stuff, copy it in one after the other",array_count);
343 for (cpt=0; cpt<array_count; cpt++) {
344 VERB2("Copy the %dth stuff out of %ld",cpt,array_count);
345 count += gras_datadesc_memcpy_rec(state,refs, sub_type, src_ptr, dst_ptr, 0,
346 detect_cycle || sub_type->cycle);
355 xbt_die("Invalid type");
361 * gras_datadesc_memcpy:
363 * Copy the data pointed by src and described by type
364 * to a new location, and store a pointer to it in dst.
367 int gras_datadesc_memcpy(gras_datadesc_type_t type,
368 void *src, void *dst) {
370 static gras_cbps_t state=NULL;
371 static xbt_dict_t refs=NULL; /* all references already sent */
374 xbt_assert0(type,"called with NULL type descriptor");
376 DEBUG3("Memcopy a %s from %p to %p",gras_datadesc_get_name(type),src,dst);
378 state = gras_cbps_new();
379 refs = xbt_dict_new();
383 size = gras_datadesc_memcpy_rec(state,refs,type,(char*)src,(char*)dst,0,
386 xbt_dict_reset(refs);
387 gras_cbps_reset(state);
395 *** Direct use functions
399 gras_datadesc_send_rec(gras_socket_t sock,
402 gras_datadesc_type_t type,
408 gras_datadesc_type_t sub_type; /* type on which we recurse */
410 VERB2("Send a %s (%s)",
411 type->name, gras_datadesc_cat_names[type->category_code]);
413 if (!strcmp(type->name,"string"))
414 VERB1("value: '%s'",*(char**)data);
417 type->send(type,state,data);
418 DEBUG0("Run the emission callback");
421 switch (type->category_code) {
422 case e_gras_datadesc_type_cat_scalar:
423 gras_trp_send(sock, data, type->size[GRAS_THISARCH], 1);
426 case e_gras_datadesc_type_cat_struct: {
427 gras_dd_cat_struct_t struct_data;
428 gras_dd_cat_field_t field;
431 struct_data = type->category.struct_data;
432 xbt_assert1(struct_data.closed,
433 "Please call gras_datadesc_declare_struct_close on %s before sending it",
435 VERB1(">> Send all fields of the structure %s",type->name);
436 xbt_dynar_foreach(struct_data.fields, cpt, field) {
438 field_data += field->offset[GRAS_THISARCH];
440 sub_type = field->type;
443 DEBUG1("Run the emission callback of field %s", field->name);
444 field->send(type,state,field_data);
447 VERB1("Send field %s",field->name);
448 gras_datadesc_send_rec(sock,state,refs,sub_type, field_data,
449 detect_cycle || sub_type->cycle);
452 VERB1("<< Sent all fields of the structure %s", type->name);
457 case e_gras_datadesc_type_cat_union: {
458 gras_dd_cat_union_t union_data;
459 gras_dd_cat_field_t field=NULL;
462 union_data = type->category.union_data;
464 xbt_assert1(union_data.closed,
465 "Please call gras_datadesc_declare_union_close on %s before sending it",
467 /* retrieve the field number */
468 field_num = union_data.selector(type, state, data);
470 xbt_assert1(field_num > 0,
471 "union field selector of %s gave a negative value",
474 xbt_assert3(field_num < xbt_dynar_length(union_data.fields),
475 "union field selector of %s returned %d but there is only %lu fields",
476 type->name, field_num, xbt_dynar_length(union_data.fields));
478 /* Send the field number */
479 gras_dd_send_int(sock, &field_num, 0 /* not stable */);
481 /* Send the content */
482 field = xbt_dynar_get_as(union_data.fields, field_num, gras_dd_cat_field_t);
483 sub_type = field->type;
486 field->send(type,state,data);
488 gras_datadesc_send_rec(sock,state,refs, sub_type, data,
489 detect_cycle || sub_type->cycle);
494 case e_gras_datadesc_type_cat_ref: {
495 gras_dd_cat_ref_t ref_data;
496 void **ref=(void**)data;
497 int reference_is_to_send;
499 ref_data = type->category.ref_data;
501 /* Detect the referenced type and send it to peer if needed */
502 sub_type = ref_data.type;
503 if (sub_type == NULL) {
504 sub_type = (*ref_data.selector)(type,state,data);
505 gras_dd_send_int(sock, &(sub_type->code),1 /*stable*/);
508 /* Send the actual value of the pointer for cycle handling */
510 pointer_type = gras_datadesc_by_name("data pointer");
511 xbt_assert(pointer_type);
514 gras_trp_send(sock, (char*)data,
515 pointer_type->size[GRAS_THISARCH], 1 /*stable*/);
517 /* Send the pointed data only if not already sent */
518 if (*(void**)data == NULL) {
519 VERB0("Not sending NULL referenced data");
523 reference_is_to_send = 0;
526 /* return ignored. Just checking whether it's known or not */
527 xbt_dict_get_ext(refs,(char*)ref, sizeof(char*));
529 reference_is_to_send = 1;
531 if (e.category != not_found_error)
533 reference_is_to_send = 1;
537 if (reference_is_to_send) {
538 VERB1("Sending data referenced at %p", (void*)*ref);
540 xbt_dict_set_ext(refs, (char*)ref, sizeof(void*), ref, NULL);
541 gras_datadesc_send_rec(sock,state,refs, sub_type, *ref,
542 detect_cycle || sub_type->cycle);
545 VERB1("Not sending data referenced at %p (already done)", (void*)*ref);
551 case e_gras_datadesc_type_cat_array: {
552 gras_dd_cat_array_t array_data;
557 array_data = type->category.array_data;
559 /* determine and send the element count */
560 count = array_data.fixed_size;
562 count = array_data.dynamic_size(type,state,data);
563 xbt_assert1(count >=0,
564 "Invalid (negative) array size for type %s",type->name);
565 gras_dd_send_int(sock, &count, 0/*non-stable*/);
568 /* send the content */
569 sub_type = array_data.type;
570 elm_size = sub_type->aligned_size[GRAS_THISARCH];
571 if (sub_type->category_code == e_gras_datadesc_type_cat_scalar) {
572 VERB1("Array of %d scalars, send it in one shot",count);
573 gras_trp_send(sock, data,
574 sub_type->aligned_size[GRAS_THISARCH] * count,
576 } else if (sub_type->category_code == e_gras_datadesc_type_cat_array &&
577 sub_type->category.array_data.fixed_size > 0 &&
578 sub_type->category.array_data.type->category_code == e_gras_datadesc_type_cat_scalar) {
580 VERB1("Array of %d fixed array of scalars, send it in one shot",count);
581 gras_trp_send(sock, data,
582 sub_type->category.array_data.type->aligned_size[GRAS_THISARCH]
583 * count * sub_type->category.array_data.fixed_size,
587 for (cpt=0; cpt<count; cpt++) {
588 gras_datadesc_send_rec(sock,state,refs, sub_type, ptr,
589 detect_cycle || sub_type->cycle);
597 xbt_die("Invalid type");
602 * gras_datadesc_send:
604 * Copy the data pointed by src and described by type to the socket
607 void gras_datadesc_send(gras_socket_t sock,
608 gras_datadesc_type_t type,
612 static gras_cbps_t state=NULL;
613 static xbt_dict_t refs=NULL; /* all references already sent */
615 xbt_assert0(type,"called with NULL type descriptor");
618 state = gras_cbps_new();
619 refs = xbt_dict_new();
623 gras_datadesc_send_rec(sock,state,refs,type,(char*)src, type->cycle);
625 xbt_dict_reset(refs);
626 gras_cbps_reset(state);
633 * gras_datadesc_recv_rec:
635 * Do the data reception job recursively.
637 * subsize used only to deal with vicious case of reference to dynamic array.
638 * This size is needed at the reference reception level (to allocate enough
639 * space) and at the array reception level (to fill enough room).
641 * Having this size passed as an argument of the recursive function is a crude
642 * hack, but I was told that working code is sometimes better than neat one ;)
645 gras_datadesc_recv_rec(gras_socket_t sock,
648 gras_datadesc_type_t type,
657 gras_datadesc_type_t sub_type;
660 VERB2("Recv a %s @%p", type->name, (void*)l_data);
663 switch (type->category_code) {
664 case e_gras_datadesc_type_cat_scalar:
665 if (type->size[GRAS_THISARCH] == type->size[r_arch]) {
666 gras_trp_recv(sock, (char*)l_data, type->size[r_arch]);
667 if (r_arch != GRAS_THISARCH)
668 gras_dd_convert_elm(type,1,r_arch, l_data,l_data);
670 void *ptr = xbt_malloc(type->size[r_arch]);
672 gras_trp_recv(sock, (char*)ptr, type->size[r_arch]);
673 if (r_arch != GRAS_THISARCH)
674 gras_dd_convert_elm(type,1,r_arch, ptr,l_data);
679 case e_gras_datadesc_type_cat_struct: {
680 gras_dd_cat_struct_t struct_data;
681 gras_dd_cat_field_t field;
683 struct_data = type->category.struct_data;
685 xbt_assert1(struct_data.closed,
686 "Please call gras_datadesc_declare_struct_close on %s before receiving it",
688 VERB1(">> Receive all fields of the structure %s",type->name);
689 xbt_dynar_foreach(struct_data.fields, cpt, field) {
690 char *field_data = l_data + field->offset[GRAS_THISARCH];
692 sub_type = field->type;
694 gras_datadesc_recv_rec(sock,state,refs, sub_type,
697 detect_cycle || sub_type->cycle);
700 DEBUG1("Run the reception callback of field %s", field->name);
701 field->recv(type,state,(void*)l_data);
705 VERB1("<< Received all fields of the structure %s", type->name);
710 case e_gras_datadesc_type_cat_union: {
711 gras_dd_cat_union_t union_data;
712 gras_dd_cat_field_t field=NULL;
715 union_data = type->category.union_data;
717 xbt_assert1(union_data.closed,
718 "Please call gras_datadesc_declare_union_close on %s before receiving it",
720 /* retrieve the field number */
721 gras_dd_recv_int(sock, r_arch, &field_num);
723 THROW1(mismatch_error,0,
724 "Received union field for %s is negative", type->name);
725 if (field_num > xbt_dynar_length(union_data.fields))
726 THROW3(mismatch_error,0,
727 "Received union field for %s is said to be #%d but there is only %lu fields",
728 type->name, field_num, xbt_dynar_length(union_data.fields));
730 /* Recv the content */
731 field = xbt_dynar_get_as(union_data.fields, field_num, gras_dd_cat_field_t);
732 sub_type = field->type;
734 gras_datadesc_recv_rec(sock,state,refs, sub_type,
737 detect_cycle || sub_type->cycle);
739 field->recv(type,state,l_data);
744 case e_gras_datadesc_type_cat_ref: {
747 gras_dd_cat_ref_t ref_data;
748 int reference_is_to_recv = 0;
750 ref_data = type->category.ref_data;
752 /* Get the referenced type locally or from peer */
753 sub_type = ref_data.type;
754 if (sub_type == NULL) {
756 gras_dd_recv_int(sock, r_arch, &ref_code);
757 sub_type = gras_datadesc_by_id(ref_code);
760 /* Get the actual value of the pointer for cycle handling */
762 pointer_type = gras_datadesc_by_name("data pointer");
763 xbt_assert(pointer_type);
766 r_ref = xbt_malloc(pointer_type->size[r_arch]);
768 gras_trp_recv(sock, (char*)r_ref,
769 pointer_type->size[r_arch]);
771 /* Receive the pointed data only if not already sent */
772 if (gras_dd_is_r_null(r_ref, pointer_type->size[r_arch])) {
773 VERB1("Not receiving data remotely referenced @%p since it's NULL",
775 *(void**)l_data = NULL;
780 reference_is_to_recv = 0;
783 l_ref = xbt_dict_get_ext(refs, (char*)r_ref, pointer_type->size[r_arch]);
785 reference_is_to_recv = 1;
788 if (e.category != not_found_error)
790 reference_is_to_recv = 1;
794 if (reference_is_to_recv) {
795 int subsubcount = -1;
796 void *l_referenced=NULL;
798 VERB2("Receiving a ref to '%s', remotely @%p",
799 sub_type->name, *(void**)r_ref);
800 if (sub_type->category_code == e_gras_datadesc_type_cat_array) {
801 /* Damn. Reference to a dynamic array. Allocating the space for it is more complicated */
802 gras_dd_cat_array_t array_data = sub_type->category.array_data;
803 gras_datadesc_type_t subsub_type;
805 subsubcount = array_data.fixed_size;
806 if (subsubcount == -1)
807 gras_dd_recv_int(sock, r_arch, &subsubcount);
809 subsub_type = array_data.type;
811 if (subsubcount != 0)
812 gras_dd_alloc_ref(refs,
813 subsub_type->size[GRAS_THISARCH] * subsubcount,
814 r_ref,pointer_type->size[r_arch],
815 (char**)&l_referenced,
820 gras_dd_alloc_ref(refs,sub_type->size[GRAS_THISARCH],
821 r_ref,pointer_type->size[r_arch],
822 (char**)&l_referenced,
826 if (l_referenced != NULL)
827 gras_datadesc_recv_rec(sock,state,refs, sub_type,
828 r_arch,r_ref,pointer_type->size[r_arch],
829 (char*)l_referenced, subsubcount,
830 detect_cycle || sub_type->cycle);
832 *(void**)l_data=l_referenced;
833 VERB3("'%s' remotely referenced at %p locally at %p",
834 sub_type->name, *(void**)r_ref, l_referenced);
837 VERB2("NOT receiving data remotely referenced @%p (already done, @%p here)",
838 *(void**)r_ref, *(void**)l_ref);
840 *(void**)l_data=*l_ref;
847 case e_gras_datadesc_type_cat_array: {
848 gras_dd_cat_array_t array_data;
853 array_data = type->category.array_data;
854 /* determine element count locally, or from caller, or from peer */
855 count = array_data.fixed_size;
859 gras_dd_recv_int(sock, r_arch, &count);
861 THROW1(mismatch_error,0,
862 "Invalid (=-1) array size for type %s",type->name);
864 /* receive the content */
865 sub_type = array_data.type;
866 if (sub_type->category_code == e_gras_datadesc_type_cat_scalar) {
867 VERB1("Array of %d scalars, get it in one shoot", count);
868 if (sub_type->aligned_size[GRAS_THISARCH] >=
869 sub_type->aligned_size[r_arch]) {
870 gras_trp_recv(sock, (char*)l_data,
871 sub_type->aligned_size[r_arch] * count);
872 if (r_arch != GRAS_THISARCH)
873 gras_dd_convert_elm(sub_type,count,r_arch, l_data,l_data);
875 ptr = xbt_malloc(sub_type->aligned_size[r_arch] * count);
877 gras_trp_recv(sock, (char*)ptr,
878 sub_type->size[r_arch] * count);
879 if (r_arch != GRAS_THISARCH)
880 gras_dd_convert_elm(sub_type,count,r_arch, ptr,l_data);
883 } else if (sub_type->category_code == e_gras_datadesc_type_cat_array &&
884 sub_type->category.array_data.fixed_size >= 0 &&
885 sub_type->category.array_data.type->category_code == e_gras_datadesc_type_cat_scalar) {
886 gras_datadesc_type_t subsub_type;
887 array_data = sub_type->category.array_data;
888 subsub_type = array_data.type;
890 VERB1("Array of %d fixed array of scalars, get it in one shot",count);
891 if (subsub_type->aligned_size[GRAS_THISARCH] >=
892 subsub_type->aligned_size[r_arch]) {
893 gras_trp_recv(sock, (char*)l_data,
894 subsub_type->aligned_size[r_arch] * count *
895 array_data.fixed_size);
896 if (r_arch != GRAS_THISARCH)
897 gras_dd_convert_elm(subsub_type,count*array_data.fixed_size,r_arch, l_data,l_data);
899 ptr = xbt_malloc(subsub_type->aligned_size[r_arch] * count*array_data.fixed_size);
901 gras_trp_recv(sock, (char*)ptr,
902 subsub_type->size[r_arch] * count*array_data.fixed_size);
903 if (r_arch != GRAS_THISARCH)
904 gras_dd_convert_elm(subsub_type,count*array_data.fixed_size,r_arch, ptr,l_data);
910 /* not scalar content, get it recursively (may contain pointers) */
911 elm_size = sub_type->aligned_size[GRAS_THISARCH];
912 VERB2("Receive a %d-long array of %s",count, sub_type->name);
915 for (cpt=0; cpt<count; cpt++) {
916 gras_datadesc_recv_rec(sock,state,refs, sub_type,
917 r_arch, NULL, 0, ptr,-1,
918 detect_cycle || sub_type->cycle);
927 xbt_die("Invalid type");
931 type->recv(type,state,l_data);
933 if (!strcmp(type->name,"string"))
934 VERB1("value: '%s'",*(char**)l_data);
939 * gras_datadesc_recv:
941 * Get an instance of the datatype described by @type from the @socket,
942 * and store a pointer to it in @dst
946 gras_datadesc_recv(gras_socket_t sock,
947 gras_datadesc_type_t type,
952 static gras_cbps_t state=NULL; /* callback persistent state */
953 static xbt_dict_t refs=NULL; /* all references already sent */
956 state = gras_cbps_new();
957 refs = xbt_dict_new();
960 xbt_assert0(type,"called with NULL type descriptor");
962 gras_datadesc_recv_rec(sock, state, refs, type,
967 xbt_dict_reset(refs);
968 gras_cbps_reset(state);