3 /* ddt_exchange - send/recv data described */
5 /* Copyright (c) 2003 Olivier Aumage. */
6 /* Copyright (c) 2003, 2004, 2005 Martin Quinson. */
7 /* All rights reserved. */
9 /* This program is free software; you can redistribute it and/or modify it
10 * under the terms of the license (GNU LGPL) which comes with this package. */
13 #include "gras/DataDesc/datadesc_private.h"
14 #include "gras/Transport/transport_interface.h" /* gras_trp_send/recv */
16 XBT_LOG_NEW_DEFAULT_SUBCATEGORY(gras_ddt_exchange,gras_ddt,
17 "Sending data over the network");
18 const char *gras_datadesc_cat_names[9] = {
20 "scalar", "struct", "union", "ref", "array", "ignored",
23 static gras_datadesc_type_t int_type = NULL;
24 static gras_datadesc_type_t pointer_type = NULL;
26 static _XBT_INLINE void
27 gras_dd_send_int(gras_socket_t sock,int *i, int stable) {
30 int_type = gras_datadesc_by_name("int");
34 DEBUG1("send_int(%d)",*i);
35 gras_trp_send(sock, (char*)i, int_type->size[GRAS_THISARCH], stable);
38 static _XBT_INLINE void
39 gras_dd_recv_int(gras_socket_t sock, int r_arch, int *i) {
42 int_type = gras_datadesc_by_name("int");
46 if (int_type->size[GRAS_THISARCH] >= int_type->size[r_arch]) {
47 gras_trp_recv(sock, (char*)i, int_type->size[r_arch]);
48 if (r_arch != GRAS_THISARCH)
49 gras_dd_convert_elm(int_type,1,r_arch, i,i);
51 void *ptr = xbt_malloc(int_type->size[r_arch]);
53 gras_trp_recv(sock, (char*)ptr, int_type->size[r_arch]);
54 if (r_arch != GRAS_THISARCH)
55 gras_dd_convert_elm(int_type,1,r_arch, ptr,i);
58 DEBUG1("recv_int(%d)",*i);
62 * Note: here we suppose that the remote NULL is a sequence
63 * of 'length' bytes set to 0.
64 * FIXME: Check in configure?
66 static _XBT_INLINE int
67 gras_dd_is_r_null(char **r_ptr, long int length) {
70 for (i=0; i<length; i++) {
71 if ( ((unsigned char*)r_ptr) [i]) {
79 static _XBT_INLINE void
80 gras_dd_alloc_ref(xbt_dict_t refs,
83 long int r_len, /* pointer_type->size[r_arch] */
88 xbt_assert1(size>0,"Cannot allocate %ld bytes!", size);
89 l_data = xbt_malloc((size_t)size);
92 DEBUG5("alloc_ref: l_data=%p, &l_data=%p; r_ref=%p; *r_ref=%p, r_len=%ld",
93 (void*)l_data,(void*)&l_data,
94 (void*)r_ref, (void*)(r_ref?*r_ref:NULL), r_len);
95 if (detect_cycle && r_ref && !gras_dd_is_r_null( r_ref, r_len)) {
96 void *ptr = xbt_malloc(sizeof(void *));
98 CRITICAL0("Check for cycles");
99 memcpy(ptr,l_ref, sizeof(void *));
101 DEBUG2("Insert l_ref=%p under r_ref=%p",*(void**)ptr, *(void**)r_ref);
104 xbt_dict_set_ext(refs,(const char *) r_ref, r_len, ptr, free);
109 gras_datadesc_copy_rec(gras_cbps_t state,
111 gras_datadesc_type_t type,
120 gras_datadesc_type_t sub_type; /* type on which we recurse */
123 VERB4("Copy a %s (%s) from %p to %p",
124 type->name, gras_datadesc_cat_names[type->category_code],
128 type->send(type,state,src);
131 switch (type->category_code) {
132 case e_gras_datadesc_type_cat_scalar:
133 memcpy(dst,src,type->size[GRAS_THISARCH]);
134 count += type->size[GRAS_THISARCH];
137 case e_gras_datadesc_type_cat_struct: {
138 gras_dd_cat_struct_t struct_data;
139 gras_dd_cat_field_t field;
143 struct_data = type->category.struct_data;
144 xbt_assert1(struct_data.closed,
145 "Please call gras_datadesc_declare_struct_close on %s before copying it",
147 VERB1(">> Copy all fields of the structure %s",type->name);
148 xbt_dynar_foreach(struct_data.fields, cpt, field) {
149 field_src = src + field->offset[GRAS_THISARCH];
150 field_dst = dst + field->offset[GRAS_THISARCH];
152 sub_type = field->type;
155 field->send(type,state,field_src);
157 VERB1("Copy field %s",field->name);
158 count += gras_datadesc_copy_rec(state,refs,sub_type, field_src, field_dst, 0,
159 detect_cycle || sub_type->cycle);
161 if (XBT_LOG_ISENABLED(gras_ddt_exchange,xbt_log_priority_debug)) {
162 if (sub_type == gras_datadesc_by_name("unsigned int")) {
163 DEBUG2("Copied value for field %s: %d (type: unsigned int)",field->name, *(unsigned int*)field_dst);
164 } else if (sub_type == gras_datadesc_by_name("int")) {
165 DEBUG2("Copied value for field %s: %d (type: int)",field->name, *(int*)field_dst);
167 } else if (sub_type == gras_datadesc_by_name("unsigned long int")) {
168 DEBUG2("Copied value for field %s: %ld (type: unsigned long int)",field->name, *(unsigned long int*)field_dst);
169 } else if (sub_type == gras_datadesc_by_name("long int")) {
170 DEBUG2("Copied value for field %s: %ld (type: long int)",field->name, *(long int*)field_dst);
172 } else if (sub_type == gras_datadesc_by_name("string")) {
173 DEBUG2("Copied value for field %s: '%s' (type: string)", field->name, *(char**)field_dst);
178 VERB1("<< Copied all fields of the structure %s", type->name);
183 case e_gras_datadesc_type_cat_union: {
184 gras_dd_cat_union_t union_data;
185 gras_dd_cat_field_t field=NULL;
188 union_data = type->category.union_data;
190 xbt_assert1(union_data.closed,
191 "Please call gras_datadesc_declare_union_close on %s before copying it",
193 /* retrieve the field number */
194 field_num = union_data.selector(type, state, src);
196 xbt_assert1(field_num > 0,
197 "union field selector of %s gave a negative value",
200 xbt_assert3(field_num < xbt_dynar_length(union_data.fields),
201 "union field selector of %s returned %d but there is only %lu fields",
202 type->name, field_num, xbt_dynar_length(union_data.fields));
204 /* Copy the content */
205 field = xbt_dynar_get_as(union_data.fields, field_num, gras_dd_cat_field_t);
206 sub_type = field->type;
209 field->send(type,state,src);
211 count += gras_datadesc_copy_rec(state,refs, sub_type, src, dst,0,
212 detect_cycle || sub_type->cycle);
217 case e_gras_datadesc_type_cat_ref: {
218 gras_dd_cat_ref_t ref_data;
221 int reference_is_to_cpy;
223 ref_data = type->category.ref_data;
225 /* Detect the referenced type */
226 sub_type = ref_data.type;
227 if (sub_type == NULL) {
228 sub_type = (*ref_data.selector)(type,state,src);
231 /* Send the pointed data only if not already sent */
232 if (*(void**)src == NULL) {
233 VERB0("Not copying NULL referenced data");
239 reference_is_to_cpy = 0;
242 /* return ignored. Just checking whether it's known or not */
243 n_ref=xbt_dict_get_ext(refs,(char*)o_ref, sizeof(char*));
245 reference_is_to_cpy = 1;
247 if (e.category != not_found_error)
249 reference_is_to_cpy = 1;
253 if (reference_is_to_cpy) {
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
265 is more complicated */
266 gras_dd_cat_array_t array_data = sub_type->category.array_data;
267 gras_datadesc_type_t subsub_type;
269 subsub_type = array_data.type;
270 subsubcount = array_data.fixed_size;
271 if (subsubcount == 0)
272 subsubcount = array_data.dynamic_size(subsub_type,state,*o_ref);
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_copy_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 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 == 0)
316 array_count = subsize;
317 if (array_count == 0) {
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_copy_rec(state,refs, sub_type, src_ptr, dst_ptr, 0,
346 detect_cycle || sub_type->cycle);
355 xbt_assert0(0, "Invalid type");
361 * gras_datadesc_copy:
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_copy(gras_datadesc_type_t type,
368 void *src, void *dst) {
371 xbt_dict_t refs; /* all references already sent */
374 xbt_assert0(type,"called with NULL type descriptor");
376 refs = xbt_dict_new();
377 state = gras_cbps_new();
380 size = gras_datadesc_copy_rec(state,refs,type,(char*)src,(char*)dst,0,
383 xbt_dict_free(&refs);
384 gras_cbps_free(&state);
392 *** Direct use functions
396 gras_datadesc_send_rec(gras_socket_t sock,
399 gras_datadesc_type_t type,
405 gras_datadesc_type_t sub_type; /* type on which we recurse */
407 VERB2("Send a %s (%s)",
408 type->name, gras_datadesc_cat_names[type->category_code]);
410 if (!strcmp(type->name,"string"))
411 VERB1("value: '%s'",*(char**)data);
414 type->send(type,state,data);
415 DEBUG0("Run the emission callback");
418 switch (type->category_code) {
419 case e_gras_datadesc_type_cat_scalar:
420 gras_trp_send(sock, data, type->size[GRAS_THISARCH], 1);
423 case e_gras_datadesc_type_cat_struct: {
424 gras_dd_cat_struct_t struct_data;
425 gras_dd_cat_field_t field;
428 struct_data = type->category.struct_data;
429 xbt_assert1(struct_data.closed,
430 "Please call gras_datadesc_declare_struct_close on %s before sending it",
432 VERB1(">> Send all fields of the structure %s",type->name);
433 xbt_dynar_foreach(struct_data.fields, cpt, field) {
435 field_data += field->offset[GRAS_THISARCH];
437 sub_type = field->type;
440 DEBUG1("Run the emission callback of field %s", field->name);
441 field->send(type,state,field_data);
444 VERB1("Send field %s",field->name);
445 gras_datadesc_send_rec(sock,state,refs,sub_type, field_data,
446 detect_cycle || sub_type->cycle);
449 VERB1("<< Sent all fields of the structure %s", type->name);
454 case e_gras_datadesc_type_cat_union: {
455 gras_dd_cat_union_t union_data;
456 gras_dd_cat_field_t field=NULL;
459 union_data = type->category.union_data;
461 xbt_assert1(union_data.closed,
462 "Please call gras_datadesc_declare_union_close on %s before sending it",
464 /* retrieve the field number */
465 field_num = union_data.selector(type, state, data);
467 xbt_assert1(field_num > 0,
468 "union field selector of %s gave a negative value",
471 xbt_assert3(field_num < xbt_dynar_length(union_data.fields),
472 "union field selector of %s returned %d but there is only %lu fields",
473 type->name, field_num, xbt_dynar_length(union_data.fields));
475 /* Send the field number */
476 gras_dd_send_int(sock, &field_num, 0 /* not stable */);
478 /* Send the content */
479 field = xbt_dynar_get_as(union_data.fields, field_num, gras_dd_cat_field_t);
480 sub_type = field->type;
483 field->send(type,state,data);
485 gras_datadesc_send_rec(sock,state,refs, sub_type, data,
486 detect_cycle || sub_type->cycle);
491 case e_gras_datadesc_type_cat_ref: {
492 gras_dd_cat_ref_t ref_data;
493 void **ref=(void**)data;
494 int reference_is_to_send;
496 ref_data = type->category.ref_data;
498 /* Detect the referenced type and send it to peer if needed */
499 sub_type = ref_data.type;
500 if (sub_type == NULL) {
501 sub_type = (*ref_data.selector)(type,state,data);
502 gras_dd_send_int(sock, (int*) &(sub_type->code),1 /*stable*/);
505 /* Send the actual value of the pointer for cycle handling */
507 pointer_type = gras_datadesc_by_name("data pointer");
508 xbt_assert(pointer_type);
511 gras_trp_send(sock, (char*)data,
512 pointer_type->size[GRAS_THISARCH], 1 /*stable*/);
514 /* Send the pointed data only if not already sent */
515 if (*(void**)data == NULL) {
516 VERB0("Not sending NULL referenced data");
520 reference_is_to_send = 0;
523 /* return ignored. Just checking whether it's known or not */
524 xbt_dict_get_ext(refs,(char*)ref, sizeof(char*));
526 reference_is_to_send = 1;
528 if (e.category != not_found_error)
530 reference_is_to_send = 1;
534 if (reference_is_to_send) {
535 VERB1("Sending data referenced at %p", (void*)*ref);
537 xbt_dict_set_ext(refs, (char*)ref, sizeof(void*), ref, NULL);
538 gras_datadesc_send_rec(sock,state,refs, sub_type, *ref,
539 detect_cycle || sub_type->cycle);
542 VERB1("Not sending data referenced at %p (already done)", (void*)*ref);
548 case e_gras_datadesc_type_cat_array: {
549 gras_dd_cat_array_t array_data;
554 array_data = type->category.array_data;
556 /* determine and send the element count */
557 count = array_data.fixed_size;
559 count = array_data.dynamic_size(type,state,data);
560 xbt_assert1(count >=0,
561 "Invalid (negative) array size for type %s",type->name);
562 gras_dd_send_int(sock, &count, 0/*non-stable*/);
565 /* send the content */
566 sub_type = array_data.type;
567 elm_size = sub_type->aligned_size[GRAS_THISARCH];
568 if (sub_type->category_code == e_gras_datadesc_type_cat_scalar) {
569 VERB1("Array of %d scalars, send it in one shot",count);
570 gras_trp_send(sock, data,
571 sub_type->aligned_size[GRAS_THISARCH] * count,
573 } else if (sub_type->category_code == e_gras_datadesc_type_cat_array &&
574 sub_type->category.array_data.fixed_size > 0 &&
575 sub_type->category.array_data.type->category_code == e_gras_datadesc_type_cat_scalar) {
577 VERB1("Array of %d fixed array of scalars, send it in one shot",count);
578 gras_trp_send(sock, data,
579 sub_type->category.array_data.type->aligned_size[GRAS_THISARCH]
580 * count * sub_type->category.array_data.fixed_size,
584 for (cpt=0; cpt<count; cpt++) {
585 gras_datadesc_send_rec(sock,state,refs, sub_type, ptr,
586 detect_cycle || sub_type->cycle);
594 xbt_assert0(0, "Invalid type");
599 * gras_datadesc_send:
601 * Copy the data pointed by src and described by type to the socket
604 void gras_datadesc_send(gras_socket_t sock,
605 gras_datadesc_type_t type,
609 static gras_cbps_t state=NULL;
610 xbt_dict_t refs; /* all references already sent */
612 xbt_assert0(type,"called with NULL type descriptor");
614 refs = xbt_dict_new();
616 state = gras_cbps_new();
619 gras_datadesc_send_rec(sock,state,refs,type,(char*)src, type->cycle);
621 xbt_dict_free(&refs);
622 gras_cbps_reset(state);
629 * gras_datadesc_recv_rec:
631 * Do the data reception job recursively.
633 * subsize used only to deal with vicious case of reference to dynamic array.
634 * This size is needed at the reference reception level (to allocate enough
635 * space) and at the array reception level (to fill enough room).
637 * Having this size passed as an argument of the recursive function is a crude
638 * hack, but I was told that working code is sometimes better than neat one ;)
641 gras_datadesc_recv_rec(gras_socket_t sock,
644 gras_datadesc_type_t type,
653 gras_datadesc_type_t sub_type;
656 VERB2("Recv a %s @%p", type->name, (void*)l_data);
659 switch (type->category_code) {
660 case e_gras_datadesc_type_cat_scalar:
661 if (type->size[GRAS_THISARCH] == type->size[r_arch]) {
662 gras_trp_recv(sock, (char*)l_data, type->size[r_arch]);
663 if (r_arch != GRAS_THISARCH)
664 gras_dd_convert_elm(type,1,r_arch, l_data,l_data);
666 void *ptr = xbt_malloc(type->size[r_arch]);
668 gras_trp_recv(sock, (char*)ptr, type->size[r_arch]);
669 if (r_arch != GRAS_THISARCH)
670 gras_dd_convert_elm(type,1,r_arch, ptr,l_data);
675 case e_gras_datadesc_type_cat_struct: {
676 gras_dd_cat_struct_t struct_data;
677 gras_dd_cat_field_t field;
679 struct_data = type->category.struct_data;
681 xbt_assert1(struct_data.closed,
682 "Please call gras_datadesc_declare_struct_close on %s before receiving it",
684 VERB1(">> Receive all fields of the structure %s",type->name);
685 xbt_dynar_foreach(struct_data.fields, cpt, field) {
686 char *field_data = l_data + field->offset[GRAS_THISARCH];
688 sub_type = field->type;
690 gras_datadesc_recv_rec(sock,state,refs, sub_type,
693 detect_cycle || sub_type->cycle);
696 DEBUG1("Run the reception callback of field %s", field->name);
697 field->recv(type,state,(void*)l_data);
701 VERB1("<< Received all fields of the structure %s", type->name);
706 case e_gras_datadesc_type_cat_union: {
707 gras_dd_cat_union_t union_data;
708 gras_dd_cat_field_t field=NULL;
711 union_data = type->category.union_data;
713 xbt_assert1(union_data.closed,
714 "Please call gras_datadesc_declare_union_close on %s before receiving it",
716 /* retrieve the field number */
717 gras_dd_recv_int(sock, r_arch, &field_num);
719 THROW1(mismatch_error,0,
720 "Received union field for %s is negative", type->name);
721 if (field_num > xbt_dynar_length(union_data.fields))
722 THROW3(mismatch_error,0,
723 "Received union field for %s is said to be #%d but there is only %lu fields",
724 type->name, field_num, xbt_dynar_length(union_data.fields));
726 /* Recv the content */
727 field = xbt_dynar_get_as(union_data.fields, field_num, gras_dd_cat_field_t);
728 sub_type = field->type;
730 gras_datadesc_recv_rec(sock,state,refs, sub_type,
733 detect_cycle || sub_type->cycle);
735 field->recv(type,state,l_data);
740 case e_gras_datadesc_type_cat_ref: {
743 gras_dd_cat_ref_t ref_data;
744 int reference_is_to_recv = 0;
746 ref_data = type->category.ref_data;
748 /* Get the referenced type locally or from peer */
749 sub_type = ref_data.type;
750 if (sub_type == NULL) {
752 gras_dd_recv_int(sock, r_arch, &ref_code);
753 sub_type = gras_datadesc_by_id(ref_code);
756 /* Get the actual value of the pointer for cycle handling */
758 pointer_type = gras_datadesc_by_name("data pointer");
759 xbt_assert(pointer_type);
762 r_ref = xbt_malloc(pointer_type->size[r_arch]);
764 gras_trp_recv(sock, (char*)r_ref,
765 pointer_type->size[r_arch]);
767 /* Receive the pointed data only if not already sent */
768 if (gras_dd_is_r_null(r_ref, pointer_type->size[r_arch])) {
769 VERB1("Not receiving data remotely referenced @%p since it's NULL",
771 *(void**)l_data = NULL;
776 reference_is_to_recv = 0;
779 l_ref = xbt_dict_get_ext(refs, (char*)r_ref, pointer_type->size[r_arch]);
781 reference_is_to_recv = 1;
783 if (e.category != not_found_error)
785 reference_is_to_recv = 1;
788 if (reference_is_to_recv) {
790 void *l_referenced=NULL;
792 VERB2("Receiving a ref to '%s', remotely @%p",
793 sub_type->name, *(void**)r_ref);
794 if (sub_type->category_code == e_gras_datadesc_type_cat_array) {
795 /* Damn. Reference to a dynamic array. Allocating the space for it
796 is more complicated */
797 gras_dd_cat_array_t array_data = sub_type->category.array_data;
798 gras_datadesc_type_t subsub_type;
800 subsubcount = array_data.fixed_size;
801 if (subsubcount == 0)
802 gras_dd_recv_int(sock, r_arch, &subsubcount);
804 subsub_type = array_data.type;
807 gras_dd_alloc_ref(refs,
808 subsub_type->size[GRAS_THISARCH] * subsubcount,
809 r_ref,pointer_type->size[r_arch],
810 (char**)&l_referenced,
813 gras_dd_alloc_ref(refs,sub_type->size[GRAS_THISARCH],
814 r_ref,pointer_type->size[r_arch],
815 (char**)&l_referenced,
819 gras_datadesc_recv_rec(sock,state,refs, sub_type,
820 r_arch,r_ref,pointer_type->size[r_arch],
821 (char*)l_referenced, subsubcount,
822 detect_cycle || sub_type->cycle);
824 *(void**)l_data=l_referenced;
825 VERB3("'%s' remotely referenced at %p locally at %p",
826 sub_type->name, *(void**)r_ref, l_referenced);
829 VERB2("NOT receiving data remotely referenced @%p (already done, @%p here)",
830 *(void**)r_ref, *(void**)l_ref);
832 *(void**)l_data=*l_ref;
839 case e_gras_datadesc_type_cat_array: {
840 gras_dd_cat_array_t array_data;
845 array_data = type->category.array_data;
846 /* determine element count locally, or from caller, or from peer */
847 count = array_data.fixed_size;
851 gras_dd_recv_int(sock, r_arch, &count);
853 THROW1(mismatch_error,0,
854 "Invalid (=0) array size for type %s",type->name);
856 /* receive the content */
857 sub_type = array_data.type;
858 if (sub_type->category_code == e_gras_datadesc_type_cat_scalar) {
859 VERB1("Array of %d scalars, get it in one shoot", count);
860 if (sub_type->aligned_size[GRAS_THISARCH] >=
861 sub_type->aligned_size[r_arch]) {
862 gras_trp_recv(sock, (char*)l_data,
863 sub_type->aligned_size[r_arch] * count);
864 if (r_arch != GRAS_THISARCH)
865 gras_dd_convert_elm(sub_type,count,r_arch, l_data,l_data);
867 ptr = xbt_malloc(sub_type->aligned_size[r_arch] * count);
869 gras_trp_recv(sock, (char*)ptr,
870 sub_type->size[r_arch] * count);
871 if (r_arch != GRAS_THISARCH)
872 gras_dd_convert_elm(sub_type,count,r_arch, ptr,l_data);
875 } else if (sub_type->category_code == e_gras_datadesc_type_cat_array &&
876 sub_type->category.array_data.fixed_size > 0 &&
877 sub_type->category.array_data.type->category_code == e_gras_datadesc_type_cat_scalar) {
878 gras_datadesc_type_t subsub_type;
879 array_data = sub_type->category.array_data;
880 subsub_type = array_data.type;
882 VERB1("Array of %d fixed array of scalars, get it in one shot",count);
883 if (subsub_type->aligned_size[GRAS_THISARCH] >=
884 subsub_type->aligned_size[r_arch]) {
885 gras_trp_recv(sock, (char*)l_data,
886 subsub_type->aligned_size[r_arch] * count *
887 array_data.fixed_size);
888 if (r_arch != GRAS_THISARCH)
889 gras_dd_convert_elm(subsub_type,count*array_data.fixed_size,r_arch, l_data,l_data);
891 ptr = xbt_malloc(subsub_type->aligned_size[r_arch] * count*array_data.fixed_size);
893 gras_trp_recv(sock, (char*)ptr,
894 subsub_type->size[r_arch] * count*array_data.fixed_size);
895 if (r_arch != GRAS_THISARCH)
896 gras_dd_convert_elm(subsub_type,count*array_data.fixed_size,r_arch, ptr,l_data);
902 /* not scalar content, get it recursively (may contain pointers) */
903 elm_size = sub_type->aligned_size[GRAS_THISARCH];
904 VERB2("Receive a %d-long array of %s",count, sub_type->name);
907 for (cpt=0; cpt<count; cpt++) {
908 gras_datadesc_recv_rec(sock,state,refs, sub_type,
909 r_arch, NULL, 0, ptr,-1,
910 detect_cycle || sub_type->cycle);
919 xbt_assert0(0, "Invalid type");
923 type->recv(type,state,l_data);
925 if (!strcmp(type->name,"string"))
926 VERB1("value: '%s'",*(char**)l_data);
931 * gras_datadesc_recv:
933 * Get an instance of the datatype described by @type from the @socket,
934 * and store a pointer to it in @dst
938 gras_datadesc_recv(gras_socket_t sock,
939 gras_datadesc_type_t type,
944 static gras_cbps_t state=NULL; /* callback persistent state */
945 xbt_dict_t refs; /* all references already sent */
947 refs = xbt_dict_new();
949 state = gras_cbps_new();
951 xbt_assert0(type,"called with NULL type descriptor");
953 gras_datadesc_recv_rec(sock, state, refs, type,
958 xbt_dict_free(&refs);
959 gras_cbps_reset(state);