Ejemplo n.º 1
0
void
v_dataViewSampleRemove(
    v_dataViewSample sample)
{
    v_dataViewInstance instance;

    assert(C_TYPECHECK(sample,v_dataViewSample));

    instance = v_dataViewInstance(v_readerSample(sample)->instance);
    CHECK_INSTANCE(instance);

    if (instance->sampleCount > 1) {
        if (sample->next != NULL) {
            v_dataViewSample(sample->next)->prev = sample->prev;
        } else {
            v_dataViewInstanceTemplate(instance)->sample = sample->prev;
        }
        if (sample->prev != NULL) {
            v_dataViewSample(sample->prev)->next = sample->next;
        }
        sample->prev = NULL;
        sample->next = NULL;
        c_free(sample);
    }
    instance->sampleCount--;
    if (instance->sampleCount > 0) {
        CHECK_INSTANCE(instance);
    } else {
        CHECK_ZERO_INSTANCE(instance);
    }
}
Ejemplo n.º 2
0
void
v_dataViewInstanceWalkSamples(
    v_dataViewInstance instance,
    v_readerSampleAction action,
    c_voidp arg)
{
    v_dataViewSample sample;
    c_bool proceed = TRUE;

    assert(C_TYPECHECK(instance,v_dataViewInstance));
    CHECK_INSTANCE(instance);

    if (instance == NULL) {
        return;
    }
    if (instance->sampleCount == 0) {
        return;
    }
    sample = v_dataViewInstanceTemplate(instance)->sample;
    while ((sample != NULL) && (proceed == TRUE)) {
        proceed = action(v_readerSample(sample),arg);
        sample = sample->prev;
    }
    CHECK_INSTANCE(instance);
}
Ejemplo n.º 3
0
c_bool
v_dataViewInstanceTest(
    v_dataViewInstance instance,
    c_query query,
    v_state sampleMask,
    v_queryAction action,
    c_voidp args)
{
    v_dataViewSample sample, firstSample;
    c_bool sampleSatisfies = FALSE;

    assert(C_TYPECHECK(instance,v_dataViewInstance));

    CHECK_INSTANCE(instance);

    if (instance == NULL) {
        return FALSE;
    }

    if (instance->sampleCount == 0) {
        return TRUE;
    }

    firstSample = v_dataViewInstanceTemplate(instance)->sample;
    assert (firstSample != NULL);
    sample = firstSample;
    while (sample != NULL && sampleSatisfies == FALSE) {
        /* The history samples are swapped with the first sample to make
         * sample-evaluation on instance level work.
         */
        if (v_sampleMaskPass(sampleMask, sample)) {
            if (query) {
                if (sample != firstSample) {
                    v_dataViewInstanceTemplate(instance)->sample = sample;
                }
                sampleSatisfies = c_queryEval(query,instance);
                if (sample != firstSample) {
                    v_dataViewInstanceTemplate(instance)->sample = firstSample;
                }
            } else {
                sampleSatisfies = TRUE;
            }
        }
        /* If a sample passed the query, then check whether it matches the
         * optional condition passed by the action routine. (This condition
         * can for example check for matching lifecycle states.)
         */
        if (sampleSatisfies && action != NULL) {
            sampleSatisfies = action(sample, args);
        }
        sample = sample->prev;
    }
    CHECK_INSTANCE(instance);
    return sampleSatisfies;
}
Ejemplo n.º 4
0
c_bool
v_dataViewInstanceReadSamples(
    v_dataViewInstance instance,
    c_query query,
    v_state sampleMask,
    v_readerSampleAction action,
    c_voidp arg)
{
    v_dataViewSample sample, firstSample;
    v_actionResult result = V_PROCEED;
    c_bool sampleSatisfies = FALSE;

    assert(C_TYPECHECK(instance,v_dataViewInstance));
    CHECK_INSTANCE(instance);

    if (instance == NULL) {
        return v_actionResultTest(result, V_PROCEED);
    }
    if (instance->sampleCount == 0) {
        return v_actionResultTest(result, V_PROCEED);
    }
    firstSample = v_dataViewInstanceTemplate(instance)->sample;
    assert (firstSample != NULL);
    sample = firstSample;
    while (sample != NULL && v_actionResultTest(result, V_PROCEED)) {
        if (v_sampleMaskPass(sampleMask, sample)) {
            if (query != NULL) {
                /* The history samples are swapped with the first sample to make
                 * sample-evaluation on instance level work.
                 */
                if (sample != firstSample) {
                    v_dataViewInstanceTemplate(instance)->sample = sample;
                }
                sampleSatisfies = c_queryEval(query,instance);
                if (sample != firstSample) {
                    v_dataViewInstanceTemplate(instance)->sample = firstSample;
                }
            } else {
                sampleSatisfies = TRUE;
            }
        }
        if (sampleSatisfies) {
            result = v_dataViewSampleReadTake(sample, action, arg, FALSE);
        }
        sample = sample->prev;
    }
    CHECK_INSTANCE(instance);
    return v_actionResultTest(result, V_PROCEED);
}
Ejemplo n.º 5
0
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);
}
Ejemplo n.º 6
0
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;
}
Ejemplo n.º 7
0
static c_bool
v_dataViewInstanceTakeWithCondition(
    v_dataViewInstance instance,
    v_sampleCondition condition,
    c_voidp conditionArg,
    v_state sampleMask,
    v_readerSampleAction action,
    c_voidp actionArg)
{
    v_dataViewSample sample, previous;
    c_bool proceed = TRUE;
    c_bool sampleSatisfies = FALSE;

    assert(C_TYPECHECK(instance,v_dataViewInstance));
    CHECK_INSTANCE(instance);

    if (instance == NULL) {
        return proceed;
    }
    if (instance->sampleCount == 0) {
        return proceed;
    }
    sample = v_dataViewInstanceTemplate(instance)->sample;
    assert (sample != NULL);
    while (proceed == TRUE && sample != NULL) {
        if (v_sampleMaskPass(sampleMask, sample)) {
            if (condition != NULL) {
                sampleSatisfies = condition(sample, conditionArg);
            } else {
                sampleSatisfies = TRUE;
            }
        }
        previous = sample->prev;
        if (sampleSatisfies) {
            proceed = v_actionResultTest(v_dataViewSampleReadTake(sample, action, actionArg, TRUE), V_PROCEED);
        }
        sample = previous;
    }

    if (instance->sampleCount > 0) {
        CHECK_INSTANCE(instance);
    } else {
        CHECK_ZERO_INSTANCE(instance);
    }
    return proceed;
}
Ejemplo n.º 8
0
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));
}
Ejemplo n.º 9
0
v_writeResult
v_dataViewInstanceWrite (
    v_dataViewInstance instance,
    v_readerSample sample)
{
    v_dataViewSample viewSample;
    v_dataViewSample *prev;
    v_dataViewSample next;

    assert(C_TYPECHECK(instance,v_dataViewInstance));
    assert(C_TYPECHECK(sample,v_readerSample));

    CHECK_INSTANCE(instance);

    viewSample = v_dataViewSampleNew(instance,sample);
    if (viewSample) {
        viewSample->next = NULL;

        prev = &v_dataViewInstanceTemplate(instance)->sample;
        next = NULL;

        while (*prev) {
            next = *prev;
            prev = &(*prev)->prev;
        }
        *prev = viewSample;
        viewSample->next = next;

        v_readerSampleAddViewSample(sample,viewSample);
        instance->sampleCount++;
        assert(c_refCount(viewSample) == 1);
        v_dataViewNotifyDataAvailable(v_dataView(instance->dataView), viewSample);
    }
    CHECK_INSTANCE(instance);
    return V_WRITE_SUCCESS;
}
Ejemplo n.º 10
0
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;
}
Ejemplo n.º 11
0
void
v_dataViewInstanceRemove(
    v_dataViewInstance instance)
{
    v_dataViewInstance found;

    assert(C_TYPECHECK(instance,v_dataViewInstance));


    if (instance->sampleCount == 0) {
        CHECK_ZERO_INSTANCE(instance);
        found = c_remove(v_dataView(instance->dataView)->instances,instance,NULL,NULL);
        assert(found == instance);
        instance->dataView  = NULL;
        v_publicFree(v_public(instance));
        c_free(instance);
    } else {
        CHECK_INSTANCE(instance);
    }
}
Ejemplo n.º 12
0
void
v_dataViewInstanceRemove(
    v_dataViewInstance instance)
{
    v_dataView dataView;
    v_dataViewInstance found;

    assert(C_TYPECHECK(instance,v_dataViewInstance));

    if (instance->sampleCount == 0) {
        CHECK_ZERO_INSTANCE(instance);
        if (v_objectKind (instance) == K_DATAVIEWINSTANCE) {
            dataView = v_dataView(v_instanceEntity(instance));
            found = c_remove(dataView->instances,instance,NULL,NULL);
            assert(found == instance);
            OS_UNUSED_ARG(found);
            v_publicFree(v_public(instance));
            c_free(instance);
        }
    } else {
        CHECK_INSTANCE(instance);
    }
}