Esempio n. 1
0
c_bool
determineFirstLeaseToExpire(
    c_object o,
    c_voidp arg)
{
    c_time headExpTime;
    c_time leaseExpTime;
    v_leaseAction leaseAction = v_leaseAction(o);
    v_leaseManager lm = v_leaseManager(arg);

    if (lm->firstLeaseToExpire == NULL)
    {
        lm->firstLeaseToExpire = c_keep(leaseAction);
    } else
    {
        headExpTime = v_leaseExpiryTime(lm->firstLeaseToExpire->lease);
        leaseExpTime = v_leaseExpiryTime(leaseAction->lease);
        if (c_timeCompare(headExpTime, leaseExpTime) == C_GT)
        {
            c_free(lm->firstLeaseToExpire);
            lm->firstLeaseToExpire = c_keep(leaseAction);
        }
    }
    return TRUE;
}
Esempio n. 2
0
v_cache
v_cacheNew (
    v_kernel kernel,
    c_type type,
    v_cacheKind kind)
{
    c_base base = NULL;
    c_type cache_t;
    v_cache cache = NULL;

    assert(C_TYPECHECK(cache,v_cache));
    assert(C_TYPECHECK(type,c_type));

    if (type) {
        base = c_getBase(type);
        if (base) {
            cache_t = c_keep(v_kernelType(kernel,K_CACHE));
            cache = c_new(cache_t);
            c_free(cache_t);
            if (cache) {
                cache->kind = kind;
                cache->itemType = c_keep(type);
                v_cacheNodeInit(v_cacheNode(cache));
            }
        }
    }
    return cache;
}
Esempio n. 3
0
/**************************************************************
 * constructor/destructor
 **************************************************************/
void
v_readerInit(
    v_reader r,
    const c_char *name,
    v_subscriber s,
    v_readerQos qos,
    v_statistics rs,
    c_bool enable)
{
    v_kernel kernel;

    assert(r != NULL);
    assert(s != NULL);
    assert(C_TYPECHECK(r,v_reader));
    assert(C_TYPECHECK(s,v_subscriber));
    assert(C_TYPECHECK(qos, v_readerQos));
    /* We demand the qos to be allocated in the kernel, by v_readerQosNew().
     * This way we are sure that the qos is consistent!
     */

    kernel = v_objectKernel(r);
    v_collectionInit(v_collection(r),name,rs,enable);

    r->subscriber = s;
    r->qos = c_keep(qos);
    r->subQos = c_keep(s->qos); /* reference is readonly */
    r->entrySet.entries = c_setNew(v_kernelType(kernel,K_ENTRY));
    c_mutexInit(&r->entrySet.mutex, SHARED_MUTEX);

    r->historicalDataRequest  = NULL;
    r->historicalDataComplete = FALSE;
    c_condInit(&r->historicalDataCondition, &(v_observer(r)->mutex), SHARED_COND);

}
Esempio n. 4
0
d_storeResult
d_groupInfoBackup(
    d_groupInfo _this,
    const d_store store,
    d_groupInfo* backup)
{
    c_base base;
    c_type groupInfoType, instanceType;
    c_string keyExpr;
    d_storeResult result;

    assert(_this);
    assert(backup);

    base = c_getBase(_this->kernel);
    groupInfoType = c_resolve(base,"durabilityModule2::d_groupInfo");
    *backup = d_groupInfo(c_new(groupInfoType));
    c_free(groupInfoType);

    if (*backup) {
        (*backup)->kernel = _this->kernel; /* Unmanaged pointer */
        (*backup)->topic = c_keep(_this->topic);
        (*backup)->partition = c_keep(_this->partition);
        (*backup)->quality = _this->quality;
        (*backup)->completeness = _this->completeness;

        instanceType = d_topicInfoGetInstanceType(_this->topic);
        keyExpr = d_topicInfoGetInstanceKeyExpr(_this->topic);

        (*backup)->instances = _this->instances; /*Here's the trick */
        _this->instances = c_tableNew(instanceType, keyExpr);

        c_free(keyExpr);
        c_free(instanceType);

        if(_this->instances){
            result = D_STORE_RESULT_OK;
        } else {
            _this->instances = (*backup)->instances;

            (*backup)->instances = NULL;
            c_free(*backup);
            *backup = NULL;

            result = D_STORE_RESULT_OUT_OF_RESOURCES;
        }
    } else {
        assert(FALSE);
        result = D_STORE_RESULT_OUT_OF_RESOURCES;
    }
    return result;
}
Esempio n. 5
0
/**************************************************************
 * Protected functions
 **************************************************************/
