예제 #1
0
v_dataReaderSample
v_dataReaderSampleNew(
    v_dataReaderInstance instance,
    v_message message)
{
    v_dataReader dataReader;
    v_dataReaderSample sample;
    v_readerQos readerQos;
    v_index index;
    os_timeE msgEpoch;

    assert(instance != NULL);
    assert(C_TYPECHECK(message,v_message));

    index = v_index(instance->index);
    dataReader = v_dataReader(index->reader);
    readerQos = v_reader(dataReader)->qos;
    assert(readerQos);

    sample = v_dataReaderSample(c_new(dataReader->sampleType));
    if (sample != NULL) {
        v_readerSample(sample)->instance = (c_voidp)instance;
        v_readerSample(sample)->viewSamples = NULL;
        v_readerSample(sample)->sampleState = 0;

        sample->insertTime = os_timeWGet();

        /* The expiry time calculation is dependent on the DestinationOrderQos(readerQos->orderby.v.kind):
         * In case of the by_reception_timestamp kind the expiry time is determined based on insertion time(sample->insertTime).
         * In case of the by_source_timestamp kind the expiry time is determined based on source time (message->writeTime).
         */

        msgEpoch = os_timeEGet();
        if (readerQos->orderby.v.kind == V_ORDERBY_SOURCETIME) {
            /* assuming wall clocks of source and destination are aligned!
             * calculate the age of the message and then correct the message epoch.
             */
            os_duration message_age = os_timeWDiff(os_timeWGet(), message->writeTime);
            msgEpoch = os_timeESub(msgEpoch, message_age);
        }
        v_dataReaderSampleTemplate(sample)->message = c_keep(message);
        sample->disposeCount = instance->disposeCount;
        sample->noWritersCount = instance->noWritersCount;
        sample->publicationHandle = message->writerGID;
        sample->readId = 0;
        sample->newer = NULL;
         /* When both ReaderLifespanQos(readerQos->lifespan.used) and the inline LifespanQos (v_messageQos_getLifespanPeriod(message->qos))
          * are set the expiryTime will be set to the earliest time among them.
          */
        if (message->qos) {
            os_duration lifespan = v_messageQos_getLifespanPeriod(message->qos);
            if (readerQos->lifespan.v.used) {
                if (os_durationCompare(readerQos->lifespan.v.duration, lifespan) == OS_LESS) {
                    v_lifespanSample(sample)->expiryTime = os_timeEAdd(msgEpoch, readerQos->lifespan.v.duration);
                } else {
                    v_lifespanSample(sample)->expiryTime = os_timeEAdd(msgEpoch, lifespan);
                }
                v_lifespanAdminInsert(v_dataReaderEntry(index->entry)->lifespanAdmin, v_lifespanSample(sample));
            } else {
                if (OS_DURATION_ISINFINITE(lifespan)) {
                    v_lifespanSample(sample)->expiryTime = OS_TIMEE_INFINITE;
                } else {
                    v_lifespanSample(sample)->expiryTime = os_timeEAdd(msgEpoch, lifespan);
                    v_lifespanAdminInsert(v_dataReaderEntry(index->entry)->lifespanAdmin, v_lifespanSample(sample));
                }
            }
        } else {
            if (readerQos->lifespan.v.used) {
                v_lifespanSample(sample)->expiryTime = os_timeEAdd(msgEpoch,readerQos->lifespan.v.duration);
                v_lifespanAdminInsert(v_dataReaderEntry(index->entry)->lifespanAdmin, v_lifespanSample(sample));
            } else {
                v_lifespanSample(sample)->expiryTime = OS_TIMEE_INFINITE;
            }
        }
    } else {
        OS_REPORT(OS_FATAL, OS_FUNCTION, V_RESULT_INTERNAL_ERROR, "Failed to allocate v_dataReaderSample.");
    }
    return sample;
}
예제 #2
0
v_dataReaderSample
v_dataReaderSampleNew(
    v_dataReaderInstance instance,
    v_message message)
{
    v_dataReader dataReader;
    v_dataReaderSample sample;
    v_readerQos readerQos;
    v_index index;

    assert(instance != NULL);
    assert(C_TYPECHECK(message,v_message));

    index = v_index(instance->index);
    dataReader = v_dataReader(index->reader);
    readerQos = v_reader(dataReader)->qos;
    if (dataReader->cachedSample != NULL) {
        sample = dataReader->cachedSample;

/* Unfinished proto for cache size control
 * #define _SL_
 */
#ifdef _SL_
        dataReader->cachedSample = sample->prev;
        sample->prev = NULL;
        dataReader->cachedSampleCount--;
#else
        dataReader->cachedSample = NULL;
#endif
    } else {
        sample = v_dataReaderSample(c_extentCreate(dataReader->sampleExtent));
    }
    v_readerSample(sample)->instance = (c_voidp)instance;
    v_readerSample(sample)->viewSamples = NULL;
    if ((message->transactionId != 0) &&
        (v_reader(dataReader)->subQos->presentation.coherent_access))
    {
        v_readerSample(sample)->sampleState = L_TRANSACTION;
    } else {
        v_readerSample(sample)->sampleState = 0;
    }
#ifdef _NAT_
    sample->insertTime = v_timeGet();
#else
#define _INCORRECT_BUT_LOW_INSERT_LATENCY_
#ifdef _INCORRECT_BUT_LOW_INSERT_LATENCY_
    if (v_timeIsZero(v_reader(dataReader)->qos->latency.duration)) {
        sample->insertTime = v_timeGet();
    } else {
        sample->insertTime = message->allocTime;
    }
#else
    sample->insertTime = v_timeGet();
#endif
#endif
    if (readerQos->lifespan.used) { 
        v_lifespanSample(sample)->expiryTime = 
            c_timeAdd(sample->insertTime, readerQos->lifespan.duration);
    } else {
        v_lifespanSample(sample)->expiryTime = 
            c_timeAdd(sample->insertTime,
                      v_messageQos_getLifespanPeriod(message->qos));
    }
    sample->disposeCount = instance->disposeCount;
    sample->noWritersCount = instance->noWritersCount;
    sample->publicationHandle = message->writerGID;
    sample->readId = 0;
    sample->prev = NULL;
    assert(message);
    v_dataReaderSampleTemplate(sample)->message = c_keep(message);
    v_lifespanAdminInsert(v_dataReaderEntry(index->entry)->lifespanAdmin,
                          v_lifespanSample(sample));

    dataReader->notReadCount++;

    return sample;
}