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 DEBUG1("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_verbose)) {
162 if (sub_type == gras_datadesc_by_name("unsigned int")) {
163 VERB2("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 VERB2("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 VERB2("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 VERB2("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 VERB2("Copied value for field %s: '%s' (type: string)", field->name, *(char**)field_dst);
175 VERB1("Copied a value for field %s (type not scalar?)", field->name);
180 VERB1("<< Copied all fields of the structure %s", type->name);
185 case e_gras_datadesc_type_cat_union: {
186 gras_dd_cat_union_t union_data;
187 gras_dd_cat_field_t field=NULL;
190 union_data = type->category.union_data;
192 xbt_assert1(union_data.closed,
193 "Please call gras_datadesc_declare_union_close on %s before copying it",
195 /* retrieve the field number */
196 field_num = union_data.selector(type, state, src);
198 xbt_assert1(field_num > 0,
199 "union field selector of %s gave a negative value",
202 xbt_assert3(field_num < xbt_dynar_length(union_data.fields),
203 "union field selector of %s returned %d but there is only %lu fields",
204 type->name, field_num, xbt_dynar_length(union_data.fields));
206 /* Copy the content */
207 field = xbt_dynar_get_as(union_data.fields, field_num, gras_dd_cat_field_t);
208 sub_type = field->type;
211 field->send(type,state,src);
213 count += gras_datadesc_copy_rec(state,refs, sub_type, src, dst,0,
214 detect_cycle || sub_type->cycle);
219 case e_gras_datadesc_type_cat_ref: {
220 gras_dd_cat_ref_t ref_data;
223 int reference_is_to_cpy;
225 ref_data = type->category.ref_data;
227 /* Detect the referenced type */
228 sub_type = ref_data.type;
229 if (sub_type == NULL) {
230 sub_type = (*ref_data.selector)(type,state,src);
233 /* Send the pointed data only if not already sent */
234 if (*(void**)src == NULL) {
235 VERB0("Not copying NULL referenced data");
241 reference_is_to_cpy = 0;
244 /* return ignored. Just checking whether it's known or not */
245 n_ref=xbt_dict_get_ext(refs,(char*)o_ref, sizeof(char*));
247 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) {
373 xbt_dict_t refs; /* all references already sent */
376 xbt_assert0(type,"called with NULL type descriptor");
378 refs = xbt_dict_new();
379 state = gras_cbps_new();
382 size = gras_datadesc_copy_rec(state,refs,type,(char*)src,(char*)dst,0,
385 xbt_dict_free(&refs);
386 gras_cbps_free(&state);
394 *** Direct use functions
398 gras_datadesc_send_rec(gras_socket_t sock,
401 gras_datadesc_type_t type,
407 gras_datadesc_type_t sub_type; /* type on which we recurse */
409 VERB2("Send a %s (%s)",
410 type->name, gras_datadesc_cat_names[type->category_code]);
412 if (!strcmp(type->name,"string"))
413 VERB1("value: '%s'",*(char**)data);
416 type->send(type,state,data);
417 DEBUG0("Run the emission callback");
420 switch (type->category_code) {
421 case e_gras_datadesc_type_cat_scalar:
422 gras_trp_send(sock, data, type->size[GRAS_THISARCH], 1);
425 case e_gras_datadesc_type_cat_struct: {
426 gras_dd_cat_struct_t struct_data;
427 gras_dd_cat_field_t field;
430 struct_data = type->category.struct_data;
431 xbt_assert1(struct_data.closed,
432 "Please call gras_datadesc_declare_struct_close on %s before sending it",
434 VERB1(">> Send all fields of the structure %s",type->name);
435 xbt_dynar_foreach(struct_data.fields, cpt, field) {
437 field_data += field->offset[GRAS_THISARCH];
439 sub_type = field->type;
442 DEBUG1("Run the emission callback of field %s", field->name);
443 field->send(type,state,field_data);
446 VERB1("Send field %s",field->name);
447 gras_datadesc_send_rec(sock,state,refs,sub_type, field_data,
448 detect_cycle || sub_type->cycle);
451 VERB1("<< Sent all fields of the structure %s", type->name);
456 case e_gras_datadesc_type_cat_union: {
457 gras_dd_cat_union_t union_data;
458 gras_dd_cat_field_t field=NULL;
461 union_data = type->category.union_data;
463 xbt_assert1(union_data.closed,
464 "Please call gras_datadesc_declare_union_close on %s before sending it",
466 /* retrieve the field number */
467 field_num = union_data.selector(type, state, data);
469 xbt_assert1(field_num > 0,
470 "union field selector of %s gave a negative value",
473 xbt_assert3(field_num < xbt_dynar_length(union_data.fields),
474 "union field selector of %s returned %d but there is only %lu fields",
475 type->name, field_num, xbt_dynar_length(union_data.fields));
477 /* Send the field number */
478 gras_dd_send_int(sock, &field_num, 0 /* not stable */);
480 /* Send the content */
481 field = xbt_dynar_get_as(union_data.fields, field_num, gras_dd_cat_field_t);
482 sub_type = field->type;
485 field->send(type,state,data);
487 gras_datadesc_send_rec(sock,state,refs, sub_type, data,
488 detect_cycle || sub_type->cycle);
493 case e_gras_datadesc_type_cat_ref: {
494 gras_dd_cat_ref_t ref_data;
495 void **ref=(void**)data;
496 int reference_is_to_send;
498 ref_data = type->category.ref_data;
500 /* Detect the referenced type and send it to peer if needed */
501 sub_type = ref_data.type;
502 if (sub_type == NULL) {
503 sub_type = (*ref_data.selector)(type,state,data);
504 gras_dd_send_int(sock, (int*) &(sub_type->code),1 /*stable*/);
507 /* Send the actual value of the pointer for cycle handling */
509 pointer_type = gras_datadesc_by_name("data pointer");
510 xbt_assert(pointer_type);
513 gras_trp_send(sock, (char*)data,
514 pointer_type->size[GRAS_THISARCH], 1 /*stable*/);
516 /* Send the pointed data only if not already sent */
517 if (*(void**)data == NULL) {
518 VERB0("Not sending NULL referenced data");
522 reference_is_to_send = 0;
525 /* return ignored. Just checking whether it's known or not */
526 xbt_dict_get_ext(refs,(char*)ref, sizeof(char*));
528 reference_is_to_send = 1;
530 if (e.category != not_found_error)
532 reference_is_to_send = 1;
536 if (reference_is_to_send) {
537 VERB1("Sending data referenced at %p", (void*)*ref);
539 xbt_dict_set_ext(refs, (char*)ref, sizeof(void*), ref, NULL);
540 gras_datadesc_send_rec(sock,state,refs, sub_type, *ref,
541 detect_cycle || sub_type->cycle);
544 VERB1("Not sending data referenced at %p (already done)", (void*)*ref);
550 case e_gras_datadesc_type_cat_array: {
551 gras_dd_cat_array_t array_data;
556 array_data = type->category.array_data;
558 /* determine and send the element count */
559 count = array_data.fixed_size;
561 count = array_data.dynamic_size(type,state,data);
562 xbt_assert1(count >=0,
563 "Invalid (negative) array size for type %s",type->name);
564 gras_dd_send_int(sock, &count, 0/*non-stable*/);
567 /* send the content */
568 sub_type = array_data.type;
569 elm_size = sub_type->aligned_size[GRAS_THISARCH];
570 if (sub_type->category_code == e_gras_datadesc_type_cat_scalar) {
571 VERB1("Array of %d scalars, send it in one shot",count);
572 gras_trp_send(sock, data,
573 sub_type->aligned_size[GRAS_THISARCH] * count,
575 } else if (sub_type->category_code == e_gras_datadesc_type_cat_array &&
576 sub_type->category.array_data.fixed_size > 0 &&
577 sub_type->category.array_data.type->category_code == e_gras_datadesc_type_cat_scalar) {
579 VERB1("Array of %d fixed array of scalars, send it in one shot",count);
580 gras_trp_send(sock, data,
581 sub_type->category.array_data.type->aligned_size[GRAS_THISARCH]
582 * count * sub_type->category.array_data.fixed_size,
586 for (cpt=0; cpt<count; cpt++) {
587 gras_datadesc_send_rec(sock,state,refs, sub_type, ptr,
588 detect_cycle || sub_type->cycle);
596 xbt_assert0(0, "Invalid type");
601 * gras_datadesc_send:
603 * Copy the data pointed by src and described by type to the socket
606 void gras_datadesc_send(gras_socket_t sock,
607 gras_datadesc_type_t type,
611 static gras_cbps_t state=NULL;
612 xbt_dict_t refs; /* all references already sent */
614 xbt_assert0(type,"called with NULL type descriptor");
616 refs = xbt_dict_new();
618 state = gras_cbps_new();
621 gras_datadesc_send_rec(sock,state,refs,type,(char*)src, type->cycle);
623 xbt_dict_free(&refs);
624 gras_cbps_reset(state);
631 * gras_datadesc_recv_rec:
633 * Do the data reception job recursively.
635 * subsize used only to deal with vicious case of reference to dynamic array.
636 * This size is needed at the reference reception level (to allocate enough
637 * space) and at the array reception level (to fill enough room).
639 * Having this size passed as an argument of the recursive function is a crude
640 * hack, but I was told that working code is sometimes better than neat one ;)
643 gras_datadesc_recv_rec(gras_socket_t sock,
646 gras_datadesc_type_t type,
655 gras_datadesc_type_t sub_type;
658 VERB2("Recv a %s @%p", type->name, (void*)l_data);
661 switch (type->category_code) {
662 case e_gras_datadesc_type_cat_scalar:
663 if (type->size[GRAS_THISARCH] == type->size[r_arch]) {
664 gras_trp_recv(sock, (char*)l_data, type->size[r_arch]);
665 if (r_arch != GRAS_THISARCH)
666 gras_dd_convert_elm(type,1,r_arch, l_data,l_data);
668 void *ptr = xbt_malloc(type->size[r_arch]);
670 gras_trp_recv(sock, (char*)ptr, type->size[r_arch]);
671 if (r_arch != GRAS_THISARCH)
672 gras_dd_convert_elm(type,1,r_arch, ptr,l_data);
677 case e_gras_datadesc_type_cat_struct: {
678 gras_dd_cat_struct_t struct_data;
679 gras_dd_cat_field_t field;
681 struct_data = type->category.struct_data;
683 xbt_assert1(struct_data.closed,
684 "Please call gras_datadesc_declare_struct_close on %s before receiving it",
686 VERB1(">> Receive all fields of the structure %s",type->name);
687 xbt_dynar_foreach(struct_data.fields, cpt, field) {
688 char *field_data = l_data + field->offset[GRAS_THISARCH];
690 sub_type = field->type;
692 gras_datadesc_recv_rec(sock,state,refs, sub_type,
695 detect_cycle || sub_type->cycle);
698 DEBUG1("Run the reception callback of field %s", field->name);
699 field->recv(type,state,(void*)l_data);
703 VERB1("<< Received all fields of the structure %s", type->name);
708 case e_gras_datadesc_type_cat_union: {
709 gras_dd_cat_union_t union_data;
710 gras_dd_cat_field_t field=NULL;
713 union_data = type->category.union_data;
715 xbt_assert1(union_data.closed,
716 "Please call gras_datadesc_declare_union_close on %s before receiving it",
718 /* retrieve the field number */
719 gras_dd_recv_int(sock, r_arch, &field_num);
721 THROW1(mismatch_error,0,
722 "Received union field for %s is negative", type->name);
723 if (field_num > xbt_dynar_length(union_data.fields))
724 THROW3(mismatch_error,0,
725 "Received union field for %s is said to be #%d but there is only %lu fields",
726 type->name, field_num, xbt_dynar_length(union_data.fields));
728 /* Recv the content */
729 field = xbt_dynar_get_as(union_data.fields, field_num, gras_dd_cat_field_t);
730 sub_type = field->type;
732 gras_datadesc_recv_rec(sock,state,refs, sub_type,
735 detect_cycle || sub_type->cycle);
737 field->recv(type,state,l_data);
742 case e_gras_datadesc_type_cat_ref: {
745 gras_dd_cat_ref_t ref_data;
746 int reference_is_to_recv = 0;
748 ref_data = type->category.ref_data;
750 /* Get the referenced type locally or from peer */
751 sub_type = ref_data.type;
752 if (sub_type == NULL) {
754 gras_dd_recv_int(sock, r_arch, &ref_code);
755 sub_type = gras_datadesc_by_id(ref_code);
758 /* Get the actual value of the pointer for cycle handling */
760 pointer_type = gras_datadesc_by_name("data pointer");
761 xbt_assert(pointer_type);
764 r_ref = xbt_malloc(pointer_type->size[r_arch]);
766 gras_trp_recv(sock, (char*)r_ref,
767 pointer_type->size[r_arch]);
769 /* Receive the pointed data only if not already sent */
770 if (gras_dd_is_r_null(r_ref, pointer_type->size[r_arch])) {
771 VERB1("Not receiving data remotely referenced @%p since it's NULL",
773 *(void**)l_data = NULL;
778 reference_is_to_recv = 0;
781 l_ref = xbt_dict_get_ext(refs, (char*)r_ref, pointer_type->size[r_arch]);
783 reference_is_to_recv = 1;
785 if (e.category != not_found_error)
787 reference_is_to_recv = 1;
790 if (reference_is_to_recv) {
792 void *l_referenced=NULL;
794 VERB2("Receiving a ref to '%s', remotely @%p",
795 sub_type->name, *(void**)r_ref);
796 if (sub_type->category_code == e_gras_datadesc_type_cat_array) {
797 /* Damn. Reference to a dynamic array. Allocating the space for it
798 is more complicated */
799 gras_dd_cat_array_t array_data = sub_type->category.array_data;
800 gras_datadesc_type_t subsub_type;
802 subsubcount = array_data.fixed_size;
803 if (subsubcount == 0)
804 gras_dd_recv_int(sock, r_arch, &subsubcount);
806 subsub_type = array_data.type;
809 gras_dd_alloc_ref(refs,
810 subsub_type->size[GRAS_THISARCH] * subsubcount,
811 r_ref,pointer_type->size[r_arch],
812 (char**)&l_referenced,
815 gras_dd_alloc_ref(refs,sub_type->size[GRAS_THISARCH],
816 r_ref,pointer_type->size[r_arch],
817 (char**)&l_referenced,
821 gras_datadesc_recv_rec(sock,state,refs, sub_type,
822 r_arch,r_ref,pointer_type->size[r_arch],
823 (char*)l_referenced, subsubcount,
824 detect_cycle || sub_type->cycle);
826 *(void**)l_data=l_referenced;
827 VERB3("'%s' remotely referenced at %p locally at %p",
828 sub_type->name, *(void**)r_ref, l_referenced);
831 VERB2("NOT receiving data remotely referenced @%p (already done, @%p here)",
832 *(void**)r_ref, *(void**)l_ref);
834 *(void**)l_data=*l_ref;
841 case e_gras_datadesc_type_cat_array: {
842 gras_dd_cat_array_t array_data;
847 array_data = type->category.array_data;
848 /* determine element count locally, or from caller, or from peer */
849 count = array_data.fixed_size;
853 gras_dd_recv_int(sock, r_arch, &count);
855 THROW1(mismatch_error,0,
856 "Invalid (=0) array size for type %s",type->name);
858 /* receive the content */
859 sub_type = array_data.type;
860 if (sub_type->category_code == e_gras_datadesc_type_cat_scalar) {
861 VERB1("Array of %d scalars, get it in one shoot", count);
862 if (sub_type->aligned_size[GRAS_THISARCH] >=
863 sub_type->aligned_size[r_arch]) {
864 gras_trp_recv(sock, (char*)l_data,
865 sub_type->aligned_size[r_arch] * count);
866 if (r_arch != GRAS_THISARCH)
867 gras_dd_convert_elm(sub_type,count,r_arch, l_data,l_data);
869 ptr = xbt_malloc(sub_type->aligned_size[r_arch] * count);
871 gras_trp_recv(sock, (char*)ptr,
872 sub_type->size[r_arch] * count);
873 if (r_arch != GRAS_THISARCH)
874 gras_dd_convert_elm(sub_type,count,r_arch, ptr,l_data);
877 } else if (sub_type->category_code == e_gras_datadesc_type_cat_array &&
878 sub_type->category.array_data.fixed_size > 0 &&
879 sub_type->category.array_data.type->category_code == e_gras_datadesc_type_cat_scalar) {
880 gras_datadesc_type_t subsub_type;
881 array_data = sub_type->category.array_data;
882 subsub_type = array_data.type;
884 VERB1("Array of %d fixed array of scalars, get it in one shot",count);
885 if (subsub_type->aligned_size[GRAS_THISARCH] >=
886 subsub_type->aligned_size[r_arch]) {
887 gras_trp_recv(sock, (char*)l_data,
888 subsub_type->aligned_size[r_arch] * count *
889 array_data.fixed_size);
890 if (r_arch != GRAS_THISARCH)
891 gras_dd_convert_elm(subsub_type,count*array_data.fixed_size,r_arch, l_data,l_data);
893 ptr = xbt_malloc(subsub_type->aligned_size[r_arch] * count*array_data.fixed_size);
895 gras_trp_recv(sock, (char*)ptr,
896 subsub_type->size[r_arch] * count*array_data.fixed_size);
897 if (r_arch != GRAS_THISARCH)
898 gras_dd_convert_elm(subsub_type,count*array_data.fixed_size,r_arch, ptr,l_data);
904 /* not scalar content, get it recursively (may contain pointers) */
905 elm_size = sub_type->aligned_size[GRAS_THISARCH];
906 VERB2("Receive a %d-long array of %s",count, sub_type->name);
909 for (cpt=0; cpt<count; cpt++) {
910 gras_datadesc_recv_rec(sock,state,refs, sub_type,
911 r_arch, NULL, 0, ptr,-1,
912 detect_cycle || sub_type->cycle);
921 xbt_assert0(0, "Invalid type");
925 type->recv(type,state,l_data);
927 if (!strcmp(type->name,"string"))
928 VERB1("value: '%s'",*(char**)l_data);
933 * gras_datadesc_recv:
935 * Get an instance of the datatype described by @type from the @socket,
936 * and store a pointer to it in @dst
940 gras_datadesc_recv(gras_socket_t sock,
941 gras_datadesc_type_t type,
946 static gras_cbps_t state=NULL; /* callback persistent state */
947 xbt_dict_t refs; /* all references already sent */
949 refs = xbt_dict_new();
951 state = gras_cbps_new();
953 xbt_assert0(type,"called with NULL type descriptor");
955 gras_datadesc_recv_rec(sock, state, refs, type,
960 xbt_dict_free(&refs);
961 gras_cbps_reset(state);