void cmx_writerUnregisterCopy( v_entity entity, c_voidp args) { v_writer kw; v_message message; void *to; sd_serializer ser; sd_serializedData data; sd_validationResult valResult; struct cmx_writerArg *arg; arg = (struct cmx_writerArg *)args; kw = v_writer(entity); message = v_topicMessageNew(kw->topic); to = C_DISPLACE(message,v_topicDataOffset(kw->topic)); ser = sd_serializerXMLNewTyped(v_topicDataType(kw->topic)); data = sd_serializerFromString(ser, arg->result); sd_serializerDeserializeIntoValidated(ser, data, to); valResult = sd_serializerLastValidationResult(ser); if(valResult != SD_VAL_SUCCESS){ OS_REPORT_2(OS_ERROR, CM_XML_CONTEXT, 0, "Unregister of userdata failed.\nReason: %s\nError: %s\n", sd_serializerLastValidationMessage(ser), sd_serializerLastValidationLocation(ser)); arg->success = CMX_RESULT_FAILED; } else { arg->success = CMX_RESULT_OK; } sd_serializedDataFree(data); sd_serializerFree(ser); /* Note that the last param of v_writerWriteDispose is NULL, performance can be improved if the instance is provided. */ v_writerUnregister(kw,message,v_timeGet(),NULL); c_free(message); }
static u_result handleParticipant( u_dataReader dataReader, c_long dataOffset, int gluelockAlreadyHeld) { v_dataReaderSample sample; u_result result; v_state state; v_message msg; struct v_participantInfo *data; in_participant participant; sample = NULL; result = u_dataReaderTake(dataReader, takeOne, &sample); while(sample && (result == U_RESULT_OK)){ state = v_readerSample(sample)->sampleState; msg = v_dataReaderSampleMessage(sample); data = (struct v_participantInfo *)(C_DISPLACE(msg, dataOffset)); if (!gluelockAlreadyHeld) os_mutexLock (&gluelock); if(v_stateTest(state, L_DISPOSED)){ participant = in_participantLookup(&(data->key)); if(participant){ in_participantFree(participant, NULL); } } else { in_participantNew(data); } if (!gluelockAlreadyHeld) os_mutexUnlock (&gluelock); c_free(sample); sample = NULL; result = u_dataReaderTake(dataReader, takeOne, &sample); } return result; }
static c_bool c_deepwalkProperty( c_metaObject object, c_metaWalkActionArg actionArg) { c_interfaceContext context = (c_interfaceContext)actionArg; c_property property; c_type propertyType; c_object propertyData; /* For now, we are interested in properties only */ if (c_baseObject(object)->kind == M_ATTRIBUTE) { property = c_property(object); propertyType = c_typeActualType(property->type); /* For now, skip attributes which are class-references */ propertyData = C_DISPLACE(*context->objectPtr, (c_address)property->offset); c_deepwalkType(propertyType, &propertyData, context->action, context->actionArg); } return TRUE; }
u_instanceHandle u_instanceHandleFix( u_instanceHandle _this, v_collection reader) { u_instanceHandleTranslator translator; struct v_publicationInfo *data; v_topic topic; v_message message; v_public instance; translator.handle = _this; if (translator.lid.lifecycleId & HANDLE_GLOBAL_MASK) { /* Is a GID therefore fix handle by lookup. */ while (v_objectKind(v_entity(reader)) == K_QUERY || v_objectKind(v_entity(reader)) == K_DATAREADERQUERY || v_objectKind(v_entity(reader)) == K_DATAVIEWQUERY) { /* If the entity derives from a query entity it can be cast to a v_query */ reader = v_querySource(v_query(reader)); } while (v_objectKind(v_entity(reader)) == K_DATAVIEW) { reader = v_collection(v_dataViewGetReader(v_dataView(reader))); } topic = v_dataReaderGetTopic(v_dataReader(reader)); message = v_topicMessageNew(topic); data = (c_voidp)C_DISPLACE(message, v_topicDataOffset(topic)); data->key = u_instanceHandleToGID(_this); instance = (v_public)v_dataReaderLookupInstance(v_dataReader(reader), message); translator.handle = u_instanceHandleNew(instance); c_free(instance); c_free(topic); c_free(message); } return translator.handle; }
void c_fieldClone( c_field srcfield, c_object src, c_field dstfield, c_object dst) { c_long i,n; c_array refs; c_voidp srcp = src; c_voidp dstp = dst; if (srcfield->refs) { refs = srcfield->refs; n = c_arraySize(refs)-1; for(i=0;i<n;i++) { srcp = *(c_voidp *)C_DISPLACE(srcp,refs[i]); } srcp = C_DISPLACE(srcp,refs[n]); } else { srcp = C_DISPLACE(srcp,srcfield->offset); } if (dstfield->refs) { refs = dstfield->refs; n = c_arraySize(refs)-1; for(i=0;i<n;i++) { dstp = *(c_voidp *)C_DISPLACE(dstp,refs[i]); } dstp = C_DISPLACE(dstp,refs[n]); } else { dstp = C_DISPLACE(dstp,dstfield->offset); } if ((dstfield->kind == V_STRING) || (dstfield->kind == V_WSTRING) || (dstfield->kind == V_FIXED)) { dstp = c_stringNew(c_getBase(dstfield), srcp); } else { memcpy(dstp,srcp,dstfield->type->size); } }
c_value c_fieldValue( c_field field, c_object o) { c_value v; c_long i,n; c_array refs; c_voidp p = o; /* initialize v! variable v has to be initialized as parts of the * union might not be initialized. * Example: * kind = V_LONG; * is.Long = 1; * then the last 4 bytes have not been initialized, * since the double field is 8 bytes, making the * c_value structure effectively 12 bytes. * This causes a lot of MLK's in purify. */ #ifndef NDEBUG memset(&v, 0, sizeof(v)); #endif if (field->refs) { refs = field->refs; n = c_arraySize(refs)-1; for(i=0;i<n;i++) { p = C_DISPLACE(p,refs[i]); if (p == NULL) { v.kind = V_UNDEFINED; return v; } p = *(c_voidp *)p; } if(p == NULL){ v.kind = V_UNDEFINED; return v; } else { p = C_DISPLACE(p,refs[n]); } } else { p = C_DISPLACE(p,field->offset); } #if 0 v.kind = field->kind; switch(v.kind) { case V_STRING: case V_WSTRING: case V_OBJECT: v.is.Object = *(c_object *)p; /* memcpy(&v.is,p,field->type->size);*/ c_keep(v.is.Object); break; case V_FIXED: case V_UNDEFINED: case V_COUNT: break; default: v.is.LongLong = *(c_longlong *)p; /* memcpy(&v.is,p,field->type->size);*/ break; } return v; #else #define _VAL_(f,t) v.is.f = *(t *)p v.kind = field->kind; switch(field->kind) { case V_ADDRESS: _VAL_(Address,c_address); break; case V_BOOLEAN: _VAL_(Boolean,c_bool); break; case V_SHORT: _VAL_(Short,c_short); break; case V_LONG: _VAL_(Long,c_long); break; case V_LONGLONG: _VAL_(LongLong,c_longlong); break; case V_OCTET: _VAL_(Octet,c_octet); break; case V_USHORT: _VAL_(UShort,c_ushort); break; case V_ULONG: _VAL_(ULong,c_ulong); break; case V_ULONGLONG: _VAL_(ULongLong,c_ulonglong); break; case V_CHAR: _VAL_(Char,c_char); break; case V_WCHAR: _VAL_(WChar,c_wchar); break; case V_STRING: _VAL_(String,c_string); c_keep(v.is.String); break; case V_WSTRING: _VAL_(WString,c_wstring); c_keep(v.is.WString); break; case V_FLOAT: _VAL_(Float,c_float); break; case V_DOUBLE: _VAL_(Double,c_double); break; case V_OBJECT: _VAL_(Object,c_object); c_keep(v.is.Object); break; case V_VOIDP: _VAL_(Voidp,c_voidp); break; case V_FIXED: case V_UNDEFINED: case V_COUNT: OS_REPORT_1(OS_ERROR,"c_fieldAssign failed",0, "illegal field value kind (%d)", v.kind); assert(FALSE); break; } return v; #undef _VAL_ #endif }
void c_fieldAssign ( c_field field, c_object o, c_value v) { c_long i,n; c_voidp p = o; c_array refs; if (field->refs) { refs = field->refs; n = c_arraySize(refs)-1; for(i=0;i<n;i++) { p = *(c_voidp *)C_DISPLACE(p,refs[i]); } p = C_DISPLACE(p,refs[n]); } else { p = C_DISPLACE(p,field->offset); } v.kind = field->kind; #define _VAL_(f,t) *((t *)p) = v.is.f switch(v.kind) { case V_ADDRESS: _VAL_(Address,c_address); break; case V_BOOLEAN: _VAL_(Boolean,c_bool); break; case V_SHORT: _VAL_(Short,c_short); break; case V_LONG: _VAL_(Long,c_long); break; case V_LONGLONG: _VAL_(LongLong,c_longlong); break; case V_OCTET: _VAL_(Octet,c_octet); break; case V_USHORT: _VAL_(UShort,c_ushort); break; case V_ULONG: _VAL_(ULong,c_ulong); break; case V_ULONGLONG: _VAL_(ULongLong,c_ulonglong); break; case V_CHAR: _VAL_(Char,c_char); break; case V_WCHAR: _VAL_(WChar,c_wchar); break; case V_STRING: c_free((c_object)(*(c_string *)p)); _VAL_(String,c_string); c_keep((c_object)(*(c_string *)p)); break; case V_WSTRING: c_free((c_object)(*(c_wstring *)p)); _VAL_(WString,c_wstring); c_keep((c_object)(*(c_wstring *)p)); break; case V_FLOAT: _VAL_(Float,c_float); break; case V_DOUBLE: _VAL_(Double,c_double); break; case V_OBJECT: c_free(*(c_object *)p); _VAL_(Object,c_object); c_keep(*(c_object *)p); break; case V_VOIDP: _VAL_(Voidp,c_voidp); break; case V_FIXED: case V_UNDEFINED: case V_COUNT: OS_REPORT_1(OS_ERROR,"c_fieldAssign failed",0, "illegal field value kind (%d)", v.kind); assert(FALSE); break; } #undef _VAL_ }
static void c_deepwalkUnion( c_union v_union, c_object *objectPtr, c_deepwalkFunc action, void *actionArg) { c_type switchType; c_type caseType; c_unionCase deflt; c_unionCase activeCase; c_unionCase currentCase; c_object unionData; c_value switchValue; c_literal label; int i,j, nCases, nLabels; c_long dataOffset; /* action for the union itself */ /* No action, but separate actions for the switch and the data */ /* action(c_type(v_union), objectPtr, actionArg); */ /* action for the switch */ c_deepwalkType(v_union->switchType, objectPtr, action, actionArg); switchType = c_typeActualType(v_union->switchType); /* Determine value of the switch field */ switch (c_baseObject(switchType)->kind) { case M_PRIMITIVE: switch (c_primitive(switchType)->kind) { #define __CASE__(prim, type) \ case prim: switchValue = type##Value(*((type *)*objectPtr)); 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 *)*objectPtr); break; default: switchValue = c_undefinedValue(); assert(FALSE); break; } /* Determine the label corresponding to this field */ activeCase = NULL; deflt = NULL; nCases = c_arraySize(v_union->cases); for (i=0; (i<nCases) && !activeCase; i++) { currentCase = c_unionCase(v_union->cases[i]); nLabels = c_arraySize(currentCase->labels); if (nLabels > 0) { for (j=0; (j<nLabels) && !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) { caseType = c_specifier(activeCase)->type; if (c_type(v_union)->alignment >= v_union->switchType->size) { dataOffset = c_type(v_union)->alignment; } else { dataOffset = v_union->switchType->size; } unionData = C_DISPLACE(*objectPtr, (c_address)dataOffset); c_deepwalkType(caseType, &unionData, action, actionArg); } }
static c_bool c__cloneReferences ( c_type type, c_voidp data, c_voidp dest) { c_type refType; c_class cls; c_array references, labels, ar, destar; c_sequence seq, destseq; c_property property; c_member member; c_long i,j,length,size; c_long nrOfRefs,nrOfLabs; c_value v; switch (c_baseObject(type)->kind) { case M_CLASS: cls = c_class(type); while (cls) { length = c_arraySize(c_interface(cls)->references); for (i=0;i<length;i++) { property = c_property(c_interface(cls)->references[i]); refType = property->type; _cloneReference(refType, C_DISPLACE(data, property->offset), C_DISPLACE(dest, property->offset)); } cls = cls->extends; } break; case M_INTERFACE: length = c_arraySize(c_interface(type)->references); for (i=0;i<length;i++) { property = c_property(c_interface(type)->references[i]); refType = property->type; _cloneReference(refType, C_DISPLACE(data, property->offset), C_DISPLACE(dest, property->offset)); } break; case M_EXCEPTION: case M_STRUCTURE: length = c_arraySize(c_structure(type)->references); for (i=0;i<length;i++) { member = c_member(c_structure(type)->references[i]); refType = c_specifier(member)->type; _cloneReference(refType, C_DISPLACE(data, member->offset), C_DISPLACE(dest, member->offset)); } break; case M_UNION: #define _CASE_(k,t) case k: v = t##Value(*((t *)data)); break switch (c_metaValueKind(c_metaObject(c_union(type)->switchType))) { _CASE_(V_BOOLEAN, c_bool); _CASE_(V_OCTET, c_octet); _CASE_(V_SHORT, c_short); _CASE_(V_LONG, c_long); _CASE_(V_LONGLONG, c_longlong); _CASE_(V_USHORT, c_ushort); _CASE_(V_ULONG, c_ulong); _CASE_(V_ULONGLONG, c_ulonglong); _CASE_(V_CHAR, c_char); _CASE_(V_WCHAR, c_wchar); default: OS_REPORT(OS_ERROR, "c__cloneReferences",0, "illegal union switch type detected"); assert(FALSE); return FALSE; break; } #undef _CASE_ references = c_union(type)->references; if (references != NULL) { i=0; refType=NULL; nrOfRefs = c_arraySize(references); while ((i<nrOfRefs) && (refType == NULL)) { labels = c_unionCase(references[i])->labels; j=0; nrOfLabs = c_arraySize(labels); while ((j<nrOfLabs) && (refType == NULL)) { if (c_valueCompare(v,c_literal(labels[j])->value) == C_EQ) { c__cloneReferences(c_type(references[i]), C_DISPLACE(data, c_type(type)->alignment), C_DISPLACE(dest, c_type(type)->alignment)); refType = c_specifier(references[i])->type; } j++; } i++; } } break; case M_COLLECTION: refType = c_typeActualType(c_collectionType(type)->subType); switch (c_collectionType(type)->kind) { case C_ARRAY: ar = c_array(data); destar = c_array(dest); length = c_collectionType(type)->maxSize; if (length == 0) { length = c_arraySize(ar); } if (c_typeIsRef(refType)) { for (i=0;i<length;i++) { c_cloneIn(refType, ar[i], &destar[i]); } } else { if (c_typeHasRef(refType)) { size = refType->size; for (i=0;i<length;i++) { _cloneReference(refType, C_DISPLACE(data, (i*size)), C_DISPLACE(dest, (i*size))); } } } break; case C_SEQUENCE: seq = c_sequence(data); destseq = c_sequence(dest); length = c_sequenceSize(seq); if (c_typeIsRef(refType)) { for (i=0;i<length;i++) { c_cloneIn(refType, seq[i], &destseq[i]); } } else { if (c_typeHasRef(refType)) { size = refType->size; for (i=0;i<length;i++) { _cloneReference(refType, C_DISPLACE(seq, (i*size)), C_DISPLACE(dest, (i*size))); } } } break; default: OS_REPORT(OS_ERROR, "c__cloneReferences",0, "illegal collectionType found"); break; } break; case M_BASE: break; case M_TYPEDEF: c__cloneReferences(c_type(c_typeDef(type)->alias), data, dest); break; case M_ATTRIBUTE: case M_RELATION: refType = c_typeActualType(c_property(type)->type); _cloneReference(refType, C_DISPLACE(data, c_property(type)->offset), C_DISPLACE(dest, c_property(type)->offset)); break; case M_MEMBER: refType = c_typeActualType(c_specifier(type)->type); _cloneReference(refType, C_DISPLACE(data, c_member(type)->offset), C_DISPLACE(dest, c_member(type)->offset)); break; case M_UNIONCASE: refType = c_typeActualType(c_specifier(type)->type); _cloneReference(refType, data, dest); break; case M_MODULE: /* Do nothing */ break; case M_PRIMITIVE: /* Do nothing */ break; case M_EXTENT: case M_EXTENTSYNC: default: OS_REPORT(OS_ERROR, "c__cloneReferences",0, "illegal meta object specified"); assert(FALSE); return FALSE; } return 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); } }
static void printCollection( c_collectionType type, toolActionData actionData) { c_long size, i, offset, esize; c_object o; c_voidp p; c_object arrayElement; c_type subtype; c_bool isRef; o = c_iterObject(actionData->stack, 0); switch (type->kind) { case C_ARRAY: case C_SEQUENCE: /* Walk over all entries */ switch (type->kind) { case C_ARRAY: if (type->maxSize == 0) { size = c_arraySize((c_array)o); } else { size = type->maxSize; } break; case C_SEQUENCE: size = c_arraySize((c_array)o); break; default: size = 0; assert(FALSE); break; } if (c_typeIsRef(type->subType)) { esize = sizeof(c_voidp); isRef = TRUE; } else { esize = type->subType->size; isRef = FALSE; } p = o; offset = 0; for (i=0; i<size; i++) { iprintf("Element (%d) Offset (%d)\n",i,offset); arrayElement = isRef ? *((c_object *)p) : (c_object) p; if (arrayElement != NULL) { OBJECT_PUSH(actionData, arrayElement); if (isRef) { subtype = c_getType(arrayElement); printType(subtype, actionData); } else { iprintf(" "); printType(type->subType, actionData); } printf("\n"); OBJECT_POP(actionData); } else { iprintf(" <0x0>\n"); } p = C_DISPLACE(p, esize); offset += esize; } break; case C_STRING: printf(" \"%s\"",(c_char *)o); break; case C_SET: case C_LIST: case C_BAG: case C_DICTIONARY: case C_QUERY: { if (o != NULL) { /* Walk over the elements */ c_walk(o, (c_action)printCollectionAction, actionData); if (c_count(o) == 0) { iprintf("<EMPTY>"); } } else { iprintf("<NULL>"); } } break; case C_SCOPE: c_scopeWalk(o, printCollectionAction, actionData); break; default: printf("Specified type <0x"PA_ADDRFMT"> is not a valid collection type\n", (os_address)type); break; } }
static void determineSampleInfoView ( readerViewActionArg *info) { gapi_unsigned_long i; v_readerSampleSeq *samples = info->samples; gapi_unsigned_long length; gapi_dataSampleSeq dataSamples; gapi_dataSample onePlaceBuffer; gapi_boolean onHeap = FALSE; gapi_boolean onStack = FALSE; assert(samples->_length > 0); length = samples->_length; if ( length == 1 ) { dataSamples._buffer = &onePlaceBuffer; } else if ( length < MAX_DATASAMPLESEQ_SIZE_ON_STACK ) { dataSamples._buffer = (gapi_dataSample *)os_alloca(length*sizeof(gapi_dataSample)); if ( dataSamples._buffer ) { onStack = TRUE; } else { dataSamples._buffer = (gapi_dataSample *)os_malloc(length*sizeof(gapi_dataSample)); onHeap = TRUE; } } else { dataSamples._buffer = (gapi_dataSample *)os_malloc(length*sizeof(gapi_dataSample)); onHeap = TRUE; } if ( dataSamples._buffer ) { dataSamples._length = length; dataSamples._maximum = length; dataSamples._release = FALSE; for ( i = 0; i < length; i++ ) { v_dataViewSampleTemplate viewSample = v_dataViewSampleTemplate(samples->_buffer[i]); v_dataReaderSampleTemplate sample = v_dataReaderSampleTemplate(viewSample->sample); v_message message = sample->message; dataSamples._buffer[i].data = (void *)C_DISPLACE(message, info->datareaderview->datareader->userdataOffset); copySampleInfoView(v_readerSample(viewSample), message, &dataSamples._buffer[i].info); } computeGenerationRanksView(samples, &dataSamples); info->readerCopy(&dataSamples, info->readerInfo); if ( onStack ) { os_freea(dataSamples._buffer); } else { if ( onHeap ) { os_free(dataSamples._buffer); } } } else { info->result = GAPI_RETCODE_OUT_OF_RESOURCES; } }
/*writes and removes elements contained within the elements set */ void DK_CollectionWriter_us_writeCollectionElements( DK_CollectionWriter* _this, DLRL_Exception* exception, DK_Collection* collection, Coll_Set* elements, void (*action)( v_entity, c_voidp), LOC_boolean destroyWrittenHolders, LOC_boolean unregisterHolders) { DMM_DLRLMultiRelation* metaCollection = NULL; Coll_List* targetKeys = NULL; Coll_List* ownerKeys = NULL; DMM_Basis base; Coll_List* collectionOwnerFields = NULL; Coll_List* collectionTargetFields = NULL; DK_ObjectAdmin* collectionOwner = NULL; c_value* ownerKeyValues = NULL; Coll_Iter* iterator = NULL; DK_ObjectHolder* holder = NULL; v_message message = NULL; c_long offset = 0; void* dataSample = NULL; DK_ObjectAdmin* elementTarget = NULL; c_value* targetKeyValues = NULL; void* keyValue = NULL; DMM_DCPSField* collectionIndexField = NULL; DK_DCPSUtilityWriteMessageArg messageArg;/* on stack def... */ u_result result; DLRL_INFO_OBJECT(INF_ENTER); assert(_this); assert(exception); assert(collection); assert(action); metaCollection = DK_Collection_us_getMetaRepresentative(collection); targetKeys = DMM_DLRLRelation_getTargetKeys((DMM_DLRLRelation*)metaCollection); ownerKeys = DMM_DLRLRelation_getOwnerKeys((DMM_DLRLRelation*)metaCollection); base = DMM_DLRLMultiRelation_getBasis(metaCollection); collectionOwnerFields = DMM_DLRLMultiRelation_getRelationTopicOwnerFields(metaCollection); collectionTargetFields = DMM_DLRLMultiRelation_getRelationTopicTargetFields(metaCollection); collectionOwner = DK_Collection_us_getOwner(collection); assert(collectionOwner); ownerKeyValues = DK_ObjectAdmin_us_getKeyValueArray(collectionOwner);/* may return NULL */ iterator = Coll_Set_getFirstElement(elements); while(iterator) { holder = (DK_ObjectHolder*)Coll_Iter_getObject(iterator); message = DK_DCPSUtility_ts_createMessageForDataWriter(_this->writer, exception, &offset); DLRL_Exception_PROPAGATE(exception); dataSample = C_DISPLACE(message, offset); /* now we have a data sample in which we can copy the key values and then write it... */ DK_DCPSUtility_us_copyFromSource(exception, ownerKeys, ownerKeyValues, collectionOwnerFields, dataSample); DLRL_Exception_PROPAGATE(exception); elementTarget = DK_ObjectHolder_us_getTarget(holder); assert(elementTarget); targetKeyValues = DK_ObjectAdmin_us_getKeyValueArray(elementTarget); DK_DCPSUtility_us_copyFromSource(exception, targetKeys, targetKeyValues, collectionTargetFields, dataSample); DLRL_Exception_PROPAGATE(exception); if(base == DMM_BASIS_STR_MAP) { keyValue = DK_ObjectHolder_us_getUserData(holder);/*used later on for freeing purposes!*/ assert(keyValue); collectionIndexField = DMM_DLRLMultiRelation_getIndexField(metaCollection);/* may return NULL */ DK_DCPSUtility_us_copyStringIntoDatabaseSample((LOC_string)keyValue, collectionIndexField, dataSample); } else if(base == DMM_BASIS_INT_MAP) { keyValue = DK_ObjectHolder_us_getUserData(holder);/*used later on for freeing purposes!*/ assert(keyValue); collectionIndexField = DMM_DLRLMultiRelation_getIndexField(metaCollection);/* may return NULL */ DK_DCPSUtility_us_copyIntegerIntoDatabaseSample((LOC_long*)keyValue, collectionIndexField, dataSample); } #ifndef NDEBUG else { /* else do nothing at all */ assert(base == DMM_BASIS_SET); } #endif /* now write the message... */ messageArg.message = message; messageArg.exception = exception; result = u_entityWriteAction((u_entity)_this->writer, action, (void*)&messageArg); DLRL_Exception_PROPAGATE_RESULT(exception, result, "An error occured while trying to write a message into the system."); DLRL_Exception_PROPAGATE(exception);/* propagate the exception wrapped in the messageArg struct... */ iterator = Coll_Iter_getNext(iterator); Coll_Set_remove(elements, holder); if(unregisterHolders && elementTarget) { #if 0 if(DK_ObjectAdmin_us_getWriteState(elementTarget) == DK_OBJECT_STATE_OBJECT_DELETED) { DK_CacheAccessAdmin_us_decreaseInvalidLinks(elementTarget->access); } #endif DK_ObjectAdmin_us_unregisterIsRelatedFrom(elementTarget, holder); } if(destroyWrittenHolders) { if(keyValue) { os_free(keyValue); DK_ObjectHolder_us_setUserData(holder, NULL); keyValue = NULL;/* must set to null to prevent mistakes in the next iteration */ } DK_ObjectHolder_us_destroy(holder); } if(message) { result = u_entityAction((u_entity)_this->writer, DK_DCPSUtility_us_freeMessage, (void*)message); DLRL_Exception_PROPAGATE_RESULT(exception, result, "An error occured while trying to free a v_message object."); message = NULL; } } DLRL_Exception_EXIT(exception); DLRL_INFO(INF_EXIT); }
c_equality c_fieldCompare ( c_field field1, c_object src1, c_field field2, c_object src2) { c_long i,n,r; c_array refs; c_voidp p1 = src1; c_voidp p2 = src2; c_equality result; result = C_NE; if (field1->refs) { refs = field1->refs; n = c_arraySize(refs)-1; for(i=0;i<n;i++) { p1 = *(c_voidp *)C_DISPLACE(p1,refs[i]); } p1 = C_DISPLACE(p1,refs[n]); } else { p1 = C_DISPLACE(p1,field1->offset); } if (field2->refs) { refs = field2->refs; n = c_arraySize(refs)-1; for(i=0;i<n;i++) { p2 = *(c_voidp *)C_DISPLACE(p2,refs[i]); } p2 = C_DISPLACE(p2,refs[n]); } else { p2 = C_DISPLACE(p2,field2->offset); } #define _CMP_(t) ((*(t*)p1)<(*(t*)p2)?C_LT:((*(t*)p1)>(*(t*)p2)?C_GT:C_EQ)) switch(field1->kind) { case V_ADDRESS: result = _CMP_(c_address); break; case V_BOOLEAN: result = _CMP_(c_bool); break; case V_SHORT: result = _CMP_(c_short); break; case V_LONG: result = _CMP_(c_long); break; case V_LONGLONG: result = _CMP_(c_longlong); break; case V_OCTET: result = _CMP_(c_octet); break; case V_USHORT: result = _CMP_(c_ushort); break; case V_ULONG: result = _CMP_(c_ulong); break; case V_ULONGLONG: result = _CMP_(c_ulonglong); break; case V_CHAR: result = _CMP_(c_char); break; case V_WCHAR: result = _CMP_(c_wchar); break; case V_FLOAT: result = _CMP_(c_float); break; case V_DOUBLE: result = _CMP_(c_double); break; case V_VOIDP: result = _CMP_(c_voidp); break; case V_OBJECT: result = _CMP_(c_object); break; case V_STRING: case V_WSTRING: case V_FIXED: p1 = (p1?*(c_voidp*)p1:NULL); p2 = (p2?*(c_voidp*)p2:NULL); if (((c_address)p1) == ((c_address)p2)) { result = C_EQ; } else if (p1 == NULL) { result = C_LT; } else if (p2 == NULL) { result = C_GT; } else { r = strcmp(p1,p2); if (r>0) { result = C_GT; } else if (r<0) { result = C_LT; } else { result = C_EQ; } } break; case V_UNDEFINED: case V_COUNT: OS_REPORT_1(OS_ERROR,"c_fieldCompare failed",0, "illegal field value kind (%d)", field1->kind); assert(FALSE); result = C_NE; break; } return result; #undef _CMP_ }
void in_messageDeserializer__readPrimArraySwapped( in_messageDeserializer _this, os_uint32 dataSize, os_uint32 length, c_voidp data) { c_octet* dstPtr; c_octet* srcPtr; os_uint32 i; os_uint32 j; os_uint32 n; os_uint32 rest; os_uint32 restElements; os_uint32 maxElements; os_uint32 max; assert(_this); assert(in_messageDeserializerIsValid(_this)); assert(data); /* remove excess padding, if any or needed. The transformer may be renewed! */ in_messageDeserializerRemoveCDRPaddingFromStream(_this, dataSize); max = dataSize-1; restElements = length; dstPtr = (c_octet *)data; while (restElements) { /* Determine the maximum number of elements * that can be copied at once. */ maxElements = in_messageTransformerGetAvailable(_this) / dataSize; if (maxElements >= restElements) { n = restElements; restElements = 0; } else { n = maxElements; restElements -= maxElements; } /* Copy the elements. */ srcPtr = in_messageTransformerGetHead(_this); in_messageTransformerClaim(_this, (n*dataSize)); for (i = 0; i < n; ++i) { for (j = 0; j < dataSize; ++j) { dstPtr[max-j] = srcPtr[j]; } dstPtr = C_DISPLACE(dstPtr, dataSize); srcPtr = C_DISPLACE(srcPtr, dataSize); } if (restElements > 0) { rest = in_messageTransformerGetAvailable(_this); if (rest) { /* Following the philosophie: write as strict as possible * and read with as much goodwill as possible, we deal * with data not following the CDR fragmentation rules, * seperating fragments at 8-octet boundaries. * * With correct 8-octet boundary seperation, * the following would not be necessary, * except the renewing! */ /* In this case not all elements are copied yet. * Because there was not enough buffer space available. * However there is still some buffer space available * less than the element size. * So the next element is devided over two buffers. */ /* Copy the first part of the element from the rest of * the current buffer. * It is asserted that the srcPtr is displaced towards the * current head position, so we do not need to get the head * again, as the srcPtr is already on the correct location. * It is also assumed the dstPrt has been placed at the first * available spot to place data into. */ assert(srcPtr == in_messageTransformerGetHead(_this)); in_messageTransformerClaim(_this, rest); for (j = 0; j < rest; ++j) { dstPtr[max-j] = srcPtr[j]; } /* Get the next buffer. */ in_messageTransformerRenew(_this); /* Copy the last part of the element from the rest of * the new buffer. */ srcPtr = in_messageTransformerGetHead(_this); in_messageTransformerClaim(_this, (dataSize-rest)); for (j = rest; j < dataSize; j++) { dstPtr[max-j] = srcPtr[j-rest]; } restElements--; } } } }
void c_copyIn ( c_type type, c_voidp data, c_voidp *dest) { c_long size, subSize, i; c_type t, refType; if (data == NULL) { *dest = NULL; return; } t = c_typeActualType(type); if (c_baseObject(t)->kind == M_COLLECTION) { switch(c_collectionType(t)->kind) { case C_STRING: *dest = c_stringNew(c_getBase(t),data); return; case C_LIST: case C_BAG: case C_SET: case C_MAP: case C_DICTIONARY: OS_REPORT(OS_WARNING,"Database misc",0, "c_copyIn: ODL collections unsupported"); break; case C_ARRAY: refType = c_typeActualType(c_collectionType(type)->subType); subSize = refType->size; size = c_collectionType(t)->maxSize; if (size == 0) { size = c_arraySize(data); *dest = c_newArray(c_collectionType(t), size); } if (size > 0) { c_array ar = c_array(data); c_array destar = c_array(*dest); if (c_typeIsRef(refType)) { for (i = 0; i < size; i++) { copyReferences(refType, destar[i], ar[i]); } } else { memcpy(*dest, data, size * subSize); /* Find indirections */ for (i = 0; i < size; i++) { copyReferences(refType, C_DISPLACE(destar, (i*subSize)), C_DISPLACE(ar, (i*subSize))); } } } break; case C_SEQUENCE: refType = c_typeActualType(c_collectionType(type)->subType); subSize = refType->size; size = c_sequenceSize(data); if (size > 0) { *dest = c_newSequence(c_collectionType(t), size); if (c_typeIsRef(refType)) { c_sequence seq = c_sequence(data); c_sequence destseq = c_sequence(*dest); for (i = 0; i < size; i++) { copyReferences(refType, destseq[i], seq[i]); } } else { memcpy(*dest, data, size * subSize); /* Find indirections */ for (i = 0; i < size; i++) { copyReferences(refType, C_DISPLACE(*dest, (i*subSize)), C_DISPLACE(data, (i*subSize))); } } } break; default: OS_REPORT_1(OS_ERROR,"Database misc",0, "c_copyIn: unknown collection kind (%d)", c_collectionType(t)->kind); assert(FALSE); break; } } else if (c_typeIsRef(t)) { *dest = c_new(t); memcpy(*dest, data, t->size); copyReferences(t, *dest, data); } else { memcpy(*dest, data, t->size); copyReferences(t, *dest, data); } }