Exemplo n.º 1
0
void
v_dataReaderSampleFree(
    v_dataReaderSample sample)
{
    v_dataReaderInstance instance;
    v_index index;
    v_dataReader dataReader;
    v_message message;

    if (sample) {
        assert(C_TYPECHECK(sample, v_dataReaderSample));
        if (c_refCount(sample) == 1) {
            /* Free the slave-samples as well */
            instance = v_readerSample(sample)->instance;
            index = v_index(instance->index);
            dataReader = v_dataReader(index->reader);
            if (!v_readerSampleTestState(sample,L_READ)) {
                dataReader->notReadCount--;
            }
#ifdef _SL_
            if (dataReader->cachedSampleCount < 1000) {
                message = v_dataReaderSampleMessage(sample);
                c_free(message);
                v_dataReaderSampleTemplate(sample)->message = NULL;
                sample->prev = dataReader->cachedSample;
                dataReader->cachedSample = sample;
                dataReader->cachedSampleCount++;
#else
            if (dataReader->cachedSample == NULL) {
                dataReader->cachedSample = sample;
                message = v_dataReaderSampleMessage(sample);
                c_free(message);
                v_dataReaderSampleTemplate(sample)->message = NULL;
#endif
            } else {
                c_free(sample);
            }
        } else {
            c_free(sample);
        }
    }
}

void
v_dataReaderSampleRemoveFromLifespanAdmin(
    v_dataReaderSample sample)
{
    v_dataReaderInstance instance;
    v_index index;

    if (sample) {
        assert(C_TYPECHECK(sample, v_dataReaderSample));
        instance = v_readerSample(sample)->instance;
        index = v_index(instance->index);
        v_lifespanAdminRemove(v_dataReaderEntry(index->entry)->lifespanAdmin,
                              v_lifespanSample(sample));
    }
}
Exemplo n.º 2
0
void
v_dataReaderSampleRemoveFromLifespanAdmin(
    v_dataReaderSample sample)
{
    v_dataReaderInstance instance;
    v_index index;

    assert(sample);
    assert(C_TYPECHECK(sample, v_dataReaderSample));

    instance = v_readerSample(sample)->instance;
    index = v_index(instance->index);
    v_lifespanAdminRemove(v_dataReaderEntry(index->entry)->lifespanAdmin, v_lifespanSample(sample));
}
Exemplo n.º 3
0
static c_bool
checkTopic (
    c_object o,
    c_voidp arg)
{
    v_dataReaderEntry entry;
    c_char *topicName = (c_char *)arg;

    if(v_object(o)->kind == K_DATAREADERENTRY){
        entry = v_dataReaderEntry(o);
        if (strcmp(v_topicName(entry->topic),topicName) == 0) {
            return FALSE;
        }
    }
    return TRUE;
}
Exemplo n.º 4
0
v_writeResult
v_entryWrite(
    v_entry e,
    v_message o,
    v_networkId writingNetworkId,
    v_instance *instance)
{
    v_writeResult writeResult;

    assert(C_TYPECHECK(e,v_entry));
    assert(C_TYPECHECK(o,v_message));

    switch(v_objectKind(e->reader)) {
    case K_DATAREADER:
        writeResult = v_dataReaderEntryWrite(v_dataReaderEntry(e),
                                             o,
                                             instance,
                                             C_TIME_MIN_INFINITE);
    break;
    case K_NETWORKREADER:
        writeResult = v_networkReaderEntryWrite(v_networkReaderEntry(e),
                                                o, writingNetworkId);
    break;
    case K_DELIVERYSERVICE:
        writeResult = v_deliveryServiceEntryWrite(v_deliveryServiceEntry(e),o,instance);
    break;
    default:
        OS_REPORT_1(OS_ERROR,
                    "v_entryWrite failed",0,
                    "illegal reader kind (%d) specified",
                    v_objectKind(e->reader));
        assert(FALSE);
        return V_WRITE_UNDEFINED;
    }
    return writeResult;
}
Exemplo n.º 5
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;
}
Exemplo n.º 6
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;
}