v_dataViewSample v_dataViewSampleNew( v_dataViewInstance instance, v_readerSample masterSample) { v_dataView dataView; v_dataViewSample sample; assert(instance != NULL); assert(masterSample != NULL); assert(C_TYPECHECK(masterSample,v_readerSample)); dataView = v_dataView(instance->dataView); #ifdef _EXTENT_ sample = v_dataViewSample(c_extentCreate(dataView->sampleExtent)); #else sample = v_dataViewSample(c_new(dataView->sampleType)); #endif if (sample) { v_readerSample(sample)->instance = (c_voidp)instance; v_readerSample(sample)->sampleState = 0; v_dataViewSampleList(sample)->next = NULL; v_dataViewSampleList(sample)->prev = NULL; sample->prev = NULL; v_dataViewSampleTemplate(sample)->sample = c_keep(masterSample); } else { OS_REPORT(OS_ERROR, "v_dataViewSampleNew",0, "Failed to allocate v_dataViewSample."); } return sample; }
void v_dataReaderSampleAddViewSample( v_readerSample sample, v_dataViewSample viewSample) { v_dataViewSampleList listSample; listSample = v_dataViewSampleList(viewSample); listSample->next = sample->viewSamples; if (sample->viewSamples != NULL) { v_dataViewSampleList(sample->viewSamples)->prev = listSample; } listSample->prev = NULL; sample->viewSamples = listSample; }
void v_dataViewInstanceWipe( v_dataViewInstance instance) { v_dataViewSample sample,prev,firstSample; if (instance == NULL) { return; } assert (C_TYPECHECK (instance, v_dataViewInstance)); CHECK_INSTANCE(instance); if (instance->sampleCount != 0) { sample = v_dataViewInstanceTemplate(instance)->sample; firstSample = c_keep(sample); while (sample != NULL) { v_dataViewSampleListRemove(v_dataViewSampleList(sample)); prev = sample->prev; sample->prev = NULL; c_free(sample); sample = prev; } instance->sampleCount = 0; v_dataViewInstanceTemplate(instance)->sample = firstSample; } CHECK_ZERO_INSTANCE(instance); }
void v_dataViewSampleListRemove( v_dataViewSampleList sample) { assert(C_TYPECHECK(sample,v_dataViewSampleList)); assert(v_dataViewInstance(v_readerSample(sample)->instance)->sampleCount > 0); CHECK_INSTANCE(v_dataViewInstance(v_readerSample(sample)->instance)); if (sample->next != NULL) { v_dataViewSampleList(sample->next)->prev = sample->prev; } if (sample->prev != NULL) { v_dataViewSampleList(sample->prev)->next = sample->next; } else { assert(v_dataViewSampleTemplate(sample)->sample->viewSamples == sample); v_dataViewSampleTemplate(sample)->sample->viewSamples = sample->next; } sample->prev = NULL; sample->next = NULL; CHECK_INSTANCE(v_dataViewInstance(v_readerSample(sample)->instance)); }
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; }