Exemple #1
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);
}
Exemple #2
0
static c_bool
evalInstanceQuery(
    v_dataViewSample sample,
    c_voidp arg)
{
    v_instanceQueryArg instanceQueryArg = (v_instanceQueryArg)arg;
    c_query query = instanceQueryArg->query;
    v_dataViewInstance instance = instanceQueryArg->instance;
    v_dataViewSample firstSample;
    c_bool result;

    assert(query != NULL);
    /* The history samples are swapped with the first sample to make
     * sample-evaluation on instance level work.
     */
    firstSample = v_dataViewInstanceTemplate(instance)->sample;
    if (sample != firstSample) {
        v_dataViewInstanceTemplate(instance)->sample = sample;
    }
    result = c_queryEval(query,instance);
    if (sample != firstSample) {
        v_dataViewInstanceTemplate(instance)->sample = firstSample;
    }

    return result;
}
Exemple #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;
}
Exemple #4
0
void
v_dataViewInstanceWrite(
    v_dataViewInstance instance,
    v_dataViewSample sample,
    v_dataViewSample position)
{
    v_dataViewSample head, *sampleptr;

    assert (instance != NULL && C_TYPECHECK (instance, v_dataViewInstance));
    assert (sample != NULL && C_TYPECHECK (sample, v_dataViewSample));
    if (position != NULL) {
        assert (C_TYPECHECK (position, v_dataViewSample));
    }

    head = v_dataViewInstanceTemplate(instance)->sample;
    /* Keep alive view sample must be discarded, but only after the new
     * view sample is inserted.
     */
    if (instance->sampleCount == 0) {
        assert (position == NULL);
        assert(head == NULL);
        sampleptr = &v_dataViewInstanceTemplate(instance)->sample;
        sample->next = sample;
        sample->prev = NULL;
        (*sampleptr) = sample;

    } else if (position == NULL) {
        assert(head);
        /* "normal" use case, append sample to list */
        sampleptr = (v_dataViewSample *)&head->next;
        sample->next = (*sampleptr);
        sample->prev = NULL;
        (*sampleptr)->prev = sample;
        (*sampleptr) = sample;

    } else {
        assert (position->next != NULL);
        assert(head);
        sample->next = position->next;
        if (position == head) {
            sampleptr = &v_dataViewInstanceTemplate(instance)->sample;
            /* verify previous pointer of tail sample is correct */
            assert (v_dataViewSample(head->next)->prev == NULL);
            (*sampleptr)->next = sample;
        } else {
            sampleptr = (v_dataViewSample *)&position->next;
            (*sampleptr)->prev = sample;
        }
        sample->prev = position;
        (*sampleptr) = sample;
    }
    instance->sampleCount++;
}
Exemple #5
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);
}
Exemple #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;
}
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);
    }
}
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);
}
Exemple #9
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;
}
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;
}
Exemple #11
0
void
checkInstance(
    v_dataViewInstance instance,
    c_bool isNotEmpty)
{
    int i = 0;
    v_dataViewSample current;
    v_dataViewSample next;

    if (instance) {
        if (!isNotEmpty) {
            REL_ASSERT(instance->sampleCount == 0);
        }
        if (!v_reader(v_dataViewReader(instance->dataView))->qos->userKey.enable && isNotEmpty) {
            REL_ASSERT(instance->sampleCount == 1);
        }
        REL_ASSERT(c_refCount(instance) > 0);
        REL_ASSERT(C_TYPECHECK(instance, v_dataViewInstance));
        next = NULL;
        current = v_dataViewInstanceTemplate(instance)->sample;
        while (current != NULL) {
            if (!isNotEmpty) {
                checkSample(current);
            }
            REL_ASSERT(current->next == next);
            if (next != NULL) {
                REL_ASSERT(next->prev == current);
            }
            next = current;
            current = current->prev;
            i++;
        }
        if (next != NULL) {
            REL_ASSERT(next->prev == current);
        }
        if (isNotEmpty) {
            REL_ASSERT(i == instance->sampleCount);
        } else {
            REL_ASSERT(i == 1);
        }
    }
}
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;
}