예제 #1
0
v_historicalDataRequest
v_historicalDataRequestNew(
    v_kernel kernel,
    c_char* filter,
    c_char* params[],
    c_ulong nofParams,
    c_time minSourceTime,
    c_time maxSourceTime,
    struct v_resourcePolicy *resourceLimits)
{
    v_historicalDataRequest request;
    c_ulong i;
    c_type type;
    c_base base;

    request = c_new(v_kernelType(kernel,K_HISTORICALDATAREQUEST));

    if (request) {
        if(filter){
            base            = c_getBase(kernel);
            request->filter = c_stringNew(base, filter);

            if(params){
                type                  = c_string_t(base);
                request->filterParams = c_arrayNew(type, nofParams);

                for(i=0; i<nofParams; i++){
                    request->filterParams[i] = c_stringNew(base, params[i]);
                }
            } else {
                request->filterParams = NULL;
            }
        } else {
            request->filter       = NULL;
            request->filterParams = NULL;
        }
        if ((minSourceTime.seconds     == C_TIME_INVALID.seconds) &&
            (minSourceTime.nanoseconds == C_TIME_INVALID.nanoseconds)) {
            request->minSourceTimestamp = C_TIME_ZERO;
        } else {
            request->minSourceTimestamp  = minSourceTime;
        }
        if ((maxSourceTime.seconds     == C_TIME_INVALID.seconds) &&
            (maxSourceTime.nanoseconds == C_TIME_INVALID.nanoseconds)) {
            request->maxSourceTimestamp = C_TIME_INFINITE;
        } else {
            request->maxSourceTimestamp  = maxSourceTime;
        }
        request->resourceLimits.max_samples              = resourceLimits->max_samples;
        request->resourceLimits.max_instances            = resourceLimits->max_instances;
        request->resourceLimits.max_samples_per_instance = resourceLimits->max_samples_per_instance;
    } else {
        OS_REPORT(OS_ERROR,
                  "v_historicalDataRequestNew",0,
                  "Failed to allocate request.");
        assert(FALSE);
    }

    return request;
}
예제 #2
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);

}
예제 #3
0
파일: v_cache.c 프로젝트: xrl/opensplice
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;
}
예제 #4
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;
}
예제 #5
0
v_persistentSnapshotRequest
v_persistentSnapshotRequestNew(
    v_kernel kernel,
    const c_char* partition_expression,
    const c_char* topic_expression,
    const c_char* uri)
{
    v_persistentSnapshotRequest request;
    c_base base;

    request = c_new(v_kernelType(kernel,K_PERSISTENTSNAPSHOTREQUEST));
    if(request)
    {
        base = c_getBase(kernel);
        if(partition_expression)
        {
            request->partitionExpr = c_stringNew(base, partition_expression);
        }
        if(topic_expression)
        {
            request->topicExpr = c_stringNew(base, topic_expression);
        }
        if(uri)
        {
            request->uri = c_stringNew(base, uri);
        }
    } else {
        OS_REPORT(OS_ERROR,
                  "v_kernel::v_persistentSnapshotRequest",0,
                  "Failed to create v_persistentSnapshotRequest object.");
        assert(FALSE);
    }

    return request;
}
예제 #6
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);
}
예제 #7
0
/**************************************************************
 * Protected functions
 **************************************************************/
