v_dataViewInstance v_dataViewInstanceNew( v_dataView dataView, v_dataViewSample viewSample) { v_dataViewInstance instance; assert(dataView); assert(viewSample); assert(C_TYPECHECK(dataView,v_dataView)); assert(C_TYPECHECK(viewSample,v_dataViewSample)); instance = v_dataViewInstance(c_new(dataView->instanceType)); if (instance) { v_object(instance)->kernel = v_objectKernel(dataView); v_objectKind(instance) = K_DATAVIEWINSTANCE; v_instanceInit(v_instance(instance), v_entity(dataView)); viewSample->next = viewSample; v_dataViewInstanceTemplate(instance)->sample = viewSample; instance->sampleCount = 1; v_stateSet(v_instanceState(instance),L_NEW); v_stateClear(v_readerSample(viewSample)->sampleState,L_READ); assert(C_TYPECHECK(instance,v_dataViewInstance)); CHECK_INSTANCE(instance); } else { OS_REPORT(OS_FATAL, OS_FUNCTION, V_RESULT_INTERNAL_ERROR, "Failed to allocate v_dataViewInstance"); assert(FALSE); } return instance; }
static d_storeResult d_instanceRemoveHistoricalData( d_instance instance, const v_groupAction until) { d_sample ptr, current; d_storeResult result; c_equality equality; v_state state; ptr = d_instanceGetTail(instance); if(ptr){ equality = v_timeCompare(until->actionTime, d_sampleGetMessage(ptr)->writeTime); while ((equality != C_LT) && ptr) { current = ptr; ptr = ptr->newer; current->newer = NULL; d_instanceSetTail(instance, ptr); state = v_nodeState(d_sampleGetMessage(current)); if (v_stateTest(state, L_WRITE)) { instance->count--; instance->messageCount--; } if (v_stateTest(state, L_DISPOSED)) { instance->count--; } if(ptr){ ptr->older = NULL; equality = v_timeCompare(until->actionTime, d_sampleGetMessage(ptr)->writeTime); } else { d_instanceSetHead(instance, NULL); } c_free(current); } if (instance->oldest == NULL) { v_stateSet(instance->state, L_EMPTY); } assert((instance->count == 0) == (d_instanceGetTail(instance) == NULL)); assert((instance->count == 0) == (d_instanceGetHead(instance) == NULL)); result = D_STORE_RESULT_OK; } else { result = D_STORE_RESULT_OK; } return result; }
static d_instance d_instanceNew( d_groupInfo groupInfo, const v_groupAction action) { d_instance instance; c_type type; c_long nrOfKeys, i; c_array messageKeyList, instanceKeyList; instanceKeyList = c_tableKeyList(groupInfo->instances); type = c_subType(groupInfo->instances); instance = d_instance(c_new(type)); c_free(type); if(instance){ /* * copy the key value of the message into the newly created instance. */ messageKeyList = v_topicMessageKeyList(v_groupTopic(action->group)); nrOfKeys = c_arraySize(messageKeyList); assert(nrOfKeys == c_arraySize(instanceKeyList)); for (i=0;i<nrOfKeys;i++) { c_fieldCopy(messageKeyList[i],action->message, instanceKeyList[i], instance); } c_free(instanceKeyList); d_instanceSetHead(instance, NULL); d_instanceSetTail(instance, NULL); instance->messageCount = 0; instance->count = 0; instance->state = 0; v_stateSet(instance->state, L_EMPTY); } else { OS_REPORT(OS_ERROR, "d_instanceNew",0, "Failed to allocate instance."); assert(FALSE); } return instance; }
v_dataViewInstance v_dataViewInstanceNew( v_dataView dataView, v_readerSample sample) { v_dataViewInstance instance; v_dataViewSample viewSample; assert(dataView); assert(sample); assert(C_TYPECHECK(dataView,v_dataView)); assert(C_TYPECHECK(sample,v_readerSample)); instance = v_dataViewInstance(c_new(dataView->instanceType)); if (instance) { v_object(instance)->kernel = v_objectKernel(dataView); v_objectKind(instance) = K_DATAVIEWINSTANCE; instance->dataView = (c_voidp)dataView; viewSample = v_dataViewSampleNew(instance,sample); if (viewSample) { v_dataViewInstanceTemplate(instance)->sample = viewSample; viewSample->next = NULL; viewSample->prev = NULL; v_readerSampleAddViewSample(sample,viewSample); instance->sampleCount = 1; v_stateSet(instance->instanceState,L_NEW); v_stateClear(v_readerSample(viewSample)->sampleState,L_READ); assert(C_TYPECHECK(instance,v_dataViewInstance)); v_dataViewNotifyDataAvailable(dataView, viewSample); } CHECK_INSTANCE(instance); } else { OS_REPORT(OS_ERROR, "v_dataViewInstanceNew",0, "Failed to allocate v_dataViewInstancem"); assert(FALSE); } return instance; }
static void v_messageExtConvertHeaderToExtCommon ( v_messageExt xmsg, const struct v_message_s *vmsg, c_bool y2038Ready) { xmsg->_parent.nodeState = vmsg->_parent.nodeState; if (y2038Ready) { v_stateSet(xmsg->_parent.nodeState, L_TIME_Y2038); xmsg->writeTime = c_timeFromUint64(OS_TIMEW_GET_VALUE(vmsg->writeTime)); } else { xmsg->writeTime = c_timeFromTimeW(vmsg->writeTime); } xmsg->writerGID = vmsg->writerGID; xmsg->writerInstanceGID = vmsg->writerInstanceGID; xmsg->sequenceNumber = vmsg->sequenceNumber; xmsg->transactionId = vmsg->transactionId; xmsg->qos = vmsg->qos; }
v_actionResult v_dataViewSampleReadTake( v_dataViewSample sample, v_readerSampleAction action, c_voidp arg, c_bool consume) { v_dataViewInstance instance; v_state state; v_state mask; v_actionResult result = 0; instance = v_dataViewSampleInstance(sample); state = v_instanceState(instance); mask = L_NEW | L_DISPOSED | L_NOWRITERS; /* Copy the value of instance state bits specified by the mask * to the sample state bits without affecting other bits. */ v_readerSampleSetState(sample,(state & mask)); v_readerSampleClearState(sample,(~state & mask)); /* If the status of the sample is READ by the previous read * operation and the flag is not yet set (specified by the * LAZYREAD flag) then correct the state before executing the * read action. */ if (v_readerSampleTestState(sample,L_LAZYREAD)) { v_readerSampleSetState(sample,L_READ); v_readerSampleClearState(sample,L_LAZYREAD); } /* An action routine is provided in case the sample needs to be returned * to the user. If an action routine is not provided, it means the sample * needs to be removed from the administration, so the reader should be * modified accordingly. That means the 'proceed' flag should be set in * that case. */ V_MESSAGE_STAMP(v_dataReaderSampleMessage(sample),readerReadTime); if (action) { /* Invoke the action routine with the typed sample. */ result = action(v_readerSample(sample), arg); } else { v_actionResultSet(result, V_PROCEED); } /* A sample is considered 'skipped' if the action routine invoked above * does not want to keep track of the sample (for example because it * didn't match its readerMasks). In that case, it sets the 'skip' flag * to true, which indicates that those samples should be considered * 'untouched' and therefore their instance and sample states should * not be modified. */ if (v_actionResultTestNot(result, V_SKIP)) { V_MESSAGE_STAMP(v_dataReaderSampleMessage(sample),readerCopyTime); V_MESSAGE_REPORT(v_dataReaderSampleMessage(sample), v_dataReaderInstanceDataReader(instance)); v_stateClear(v_instanceState(instance),L_NEW); if (!v_stateTest(v_readerSample(sample)->sampleState,L_READ)) { v_stateSet(v_readerSample(sample)->sampleState,L_LAZYREAD); } if (consume) { v_dataViewSampleListRemove(v_dataViewSampleList(sample)); v_dataViewSampleRemove(sample); } } return result; }
static d_storeResult d_instanceRemove ( d_instance instance, v_message message) { d_sample current, sample; v_state state; v_message m; d_storeResult result; if ((instance != NULL) && (message != NULL)) { sample = NULL; current = d_instanceGetHead(instance); while(!sample && current){ m = d_sampleGetMessage(current); if(c_timeCompare(m->writeTime, message->writeTime) == C_EQ){ if(v_gidCompare(m->writerGID, message->writerGID) == C_EQ){ if(m->sequenceNumber == message->sequenceNumber){ sample = current; } } } if(!sample){ current = current->older; } } if(sample){ if (sample->newer != NULL) { d_sample(sample->newer)->older = c_keep(sample->older); } else { assert(d_instanceGetHead(instance) == sample); d_instanceSetHead(instance,sample->older); } if (sample->older != NULL) { d_sample(sample->older)->newer = sample->newer; } else { assert(d_instanceGetTail(instance) == sample); d_instanceSetTail(instance,sample->newer); } state = v_nodeState(d_sampleGetMessage(sample)); if (v_stateTest(state, L_WRITE)) { instance->count--; instance->messageCount--; } if (v_stateTest(state, L_DISPOSED)) { instance->count--; } c_free(sample); if (instance->oldest == NULL) { v_stateSet(instance->state, L_EMPTY); } } assert((instance->count == 0) == (d_instanceGetTail(instance) == NULL)); assert((instance->count == 0) == (d_instanceGetHead(instance) == NULL)); result = D_STORE_RESULT_OK; } else { result = D_STORE_RESULT_ILL_PARAM; } return result; }
static d_storeResult d_instanceInsert( d_instance instance, v_message msg, d_groupInfo groupInfo, d_sample toInsert) { d_sample sample; d_sample oldest; d_sample ptr; v_state state; c_equality equality; v_topicQos topicQos; assert(C_TYPECHECK(instance, d_instance)); assert(C_TYPECHECK(msg, v_message)); assert(C_TYPECHECK(groupInfo, d_groupInfo)); if (msg == NULL) { return D_STORE_RESULT_ILL_PARAM; } topicQos = groupInfo->topic->qos; if(toInsert){ sample = toInsert; sample->instance = instance; } else { sample = d_groupInfoSampleNew(groupInfo, instance, msg); } if (!sample) { return D_STORE_RESULT_OUT_OF_RESOURCES; } if (v_stateTest(instance->state, L_EMPTY)) { assert(d_instanceGetHead(instance) == NULL); assert(d_instanceGetTail(instance) == NULL); assert(instance->count == 0); d_instanceSetHead(instance,sample); v_stateClear(instance->state, L_EMPTY); } else { assert(d_instanceGetHead(instance) != NULL); assert(d_instanceGetTail(instance) != NULL); assert(instance->count != 0); if(topicQos->orderby.kind == V_ORDERBY_RECEPTIONTIME){ sample->older = d_instanceGetHead(instance); d_instanceSetHead(instance, sample); } else { ptr = d_instanceGetHead(instance); equality = v_timeCompare(msg->writeTime, d_sampleGetMessage(ptr)->writeTime); if (equality == C_LT) { while (ptr->older != NULL) { equality = v_timeCompare(msg->writeTime, d_sampleGetMessage(ptr->older)->writeTime); if (equality != C_LT) { break; } ptr = ptr->older; } sample->newer = ptr; sample->older = ptr->older; ptr->older = c_keep(sample); } else { sample->older = d_instanceGetHead(instance); d_instanceSetHead(instance,sample); } } } assert(c_refCount(sample) == 2); if (sample->older != NULL) { sample->older->newer = sample; } else { d_instanceSetTail(instance,sample); } sample->instance = instance; state = v_nodeState(msg); if (v_stateTest(state,L_DISPOSED)) { instance->count++; } if (v_stateTest(state, L_WRITE)) { if (topicQos->history.kind == V_HISTORY_KEEPALL || instance->messageCount < topicQos->history.depth) { instance->count++; instance->messageCount++; } else { ptr = NULL; oldest = instance->oldest; while (!v_messageStateTest(d_sampleGetMessage(oldest),L_WRITE)) { instance->count--; ptr = oldest; oldest = oldest->newer; } if (v_messageStateTest(d_sampleGetMessage(oldest),L_DISPOSED)) { instance->count--; } ptr = oldest; oldest = oldest->newer; while (!v_messageStateTest(d_sampleGetMessage(oldest),L_WRITE)) { instance->count--; ptr = oldest; oldest = oldest->newer; } d_instanceSetTail(instance,oldest); oldest->older = NULL; ptr->newer = NULL; while(ptr){ oldest = ptr->older; ptr->older = NULL; c_free(ptr); ptr = oldest; } } } if (v_messageStateTest(d_sampleGetMessage(d_instanceGetHead(instance)), L_DISPOSED)) { v_stateSet(instance->state, L_DISPOSED); } else { if (v_stateTest(instance->state, L_DISPOSED)) { v_stateClear(instance->state, L_DISPOSED); } } c_free(sample); assert((instance->count == 0) == (d_instanceGetTail(instance) == NULL)); assert((instance->count == 0) == (d_instanceGetHead(instance) == NULL)); return D_STORE_RESULT_OK; }