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?
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, xbt_free_f);
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 static xbt_dict_t refs=NULL; /* all references already sent */
376 xbt_assert0(type,"called with NULL type descriptor");
379 state = gras_cbps_new();
380 refs = xbt_dict_new();
384 size = gras_datadesc_copy_rec(state,refs,type,(char*)src,(char*)dst,0,
387 xbt_dict_reset(refs);
388 gras_cbps_reset(state);
396 *** Direct use functions
400 gras_datadesc_send_rec(gras_socket_t sock,
403 gras_datadesc_type_t type,
409 gras_datadesc_type_t sub_type; /* type on which we recurse */
411 VERB2("Send a %s (%s)",
412 type->name, gras_datadesc_cat_names[type->category_code]);
414 if (!strcmp(type->name,"string"))
415 VERB1("value: '%s'",*(char**)data);
418 type->send(type,state,data);
419 DEBUG0("Run the emission callback");
422 switch (type->category_code) {
423 case e_gras_datadesc_type_cat_scalar:
424 gras_trp_send(sock, data, type->size[GRAS_THISARCH], 1);
427 case e_gras_datadesc_type_cat_struct: {
428 gras_dd_cat_struct_t struct_data;
429 gras_dd_cat_field_t field;
432 struct_data = type->category.struct_data;
433 xbt_assert1(struct_data.closed,
434 "Please call gras_datadesc_declare_struct_close on %s before sending it",
436 VERB1(">> Send all fields of the structure %s",type->name);
437 xbt_dynar_foreach(struct_data.fields, cpt, field) {
439 field_data += field->offset[GRAS_THISARCH];
441 sub_type = field->type;
444 DEBUG1("Run the emission callback of field %s", field->name);
445 field->send(type,state,field_data);
448 VERB1("Send field %s",field->name);
449 gras_datadesc_send_rec(sock,state,refs,sub_type, field_data,
450 detect_cycle || sub_type->cycle);
453 VERB1("<< Sent all fields of the structure %s", type->name);
458 case e_gras_datadesc_type_cat_union: {
459 gras_dd_cat_union_t union_data;
460 gras_dd_cat_field_t field=NULL;
463 union_data = type->category.union_data;
465 xbt_assert1(union_data.closed,
466 "Please call gras_datadesc_declare_union_close on %s before sending it",
468 /* retrieve the field number */
469 field_num = union_data.selector(type, state, data);
471 xbt_assert1(field_num > 0,
472 "union field selector of %s gave a negative value",
475 xbt_assert3(field_num < xbt_dynar_length(union_data.fields),
476 "union field selector of %s returned %d but there is only %lu fields",
477 type->name, field_num, xbt_dynar_length(union_data.fields));
479 /* Send the field number */
480 gras_dd_send_int(sock, &field_num, 0 /* not stable */);
482 /* Send the content */
483 field = xbt_dynar_get_as(union_data.fields, field_num, gras_dd_cat_field_t);
484 sub_type = field->type;
487 field->send(type,state,data);
489 gras_datadesc_send_rec(sock,state,refs, sub_type, data,
490 detect_cycle || sub_type->cycle);
495 case e_gras_datadesc_type_cat_ref: {
496 gras_dd_cat_ref_t ref_data;
497 void **ref=(void**)data;
498 int reference_is_to_send;
500 ref_data = type->category.ref_data;
502 /* Detect the referenced type and send it to peer if needed */
503 sub_type = ref_data.type;
504 if (sub_type == NULL) {
505 sub_type = (*ref_data.selector)(type,state,data);
506 gras_dd_send_int(sock, (int*) &(sub_type->code),1 /*stable*/);
509 /* Send the actual value of the pointer for cycle handling */
511 pointer_type = gras_datadesc_by_name("data pointer");
512 xbt_assert(pointer_type);
515 gras_trp_send(sock, (char*)data,
516 pointer_type->size[GRAS_THISARCH], 1 /*stable*/);
518 /* Send the pointed data only if not already sent */
519 if (*(void**)data == NULL) {
520 VERB0("Not sending NULL referenced data");
524 reference_is_to_send = 0;
527 /* return ignored. Just checking whether it's known or not */
528 xbt_dict_get_ext(refs,(char*)ref, sizeof(char*));
530 reference_is_to_send = 1;
532 if (e.category != not_found_error)
534 reference_is_to_send = 1;
538 if (reference_is_to_send) {
539 VERB1("Sending data referenced at %p", (void*)*ref);
541 xbt_dict_set_ext(refs, (char*)ref, sizeof(void*), ref, NULL);
542 gras_datadesc_send_rec(sock,state,refs, sub_type, *ref,
543 detect_cycle || sub_type->cycle);
546 VERB1("Not sending data referenced at %p (already done)", (void*)*ref);
552 case e_gras_datadesc_type_cat_array: {
553 gras_dd_cat_array_t array_data;
558 array_data = type->category.array_data;
560 /* determine and send the element count */
561 count = array_data.fixed_size;
563 count = array_data.dynamic_size(type,state,data);
564 xbt_assert1(count >=0,
565 "Invalid (negative) array size for type %s",type->name);
566 gras_dd_send_int(sock, &count, 0/*non-stable*/);
569 /* send the content */
570 sub_type = array_data.type;
571 elm_size = sub_type->aligned_size[GRAS_THISARCH];
572 if (sub_type->category_code == e_gras_datadesc_type_cat_scalar) {
573 VERB1("Array of %d scalars, send it in one shot",count);
574 gras_trp_send(sock, data,
575 sub_type->aligned_size[GRAS_THISARCH] * count,
577 } else if (sub_type->category_code == e_gras_datadesc_type_cat_array &&
578 sub_type->category.array_data.fixed_size > 0 &&
579 sub_type->category.array_data.type->category_code == e_gras_datadesc_type_cat_scalar) {
581 VERB1("Array of %d fixed array of scalars, send it in one shot",count);
582 gras_trp_send(sock, data,
583 sub_type->category.array_data.type->aligned_size[GRAS_THISARCH]
584 * count * sub_type->category.array_data.fixed_size,
588 for (cpt=0; cpt<count; cpt++) {
589 gras_datadesc_send_rec(sock,state,refs, sub_type, ptr,
590 detect_cycle || sub_type->cycle);
598 xbt_assert0(0, "Invalid type");
603 * gras_datadesc_send:
605 * Copy the data pointed by src and described by type to the socket
608 void gras_datadesc_send(gras_socket_t sock,
609 gras_datadesc_type_t type,
613 static gras_cbps_t state=NULL;
614 static xbt_dict_t refs=NULL; /* all references already sent */
616 xbt_assert0(type,"called with NULL type descriptor");
619 state = gras_cbps_new();
620 refs = xbt_dict_new();
624 gras_datadesc_send_rec(sock,state,refs,type,(char*)src, type->cycle);
626 xbt_dict_reset(refs);
627 gras_cbps_reset(state);
634 * gras_datadesc_recv_rec:
636 * Do the data reception job recursively.
638 * subsize used only to deal with vicious case of reference to dynamic array.
639 * This size is needed at the reference reception level (to allocate enough
640 * space) and at the array reception level (to fill enough room).
642 * Having this size passed as an argument of the recursive function is a crude
643 * hack, but I was told that working code is sometimes better than neat one ;)
646 gras_datadesc_recv_rec(gras_socket_t sock,
649 gras_datadesc_type_t type,
658 gras_datadesc_type_t sub_type;
661 VERB2("Recv a %s @%p", type->name, (void*)l_data);
664 switch (type->category_code) {
665 case e_gras_datadesc_type_cat_scalar:
666 if (type->size[GRAS_THISARCH] == type->size[r_arch]) {
667 gras_trp_recv(sock, (char*)l_data, type->size[r_arch]);
668 if (r_arch != GRAS_THISARCH)
669 gras_dd_convert_elm(type,1,r_arch, l_data,l_data);
671 void *ptr = xbt_malloc(type->size[r_arch]);
673 gras_trp_recv(sock, (char*)ptr, type->size[r_arch]);
674 if (r_arch != GRAS_THISARCH)
675 gras_dd_convert_elm(type,1,r_arch, ptr,l_data);
680 case e_gras_datadesc_type_cat_struct: {
681 gras_dd_cat_struct_t struct_data;
682 gras_dd_cat_field_t field;
684 struct_data = type->category.struct_data;
686 xbt_assert1(struct_data.closed,
687 "Please call gras_datadesc_declare_struct_close on %s before receiving it",
689 VERB1(">> Receive all fields of the structure %s",type->name);
690 xbt_dynar_foreach(struct_data.fields, cpt, field) {
691 char *field_data = l_data + field->offset[GRAS_THISARCH];
693 sub_type = field->type;
695 gras_datadesc_recv_rec(sock,state,refs, sub_type,
698 detect_cycle || sub_type->cycle);
701 DEBUG1("Run the reception callback of field %s", field->name);
702 field->recv(type,state,(void*)l_data);
706 VERB1("<< Received all fields of the structure %s", type->name);
711 case e_gras_datadesc_type_cat_union: {
712 gras_dd_cat_union_t union_data;
713 gras_dd_cat_field_t field=NULL;
716 union_data = type->category.union_data;
718 xbt_assert1(union_data.closed,
719 "Please call gras_datadesc_declare_union_close on %s before receiving it",
721 /* retrieve the field number */
722 gras_dd_recv_int(sock, r_arch, &field_num);
724 THROW1(mismatch_error,0,
725 "Received union field for %s is negative", type->name);
726 if (field_num > xbt_dynar_length(union_data.fields))
727 THROW3(mismatch_error,0,
728 "Received union field for %s is said to be #%d but there is only %lu fields",
729 type->name, field_num, xbt_dynar_length(union_data.fields));
731 /* Recv the content */
732 field = xbt_dynar_get_as(union_data.fields, field_num, gras_dd_cat_field_t);
733 sub_type = field->type;
735 gras_datadesc_recv_rec(sock,state,refs, sub_type,
738 detect_cycle || sub_type->cycle);
740 field->recv(type,state,l_data);
745 case e_gras_datadesc_type_cat_ref: {
748 gras_dd_cat_ref_t ref_data;
749 int reference_is_to_recv = 0;
751 ref_data = type->category.ref_data;
753 /* Get the referenced type locally or from peer */
754 sub_type = ref_data.type;
755 if (sub_type == NULL) {
757 gras_dd_recv_int(sock, r_arch, &ref_code);
758 sub_type = gras_datadesc_by_id(ref_code);
761 /* Get the actual value of the pointer for cycle handling */
763 pointer_type = gras_datadesc_by_name("data pointer");
764 xbt_assert(pointer_type);
767 r_ref = xbt_malloc(pointer_type->size[r_arch]);
769 gras_trp_recv(sock, (char*)r_ref,
770 pointer_type->size[r_arch]);
772 /* Receive the pointed data only if not already sent */
773 if (gras_dd_is_r_null(r_ref, pointer_type->size[r_arch])) {
774 VERB1("Not receiving data remotely referenced @%p since it's NULL",
776 *(void**)l_data = NULL;
781 reference_is_to_recv = 0;
784 l_ref = xbt_dict_get_ext(refs, (char*)r_ref, pointer_type->size[r_arch]);
786 reference_is_to_recv = 1;
789 if (e.category != not_found_error)
791 reference_is_to_recv = 1;
795 if (reference_is_to_recv) {
797 void *l_referenced=NULL;
799 VERB2("Receiving a ref to '%s', remotely @%p",
800 sub_type->name, *(void**)r_ref);
801 if (sub_type->category_code == e_gras_datadesc_type_cat_array) {
802 /* Damn. Reference to a dynamic array. Allocating the space for it
803 is more complicated */
804 gras_dd_cat_array_t array_data = sub_type->category.array_data;
805 gras_datadesc_type_t subsub_type;
807 subsubcount = array_data.fixed_size;
808 if (subsubcount == 0)
809 gras_dd_recv_int(sock, r_arch, &subsubcount);
811 subsub_type = array_data.type;
814 gras_dd_alloc_ref(refs,
815 subsub_type->size[GRAS_THISARCH] * subsubcount,
816 r_ref,pointer_type->size[r_arch],
817 (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 gras_datadesc_recv_rec(sock,state,refs, sub_type,
827 r_arch,r_ref,pointer_type->size[r_arch],
828 (char*)l_referenced, subsubcount,
829 detect_cycle || sub_type->cycle);
831 *(void**)l_data=l_referenced;
832 VERB3("'%s' remotely referenced at %p locally at %p",
833 sub_type->name, *(void**)r_ref, l_referenced);
836 VERB2("NOT receiving data remotely referenced @%p (already done, @%p here)",
837 *(void**)r_ref, *(void**)l_ref);
839 *(void**)l_data=*l_ref;
846 case e_gras_datadesc_type_cat_array: {
847 gras_dd_cat_array_t array_data;
852 array_data = type->category.array_data;
853 /* determine element count locally, or from caller, or from peer */
854 count = array_data.fixed_size;
858 gras_dd_recv_int(sock, r_arch, &count);
860 THROW1(mismatch_error,0,
861 "Invalid (=0) array size for type %s",type->name);
863 /* receive the content */
864 sub_type = array_data.type;
865 if (sub_type->category_code == e_gras_datadesc_type_cat_scalar) {
866 VERB1("Array of %d scalars, get it in one shoot", count);
867 if (sub_type->aligned_size[GRAS_THISARCH] >=
868 sub_type->aligned_size[r_arch]) {
869 gras_trp_recv(sock, (char*)l_data,
870 sub_type->aligned_size[r_arch] * count);
871 if (r_arch != GRAS_THISARCH)
872 gras_dd_convert_elm(sub_type,count,r_arch, l_data,l_data);
874 ptr = xbt_malloc(sub_type->aligned_size[r_arch] * count);
876 gras_trp_recv(sock, (char*)ptr,
877 sub_type->size[r_arch] * count);
878 if (r_arch != GRAS_THISARCH)
879 gras_dd_convert_elm(sub_type,count,r_arch, ptr,l_data);
882 } else if (sub_type->category_code == e_gras_datadesc_type_cat_array &&
883 sub_type->category.array_data.fixed_size > 0 &&
884 sub_type->category.array_data.type->category_code == e_gras_datadesc_type_cat_scalar) {
885 gras_datadesc_type_t subsub_type;
886 array_data = sub_type->category.array_data;
887 subsub_type = array_data.type;
889 VERB1("Array of %d fixed array of scalars, get it in one shot",count);
890 if (subsub_type->aligned_size[GRAS_THISARCH] >=
891 subsub_type->aligned_size[r_arch]) {
892 gras_trp_recv(sock, (char*)l_data,
893 subsub_type->aligned_size[r_arch] * count *
894 array_data.fixed_size);
895 if (r_arch != GRAS_THISARCH)
896 gras_dd_convert_elm(subsub_type,count*array_data.fixed_size,r_arch, l_data,l_data);
898 ptr = xbt_malloc(subsub_type->aligned_size[r_arch] * count*array_data.fixed_size);
900 gras_trp_recv(sock, (char*)ptr,
901 subsub_type->size[r_arch] * count*array_data.fixed_size);
902 if (r_arch != GRAS_THISARCH)
903 gras_dd_convert_elm(subsub_type,count*array_data.fixed_size,r_arch, ptr,l_data);
909 /* not scalar content, get it recursively (may contain pointers) */
910 elm_size = sub_type->aligned_size[GRAS_THISARCH];
911 VERB2("Receive a %d-long array of %s",count, sub_type->name);
914 for (cpt=0; cpt<count; cpt++) {
915 gras_datadesc_recv_rec(sock,state,refs, sub_type,
916 r_arch, NULL, 0, ptr,-1,
917 detect_cycle || sub_type->cycle);
926 xbt_assert0(0, "Invalid type");
930 type->recv(type,state,l_data);
932 if (!strcmp(type->name,"string"))
933 VERB1("value: '%s'",*(char**)l_data);
938 * gras_datadesc_recv:
940 * Get an instance of the datatype described by @type from the @socket,
941 * and store a pointer to it in @dst
945 gras_datadesc_recv(gras_socket_t sock,
946 gras_datadesc_type_t type,
951 static gras_cbps_t state=NULL; /* callback persistent state */
952 static xbt_dict_t refs=NULL; /* all references already sent */
955 state = gras_cbps_new();
956 refs = xbt_dict_new();
959 xbt_assert0(type,"called with NULL type descriptor");
961 gras_datadesc_recv_rec(sock, state, refs, type,
966 xbt_dict_reset(refs);
967 gras_cbps_reset(state);