v_partitionAdmin
v_partitionAdminNew(
    v_kernel kernel)
{
    v_partitionAdmin da;

    assert(C_TYPECHECK(kernel,v_kernel));

    da = v_partitionAdmin(v_objectNew(kernel, K_DOMAINADMIN));
    if (da != NULL) {
        da->partitions         = c_tableNew(v_kernelType(kernel, K_DOMAIN),"name");
        da->partitionInterests = c_tableNew(v_kernelType(kernel, K_DOMAININTEREST), "expression");
        c_mutexInit(&da->mutex,SHARED_MUTEX);

        if ((da->partitions == NULL) || (da->partitionInterests == NULL)) {
            c_free(da);
            da = NULL;
        }
    }
    return da;
}
예제 #8
0
v_readerStatistics v_readerStatisticsNew(v_kernel k)
{
    v_readerStatistics rs;
    c_type readerStatisticsType;

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

    readerStatisticsType = v_kernelType(k,K_READERSTATISTICS);
    rs = v_readerStatistics(v_new(k, readerStatisticsType));
    v_readerStatisticsInit(rs);
    return rs;
}
예제 #9
0
v_queryStatistics v_queryStatisticsNew(v_kernel k)
{
    v_queryStatistics qs;
    c_type queryStatisticsType;

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

    queryStatisticsType = v_kernelType(k,K_QUERYSTATISTICS);
    qs = v_queryStatistics(v_new(k, queryStatisticsType));
    v_queryStatisticsInit(qs);
    return qs;
}
예제 #10
0
v_writerStatistics
v_writerStatisticsNew(
    v_kernel k)
{
    v_writerStatistics ws;
    c_type writerStatisticsType;

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

    writerStatisticsType = v_kernelType(k,K_WRITERSTATISTICS);
    ws = v_writerStatistics(v_new(k, writerStatisticsType));
    v_writerStatisticsInit(ws);
    return ws;
}
예제 #11
0
void
v_leaseManagerInit(
    v_leaseManager _this)
{
    v_kernel k;

    assert(C_TYPECHECK(_this, v_leaseManager));

    k = v_objectKernel(_this);
    c_mutexInit(&_this->mutex, SHARED_MUTEX);
    c_condInit(&_this->cond, &_this->mutex, SHARED_COND);
    _this->quit = FALSE;
    _this->firstLeaseToExpire = NULL;
    _this->leases = c_setNew(v_kernelType(k, K_LEASEACTION));
}
예제 #12
0
void
v_leaseInit(
    v_lease _this,
    v_kernel k,
    v_duration leaseDuration)
{
    if (_this != NULL)
    {
        assert(C_TYPECHECK(_this, v_lease));

        c_mutexInit(&_this->mutex,SHARED_MUTEX);
        _this->expiryTime = c_timeAdd(v_timeGet(), leaseDuration);
        _this->duration = leaseDuration;
        _this->observers = c_setNew(v_kernelType(k, K_LEASEMANAGER));
    }
}
예제 #13
0
파일: v_entry.c 프로젝트: xrl/opensplice
/* protected */
void
v_entryInit(
    v_entry e,
    v_reader r)
{
    v_kernel kernel;

    assert(C_TYPECHECK(e,v_entry));
    assert(C_TYPECHECK(r,v_reader));

    kernel = v_objectKernel(r);
    e->reader = r;
    e->groups = c_tableNew(v_kernelType(kernel,K_PROXY),
                          "source.index,source.server");
    assert(e->groups != NULL);
}
예제 #14
0
파일: v_service.c 프로젝트: osrf/opensplice
void
v_serviceFillNewGroups(
    v_service service)
{
    c_set newGroups;
    C_STRUCT(v_event) ge;
    v_group g;
    v_kernel kernel;
    c_iter groups = NULL;

    assert(service != NULL);
    assert(C_TYPECHECK(service, v_service));

    kernel = v_objectKernel(service);
    newGroups = (c_voidp)c_setNew(v_kernelType(kernel, K_GROUP));

    if (newGroups != NULL) {
        groups = v_groupSetSelectAll(kernel->groupSet);

        /* Take the first group and at the end notify the service about this new group.
         * But before push all other groups to the servive newGroup set so that only one trigger
         * is required to notify all groups.
         * The first group is automatically added to the newGroup set by the notification.
         * TODO : get rid of this mechanism.
         */
        ge.data = v_group(c_iterTakeFirst(groups));
        if (ge.data) {
            ge.kind = V_EVENT_NEW_GROUP;
            ge.source = v_observable(kernel);
            ospl_c_insert(newGroups, ge.data);
            while ((g = v_group(c_iterTakeFirst(groups))) != NULL) {
                ospl_c_insert(newGroups, g);
                c_free(g);
            }

            OSPL_BLOCK_EVENTS(service);
            c_free(service->newGroups);
            service->newGroups = (c_voidp)newGroups;
            OSPL_UNBLOCK_EVENTS(service);

            OSPL_TRIGGER_EVENT((service), &ge, NULL);
        }
        c_iterFree(groups);
    }
}
예제 #15
0
void
v_groupStreamInit(
    v_groupStream stream,
    const c_char *name,
    v_subscriber subscriber,
    v_readerQos qos)
{
    v_kernel kernel;

    assert(C_TYPECHECK(stream, v_groupStream));
    assert(C_TYPECHECK(subscriber, v_subscriber));

    kernel = v_objectKernel(subscriber);

    stream->groups = c_setNew(v_kernelType(kernel,K_GROUP));
    v_readerInit(v_reader(stream),name,subscriber,qos,NULL,TRUE);
    v_subscriberAddReader(subscriber,v_reader(stream));
}
예제 #16
0
void
v_serviceFillNewGroups(
    v_service service)
{
    c_set newGroups;
    C_STRUCT(v_event) ge;
    v_group g, oldGroup;
    c_iter oldGroups;
    v_kernel kernel;

    assert(service != NULL);
    assert(C_TYPECHECK(service, v_service));

    kernel = v_objectKernel(service);
    newGroups = (c_voidp)c_setNew(v_kernelType(kernel, K_GROUP));

    if (newGroups != NULL) {
        addAllGroups(newGroups, kernel->groupSet);
        v_observerLock(v_observer(service));
        g = v_group(c_read(newGroups)); /* need a group for the event */

        if(v_observer(service)->eventData != NULL){
            oldGroups = ospl_c_select((c_set)v_observer(service)->eventData, 0);
            oldGroup = v_group(c_iterTakeFirst(oldGroups));

            while(oldGroup){
                newGroups = c_setInsert(newGroups, oldGroup);
                c_free(oldGroup);
                oldGroup = v_group(c_iterTakeFirst(oldGroups));
            }
            c_iterFree(oldGroups);
        }
        /* just for safety, when assertion are compiled out, free the prev set */
        c_free((c_object)v_observer(service)->eventData);
        v_observer(service)->eventData = (c_voidp)newGroups;

        ge.kind = V_EVENT_NEW_GROUP;
        ge.source = v_publicHandle(v_public(kernel));
        ge.userData = g;
        v_observerNotify(v_observer(service), &ge, NULL);
        v_observerUnlock(v_observer(service));
        c_free(g);
    }
}
예제 #17
0
v_partitionInterest
v_partitionInterestNew(
    v_kernel kernel,
    const char *partitionExpression)
{
    v_partitionInterest result = NULL;


    result = c_new(v_kernelType(kernel, K_DOMAININTEREST));
    if (result) {
        result->expression = c_stringNew(c_getBase(c_object(kernel)), partitionExpression);
    } else {
        OS_REPORT(OS_ERROR,
                  "v_partitionInterestNew",0,
                  "Failed to allocate partition interest.");
    }

    return result;
}
예제 #18
0
v_object
v_objectNew(
    v_kernel kernel,
    v_kind kind)
{
    v_object o;

    assert(C_TYPECHECK(kernel,v_kernel));

    o = c_new(v_kernelType(kernel,kind));
    if (o) {
        assert(C_TYPECHECK(o,v_object));
        o->kind = kind;
        o->kernel = kernel;
    } else {
        OS_REPORT(OS_ERROR,
                  "v_objectNew",0,
                  "Failed to create kernel object.");
        assert(FALSE);
    }
    return o;
}
예제 #19
0
static v_waitsetEvent
v_waitsetEventNew(
    v_waitset _this)
{
    v_kernel k;
    v_waitsetEvent event;

    if (_this->eventCache) {
        event = _this->eventCache;
        _this->eventCache = event->next;
    } else {
        k = v_objectKernel(_this);
        event = c_new(v_kernelType(k,K_WAITSETEVENT));

        if (!event) {
            OS_REPORT(OS_ERROR,
                      "v_waitsetEventNew",0,
                      "Failed to allocate event.");
        }
    }
    return event;
}
예제 #20
0
void
v_groupStreamInit(
    v_groupStream stream,
    const c_char *name,
    v_subscriber subscriber,
    v_readerQos qos,
    v_statistics rs,
    c_iter expr)
{
    v_kernel kernel;

    assert(C_TYPECHECK(stream, v_groupStream));
    assert(C_TYPECHECK(subscriber, v_subscriber));

    kernel = v_objectKernel(subscriber);

    stream->groups = c_setNew(v_kernelType(kernel,K_GROUP));
    stream->expr = c_listNew(c_resolve(c_getBase(stream), "::c_string"));
    c_iterWalk(expr, fillExprList, stream->expr);

    v_readerInit(v_reader(stream),name,subscriber,qos,rs,TRUE);
    v_subscriberAddReader(subscriber,v_reader(stream));
}
예제 #21
0
v_waitset
v_waitsetNew(
    v_participant p)
{
    v_waitset _this;
    v_kernel kernel;
    c_type proxyType;

    assert(C_TYPECHECK(p,v_participant));

    kernel = v_objectKernel(p);
    _this = v_waitset(v_objectNew(kernel,K_WAITSET));
    if (_this != NULL) {
        v_observerInit(v_observer(_this),"Waitset", NULL, TRUE);
        _this->participant = p;
        _this->eventCache = NULL;
        proxyType = v_kernelType(kernel,K_PROXY);
        _this->observables = c_setNew(proxyType);
        v_observerSetEventData(v_observer(_this), NULL);
        v_participantAdd(p, v_entity(_this));
    }

    return _this;
}
예제 #22
0
c_bool
v_partitionAdminSet(
    v_partitionAdmin da,
    v_partitionPolicy partitionExpr,
    c_iter *addedPartitions,
    c_iter *removedPartitions)
{
    c_iter                   dexpressions;    /* iterator of partition expressions */
    c_char                   *dexpr;          /* partition expression */
    v_partitionInterest         di;
    struct resolvePartitionsArg resolveArg;
    struct updatePartitionsArg  updateArg;

    assert(C_TYPECHECK(da, v_partitionAdmin));
    assert(removedPartitions != NULL);
    assert(addedPartitions != NULL);

    *removedPartitions = NULL;
    *addedPartitions = NULL;

    resolveArg.kernel = v_objectKernel(da);

    c_mutexLock(&da->mutex);
    /*
     * The absolute partition names will be added at the end of
     * the algorithm.
     * The partition expressions in the parameter of partitionExpr,
     * replace the existing in da->partitionInterests.
     */
    c_free(da->partitionInterests);
    da->partitionInterests = c_tableNew(v_kernelType(resolveArg.kernel, K_DOMAININTEREST),
                                        "expression");
    assert(c_count(da->partitionInterests) == 0);
    dexpressions = v_partitionPolicySplit(partitionExpr);
    if (dexpressions == NULL) {
        /* switch to default */
        *addedPartitions = c_iterInsert(*addedPartitions, v_partitionNew(resolveArg.kernel, "", NULL));
    } else {
        dexpr = (c_char *)c_iterTakeFirst(dexpressions);
        while (dexpr != NULL) {
            if (v_partitionExpressionIsAbsolute(dexpr)) {
                *addedPartitions = c_iterInsert(*addedPartitions,
                                                v_partitionNew(resolveArg.kernel, dexpr, NULL));
                /* ref transferred to addedPartitions */
            } else {
                di = v_partitionInterestNew(resolveArg.kernel, (const c_char *)dexpr);
                c_tableInsert(da->partitionInterests, di);
                c_free(di);
            }
            os_free(dexpr);
            dexpr = (c_char *)c_iterTakeFirst(dexpressions);
        }
        c_iterFree(dexpressions);
    }

    /*
     * The given expressions are now divided across
     * 'addedpartitions' and 'da->partitionInterests'.
     * Now first add partitions to 'addedpartitions' that fit the
     * expressions in 'da->partitionInterests'.
     */
    resolveArg.partitions = addedPartitions;
    c_tableWalk(da->partitionInterests, resolvePartitions, (c_voidp)&resolveArg);

    /*
     * Now 'addedpartitions' contains all partitions to be added
     * by the publisher/subscriber.
     * 'da->partitions' contains the old set of partitions.
     * We must check whether those partitions must remain in
     * the set or must be removed.
     * For every partition in 'da->partitions' do
     *    if partition in 'addedpartitions' then remove from 'addedpartitions'
     *    else add to 'removedpartitions'
     * For every partition in 'removedpartitions' remove from 'da->partitions'.
     */
    updateArg.addPartitions = addedPartitions;
    updateArg.removePartitions = removedPartitions;
    c_tableWalk(da->partitions, updatePartitions, (c_voidp)&updateArg);

    c_iterWalk(*removedPartitions, removePartition, (c_voidp)da->partitions);

    /*
     * The da->partitions now contains partitions that still comply to new
     * partitionPolicy. So all partitions in added partitions, must be added
     * to da->partitions, so it reflects all connected partitions.
     */
    c_iterWalk(*addedPartitions, addPartition, (c_voidp)da->partitions);
    c_mutexUnlock(&da->mutex);

    return TRUE;
}
예제 #23
0
void
v_waitsetNotify(
    v_waitset _this,
    v_event e,
    c_voidp userData)