void
v_lifespanAdminInsert(
    v_lifespanAdmin admin,
    v_lifespanSample sample)
{
    v_lifespanSample placeHolder;
    c_equality eq;

    assert(C_TYPECHECK(admin,v_lifespanAdmin));
    assert(C_TYPECHECK(sample,v_lifespanSample));
    assert(admin->sampleCount >= 0);

    CHECK_ADMIN(admin, sample);
    eq = c_timeCompare(sample->expiryTime, C_TIME_INFINITE);
    if (eq == C_EQ) {
        return; /* no insert, since sample never expires! */
    }

    if (admin->head == NULL) {
        assert(admin->tail == NULL);
        admin->head = c_keep(sample);
        admin->tail = c_keep(sample);
    } else {
        placeHolder = admin->tail;
        eq = c_timeCompare(placeHolder->expiryTime, sample->expiryTime);
        while ((placeHolder->prev != NULL) && (eq != C_LT) /* >= */) {
            placeHolder = placeHolder->prev;
            if (placeHolder != NULL) {
                eq = c_timeCompare(placeHolder->expiryTime, sample->expiryTime);
            }
        }
        if (eq != C_LT) { /* insert before placeholder */
            assert(placeHolder == admin->head);
            sample->next = admin->head; /* transfer ref count */
            admin->head->prev = sample;
            admin->head = c_keep(sample);
        } else {
            if (placeHolder->next != NULL) {                
                placeHolder->next->prev = sample;
            } else {
                assert(placeHolder == admin->tail);
                c_free(admin->tail);
                admin->tail = c_keep(sample);
	    }
            sample->next = placeHolder->next; /* transfer refcount */
            placeHolder->next = c_keep(sample);
            sample->prev = placeHolder;
        }
    }
    admin->sampleCount++;
    CHECK_ADMIN(admin, sample);
}
Esempio n. 6
0
c_bool
collectExpired(
    c_object o,
    c_voidp arg)
{
    v_leaseAction leaseAction = v_leaseAction(o);
    struct collectExpiredArg *a = (struct collectExpiredArg *)arg;
    c_time headExpTime;
    c_time leaseExpTime;
    c_bool setHead;
    c_equality cmp;

    setHead = TRUE;
    leaseExpTime = v_leaseExpiryTime(leaseAction->lease);
    /*
     * A lease is expired if the expiry time is greater than or equal
     * to the current time!
     */
    cmp = c_timeCompare(a->now, leaseExpTime);
    if ((cmp ==  C_GT) || (cmp == C_EQ)) {
        a->expiredLeases = c_iterInsert(a->expiredLeases, c_keep(leaseAction));
        /* An expired lease can still become the next expirytime,
         * if it should be repeated
         */
        if (leaseAction->repeat)
        {
            v_leaseRenew(leaseAction->lease, NULL);
        } else
        {
            setHead = FALSE;
        }
    }
    if (setHead) {
        if (a->firstLeaseToExpire == NULL) {
            a->firstLeaseToExpire = c_keep(leaseAction);
        } else {
            headExpTime = v_leaseExpiryTime(a->firstLeaseToExpire->lease);
            leaseExpTime = v_leaseExpiryTime(leaseAction->lease);

            if (c_timeCompare(headExpTime, leaseExpTime) == C_GT) {
                c_free(a->firstLeaseToExpire);
                a->firstLeaseToExpire = c_keep(leaseAction);
            }
        }
    }

    return TRUE;
}
static v_actionResult
readerActionView (
    c_object o,
    c_voidp copyArg)
{
    readerViewActionArg    *info    = (readerViewActionArg *) copyArg;
    v_readerSampleSeq  *samples = info->samples;
    v_readerSample      sample;
    v_actionResult      result  = V_PROCEED;
    gapi_unsigned_long  i;

    if ( o ) {
        sample = v_readerSample(o);
        if (gapi_matchesReaderMask(o, &info->datareaderview->reader_mask)) {
            if ( !sampleSeqContains(samples, sample) ) {
                i = samples->_length;

                if ( v_readerSampleSeq_setLength(samples, i+1) ) {
                    samples->_buffer[i] = c_keep(sample);
                    c_keep(sample->instance);
                } else {
                    info->result = GAPI_RETCODE_OUT_OF_RESOURCES;
                    v_actionResultClear(result, V_PROCEED);
                }

                if ( samples->_length >= info->max ) {
                    v_actionResultClear(result, V_PROCEED);
                }
            }
        } else {
            v_actionResultSet(result, V_SKIP);
        }
    } else {
        if ( samples->_length > 0 ) {
            determineSampleInfoView(info);
            for ( i = 0UL; i < samples->_length; i++ ) {
                c_free(samples->_buffer[i]->instance);
                c_free(samples->_buffer[i]);
            }
        } else {
            info->readerCopy(NULL, info->readerInfo);
            info->result = GAPI_RETCODE_NO_DATA;
        }
        v_actionResultClear(result, V_PROCEED);
    }

    return result;
}
Esempio n. 8
0
static c_bool
takeOne(
    c_object o,
    c_voidp arg)
{
    v_readerSample s;
    v_readerSample *sample;
    c_bool result;

    s      = (v_readerSample)o;
    sample = (v_readerSample *)arg;

    if (s != NULL) {
        result = TRUE;
        if (v_stateTest(s->sampleState, L_VALIDDATA)) {
            *sample = c_keep(s);
            result = FALSE;
        } else {
            *sample = NULL;
        }
    } else { /* last sample */
        result = FALSE;
    }

    return result;
}
Esempio n. 9
0
void
v_networkReaderFree(
    v_networkReader reader)
{
    c_bool sendTo, more;
    v_message message;
    c_ulong sequenceNumber, priority;
    v_gid sender, receiver;
    os_timeE sendBefore;
    v_networkReaderEntry entry;
    c_ulong i;

    c_keep(reader);

    /* call inherited free,
     * which will remove the entry from the associated groups
     */
    v_readerFree(v_reader(reader));

    /* remove the messages still pressent in the network queues */
    for (i = 0; i < reader->nofQueues; i++) {
        while (v_networkQueueTakeFirst (
                    v_networkQueue(reader->queues[i]), &message, &entry, &sequenceNumber,
                    &sender, &sendTo, &receiver, &sendBefore, &priority, &more)) {
            c_free(message);
            c_free(entry);
        }
    }

    c_free(reader);
}
Esempio n. 10
0
c_metaObject
c_scopeInsert(
    c_scope scope,
    c_metaObject object)
{
    c_binding binding, found;

    binding = c_bindingNew(scope, object);
    found = c_binding(c_avlTreeInsert(c_avlTree(scope),
                                      (void *)binding,
                                      c_bindingCompare,
                                      NULL));
    if (found == binding) {
        if (!scope->headInsOrder) {
            scope->headInsOrder = binding;
        }
        if (scope->tailInsOrder) {
           scope->tailInsOrder->nextInsOrder = binding;
        }
        scope->tailInsOrder = binding;
    } else {
        if (c_isFinal(found->object) == FALSE) {
            c_metaCopy(object,found->object);
        }
        c_bindingFree(binding,MM(scope));
    }

    c_keep(found->object);

    /** Note that if inserted (found == binding) the object reference count is increased by 2.
        one for being inserted and one for being returned.
     */
    return found->object;
}
Esempio n. 11
0
c_metaObject
c_scopeLookup(
    c_scope scope,
    const c_char *name,
    c_long metaFilter)
{
    c_binding binding;
    c_metaObject o;
    struct c_resolveArg resolve;

    if (scope == NULL) {
        return NULL;
    }

    resolve.name = (char *)name;
    resolve.metaFilter = metaFilter;
    binding = c_avlTreeFind(c_avlTree(scope),
                            NULL,
                            c_bindingCompare,
                            &resolve);
    if (binding != NULL) {
	if (CQ_KIND_IN_MASK (binding->object, metaFilter)) {
            o = c_keep(binding->object);
        } else {
            o = NULL;
        }
    } else {
        o = NULL;
    }
    return o;
}
Esempio n. 12
0
void
v_topicAdapterInit(
    v_topicAdapter adapter,
    v_topic        topic,
    v_participant  p,
    const c_char  *name)
{
    v_eventMask mask = V_EVENT_ALL_DATA_DISPOSED | V_EVENT_INCONSISTENT_TOPIC;

    assert(adapter != NULL);
    assert(p != NULL);
    assert(C_TYPECHECK(adapter, v_topicAdapter));
    assert(C_TYPECHECK(p,v_participant));
    assert(C_TYPECHECK(topic,v_topic));

    v_entityInit(v_entity(adapter), name);
    adapter->topic = c_keep(topic);
    (void)v_entityEnable(v_entity(adapter));

    (void)v_observerSetEvent(v_observer(adapter), mask);

    OSPL_ADD_OBSERVER(topic, adapter, mask, NULL);
    v_participantAdd(p, v_object(adapter));
    v_topic(adapter)->owner = p;
}
Esempio n. 13
0
v_writerSample
_v_writerSampleNew(
    v_writer writer,
    v_message message)
{
    v_writerSample sample;

    assert(writer != NULL);
    assert(C_TYPECHECK(writer,v_writer));
    assert(message);
    assert(C_TYPECHECK(message,v_message));

#ifdef _EXTENT_
    sample = v_writerSample(c_extentCreate(writer->sampleExtent));
#else
    sample = v_writerSample(c_new(writer->sampleField->type));
#endif

    if (sample) {
        v_writerSampleTemplate(sample)->message = c_keep(message);
        sample->next = NULL;
        sample->prev = NULL;
        sample->sequenceNumber = 1;
        sample->sentBefore = FALSE;
        v_writerSampleClear(sample);
    } else {
        OS_REPORT(OS_ERROR,
                  "v_writerSampleNew",0,
                  "Failed to allocate sample.");
    }

    assert(C_TYPECHECK(sample,v_writerSample));

    return sample;
}
Esempio n. 14
0
/* This method registers a database object to be managed by the user-layer.
 * Once a process has registered an object it can free its reference.
 * The user-layer will keep the registered object alive until it is deregistered
 * using the u_userFree method.
 * The user-layer will free all references of registered objects on process
 * termination via the installed exit handler (u_userExit).
 */
