static c_bool walkProperty( c_metaObject object, c_metaWalkActionArg actionArg) { toolActionData actionData = (toolActionData)actionArg; c_object o; c_voidp addr; o = c_iterObject(actionData->stack, 0); if (c_baseObjectKind(object) == M_ATTRIBUTE) { addr = C_DISPLACE(o, (c_address)c_property(object)->offset); if (c_typeIsRef(c_property(object)->type)) { addr = *(c_voidp *)addr; if (c_baseObjectKind(c_property(object)->type) == M_COLLECTION) { if (addr) { if (c_iterContains(actionData->stack, addr)) { printf("Ignore cyclic reference 0x"PA_ADDRFMT"\n", (os_address)addr); } else { OBJECT_PUSH(actionData, addr); iprintf("%s ",_METANAME(object)); printType(c_property(object)->type, actionData); OBJECT_POP(actionData); } } else { iprintf(" %s <0x"PA_ADDRFMT">", _METANAME(object), (os_address)addr); } } else { iprintf(" %s <0x"PA_ADDRFMT">", _METANAME(object), (os_address)addr); if (addr) { /* Section for code to print additional type specific info. */ if (c_property(object)->type == v_topic_t) { printf(" /* topic name is: %s */", v_topicName(addr)); } if (c_property(object)->type == v_partition_t) { printf(" /* Partition: %s */", v_partitionName(addr)); } if (c_property(object)->type == c_type_t(c_getBase(object))) { printf(" /* Type: %s */", _METANAME(c_type(addr))); } } } printf("\n"); } else { OBJECT_PUSH(actionData, addr); iprintf("%s ",_METANAME(object)); printType(c_property(object)->type, actionData); printf("\n"); OBJECT_POP(actionData); } } return TRUE; }
os_boolean in_messageDeserializerReadPropertyAction( c_object object, c_voidp arg) { in_messageDeserializerPropertyActionArg* a = (in_messageDeserializerPropertyActionArg*)arg; c_property property; c_type type; c_voidp data; assert(object); assert(arg); assert(a->object); assert(a->transformer); assert(in_messageDeserializerIsValid(a->transformer)); /* For now, we are interested in properties only */ if (c_baseObjectKind(object) == M_ATTRIBUTE) { property = c_property(object); type = c_typeActualType(property->type); data = C_DISPLACE(a->object, (c_address)property->offset); in_messageDeserializerReadType(a->transformer, type, data); } return OS_TRUE; }
/* TODO should propagate the result code, might have an out of memory error * if allocation of the array failed */ void in_messageDeserializerReadArray( in_messageDeserializer _this, c_type type, c_voidp data) { in_result result = IN_RESULT_OK; c_collectionType ctype = c_collectionType(type); os_uint32 size; os_uint32 length; os_uint32 i; c_voidp array = NULL; c_object o; c_collKind typeKind; c_metaKind subTypeKind; assert(_this); assert(in_messageDeserializerIsValid(_this)); assert(type); assert(data); /* First determine the length of the array. For IDL array types the length * is known, but for sequences it is encoded ahead of the elements as an * unsigned long */ typeKind = ctype->kind; if(typeKind == C_ARRAY) { array = data; length = ctype->maxSize; assert(array); } else { assert(typeKind == C_SEQUENCE); /* For a sequence the length is encoded as an unsigned long, which in * CDR is 4 octets(bytes) in size. */ assert(sizeof(os_uint32) == 4); in_messageDeserializerReadPrim(_this, 4, &length); /* Verify that the length is equal to or smaller then the maxSize if * maxSize is bigger then 0 */ if(ctype->maxSize > 0) { array = data; assert((c_long)length <= ctype->maxSize); assert(array); } else { if(*(c_voidp *)data) { array = *(c_voidp *)data; } else { array = c_arrayNew(type, (c_long)length); if(length > 0 && !array) { result = IN_RESULT_OUT_OF_MEMORY; } *(c_voidp *)data = array; } } } if (length > 0 && result == IN_RESULT_OK) { assert(array); subTypeKind = c_baseObjectKind(c_baseObject(ctype->subType)); if((subTypeKind == M_PRIMITIVE) ||(subTypeKind == M_ENUMERATION)) { o = array; /* in_messageDeserializerReadPrimArray( _this, ctype->subType->size, length, o);*/ } else { if (c_typeIsRef(ctype->subType)) { size = sizeof(c_voidp); } else { size = ctype->subType->size; } o = array; for (i = 0; i < length; i++) { in_messageDeserializerReadType(_this, ctype->subType, o); o = C_DISPLACE(o, size); } } } }
void in_messageDeserializerReadUnion( in_messageDeserializer _this, c_type type, c_voidp data) { c_union utype = c_union(type); c_type caseType; c_type switchType; c_unionCase deflt; c_unionCase activeCase; c_unionCase currentCase; c_value switchValue; c_literal label; c_voidp o; os_uint32 length; os_uint32 i; os_uint32 j; os_uint32 n; assert(_this); assert(type); assert(data); /* action for the switch */ switchType = c_typeActualType(utype->switchType); in_messageDeserializerReadType(_this, switchType, data); /* Determine value of the switch field */ switch (c_baseObjectKind(switchType)) { case M_PRIMITIVE: switch (c_primitiveKind(switchType)) { #define __CASE__(prim, type) \ case prim: switchValue = type##Value(*((type *)data)); break; __CASE__(P_BOOLEAN,c_bool) __CASE__(P_CHAR,c_char) __CASE__(P_SHORT,c_short) __CASE__(P_USHORT,c_ushort) __CASE__(P_LONG,c_long) __CASE__(P_ULONG,c_ulong) __CASE__(P_LONGLONG,c_longlong) __CASE__(P_ULONGLONG,c_ulonglong) #undef __CASE__ default: switchValue = c_undefinedValue(); assert(FALSE); break; } break; case M_ENUMERATION: switchValue = c_longValue(*(c_long *)data); break; default: switchValue = c_undefinedValue(); assert(FALSE); break; } /* Determine the label corresponding to this field */ activeCase = NULL; deflt = NULL; length = c_arraySize(utype->cases); for (i = 0; (i < length) && !activeCase; i++) { currentCase = c_unionCase(utype->cases[i]); n = c_arraySize(currentCase->labels); if (n > 0) { for (j = 0; (j < n) && !activeCase; j++) { label = c_literal(currentCase->labels[j]); if (c_valueCompare(switchValue, label->value) == C_EQ) { activeCase = currentCase; } } } else { deflt = currentCase; } } if(!activeCase) { activeCase = deflt; } assert(activeCase); if (activeCase) { if (c_type(utype)->alignment >= utype->switchType->size) { length = c_type(utype)->alignment; } else { length = utype->switchType->size; } o = C_DISPLACE(data, (c_address)length); caseType = c_typeActualType(c_specifierType(activeCase)); in_messageDeserializerReadType(_this, caseType, o); } }