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 memcpy(ptr,l_ref, sizeof(void *));
100 DEBUG2("Insert l_ref=%p under r_ref=%p",*(void**)ptr, *(void**)r_ref);
103 xbt_dict_set_ext(refs,(const char *) r_ref, r_len, ptr, free);
108 gras_datadesc_copy_rec(gras_cbps_t state,
110 gras_datadesc_type_t type,
119 gras_datadesc_type_t sub_type; /* type on which we recurse */
122 VERB4("Copy a %s (%s) from %p to %p",
123 type->name, gras_datadesc_cat_names[type->category_code],
127 type->send(type,state,src);
130 switch (type->category_code) {
131 case e_gras_datadesc_type_cat_scalar:
132 memcpy(dst,src,type->size[GRAS_THISARCH]);
133 count += type->size[GRAS_THISARCH];
136 case e_gras_datadesc_type_cat_struct: {
137 gras_dd_cat_struct_t struct_data;
138 gras_dd_cat_field_t field;
142 struct_data = type->category.struct_data;
143 xbt_assert1(struct_data.closed,
144 "Please call gras_datadesc_declare_struct_close on %s before copying it",
146 VERB1(">> Copy all fields of the structure %s",type->name);
147 xbt_dynar_foreach(struct_data.fields, cpt, field) {
148 field_src = src + field->offset[GRAS_THISARCH];
149 field_dst = dst + field->offset[GRAS_THISARCH];
151 sub_type = field->type;
154 field->send(type,state,field_src);
156 DEBUG1("Copy field %s",field->name);
157 count += gras_datadesc_copy_rec(state,refs,sub_type, field_src, field_dst, 0,
158 detect_cycle || sub_type->cycle);
160 if (XBT_LOG_ISENABLED(gras_ddt_exchange,xbt_log_priority_verbose)) {
161 if (sub_type == gras_datadesc_by_name("unsigned int")) {
162 VERB2("Copied value for field '%s': %d (type: unsigned int)",field->name, *(unsigned int*)field_dst);
163 } else if (sub_type == gras_datadesc_by_name("int")) {
164 VERB2("Copied value for field '%s': %d (type: int)",field->name, *(int*)field_dst);
166 } else if (sub_type == gras_datadesc_by_name("unsigned long int")) {
167 VERB2("Copied value for field '%s': %ld (type: unsigned long int)",field->name, *(unsigned long int*)field_dst);
168 } else if (sub_type == gras_datadesc_by_name("long int")) {
169 VERB2("Copied value for field '%s': %ld (type: long int)",field->name, *(long int*)field_dst);
171 } else if (sub_type == gras_datadesc_by_name("string")) {
172 VERB2("Copied value for field '%s': '%s' (type: string)", field->name, *(char**)field_dst);
174 VERB1("Copied a value for field '%s' (type not scalar?)", field->name);
179 VERB1("<< Copied all fields of the structure %s", type->name);
184 case e_gras_datadesc_type_cat_union: {
185 gras_dd_cat_union_t union_data;
186 gras_dd_cat_field_t field=NULL;
189 union_data = type->category.union_data;
191 xbt_assert1(union_data.closed,
192 "Please call gras_datadesc_declare_union_close on %s before copying it",
194 /* retrieve the field number */
195 field_num = union_data.selector(type, state, src);
197 xbt_assert1(field_num > 0,
198 "union field selector of %s gave a negative value",
201 xbt_assert3(field_num < xbt_dynar_length(union_data.fields),
202 "union field selector of %s returned %d but there is only %lu fields",
203 type->name, field_num, xbt_dynar_length(union_data.fields));
205 /* Copy the content */
206 field = xbt_dynar_get_as(union_data.fields, field_num, gras_dd_cat_field_t);
207 sub_type = field->type;
210 field->send(type,state,src);
212 count += gras_datadesc_copy_rec(state,refs, sub_type, src, dst,0,
213 detect_cycle || sub_type->cycle);
218 case e_gras_datadesc_type_cat_ref: {
219 gras_dd_cat_ref_t ref_data;
222 int reference_is_to_cpy;
224 ref_data = type->category.ref_data;
226 /* Detect the referenced type */
227 sub_type = ref_data.type;
228 if (sub_type == NULL) {
229 sub_type = (*ref_data.selector)(type,state,src);
232 /* Send the pointed data only if not already sent */
233 if (*(void**)src == NULL) {
234 VERB0("Not copying NULL referenced data");
240 reference_is_to_cpy = 0;
243 /* return ignored. Just checking whether it's known or not */
244 n_ref=xbt_dict_get_ext(refs,(char*)o_ref, sizeof(char*));
246 reference_is_to_cpy = 1;
249 if (e.category != not_found_error)
251 reference_is_to_cpy = 1;
255 if (reference_is_to_cpy) {
257 void *l_referenced=NULL;
258 VERB2("Copy a ref to '%s' referenced at %p",sub_type->name, (void*)*o_ref);
261 pointer_type = gras_datadesc_by_name("data pointer");
262 xbt_assert(pointer_type);
265 if (sub_type->category_code == e_gras_datadesc_type_cat_array) {
266 /* Damn. Reference to a dynamic array. Allocating the space for it
267 is more complicated */
268 gras_dd_cat_array_t array_data = sub_type->category.array_data;
269 gras_datadesc_type_t subsub_type;
271 subsub_type = array_data.type;
272 subsubcount = array_data.fixed_size;
273 if (subsubcount == 0)
274 subsubcount = array_data.dynamic_size(subsub_type,state,*o_ref);
276 gras_dd_alloc_ref(refs,
277 subsub_type->size[GRAS_THISARCH] * subsubcount,
278 o_ref,pointer_type->size[GRAS_THISARCH],
279 (char**)&l_referenced,
282 gras_dd_alloc_ref(refs,sub_type->size[GRAS_THISARCH],
283 o_ref,pointer_type->size[GRAS_THISARCH],
284 (char**)&l_referenced,
288 count += gras_datadesc_copy_rec(state,refs, sub_type,
289 *o_ref,(char*)l_referenced, subsubcount,
290 detect_cycle || sub_type->cycle);
292 *(void**)dst=l_referenced;
293 VERB3("'%s' previously referenced at %p now at %p",
294 sub_type->name, *(void**)o_ref, l_referenced);
297 VERB2("NOT copying data previously referenced @%p (already done, @%p now)",
298 *(void**)o_ref, *(void**)n_ref);
306 case e_gras_datadesc_type_cat_array: {
307 gras_dd_cat_array_t array_data;
308 long int array_count;
313 array_data = type->category.array_data;
315 /* determine and send the element count */
316 array_count = array_data.fixed_size;
317 if (array_count == 0)
318 array_count = subsize;
319 if (array_count == 0) {
320 array_count = array_data.dynamic_size(type,state,src);
321 xbt_assert1(array_count >=0,
322 "Invalid (negative) array size for type %s",type->name);
325 /* send the content */
326 sub_type = array_data.type;
327 elm_size = sub_type->aligned_size[GRAS_THISARCH];
328 if (sub_type->category_code == e_gras_datadesc_type_cat_scalar) {
329 VERB1("Array of %ld scalars, copy it in one shot",array_count);
330 memcpy(dst, src, sub_type->aligned_size[GRAS_THISARCH] * array_count);
331 count += sub_type->aligned_size[GRAS_THISARCH] * array_count;
332 } else if (sub_type->category_code == e_gras_datadesc_type_cat_array &&
333 sub_type->category.array_data.fixed_size > 0 &&
334 sub_type->category.array_data.type->category_code == e_gras_datadesc_type_cat_scalar) {
336 VERB1("Array of %ld fixed array of scalars, copy it in one shot",
338 memcpy(dst,src,sub_type->category.array_data.type->aligned_size[GRAS_THISARCH]
339 * array_count * sub_type->category.array_data.fixed_size);
340 count += sub_type->category.array_data.type->aligned_size[GRAS_THISARCH]
341 * array_count * sub_type->category.array_data.fixed_size;
344 VERB1("Array of %ld stuff, copy it in one after the other",array_count);
345 for (cpt=0; cpt<array_count; cpt++) {
346 VERB2("Copy the %dth stuff out of %ld",cpt,array_count);
347 count += gras_datadesc_copy_rec(state,refs, sub_type, src_ptr, dst_ptr, 0,
348 detect_cycle || sub_type->cycle);
357 xbt_assert0(0, "Invalid type");
363 * gras_datadesc_copy:
365 * Copy the data pointed by src and described by type
366 * to a new location, and store a pointer to it in dst.
369 int gras_datadesc_copy(gras_datadesc_type_t type,
370 void *src, void *dst) {
372 static gras_cbps_t state=NULL;
373 xbt_dict_t refs; /* all references already sent */
376 xbt_assert0(type,"called with NULL type descriptor");
378 refs = xbt_dict_new();
380 state = gras_cbps_new();
383 size = gras_datadesc_copy_rec(state,refs,type,(char*)src,(char*)dst,0,
386 xbt_dict_free(&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, (int*) &(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_assert0(0, "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 xbt_dict_t refs; /* all references already sent */
615 xbt_assert0(type,"called with NULL type descriptor");
617 refs = xbt_dict_new();
619 state = gras_cbps_new();
622 gras_datadesc_send_rec(sock,state,refs,type,(char*)src, type->cycle);
624 xbt_dict_free(&refs);
625 gras_cbps_reset(state);
632 * gras_datadesc_recv_rec:
634 * Do the data reception job recursively.
636 * subsize used only to deal with vicious case of reference to dynamic array.
637 * This size is needed at the reference reception level (to allocate enough
638 * space) and at the array reception level (to fill enough room).
640 * Having this size passed as an argument of the recursive function is a crude
641 * hack, but I was told that working code is sometimes better than neat one ;)
644 gras_datadesc_recv_rec(gras_socket_t sock,
647 gras_datadesc_type_t type,
656 gras_datadesc_type_t sub_type;
659 VERB2("Recv a %s @%p", type->name, (void*)l_data);
662 switch (type->category_code) {
663 case e_gras_datadesc_type_cat_scalar:
664 if (type->size[GRAS_THISARCH] == type->size[r_arch]) {
665 gras_trp_recv(sock, (char*)l_data, type->size[r_arch]);
666 if (r_arch != GRAS_THISARCH)
667 gras_dd_convert_elm(type,1,r_arch, l_data,l_data);
669 void *ptr = xbt_malloc(type->size[r_arch]);
671 gras_trp_recv(sock, (char*)ptr, type->size[r_arch]);
672 if (r_arch != GRAS_THISARCH)
673 gras_dd_convert_elm(type,1,r_arch, ptr,l_data);
678 case e_gras_datadesc_type_cat_struct: {
679 gras_dd_cat_struct_t struct_data;
680 gras_dd_cat_field_t field;
682 struct_data = type->category.struct_data;
684 xbt_assert1(struct_data.closed,
685 "Please call gras_datadesc_declare_struct_close on %s before receiving it",
687 VERB1(">> Receive all fields of the structure %s",type->name);
688 xbt_dynar_foreach(struct_data.fields, cpt, field) {
689 char *field_data = l_data + field->offset[GRAS_THISARCH];
691 sub_type = field->type;
693 gras_datadesc_recv_rec(sock,state,refs, sub_type,
696 detect_cycle || sub_type->cycle);
699 DEBUG1("Run the reception callback of field %s", field->name);
700 field->recv(type,state,(void*)l_data);
704 VERB1("<< Received all fields of the structure %s", type->name);
709 case e_gras_datadesc_type_cat_union: {
710 gras_dd_cat_union_t union_data;
711 gras_dd_cat_field_t field=NULL;
714 union_data = type->category.union_data;
716 xbt_assert1(union_data.closed,
717 "Please call gras_datadesc_declare_union_close on %s before receiving it",
719 /* retrieve the field number */
720 gras_dd_recv_int(sock, r_arch, &field_num);
722 THROW1(mismatch_error,0,
723 "Received union field for %s is negative", type->name);
724 if (field_num > xbt_dynar_length(union_data.fields))
725 THROW3(mismatch_error,0,
726 "Received union field for %s is said to be #%d but there is only %lu fields",
727 type->name, field_num, xbt_dynar_length(union_data.fields));
729 /* Recv the content */
730 field = xbt_dynar_get_as(union_data.fields, field_num, gras_dd_cat_field_t);
731 sub_type = field->type;
733 gras_datadesc_recv_rec(sock,state,refs, sub_type,
736 detect_cycle || sub_type->cycle);
738 field->recv(type,state,l_data);
743 case e_gras_datadesc_type_cat_ref: {
746 gras_dd_cat_ref_t ref_data;
747 int reference_is_to_recv = 0;
749 ref_data = type->category.ref_data;
751 /* Get the referenced type locally or from peer */
752 sub_type = ref_data.type;
753 if (sub_type == NULL) {
755 gras_dd_recv_int(sock, r_arch, &ref_code);
756 sub_type = gras_datadesc_by_id(ref_code);
759 /* Get the actual value of the pointer for cycle handling */
761 pointer_type = gras_datadesc_by_name("data pointer");
762 xbt_assert(pointer_type);
765 r_ref = xbt_malloc(pointer_type->size[r_arch]);
767 gras_trp_recv(sock, (char*)r_ref,
768 pointer_type->size[r_arch]);
770 /* Receive the pointed data only if not already sent */
771 if (gras_dd_is_r_null(r_ref, pointer_type->size[r_arch])) {
772 VERB1("Not receiving data remotely referenced @%p since it's NULL",
774 *(void**)l_data = NULL;
779 reference_is_to_recv = 0;
782 l_ref = xbt_dict_get_ext(refs, (char*)r_ref, pointer_type->size[r_arch]);
784 reference_is_to_recv = 1;
787 if (e.category != not_found_error)
789 reference_is_to_recv = 1;
793 if (reference_is_to_recv) {
795 void *l_referenced=NULL;
797 VERB2("Receiving a ref to '%s', remotely @%p",
798 sub_type->name, *(void**)r_ref);
799 if (sub_type->category_code == e_gras_datadesc_type_cat_array) {
800 /* Damn. Reference to a dynamic array. Allocating the space for it
801 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 == 0)
807 gras_dd_recv_int(sock, r_arch, &subsubcount);
809 subsub_type = array_data.type;
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,
818 gras_dd_alloc_ref(refs,sub_type->size[GRAS_THISARCH],
819 r_ref,pointer_type->size[r_arch],
820 (char**)&l_referenced,
824 gras_datadesc_recv_rec(sock,state,refs, sub_type,
825 r_arch,r_ref,pointer_type->size[r_arch],
826 (char*)l_referenced, subsubcount,
827 detect_cycle || sub_type->cycle);
829 *(void**)l_data=l_referenced;
830 VERB3("'%s' remotely referenced at %p locally at %p",
831 sub_type->name, *(void**)r_ref, l_referenced);
834 VERB2("NOT receiving data remotely referenced @%p (already done, @%p here)",
835 *(void**)r_ref, *(void**)l_ref);
837 *(void**)l_data=*l_ref;
844 case e_gras_datadesc_type_cat_array: {
845 gras_dd_cat_array_t array_data;
850 array_data = type->category.array_data;
851 /* determine element count locally, or from caller, or from peer */
852 count = array_data.fixed_size;
856 gras_dd_recv_int(sock, r_arch, &count);
858 THROW1(mismatch_error,0,
859 "Invalid (=0) array size for type %s",type->name);
861 /* receive the content */
862 sub_type = array_data.type;
863 if (sub_type->category_code == e_gras_datadesc_type_cat_scalar) {
864 VERB1("Array of %d scalars, get it in one shoot", count);
865 if (sub_type->aligned_size[GRAS_THISARCH] >=
866 sub_type->aligned_size[r_arch]) {
867 gras_trp_recv(sock, (char*)l_data,
868 sub_type->aligned_size[r_arch] * count);
869 if (r_arch != GRAS_THISARCH)
870 gras_dd_convert_elm(sub_type,count,r_arch, l_data,l_data);
872 ptr = xbt_malloc(sub_type->aligned_size[r_arch] * count);
874 gras_trp_recv(sock, (char*)ptr,
875 sub_type->size[r_arch] * count);
876 if (r_arch != GRAS_THISARCH)
877 gras_dd_convert_elm(sub_type,count,r_arch, ptr,l_data);
880 } else if (sub_type->category_code == e_gras_datadesc_type_cat_array &&
881 sub_type->category.array_data.fixed_size > 0 &&
882 sub_type->category.array_data.type->category_code == e_gras_datadesc_type_cat_scalar) {
883 gras_datadesc_type_t subsub_type;
884 array_data = sub_type->category.array_data;
885 subsub_type = array_data.type;
887 VERB1("Array of %d fixed array of scalars, get it in one shot",count);
888 if (subsub_type->aligned_size[GRAS_THISARCH] >=
889 subsub_type->aligned_size[r_arch]) {
890 gras_trp_recv(sock, (char*)l_data,
891 subsub_type->aligned_size[r_arch] * count *
892 array_data.fixed_size);
893 if (r_arch != GRAS_THISARCH)
894 gras_dd_convert_elm(subsub_type,count*array_data.fixed_size,r_arch, l_data,l_data);
896 ptr = xbt_malloc(subsub_type->aligned_size[r_arch] * count*array_data.fixed_size);
898 gras_trp_recv(sock, (char*)ptr,
899 subsub_type->size[r_arch] * count*array_data.fixed_size);
900 if (r_arch != GRAS_THISARCH)
901 gras_dd_convert_elm(subsub_type,count*array_data.fixed_size,r_arch, ptr,l_data);
907 /* not scalar content, get it recursively (may contain pointers) */
908 elm_size = sub_type->aligned_size[GRAS_THISARCH];
909 VERB2("Receive a %d-long array of %s",count, sub_type->name);
912 for (cpt=0; cpt<count; cpt++) {
913 gras_datadesc_recv_rec(sock,state,refs, sub_type,
914 r_arch, NULL, 0, ptr,-1,
915 detect_cycle || sub_type->cycle);
924 xbt_assert0(0, "Invalid type");
928 type->recv(type,state,l_data);
930 if (!strcmp(type->name,"string"))
931 VERB1("value: '%s'",*(char**)l_data);
936 * gras_datadesc_recv:
938 * Get an instance of the datatype described by @type from the @socket,
939 * and store a pointer to it in @dst
943 gras_datadesc_recv(gras_socket_t sock,
944 gras_datadesc_type_t type,
949 static gras_cbps_t state=NULL; /* callback persistent state */
950 xbt_dict_t refs; /* all references already sent */
952 refs = xbt_dict_new();
954 state = gras_cbps_new();
956 xbt_assert0(type,"called with NULL type descriptor");
958 gras_datadesc_recv_rec(sock, state, refs, type,
963 xbt_dict_free(&refs);
964 gras_cbps_reset(state);