/* the userData argument is the data associated to the observable
 * for this waitset during the v_waitsetAttach call.
 * This data is unique for this association between this waitset and
 * the attached observable.
 */
{
    v_waitsetEvent event,found;
    c_base base;
    v_historyDeleteEventData hde;
    v_waitsetEventHistoryDelete wehd;
    v_waitsetEventHistoryRequest wehr;
    v_waitsetEventPersistentSnapshot weps;
    v_kernel k;

    assert(_this != NULL);
    assert(C_TYPECHECK(_this,v_waitset));

    if (e != NULL) {
        k = v_objectKernel(_this);
        if (e->kind == V_EVENT_HISTORY_DELETE) {
            /* delete historical data */
            wehd = c_new(v_kernelType(k,K_WAITSETEVENTHISTORYDELETE));
            base = c_getBase(c_object(_this));
            hde = (v_historyDeleteEventData)e->userData;

            wehd->deleteTime    = hde->deleteTime;
            wehd->partitionExpr = c_stringNew(base,hde->partitionExpression);
            wehd->topicExpr     = c_stringNew(base,hde->topicExpression);
            event = (v_waitsetEvent)wehd;
        } else if (e->kind == V_EVENT_HISTORY_REQUEST) {
            /* request historical data */
            wehr = c_new(v_kernelType(k, K_WAITSETEVENTHISTORYREQUEST));
            wehr->request = (v_historicalDataRequest)c_keep(e->userData);
            event = (v_waitsetEvent)wehr;
        } else if (e->kind == V_EVENT_PERSISTENT_SNAPSHOT) {
            /* request persistent snapshot data */
            weps = c_new(v_kernelType(k, K_WAITSETEVENTPERSISTENTSNAPSHOT));
            weps->request = (v_persistentSnapshotRequest)c_keep(e->userData);
            event = (v_waitsetEvent)weps;

        } else {
            /* Group events by origin of event */
            /* What about events while no threads are waiting?
             * It seems that the list of events can grow to infinite length.
             */
            found = v_waitsetEvent(v_waitsetEventList(_this));
            while ((found != NULL) && (!v_handleIsEqual(found->source,e->source))){
                found = found->next;
            }
            if (found == NULL) {
                event = v_waitsetEventNew(_this);
            } else {
                found->kind |= e->kind;
                event = NULL;
            }
        }
        if (event) {
            event->source.server = e->source.server;
            event->source.index  = e->source.index;
            event->source.serial = e->source.serial;
            event->kind          = e->kind;
            event->userData      = userData;
            event->next = v_waitsetEvent(v_waitsetEventList(_this));
            v_waitsetEventList(_this) = (c_voidp)event;
        }
    }
}
예제 #24
0
v_kernel
v_kernelNew(
    c_base base,
    const c_char *name,
    v_kernelQos qos)
{
    v_kernel kernel;
    v_kernelStatistics kernelStatistics;
    v_spliced sd;

    kernel = c_lookup(base,name);
    if (kernel != NULL) {
        assert(C_TYPECHECK(kernel,v_kernel));
        kernel->userCount++;
        return kernel;
    }

    loadkernelModule(base);

    kernel = (v_kernel)c_new(c_resolve(base,"kernelModule::v_kernel"));
    if (!kernel) {
        OS_REPORT(OS_ERROR,
                  "v_kernelNew",0,
                  "Failed to allocate kernel.");
        return NULL;
    }
    v_objectKind(kernel) = K_KERNEL;
    v_object(kernel)->kernel = (c_voidp)kernel;
    kernel->handleServer = v_handleServerNew(base);

#define INITTYPE(k,t,l) k->type[l] = c_resolve(base,#t)

    INITTYPE(kernel,kernelModule::v_kernel,             K_KERNEL);
    INITTYPE(kernel,kernelModule::v_participant,        K_PARTICIPANT);
    INITTYPE(kernel,kernelModule::v_waitset,            K_WAITSET);
    INITTYPE(kernel,kernelModule::v_condition,          K_CONDITION);
    INITTYPE(kernel,kernelModule::v_query,              K_QUERY);
    INITTYPE(kernel,kernelModule::v_dataReaderQuery,    K_DATAREADERQUERY);
    INITTYPE(kernel,kernelModule::v_dataViewQuery,      K_DATAVIEWQUERY);
    INITTYPE(kernel,kernelModule::v_dataView,           K_DATAVIEW);
    INITTYPE(kernel,kernelModule::v_dataViewSample,     K_DATAVIEWSAMPLE);
    INITTYPE(kernel,kernelModule::v_dataViewInstance,   K_DATAVIEWINSTANCE);
    INITTYPE(kernel,kernelModule::v_projection,         K_PROJECTION);
    INITTYPE(kernel,kernelModule::v_mapping,            K_MAPPING);
    INITTYPE(kernel,kernelModule::v_topic,              K_TOPIC);
    INITTYPE(kernel,kernelModule::v_message,            K_MESSAGE);
    INITTYPE(kernel,kernelModule::v_transaction,        K_TRANSACTION);
    INITTYPE(kernel,kernelModule::v_dataReaderInstance, K_DATAREADERINSTANCE);
    INITTYPE(kernel,kernelModule::v_purgeListItem,      K_PURGELISTITEM);
    INITTYPE(kernel,kernelModule::v_groupPurgeItem,     K_GROUPPURGEITEM);
    INITTYPE(kernel,kernelModule::v_dataReaderSample,   K_READERSAMPLE);
    INITTYPE(kernel,kernelModule::v_publisher,          K_PUBLISHER);
    INITTYPE(kernel,kernelModule::v_subscriber,         K_SUBSCRIBER);
    INITTYPE(kernel,kernelModule::v_partition,             K_DOMAIN);
    INITTYPE(kernel,kernelModule::v_partitionInterest,     K_DOMAININTEREST);
    INITTYPE(kernel,kernelModule::v_partitionAdmin,        K_DOMAINADMIN);
    INITTYPE(kernel,kernelModule::v_reader,             K_READER);
    INITTYPE(kernel,kernelModule::v_writer,             K_WRITER);
    INITTYPE(kernel,kernelModule::v_writerGroup,        K_WRITERGROUP);
    INITTYPE(kernel,kernelModule::v_group,              K_GROUP);
    INITTYPE(kernel,kernelModule::v_groupInstance,      K_GROUPINSTANCE);
    INITTYPE(kernel,kernelModule::v_groupSample,        K_GROUPSAMPLE);
    INITTYPE(kernel,kernelModule::v_groupCacheItem,     K_GROUPCACHEITEM);
    INITTYPE(kernel,kernelModule::v_cache,              K_CACHE);
    INITTYPE(kernel,kernelModule::v_entry,              K_ENTRY);
    INITTYPE(kernel,kernelModule::v_dataReaderEntry,    K_DATAREADERENTRY);
    INITTYPE(kernel,kernelModule::v_groupAction,        K_GROUPACTION);
    INITTYPE(kernel,kernelModule::v_groupStream,        K_GROUPSTREAM);
    INITTYPE(kernel,kernelModule::v_groupQueue,         K_GROUPQUEUE);
    INITTYPE(kernel,kernelModule::v_groupQueueSample,   K_GROUPQUEUESAMPLE);
    INITTYPE(kernel,kernelModule::v_dataReader,         K_DATAREADER);
    INITTYPE(kernel,kernelModule::v_deliveryService,    K_DELIVERYSERVICE);
    INITTYPE(kernel,kernelModule::v_deliveryServiceEntry, K_DELIVERYSERVICEENTRY);
    INITTYPE(kernel,kernelModule::v_index,              K_INDEX);
    INITTYPE(kernel,kernelModule::v_filter,             K_FILTER);
    INITTYPE(kernel,kernelModule::v_readerStatus,       K_READERSTATUS);
    INITTYPE(kernel,kernelModule::v_writerStatus,       K_WRITERSTATUS);
    INITTYPE(kernel,kernelModule::v_partitionStatus,    K_DOMAINSTATUS);
    INITTYPE(kernel,kernelModule::v_topicStatus,        K_TOPICSTATUS);
    INITTYPE(kernel,kernelModule::v_subscriberStatus,   K_SUBSCRIBERSTATUS);
    INITTYPE(kernel,kernelModule::v_status,             K_PUBLISHERSTATUS);
    INITTYPE(kernel,kernelModule::v_status,             K_PARTICIPANTSTATUS);
    INITTYPE(kernel,kernelModule::v_kernelStatus,       K_KERNELSTATUS);
    INITTYPE(kernel,kernelModule::v_readerStatistics,   K_READERSTATISTICS);
    INITTYPE(kernel,kernelModule::v_writerStatistics,   K_WRITERSTATISTICS);
    INITTYPE(kernel,kernelModule::v_queryStatistics,    K_QUERYSTATISTICS);
    INITTYPE(kernel,kernelModule::v_lease,              K_LEASE);
    INITTYPE(kernel,kernelModule::v_leaseAction,        K_LEASEACTION);
    INITTYPE(kernel,kernelModule::v_serviceManager,     K_SERVICEMANAGER);
    INITTYPE(kernel,kernelModule::v_service,            K_SERVICE);
    INITTYPE(kernel,kernelModule::v_serviceState,       K_SERVICESTATE);
    INITTYPE(kernel,kernelModule::v_networking,         K_NETWORKING);
    INITTYPE(kernel,kernelModule::v_durability,         K_DURABILITY);
    INITTYPE(kernel,kernelModule::v_cmsoap,             K_CMSOAP);
    INITTYPE(kernel,kernelModule::v_leaseManager,       K_LEASEMANAGER);
    INITTYPE(kernel,kernelModule::v_groupSet,           K_GROUPSET);
    INITTYPE(kernel,kernelModule::v_proxy,              K_PROXY);
    INITTYPE(kernel,kernelModule::v_waitsetEvent,       K_WAITSETEVENT);
    INITTYPE(kernel,kernelModule::v_waitsetEventHistoryDelete,  K_WAITSETEVENTHISTORYDELETE);
    INITTYPE(kernel,kernelModule::v_waitsetEventHistoryRequest, K_WAITSETEVENTHISTORYREQUEST);
    INITTYPE(kernel,kernelModule::v_waitsetEventPersistentSnapshot, K_WAITSETEVENTPERSISTENTSNAPSHOT);
    INITTYPE(kernel,kernelModule::v_writerSample,       K_WRITERSAMPLE);
    INITTYPE(kernel,kernelModule::v_writerInstance,     K_WRITERINSTANCE);
    INITTYPE(kernel,kernelModule::v_writerInstanceTemplate, K_WRITERINSTANCETEMPLATE);
    INITTYPE(kernel,kernelModule::v_writerCacheItem,    K_WRITERCACHEITEM);
    /* Networking types */
    INITTYPE(kernel,kernelModule::v_networkReader,      K_NETWORKREADER);
    INITTYPE(kernel,kernelModule::v_networkReaderEntry, K_NETWORKREADERENTRY);
    INITTYPE(kernel,kernelModule::v_networkMessage,     K_NETWORKMESSAGE);
    INITTYPE(kernel,kernelModule::v_networkMapEntry,    K_NETWORKMAPENTRY);

    INITTYPE(kernel,kernelModule::v_spliced,            K_SPLICED);
    INITTYPE(kernel,kernelModule::v_configuration,      K_CONFIGURATION);
    INITTYPE(kernel,kernelModule::v_registration,       K_REGISTRATION);

    INITTYPE(kernel,kernelModule::v_historicalDataRequest,K_HISTORICALDATAREQUEST);
    INITTYPE(kernel,kernelModule::v_persistentSnapshotRequest,K_PERSISTENTSNAPSHOTREQUEST);
    INITTYPE(kernel,kernelModule::v_pendingDisposeElement,K_PENDINGDISPOSEELEMENT);

#undef INITTYPE


    kernel->pendingDisposeList =
       c_listNew(v_kernelType(kernel, K_PENDINGDISPOSEELEMENT ));
    c_mutexInit(&kernel->pendingDisposeListMutex, SHARED_MUTEX);

    kernelStatistics = v_kernelStatisticsNew(kernel);
    v_observableInit(v_observable(kernel),
                     V_KERNEL_VERSION,
                     v_statistics(kernelStatistics),
                     TRUE);
    c_lockInit(&kernel->lock,SHARED_LOCK);
    kernel->qos = v_kernelQosNew(kernel, qos);
    {
        os_time time;
        /* Fill GID with 'random' value */
        memset(&kernel->GID, 0, sizeof(kernel->GID));
        time = os_timeGet();
        kernel->GID.systemId = time.tv_nsec;
    }
    kernel->participants = c_setNew(v_kernelType(kernel,K_PARTICIPANT));
    kernel->partitions = c_tableNew(v_kernelType(kernel,K_DOMAIN),"name");
    kernel->topics = c_tableNew(v_kernelType(kernel,K_TOPIC),"name");
    kernel->groupSet = v_groupSetNew(kernel);
    kernel->serviceManager = v_serviceManagerNew(kernel);
    kernel->livelinessLM = v_leaseManagerNew(kernel);
    kernel->configuration = NULL;
    kernel->userCount = 1;
    kernel->transactionCount = 0;
    kernel->splicedRunning = TRUE;
    kernel->maxSamplesWarnLevel = V_KERNEL_MAX_SAMPLES_WARN_LEVEL_DEF;
    kernel->maxSamplesWarnShown = FALSE;
    kernel->maxSamplesPerInstanceWarnLevel = V_KERNEL_MAX_SAMPLES_PER_INSTANCES_WARN_LEVEL_DEF;
    kernel->maxSamplesPerInstanceWarnShown = FALSE;
    kernel->maxInstancesWarnLevel = V_KERNEL_MAX_INSTANCES_WARN_LEVEL_DEF;
    kernel->maxInstancesWarnShown = FALSE;
    kernel->enabledStatisticsCategories =
        c_listNew(c_resolve(base, "kernelModule::v_statisticsCategory"));

    c_mutexInit(&kernel->sharesMutex, SHARED_MUTEX);
    kernel->shares = c_tableNew(v_kernelType(kernel,K_SUBSCRIBER),
                                "qos.share.name");

    kernel->crc = v_crcNew(kernel, V_CRC_KEY);
    kernel->builtin = v_builtinNew(kernel);

    kernel->deliveryService = NULL;

    sd = v_splicedNew(kernel);
    c_free(sd);


    c_bind(kernel,name);

    return kernel;
}
예제 #25
0
void
v_listenerNotify(
    v_listener _this,
    v_event e,
    v_entity listener)
{
   /* The userData argument is typical the user layer entity to which
    * this listener is attached.
    * The userData is passed to the v_listenerWait operation.
    * The eventData is optional for passing additional data,
    * typically status information is passed.
    */
    v_listenerEvent event,found;
    v_status status;

    assert(_this != NULL);
    assert(C_TYPECHECK(_this,v_listener));

    c_mutexLock(&_this->mutex);
    if (e != NULL) {
        found = NULL;
        event = NULL;
        if (_this->combine &&
            ((e->kind & V_EVENT_DATA_AVAILABLE) || (e->kind & V_EVENT_ON_DATA_ON_READERS)) )
        {
            /* Optimization for data availability: look for pending event and combine
             * to avoid triggering after data is already read on behalf of the first
             * trigger.
             */
            c_voidp source = v_publicGetUserData(v_public(e->source));
            found = _this->eventList;
            while (found != NULL) {
                if ((found->source == source) &&
                    (found->kind == e->kind)) {
                    break;
                } else {
                    found = found->next;
                }
            }
        }
        if (found == NULL) {
            event = c_new(v_kernelType(v_objectKernel(_this),K_LISTENEREVENT));
            event->next = NULL;
            event->kind = e->kind;
            event->source = v_publicGetUserData(v_public(e->source));
            /* For all events except for data availability
             * copy the entity status to keep the actual value until the
             * data is processed. The aforementioned events do not affect
             * status, so there is no need to copy the value nor reset any
             * counters.
             */
            if (event->kind == V_EVENT_DATA_AVAILABLE) {
                c_free(event->eventData);
                event->eventData = c_keep(e->data);
            } else {
                status = v_entityStatus(v_entity(e->source));
                c_free(event->eventData);
                event->eventData = v_statusCopyOut(status);
                v_statusResetCounters(status, e->kind);
                c_free(status);
            }
        }
    } else {
        event = c_new(v_kernelType(v_objectKernel(_this),K_LISTENEREVENT));
        event->next = NULL;
        event->kind = V_EVENT_TRIGGER;
        event->source = NULL;
        event->eventData = NULL;
    }
    if (event) {
        /* insert constructed listener event in the listeners event list. */
        if (_this->lastEvent) {
            _this->lastEvent->next = c_keep(event);
            c_free(_this->lastEvent);
        } else {
            assert(_this->eventList == NULL);
            _this->eventList = c_keep(event);
        }
        _this->lastEvent = event /* transfer ref */;
        if (listener) {
            event->listenerData = listener->listenerData;
            event->userData = v_publicGetUserData(v_public(listener)); /* Typical the language binding entity */
        } else {
            event->listenerData = NULL;
            event->userData = NULL; /* Typical the language binding entity */
        }
    }
    _TRACE_EVENTS_("v_listenerNotify: listener 0x%x, events 0x%x\n", _this, (e?e->kind:V_EVENT_TRIGGER));
    c_condBroadcast(&_this->cv);
    c_mutexUnlock(&_this->mutex);
}
예제 #26
0
v_subscriber
v_subscriberNew(
    v_participant p,
    const c_char *name,
    v_subscriberQos qos,
    c_bool enable)
{
    v_kernel kernel;
    v_subscriber s;
    v_subscriberQos q;
    v_entity found;
    v_accessMode access;

    kernel = v_objectKernel(p);
    /* ES, dds1576: If a partition policy was provided then we need to verify
     * if the partition policy does not contain any partition expressions for
     * which read access is not allowed.
     * If read access is not allowed for one of the partitions listed in the
     * partition policy of the qos, then the subscriber will not be created at
     * all.
     */
    if(qos && qos->partition)
    {
        access = v_kernelPartitionAccessMode(kernel, qos->partition);
    } else
    {
        access = V_ACCESS_MODE_READ_WRITE;/* default */
    }
    if(access == V_ACCESS_MODE_READ_WRITE || access == V_ACCESS_MODE_READ)
    {
        q = v_subscriberQosNew(kernel,qos);
        if (q != NULL) {
            s = v_subscriber(v_objectNew(kernel,K_SUBSCRIBER));
            v_observerInit(v_observer(s),name, NULL, enable);
            s->qos = q;
            c_mutexInit(&s->sharesMutex, SHARED_MUTEX);
            if (q->share.enable) {
                v_lockShares(kernel);
                found = v_addShareUnsafe(kernel,v_entity(s));
                if (found != v_entity(s)) {
                    /* Make sure to set the partition list to NULL, because
                     * v_publicFree will cause a crash in the v_subscriberDeinit
                     * otherwise.
                     */
                    s->partitions = NULL;
                    /*v_publicFree to free reference held by the handle server.*/
                    v_publicFree(v_public(s));
                    /*Now free the local reference as well.*/
                    c_free(s);
                    pa_increment(&(v_subscriber(found)->shareCount));
                    v_unlockShares(kernel);
                    return c_keep(found);
                }
                s->shares = c_tableNew(v_kernelType(kernel,K_READER),
                                       "qos.share.name");
            } else {
                s->shares = NULL;
            }
            s->shareCount  = 1;
            s->partitions  = v_partitionAdminNew(kernel);
            s->readers     = c_setNew(v_kernelType(kernel,K_READER));

            if (q->share.enable) {
                s->participant = kernel->builtin->participant;
            } else {
                s->participant = p;
            }

            c_lockInit(&s->lock,SHARED_LOCK);
            v_participantAdd(v_participant(s->participant),v_entity(s));

            if (q->share.enable) {
                v_unlockShares(kernel);
            }
            if (enable) {
                v_subscriberEnable(s);
            }
        } else {
            OS_REPORT(OS_ERROR,
                      "v_subscriberNew", 0,
                      "Subscriber not created: inconsistent qos");
            s = NULL;
        }
    } else
    {
        OS_REPORT(OS_ERROR,
              "v_subscriberNew", 0,
              "Subscriber not created: Access rights for one of the partitions listed in the partition list was not sufficient (i.e. read or readwrite).");
        s = NULL;
    }
    return s;
}