Ejemplo n.º 1
0
d_waitsetEntity
d_waitsetEntityNew(
    const c_char* name,
    u_dispatcher dispatcher,
    d_waitsetAction action,
    c_ulong mask,
    os_threadAttr attr,
    c_voidp usrData)
{
    d_waitsetEntity we = NULL;

    assert(dispatcher);
    assert(action);

    if(dispatcher && action) {
        we = d_waitsetEntity(os_malloc(C_SIZEOF(d_waitsetEntity)));

        if(name){
            we->name   = os_strdup(name);
        } else {
            we->name   = os_strdup("waitsetEntity");
        }
        we->action     = action;
        we->dispatcher = dispatcher;
        we->mask       = mask;
        we->usrData    = usrData;
        we->attr       = attr;
        we->waitset    = NULL;

        d_objectInit(d_object(we), D_WAITSET_ENTITY, d_waitsetEntityDeinit);
    }
    return we;
}
Ejemplo n.º 2
0
void
d_lockInit(
    d_lock lock,
    d_kind kind,
    d_objectDeinitFunc deinit)
{
    os_mutexAttr attr;
    os_result osr;
    
    d_objectInit(d_object(lock), kind, d_lockDeinit);
    
    if(lock){
        lock->deinit = deinit;
        osr = os_mutexAttrInit(&attr);
        
        if(osr == os_resultSuccess){
            attr.scopeAttr = OS_SCOPE_PRIVATE;
            osr = os_mutexInit(&lock->lock, &attr);
            
            if(osr != os_resultSuccess){
                d_objectFree(d_object(lock), kind);
            }
        } else {
            d_objectFree(d_object(lock), kind);
        }
    }
}
Ejemplo n.º 3
0
d_table
d_tableNew(
    int ( *  compare )(),
    void ( * cleanAction )() )
{
    d_table table;

    assert(compare != 0);
    /* Allocate table object */
    table = (d_table)d_malloc(C_SIZEOF(d_table), "Table");
    if (table) {
        /* QAC EXPECT 3892; */
        /* Call super-init */
        d_objectInit(d_object(table), D_TABLE,
                     (d_objectDeinitFunc)d_tableDeinit);
        /* Initialize table object */
        ut_avlCTreedefInit (&table->td,
                            offsetof (C_STRUCT(d_tableNode), avlnode), offsetof (C_STRUCT(d_tableNode), object),
                            (int (*) (const void *, const void *)) compare, 0,
                            UT_AVL_TREEDEF_FLAG_INDKEY);
        ut_avlCInit (&table->td, &table->tree);
        table->cleanAction = cleanAction;
    }
    return table;
}
Ejemplo n.º 4
0
d_eventListener
d_eventListenerNew(
    c_ulong interest,
    d_eventListenerFunc func,
    c_voidp args)
{
    d_eventListener listener;

    listener = NULL;

    if(func) {
        listener = d_eventListener(os_malloc(C_SIZEOF(d_eventListener)));
        d_objectInit(d_object(listener), D_EVENT_LISTENER, d_eventListenerDeinit);
        listener->interest  = interest;
        listener->func      = func;
        listener->args      = args;
    }
    return listener;
}
Ejemplo n.º 5
0
d_publisher
d_publisherNew(
    d_admin admin)
{
    d_publisher     publisher;
    d_durability    durability;
    d_configuration config;
    v_publisherQos  publisherQos;
    v_writerQos     writerQos;

    publisher = NULL;

    if(admin){
        publisher            = d_publisher(os_malloc(C_SIZEOF(d_publisher)));
        d_objectInit(d_object(publisher), D_PUBLISHER, d_publisherDeinit);
        publisher->enabled   = TRUE;
        publisher->admin     = admin;
        durability           = d_adminGetDurability(admin);
        config               = d_durabilityGetConfiguration(durability);
        publisherQos         = d_publisherQosNew(config->partitionName);
        publisher->publisher = u_publisherNew(
                                    u_participant(d_durabilityGetService(durability)),
                                    config->publisherName, publisherQos, TRUE);

        d_publisherQosFree(publisherQos);

        if(publisher->publisher){


            publisher->statusWriter            = NULL;
            publisher->newGroupWriter          = NULL;
            publisher->groupsRequestWriter     = NULL;
            publisher->statusRequestWriter     = NULL;
            publisher->sampleRequestWriter     = NULL;
            publisher->sampleChainWriter       = NULL;
            publisher->nameSpacesWriter        = NULL;
            publisher->nameSpacesRequestWriter = NULL;
            publisher->deleteDataWriter        = NULL;
            writerQos                          = d_writerQosNew(
                                                    V_DURABILITY_VOLATILE,
                                                    V_RELIABILITY_RELIABLE,
                                                    config->heartbeatLatencyBudget,
                                                    config->heartbeatTransportPriority);

            publisher->statusNumber = 0;
            publisher->statusWriter = u_writerNew (publisher->publisher,
                                                   "statusWriter",
                                                   d_adminGetStatusTopic(admin),
                                                   d_publisherStatusWriterCopy,
                                                   writerQos,
                                                   TRUE);
            assert(publisher->statusWriter);

            d_writerQosFree(writerQos);
            writerQos = d_writerQosNew (V_DURABILITY_VOLATILE,
                                        V_RELIABILITY_RELIABLE,
                                        config->latencyBudget,
                                        config->transportPriority);

            u_entityAction(u_entity(publisher->statusWriter), d_publisherEnsureServicesAttached, durability);

            publisher->newGroupNumber = 0;
            publisher->newGroupWriter = u_writerNew (publisher->publisher,
                                                     "newGroupWriter",
                                                     d_adminGetNewGroupTopic(admin),
                                                     d_publisherNewGroupWriterCopy,
                                                     writerQos,
                                                     TRUE);
            assert(publisher->newGroupWriter);
            u_entityAction(u_entity(publisher->newGroupWriter), d_publisherEnsureServicesAttached, durability);


            publisher->groupsRequestNumber = 0;
            publisher->groupsRequestWriter = u_writerNew (publisher->publisher,
                                                          "groupsRequestWriter",
                                                          d_adminGetGroupsRequestTopic(admin),
                                                          d_publisherGroupsRequestWriterCopy,
                                                          writerQos,
                                                          TRUE);
            assert(publisher->groupsRequestWriter);
            u_entityAction(u_entity(publisher->groupsRequestWriter), d_publisherEnsureServicesAttached, durability);

            publisher->statusRequestNumber = 0;
            publisher->statusRequestWriter = u_writerNew (publisher->publisher,
                                                          "statusRequestWriter",
                                                          d_adminGetStatusRequestTopic(admin),
                                                          d_publisherStatusRequestWriterCopy,
                                                          writerQos,
                                                          TRUE);
            assert(publisher->statusRequestWriter);
            u_entityAction(u_entity(publisher->statusRequestWriter), d_publisherEnsureServicesAttached, durability);

            publisher->sampleRequestNumber = 0;
            publisher->sampleRequestWriter = u_writerNew (publisher->publisher,
                                                          "sampleRequestWriter",
                                                          d_adminGetSampleRequestTopic(admin),
                                                          d_publisherSampleRequestWriterCopy,
                                                          writerQos,
                                                          TRUE);
            assert(publisher->sampleRequestWriter);
            u_entityAction(u_entity(publisher->sampleRequestWriter), d_publisherEnsureServicesAttached, durability);

            publisher->nameSpacesNumber = 0;
            publisher->nameSpacesWriter = u_writerNew (publisher->publisher,
                                                       "nameSpacesWriter",
                                                       d_adminGetNameSpacesTopic(admin),
                                                       d_publisherNameSpacesWriterCopy,
                                                       writerQos,
                                                       TRUE);
            assert(publisher->nameSpacesWriter);
            u_entityAction(u_entity(publisher->nameSpacesWriter), d_publisherEnsureServicesAttached, durability);

            publisher->nameSpacesRequestNumber = 0;
            publisher->nameSpacesRequestWriter = u_writerNew (publisher->publisher,
                                                              "nameSpacesRequestWriter",
                                                              d_adminGetNameSpacesRequestTopic(admin),
                                                              d_publisherNameSpacesRequestWriterCopy,
                                                              writerQos,
                                                              TRUE);
            assert(publisher->nameSpacesRequestWriter);
            u_entityAction(u_entity(publisher->nameSpacesRequestWriter), d_publisherEnsureServicesAttached, durability);

            publisher->deleteDataNumber = 0;
            publisher->deleteDataWriter = u_writerNew (publisher->publisher,
                                                       "deleteDataWriter",
                                                       d_adminGetDeleteDataTopic(admin),
                                                       d_publisherDeleteDataWriterCopy,
                                                       writerQos,
                                                       TRUE);
            assert(publisher->deleteDataWriter);
            u_entityAction(u_entity(publisher->deleteDataWriter), d_publisherEnsureServicesAttached, durability);

            d_writerQosFree(writerQos);
            writerQos = d_writerQosNew (V_DURABILITY_VOLATILE,
                                        V_RELIABILITY_RELIABLE,
                                        config->alignerLatencyBudget,
                                        config->alignerTransportPriority);
            publisher->sampleChainNumber = 0;
            publisher->sampleChainWriter = u_writerNew (publisher->publisher,
                                                        "sampleChainWriter",
                                                        d_adminGetSampleChainTopic(admin),
                                                        d_publisherSampleChainWriterCopy,
                                                        writerQos,
                                                        TRUE);
            assert(publisher->sampleChainWriter);
            u_entityAction(u_entity(publisher->sampleChainWriter), d_publisherEnsureServicesAttached, durability);

            d_writerQosFree(writerQos);
        } else {
            d_publisherFree(publisher);
            publisher = NULL;
        }
    }
    return publisher;
}
Ejemplo n.º 6
0
d_subscriber
d_subscriberNew(
    d_admin admin)
{
    d_subscriber    subscriber;
    d_durability    durability;
    d_configuration config;
    v_subscriberQos subscriberQos, psubscriberQos;
    c_char*         partitionExpr;
    struct initialQualityWalkData walkData;
    d_storeResult       result;
    d_nameSpace         nameSpace;
    c_iter              nameSpaces;
    c_bool              nsComplete;
    d_durabilityKind    dkind;

    subscriber = NULL;

    if(admin){
        subscriber        = d_subscriber(os_malloc(C_SIZEOF(d_subscriber)));
        d_objectInit(d_object(subscriber), D_SUBSCRIBER, d_subscriberDeinit);

        subscriber->admin = admin;
        durability        = d_adminGetDurability(admin);
        config            = d_durabilityGetConfiguration(durability);
        subscriberQos     = d_subscriberQosNew(config->partitionName);
        partitionExpr     = getPersistentPartitionExpression(admin, durability);
        psubscriberQos    = d_subscriberQosNew(partitionExpr);

        os_free(partitionExpr);

        subscriber->subscriber = u_subscriberNew (u_participant(d_durabilityGetService(durability)),
                                                  config->subscriberName,
                                                  subscriberQos,
                                                  TRUE);

        subscriber->waitset         = d_waitsetNew(subscriber, FALSE, FALSE);
        subscriber->persistentStore = d_storeOpen(durability, config->persistentStoreMode);

        if(subscriber->persistentStore) {
            if(psubscriberQos->partition){

                /* Collect nameSpaces from admin. */
                nameSpaces = d_adminNameSpaceCollect(admin);

                /* Loop nameSpaces */
                while((nameSpace = c_iterTakeFirst(nameSpaces))) {
                    dkind = d_nameSpaceGetDurabilityKind(nameSpace);

                    /* Walk only over persistent nameSpaces */
                    if((dkind == D_DURABILITY_PERSISTENT) || (dkind == D_DURABILITY_ALL)){

                        /* If persistent nameSpace is not complete, restore backup */
                        result = d_storeNsIsComplete (subscriber->persistentStore, nameSpace, &nsComplete);
                        if ( (result == D_STORE_RESULT_OK) && !nsComplete)
                        {
                            /* Incomplete namespace, restore backup. */
                            d_printTimedEvent(durability, D_LEVEL_WARNING,
                                D_THREAD_GROUP_LOCAL_LISTENER,
                                "Namespace '%s' is incomplete, trying to restore backup.\n",
                                d_nameSpaceGetName(nameSpace));

                            if (d_storeRestoreBackup (subscriber->persistentStore, nameSpace) != D_STORE_RESULT_OK)
                            {
                                d_printTimedEvent(durability, D_LEVEL_WARNING,
                                    D_THREAD_GROUP_LOCAL_LISTENER,
                                    "Backup for namespace '%s' could not be restored as no complete backup did exist on disk. Marking namespace as incomplete and continuing.\n",
                                    d_nameSpaceGetName(nameSpace));

                                OS_REPORT_1(OS_WARNING, D_CONTEXT_DURABILITY, 0,
                                    "Backup for namespace '%s' could not be restored as no complete backup did exist on disk. Marking namespace as incomplete and continuing.\n",
                                    d_nameSpaceGetName (nameSpace));

                                /* If backup fails, mark master state for nameSpace !D_STATE_COMPLETE */
                                d_nameSpaceSetMasterState (nameSpace, D_STATE_INIT);
                            }
                        }
                    }
                    d_nameSpaceFree(nameSpace);
                }

                /* Free nameSpaces iterator */
                assert(c_iterLength(nameSpaces) == 0);
                c_iterFree(nameSpaces);

                subscriber->persistentSubscriber = u_subscriberNew(u_participant(d_durabilityGetService(durability)),
                                                                   config->subscriberName,
                                                                   psubscriberQos,
                                                                   TRUE);

                assert(subscriber->persistentSubscriber);
            } else {
                subscriber->persistentSubscriber = NULL;
            }

            walkData.subscriber = subscriber;
            walkData.i = 0;
            d_adminNameSpaceWalk(admin, nsInitialQualityWalk, &walkData);

        } else {
            subscriber->persistentSubscriber = NULL;
        }
        assert(subscriber->subscriber);

        if(subscriber->subscriber){
            subscriber->statusListener            = NULL;
            subscriber->groupLocalListener        = NULL;
            subscriber->groupRemoteListener       = NULL;
            subscriber->groupsRequestListener     = NULL;
            subscriber->sampleRequestListener     = NULL;
            subscriber->sampleChainListener       = NULL;
            subscriber->nameSpacesRequestListener = NULL;
            subscriber->nameSpacesListener        = NULL;
            subscriber->persistentDataListener    = NULL;
            subscriber->deleteDataListener        = NULL;
        } else {
            d_subscriberFree(subscriber);
            subscriber = NULL;
        }
        d_subscriberQosFree(subscriberQos);
        d_subscriberQosFree(psubscriberQos);
    }
    return subscriber;
}