示例#1
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;
}
示例#2
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;
}
示例#3
0
static void
v_messageExtConvertHeaderFromExtCommon (
    v_message vmsg,
    const struct v_messageExt_s *xmsg,
    c_bool y2038Ready)
{
    vmsg->_parent.nodeState = xmsg->_parent.nodeState;
    if (y2038Ready) {
        OS_TIMEW_GET_VALUE(vmsg->writeTime) = c_timeToUint64(xmsg->writeTime);
        v_stateClear(vmsg->_parent.nodeState, L_TIME_Y2038);
    } else {
        vmsg->writeTime = c_timeToTimeW(xmsg->writeTime);
    }
    vmsg->writerGID = xmsg->writerGID;
    vmsg->writerInstanceGID = xmsg->writerInstanceGID;
    vmsg->sequenceNumber = xmsg->sequenceNumber;
    vmsg->transactionId = xmsg->transactionId;
    vmsg->qos = xmsg->qos;
}
示例#4
0
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;
}
示例#5
0
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;
}