Ejemplo n.º 1
0
d_groupCreationQueue
d_groupCreationQueueNew(
    d_admin admin)
{
    d_groupCreationQueue queue;
    os_result osr;
    os_threadAttr attr;

    assert(admin);

    queue = d_groupCreationQueue(os_malloc(C_SIZEOF(d_groupCreationQueue)));

    if(queue) {
        d_lockInit(d_lock(queue), D_GROUP_CREATION_QUEUE, d_groupCreationQueueDeinit);

        if(queue) {
            queue->groups                   = c_iterNew(NULL);
            queue->terminate                = FALSE;
            queue->admin                    = admin;
            queue->groupsToCreateVolatile   = 0;
            queue->groupsToCreateTransient  = 0;
            queue->groupsToCreatePersistent = 0;

            osr                             = os_threadAttrInit(&attr);

            if(osr == os_resultSuccess) {
                osr = os_threadCreate(&queue->actionThread, "groupCreationThread",
                                      &attr, (void*(*)(void*))d_groupCreationQueueRun,
                                      (void*)queue);

                if(osr != os_resultSuccess) {
                    d_groupCreationQueueFree(queue);
                    queue = NULL;
                }
            } else {
                d_groupCreationQueueFree(queue);
                queue = NULL;
            }
        }
    }
    return queue;
}
Ejemplo n.º 2
0
d_readerRequest
d_readerRequestProxyNew(
    v_handle source)
{
    d_readerRequest request;

    request = d_readerRequest(os_malloc(C_SIZEOF(d_readerRequest)));

    if(request){
        d_lockInit(d_lock(request), D_READER_REQUEST, d_readerRequestDeinit);

        request->admin               = NULL;
        request->readerHandle.index  = source.index;
        request->readerHandle.serial = source.serial;
        request->readerHandle.server = 0;
        request->requests            = NULL;
        request->filter              = NULL;
        request->filterParams        = NULL;
        request->filterParamsCount   = 0;
        request->groups              = NULL;

    }
    return request;
}
Ejemplo n.º 3
0
d_waitset
d_waitsetNew(
    d_subscriber subscriber,
    c_bool runToCompletion,
    c_bool timedWait)
{
    d_durability durability;
    d_admin admin;
    u_participant uparticipant;
    os_threadAttr attr;
    os_result osr;
    c_ulong mask;

    d_waitset waitset = NULL;

    assert(d_objectIsValid(d_object(subscriber), D_SUBSCRIBER) == TRUE);

    if(subscriber){
        waitset = d_waitset(os_malloc(C_SIZEOF(d_waitset)));

        if(waitset) {
            d_lockInit(d_lock(waitset), D_WAITSET, d_waitsetDeinit);
            admin                    = d_subscriberGetAdmin(subscriber);
            durability               = d_adminGetDurability(admin);
            uparticipant             = u_participant(d_durabilityGetService(durability));
            waitset->terminate       = FALSE;
            waitset->subscriber      = subscriber;
            waitset->entities        = c_iterNew(NULL);
            waitset->runToCompletion = runToCompletion;
            waitset->timedWait       = timedWait;

            if(runToCompletion == TRUE){
                waitset->uwaitset   = u_waitsetNew(uparticipant);
                mask = V_EVENT_DATA_AVAILABLE;
                mask |= V_EVENT_NEW_GROUP;
                mask |= V_EVENT_HISTORY_DELETE;
                mask |= V_EVENT_HISTORY_REQUEST;
                mask |= V_EVENT_PERSISTENT_SNAPSHOT;
                mask |= V_EVENT_TRIGGER;
                u_waitsetSetEventMask(waitset->uwaitset, mask);

                osr = os_threadAttrInit(&attr);

                if(osr == os_resultSuccess) {
                    osr = os_threadCreate(&waitset->thread, "waitsetThread", &attr,
                                d_waitsetEventHandlerRunToCompletion, waitset);
                }

                if(osr != os_resultSuccess) {
                    d_waitsetFree(waitset);
                }
                waitset->threads = NULL;
            } else {
                waitset->threads = c_iterNew(NULL);
                waitset->uwaitset = NULL;
                waitset->thread = OS_THREAD_ID_NONE;
            }
        }
    }
    return waitset;
}
Ejemplo n.º 4
0
d_readerRequest
d_readerRequestNew(
    d_admin admin,
    v_handle source,
    c_char* filter,
    c_char** filterParams,
    c_long filterParamsCount,
    struct v_resourcePolicy resourceLimits,
    c_time minSourceTimestamp,
    c_time maxSourceTimestamp)
{
    d_readerRequest request;
    c_long i;
    v_handleResult handleResult;
    v_reader vreader, *vreaderPtr;
    c_iter partitions;
    v_partition partition;
    v_topic topic;
    d_group dgroup;
    c_char *topicName;
    d_quality quality;

    request = d_readerRequest(os_malloc(C_SIZEOF(d_readerRequest)));

    if(request){
        d_lockInit(d_lock(request), D_READER_REQUEST, d_readerRequestDeinit);

        request->admin               = admin;
        request->readerHandle.index  = source.index;
        request->readerHandle.serial = source.serial;
        request->readerHandle.server = source.server;
        request->requests            = d_tableNew(d_chainCompare, d_chainFree);

        if(filter){
            request->filter          = os_strdup(filter);
        } else {
            request->filter          = NULL;
        }
        request->resourceLimits      = resourceLimits;
        request->minSourceTimestamp  = minSourceTimestamp;
        request->maxSourceTimestamp  = maxSourceTimestamp;
        request->filterParamsCount   = filterParamsCount;

        if(filterParamsCount > 0){
            request->filterParams = (c_char**)(os_malloc(
                                filterParamsCount*sizeof(c_char*)));

            for(i=0; i<filterParamsCount; i++){
                request->filterParams[i] = os_strdup(filterParams[i]);
            }
        } else {
            request->filterParams = NULL;
        }
        request->groups = d_tableNew(d_groupCompare, d_groupFree);

        handleResult = v_handleClaim(source, (v_object*)(vreaderPtr = &vreader));

        if(handleResult == V_HANDLE_OK){
            if(v_object(vreader)->kind == K_DATAREADER){
                topic      = v_dataReaderGetTopic(v_dataReader(vreader));
                topicName  = v_entity(topic)->name;
                partitions = ospl_c_select(v_subscriber(vreader->subscriber)->partitions->partitions, 0);
                partition  = v_partition(c_iterTakeFirst(partitions));

                while(partition){
                    quality.seconds = 0;
                    quality.nanoseconds = 0;
                    dgroup = d_groupNew(
                                v_entity(partition)->name, topicName,
                                topic->qos->durability.kind,
                                D_GROUP_KNOWLEDGE_UNDEFINED,
                                quality);
                    d_tableInsert(request->groups, dgroup);
                    c_free(partition);
                    partition  = v_partition(c_iterTakeFirst(partitions));
                }
                c_free(topic);
            } else {
                d_readerRequestFree(request);
                request = NULL;
            }
            v_handleRelease(source);
        } else {
            d_readerRequestFree(request);
            request = NULL;
        }
    }
    return request;
}