c_object
u_userKeep(
    c_object o)
{
    u_user u;
    u_domainAdmin ka;
    c_long i;

    if (o) {
        u = u__userLock();
        if (u) {
            /* the user-layer object exists so now find the domain that holds
             * the given object.
             */
            for (i=1; i <= u->domainCount; i++) {
                ka = &u->domainList[i];
                if (ka->domain) {
                    /* A valid domain admin exists, now check if the objects
                     * address is in the domains address range.
                     */
                    if (((c_address)o >= ka->lowerBound) &&
                        ((c_address)o <= ka->upperBound))
                    {
                        c_keep(o);
                        ka->keepList = c_iterInsert(ka->keepList,o);
                        i = u->domainCount + 1; /* jump out of the loop */
                    }
                }
            }
            u__userUnlock();
        }
    }
    return o;
}
Esempio n. 15
0
v_partition
v_partitionNew(
    v_kernel kernel,
    const c_char *name,
    v_partitionQos qos)
{
    v_partition partition, found;

    assert(kernel != NULL);
    assert(C_TYPECHECK(kernel,v_kernel));

    assert(name != NULL);
    assert(v_partitionExpressionIsAbsolute(name));

    partition = v_partition(v_objectNew(kernel,K_DOMAIN));
    v_entityInit(v_entity(partition),name, NULL, TRUE);

    found = v_addPartition(kernel,partition);

    if (found != partition) {
        v_partitionFree(partition);
        c_free(partition); /* v_partitionFree has removed all dependancies, now delete local reference */
        partition = c_keep(found); /* this one will be returned, so a keep is required */
    }
    return partition;
}
Esempio n. 16
0
c_baseObject
c_scopeResolve(
    c_scope scope,
    const char *name,
    c_long metaFilter)
{
    c_metaObject o = NULL;
    struct c_walkArg warg;
    struct c_findArg farg;

    if (scope == NULL) {
        return NULL;
    }
    if (metaFilter & CQ_CASEINSENSITIVE) {

        warg.arg = &farg;
        warg.compare = c_metaNameCompare;
        warg.object = NULL;
	farg.name = name;
	farg.metaFilter = metaFilter;
	farg.object = NULL;
        if (c_avlTreeWalk(c_avlTree(scope),walkCompare,&warg,C_POSTFIX) == FALSE) {
            if (warg.object) {
                o = c_keep(warg.object);
            }
        } else {
            o = NULL;
        }
    } else {
        o = c_scopeLookup(scope, name, metaFilter);
    }
    return c_baseObject(o);
}
Esempio n. 17
0
c_bool
d_readerListenerCopy(
    c_object object,
    c_voidp copyArg)
{
    d_readerListener listener;
    d_message        message;
    v_message        readerMessage;
    c_bool result = FALSE;

    if(object != NULL) {
        if (v_stateTest(v_readerSampleState(object), L_VALIDDATA)) {
            listener  = d_readerListener(copyArg);
            readerMessage = v_message(v_dataReaderSampleTemplate(object)->message);
            message   = C_DISPLACE(readerMessage, listener->fieldOffset);
            listener->lastInsertTime = v_dataReaderSample(object)->insertTime;
            listener->lastSourceTime = readerMessage->writeTime;
            listener->value = c_keep(object);

            if(listener->value){
                listener->message = message;
            }
            listener->processMessage = TRUE;
        } else {
            /* Ignore data that is not valid but continue with the read action */
            result = TRUE;
        }
    }
    return result;
}
Esempio n. 18
0
v_deadLineInstanceList
v_deadLineInstanceListNew(
    c_base base,
    v_leaseManager leaseManager,
    v_duration leaseDuration,
    v_leaseActionId actionId,
    v_public o)
{
    v_deadLineInstanceList list;
    c_type type;

    assert(C_TYPECHECK(leaseManager,v_leaseManager));
    assert(C_TYPECHECK(o,v_public));

    type = c_resolve(base, "kernelModule::v_deadLineInstanceList");
    assert(type);
    list = c_new(type);
    c_free(type);
    if (list) {
        v_objectKind(list) = K_DEADLINEINSTANCE;
        v_instanceInit(v_instance(list));
        list->leaseManager = c_keep(leaseManager);
        list->leaseDuration = leaseDuration;
        list->deadlineLease = NULL;
        list->actionObject = o; /* no keep, since actionObject is onwer of v_deadLineInstanceList */
        list->actionId = actionId;
    } else {
        OS_REPORT(OS_ERROR,
                  "v_deadLineInstanceListNew",0,
                  "Failed to allocate v_deadLineInstanceList.");
    }

    return list;
}
Esempio n. 19
0
v_cache
v_groupCacheNew (
    v_kernel kernel,
    v_cacheKind kind)
{
    c_base base;
    c_type type;
    v_cache cache;

    assert(C_TYPECHECK(kernel,v_kernel));

    base = c_getBase(kernel);
    type = c_keep(v_kernelType(kernel,K_GROUPCACHEITEM));
    cache = v_cacheNew(kernel,type,kind);
    c_free(type);

    if (!cache) {
        OS_REPORT(OS_ERROR,
                  "v_groupCacheNew",0,
                  "Failed to allocate group cache.");
    }

    assert(C_TYPECHECK(cache, v_cache));

    return cache;
}
Esempio n. 20
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);
}
Esempio n. 21
0
v_dataViewSample
v_dataViewSampleNew(
    v_dataViewInstance instance,
    v_readerSample masterSample)
{
    v_dataView dataView;
    v_dataViewSample sample;

    assert(instance != NULL);
    assert(masterSample != NULL);
    assert(C_TYPECHECK(masterSample,v_readerSample));

    dataView = v_dataView(instance->dataView);
#ifdef _EXTENT_
    sample = v_dataViewSample(c_extentCreate(dataView->sampleExtent));
#else
    sample = v_dataViewSample(c_new(dataView->sampleType));
#endif
    if (sample) {
        v_readerSample(sample)->instance = (c_voidp)instance;
        v_readerSample(sample)->sampleState = 0;
        v_dataViewSampleList(sample)->next = NULL;
        v_dataViewSampleList(sample)->prev = NULL;
        sample->prev = NULL;
        v_dataViewSampleTemplate(sample)->sample = c_keep(masterSample);
    } else {
        OS_REPORT(OS_ERROR,
                  "v_dataViewSampleNew",0,
                  "Failed to allocate v_dataViewSample.");
    }
    return sample;
}
Esempio n. 22
0
static void
v_networkReaderEntryInit(
    v_networkReaderEntry entry,
    v_networkReader reader,
    v_group group,
    v_networkId networkId,
    c_ulong channelsToConnect,
    v_networkPartitionId networkPartitionId,
    c_bool isRouting)
{
    v_networkReaderEntry found;

    v_entryInit(v_entry(entry),v_reader(reader));

    entry->group = c_keep(group);
    entry->networkId = networkId;
    entry->channelCountdown = channelsToConnect;
    c_mutexInit(&entry->channelCountdownMutex, SHARED_MUTEX);
    entry->networkPartitionId = networkPartitionId;
    entry->hashValue = v_networkReaderEntryCalculateHashValue(entry);
    entry->isRouting = isRouting;

    found = v_networkReaderEntry(v_readerAddEntry(v_reader(reader), v_entry(entry)));
    assert(found == entry);
    c_free(found);
}
Esempio n. 23
0
static c_type
createKeyType(
    const c_char *name,
    c_array keyList)
{
    c_base base;
    c_type foundType;
    c_char *typeName;
    c_char keyName[16];
    c_long i, length, sres;
    c_array members;
    c_metaObject o;
    c_field field;

    if (keyList == NULL) {
        return NULL;
    }
    base = c_getBase(keyList);
    length = c_arraySize(keyList);
    if (length == 0) {
        return NULL;
    }
    o = c_metaDefine(c_metaObject(base),M_STRUCTURE);
    members = c_arrayNew(c_member_t(base),length);

    for (i=0;i<length;i++) {
        field = keyList[i];
        assert(field != NULL);
        members[i] = (c_voidp)c_metaDefine(c_metaObject(base),M_MEMBER);
            sprintf(keyName,"field%d",i);
            c_specifier(members[i])->name = c_stringNew(base,keyName);
            c_specifier(members[i])->type = c_keep(c_fieldType(field));
    }
    c_structure(o)->members = members;
    c_metaObject(o)->definedIn = c_metaObject(base);
    c_metaFinalize(o);
#define KEY_NAME   "<Key>"
#define KEY_FORMAT "%s<Key>"

    if (name != NULL) {
        length = sizeof(KEY_NAME) + strlen(name);
        typeName = os_malloc(length);
        sres = snprintf(typeName,length,KEY_FORMAT,name);
        assert(sres == (length-1));
    } else {
        assert(FALSE);
        length = 100;
        typeName = os_malloc(length);
        os_sprintf(typeName,PA_ADDRFMT KEY_NAME,(c_address)o);
    }
#undef KEY_NAME
#undef KEY_FORMAT
    foundType = c_type(c_metaBind(c_metaObject(base),typeName,o));

    c_free(o);
    os_free(typeName);

    return foundType;

}
Esempio n. 24
0
void
v_participantInit(
    v_participant p,
    const c_char *name,
    v_participantQos qos,
    v_statistics s,
    c_bool enable)
{
    v_kernel kernel;
    c_base base;
    v_message builtinMsg;
    c_type writerProxyType;

    assert(C_TYPECHECK(p,v_participant));
    assert(C_TYPECHECK(qos, v_participantQos));

    kernel = v_objectKernel(p);
    base = c_getBase(p);
    v_observerInit(v_observer(p),name,s,enable);

    p->entities = c_setNew(c_resolve(base,"kernelModule::v_entity"));
    p->qos = c_keep(qos);
    /* Currently default LIVELINESS policy is used: kind=AUTOMATIC,
     * duration=INFINITE This setting implies no lease registration.
    */
    p->lease = NULL;
    p->leaseManager = v_leaseManagerNew(kernel);
    p->resendQuit = FALSE;
    c_mutexInit(&p->resendMutex, SHARED_MUTEX);
    c_condInit(&p->resendCond, &p->resendMutex, SHARED_COND);
    writerProxyType = v_kernelType(kernel,K_PROXY);
    p->resendWriters = c_tableNew(writerProxyType, "source.index,source.serial");

    p->builtinSubscriber = NULL;
    if (!v_observableAddObserver(v_observable(kernel),v_observer(p), NULL)) {
        if (name != NULL) {
            OS_REPORT_1(OS_WARNING,"Kernel Participant",0,
                        "%s: Cannot observe Kernel events",name);
        } else {
            OS_REPORT(OS_WARNING,"Kernel Participant",0,
                      "Cannot observe Kernel events");
        }
    }

    c_mutexInit(&p->newGroupListMutex,SHARED_MUTEX);
    p->newGroupList = c_listNew(c_resolve(base, "kernelModule::v_group"));

    v_observerSetEventMask(v_observer(p), V_EVENT_NEW_GROUP);

    c_lockInit(&p->lock,SHARED_LOCK);
    c_mutexInit(&p->builtinLock,SHARED_MUTEX);

    /* Here the Builtin Topic of the participant is published.
     * This call mabe a noop in case builtin is disabled on kernel level.
     */
    builtinMsg = v_builtinCreateParticipantInfo(kernel->builtin,p);
    v_writeBuiltinTopic(kernel, V_PARTICIPANTINFO_ID, builtinMsg);
    c_free(builtinMsg);
}
Esempio n. 25
0
static c_type
createSampleType(
    c_type messageType,
    const c_char* topicName)
{
    c_base base;
    c_type sampleType, baseType, foundType, found;
    c_metaObject o;
    c_char *name;
    c_long length,sres;

    base = c_getBase(messageType);
    baseType = c_resolve(base, "durabilityModule2::d_sample");
    assert(baseType != NULL);

    sampleType = c_type(c_metaDefine(c_metaObject(base),M_CLASS));
    c_class(sampleType)->extends = c_class(baseType);

    o = c_metaDefine(c_metaObject(sampleType),M_ATTRIBUTE);
    c_property(o)->type = c_keep(messageType);
    found = c_type(c_metaBind(c_metaObject(sampleType),"message",o));
    c_free(o);
    c_free(found);

    c_metaObject(sampleType)->definedIn = c_keep(base);
    c_metaFinalize(c_metaObject(sampleType));

#define SAMPLE_NAME   "d_sample<>"
#define SAMPLE_FORMAT "d_sample<%s>"
    /* Create a name and bind type to name */
    /* The sizeof contains \0 */
    length = sizeof(SAMPLE_NAME) + strlen(topicName);
    name = os_malloc(length);
    sres = snprintf(name,length,SAMPLE_FORMAT,topicName);
    assert(sres == (length-1));
#undef SAMPLE_NAME
#undef SAMPLE_FORMAT

    foundType = c_type(c_metaBind(c_metaObject(base),
                                  name,
                                  c_metaObject(sampleType)));
    os_free(name);
    c_free(sampleType);

    return foundType;
}
Esempio n. 26
0
v_leaseManager
v_participantGetLeaseManager(
    v_participant p)
{
    assert(C_TYPECHECK(p,v_participant));

    return c_keep(p->leaseManager);
}
Esempio n. 27
0
v_subscriber
v_participantGetBuiltinSubscriber(
    v_participant p)
{
    v_subscriberQos sQos;
    v_readerQos rQos;
    v_kernel kernel;
    c_bool create_builtin_readers = FALSE;

    assert(p != NULL);
    assert(C_TYPECHECK(p, v_participant));

    c_mutexLock(&p->builtinLock);
    if (p->builtinSubscriber == NULL) {
        kernel = v_objectKernel(p);
        sQos = v_subscriberQosNew(kernel, NULL);
        sQos->presentation.access_scope = V_PRESENTATION_TOPIC;
        c_free(sQos->partition);
        sQos->partition = c_stringNew(c_getBase(c_object(kernel)),
                                      V_BUILTIN_PARTITION);
        sQos->entityFactory.autoenable_created_entities = TRUE;

        p->builtinSubscriber = v_subscriberNew(p, V_BUILTINSUBSCRIBER_NAME,
                                               sQos, TRUE);
        v_subscriberQosFree(sQos);

        create_builtin_readers = TRUE;
        c_mutexUnlock(&p->builtinLock);

        assert(p->builtinSubscriber != NULL);

        rQos = v_readerQosNew(kernel, NULL);
        rQos->durability.kind = V_DURABILITY_TRANSIENT;
        rQos->reliability.kind = V_RELIABILITY_RELIABLE;
        rQos->history.kind = V_HISTORY_KEEPLAST;
        rQos->history.depth = 1;

#define _CREATE_READER_(topicName) {\
            q_expr expr; \
            v_dataReader dr; \
            expr = q_parse("select * from " topicName);\
            dr = v_dataReaderNew(p->builtinSubscriber, topicName "Reader", \
                                   expr, NULL, rQos, TRUE);\
            c_free(dr); \
            q_dispose(expr); \
        }
        _CREATE_READER_(V_PARTICIPANTINFO_NAME)
        _CREATE_READER_(V_TOPICINFO_NAME)
        _CREATE_READER_(V_PUBLICATIONINFO_NAME)
        _CREATE_READER_(V_SUBSCRIPTIONINFO_NAME)
#undef _CREATE_READER_
        v_readerQosFree(rQos);
    } else {
        c_mutexUnlock(&p->builtinLock);
    }

    return c_keep(p->builtinSubscriber);
}
Esempio n. 28
0
static c_type
messageTypeNew(
    c_base base,
    const c_char *typeName)
{
    c_metaObject o;
    c_type baseType,dataType,type, foundType;
    c_char *name;
    c_long length, sres;

    if (base == NULL) {
        return NULL;
    }
    dataType = c_resolve(base,typeName);
    if (dataType == NULL) {
        return NULL;
    }
    baseType = c_resolve(base, "kernelModule::v_message");
    assert(baseType != NULL);

    type = c_type(c_metaDefine(c_metaObject(base),M_CLASS));
    c_class(type)->extends = c_keep(c_class(baseType));
    o = c_metaDeclare(c_metaObject(type),
                      USERDATA_FIELD_NAME,
                      M_ATTRIBUTE);
    c_property(o)->type = dataType;
    c_free(o);
    c_metaObject(type)->definedIn = c_keep(base);
    c_metaFinalize(c_metaObject(type));


#define MESSAGE_FORMAT "v_message<%s>"
#define MESSAGE_NAME "v_message<>"
    length = sizeof(MESSAGE_NAME) + strlen(typeName);
    name = os_malloc(length);
    sres = snprintf(name,length,MESSAGE_FORMAT,typeName);
    assert(sres == (length-1));
#undef MESSAGE_FORMAT
#undef MESSAGE_NAME
    foundType = c_type(c_metaBind(c_metaObject(base),name,c_metaObject(type)));
    os_free(name);
    c_free(type);

    return foundType;
}
Esempio n. 29
0
c_bool
v_leaseCollectObservers(
    c_object o,
    c_voidp arg)
{
    c_iter *observers = (c_iter*)arg;
    *observers = c_iterInsert(*observers, c_keep(o));
    return TRUE;
}
Esempio n. 30
0
q_expr
q_newTyp(
    c_type type)
{
    q_expr expr;

    expr = q_exprMalloc();
    expr->kind = T_TYP;
    expr->info.type = c_keep(type);
    return expr;
}