static void copySampleInfoView ( v_readerSample sample, v_message message, gapi_sampleInfo *to ) { v_state state; v_dataReaderSample master; v_dataViewInstance viewInstance; v_dataReaderInstance masterInstance; viewInstance = (v_dataViewInstance)sample->instance; master = v_dataReaderSample(v_dataViewSampleTemplate(sample)->sample); masterInstance = (v_dataReaderInstance)v_readerSampleInstance(master); state = v_readerSample(sample)->sampleState; if (v_stateTest (state, L_READ)) { to->sample_state = GAPI_READ_SAMPLE_STATE; } else { to->sample_state = GAPI_NOT_READ_SAMPLE_STATE; } if (v_stateTest (state, L_NEW)) { to->view_state = GAPI_NEW_VIEW_STATE; } else { to->view_state = GAPI_NOT_NEW_VIEW_STATE; } state = masterInstance->instanceState; to->instance_state = GAPI_ALIVE_INSTANCE_STATE; if (v_stateTest (state, L_NOWRITERS)) { to->instance_state = GAPI_NOT_ALIVE_NO_WRITERS_INSTANCE_STATE; } if (v_stateTest (state, L_DISPOSED)) { to->instance_state = GAPI_NOT_ALIVE_DISPOSED_INSTANCE_STATE; } /* Data is always valid for views */ to->valid_data = TRUE; to->source_timestamp.sec = (gapi_long)(message->writeTime.seconds); to->source_timestamp.nanosec = (gapi_unsigned_long)(message->writeTime.nanoseconds); to->disposed_generation_count = master->disposeCount; to->no_writers_generation_count = master->noWritersCount; to->sample_rank = 0; to->generation_rank = 0; to->absolute_generation_rank = 0; to->instance_handle = u_instanceHandleNew(v_public(viewInstance)); to->publication_handle = u_instanceHandleFromGID(master->publicationHandle); to->reception_timestamp.sec = (gapi_long)(master->insertTime.seconds); to->reception_timestamp.nanosec = (gapi_unsigned_long)(master->insertTime.nanoseconds); }
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; }
c_bool d_readerListenerCopy( c_object object, c_voidp copyArg) { d_readerListener listener; d_message message; v_message readerMessage; c_bool result = FALSE; if(object != NULL) { if (v_stateTest(v_readerSampleState(object), L_VALIDDATA)) { listener = d_readerListener(copyArg); readerMessage = v_message(v_dataReaderSampleTemplate(object)->message); message = C_DISPLACE(readerMessage, listener->fieldOffset); listener->lastInsertTime = v_dataReaderSample(object)->insertTime; listener->lastSourceTime = readerMessage->writeTime; listener->value = c_keep(object); if(listener->value){ listener->message = message; } listener->processMessage = TRUE; } else { /* Ignore data that is not valid but continue with the read action */ result = TRUE; } } return result; }
v_actionResult cmx_readerReadCopy( c_object o, c_voidp args) { sd_serializer ser; sd_serializedData data; v_dataReaderSample sample, newer; struct cmx_readerArg *arg; v_actionResult result; result = 0; if(o != NULL){ sample = v_dataReaderSample(o); if(v_stateTest(v_readerSampleState(sample), L_READ)){ v_actionResultSet(result, V_PROCEED); } else { sample = v_dataReaderSample(o); newer = sample->newer; sample->newer = NULL; arg = (struct cmx_readerArg *)args; ser = sd_serializerXMLNewTyped(c_getType(o)); data = sd_serializerSerialize(ser, o); arg->result = sd_serializerToString(ser, data); sd_serializedDataFree(data); sd_serializerFree(ser); sample->newer = newer; } } return result; }
static c_bool takeOne( c_object o, c_voidp arg) { v_readerSample s; v_readerSample *sample; c_bool result; s = (v_readerSample)o; sample = (v_readerSample *)arg; if (s != NULL) { result = TRUE; if (v_stateTest(s->sampleState, L_VALIDDATA)) { *sample = c_keep(s); result = FALSE; } else { *sample = NULL; } } else { /* last sample */ result = FALSE; } return result; }
c_bool cmx_readerReadCopy( c_object o, c_voidp args) { sd_serializer ser; sd_serializedData data; v_dataReaderSample sample, prev; struct cmx_readerArg *arg; c_bool result; result = FALSE; if(o != NULL){ sample = v_dataReaderSample(o); if(v_stateTest(v_readerSampleState(sample), L_READ)){ result = TRUE; } else { sample = v_dataReaderSample(o); prev = sample->prev; sample->prev = NULL; arg = (struct cmx_readerArg *)args; ser = sd_serializerXMLNewTyped(c_getType(o)); data = sd_serializerSerialize(ser, o); arg->result = sd_serializerToString(ser, data); sd_serializedDataFree(data); sd_serializerFree(ser); sample->prev = prev; } } return result; }
u_result nb_topicObjectWrite( u_writer writer, nb_topicObject _this) { u_result result = U_RESULT_UNSUPPORTED; os_timeW timestamp; assert(writer); nb_objectIsValid(_this); timestamp = _this->writeTime; if(v_stateTest(_this->state, L_REGISTER)){ result = u_writerRegisterInstance( writer, nb_topicObjectCopyIn, _this, timestamp, U_INSTANCEHANDLE_NIL); } else if(v_stateTest(_this->state, L_WRITE) && v_stateTest(_this->state, L_DISPOSED)){ result = u_writerWriteDispose( writer, nb_topicObjectCopyIn, _this, timestamp, U_INSTANCEHANDLE_NIL); } else if(v_stateTest(_this->state, L_WRITE)) { result = u_writerWrite( writer, nb_topicObjectCopyIn, _this, timestamp, U_INSTANCEHANDLE_NIL); } else if(v_stateTest(_this->state, L_DISPOSED)) { result = u_writerDispose( writer, nb_topicObjectCopyIn, _this, timestamp, U_INSTANCEHANDLE_NIL); } return result; }
static u_result handlePublication( u_dataReader dataReader, c_long dataOffset, u_dataReader pDataReader, c_long pDataOffset) { v_dataReaderSample sample; u_result result; v_state state; v_message msg; struct v_publicationInfo *data; in_writer writer; 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_publicationInfo *)(C_DISPLACE(msg, dataOffset)); os_mutexLock (&gluelock); if(v_stateTest(state, L_DISPOSED)){ writer = in_writerLookup(&data->key); if(writer){ in_writerFree(writer, NULL); } else { nn_log (LC_WARNING, "handlePublication: disposed writer not found\n"); /*abort();*/ } } else { participant = in_participantLookup(&(data->participant_key)); if(!participant){ result = handleParticipant(pDataReader, pDataOffset, 1); if(result == U_RESULT_OK){ participant = in_participantLookup(&(data->participant_key)); } } if(participant){ in_writerNew(participant, data); } else { nn_log (LC_ERROR, "handlePublication: participant not found\n"); result = U_RESULT_INTERNAL_ERROR; /*abort();*/ } } os_mutexUnlock (&gluelock); c_free(sample); sample = NULL; result = u_dataReaderTake(dataReader, takeOne, &sample); } return result; }
void v_messageExtConvertHeaderFromExtNoAllocTime ( v_message vmsg, const struct v_messageExt_s *xmsg) { c_bool y2038Ready = v_stateTest(xmsg->_parent.nodeState, L_TIME_Y2038); v_messageExtConvertHeaderFromExtCommon(vmsg, xmsg, y2038Ready); vmsg->allocTime = os_timeEGet(); }
static v_ownershipResult claimOwnership( struct v_owner *owner, const struct v_owner *candidate, v_state messageState) { v_ownershipResult result; if (v_stateTest(messageState, L_REGISTER)) { /* Don't modify anything: a register does not change state (yet). */ result = V_OWNERSHIP_NOT_OWNER; } else if (v_stateTest(messageState, L_UNREGISTER)) { /* If the current owner unregisters, the ownership is reset. */ v_gidSetNil (owner->gid); owner->strength = 0; result = V_OWNERSHIP_OWNER_RESET; } else { owner->gid = candidate->gid; owner->strength = candidate->strength; result = V_OWNERSHIP_OWNER; } return result; }
void v_messageExtConvertHeaderFromExt ( v_message vmsg, const struct v_messageExt_s *xmsg) { c_bool y2038Ready = v_stateTest(xmsg->_parent.nodeState, L_TIME_Y2038); v_messageExtConvertHeaderFromExtCommon(vmsg, xmsg, y2038Ready); if (y2038Ready) { OS_TIMEE_GET_VALUE(vmsg->allocTime) = c_timeToUint64(xmsg->allocTime); } else { vmsg->allocTime = c_timeToTimeE(xmsg->allocTime); } }
static void computeGenerationRanksView ( v_readerSampleSeq *samples, gapi_dataSampleSeq *dataSamples) { gapi_unsigned_long first = 0; while ( first < samples->_length ) { gapi_unsigned_long i; gapi_unsigned_long next = first + 1; gapi_unsigned_long last = first; gapi_boolean found = FALSE; v_readerSample fs; c_voidp instance; gapi_viewStateKind vs; fs = samples->_buffer[first]; instance = fs->instance; while ( !found && (next < samples->_length) ) { v_readerSample s = samples->_buffer[next]; if ( instance != s->instance ) { found = TRUE; } else { last = next++; } } if ( v_stateTest(fs->sampleState, L_NEW) ) { vs = GAPI_NEW_VIEW_STATE; } else { vs = GAPI_NOT_NEW_VIEW_STATE; } for ( i = first; i <= last; i++ ) { dataSamples->_buffer[i].info.sample_rank = last - i; dataSamples->_buffer[i].info.generation_rank = 0; dataSamples->_buffer[i].info.absolute_generation_rank = 0; /* copy new state of last sample of an instance */ dataSamples->_buffer[i].info.view_state = vs; } first = last + 1; } }
static v_message createUnregisterMessage( v_group group, v_message message) { c_array messageKeyList; c_long i, nrOfKeys; v_message unregisterMessage; assert(!v_stateTest(v_nodeState(message), L_UNREGISTER)); /* Create new message objec */ unregisterMessage = v_topicMessageNew (group->topic); /* Copy keyvalues to unregistermessage */ messageKeyList = v_topicMessageKeyList(v_groupTopic(group)); nrOfKeys = c_arraySize(messageKeyList); for (i=0;i<nrOfKeys;i++) { c_fieldAssign (messageKeyList[i], unregisterMessage, c_fieldValue(messageKeyList[i],message)); } /* Set instance & writer GID */ unregisterMessage->writerGID = message->writerGID; unregisterMessage->writerInstanceGID = message->writerInstanceGID; /* Copy messageQos */ c_keep (message->qos); unregisterMessage->qos = message->qos; /* Set nodestate to unregister */ v_nodeState(unregisterMessage) = L_UNREGISTER; unregisterMessage->writeTime = v_timeGet(); #ifndef _NAT_ unregisterMessage->allocTime = unregisterMessage->writeTime; #endif return unregisterMessage; }
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; }
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; }