Esempio n. 1
0
static void
s_configurationValueULong(
    s_configuration configuration,
    u_cfElement     element,
    const char      *tag,
    void            (* const setAction)(s_configuration config, c_ulong longValue))
{
    c_iter   iter;
    u_cfData data;
    c_long   longValue;
    c_ulong  ulongValue;
    c_bool   found;

    iter = u_cfElementXPath(element, tag);
    data = u_cfData(c_iterTakeFirst(iter));
    while (data != NULL) {
        found = u_cfDataLongValue(data, &longValue);
        /* QAC EXPECT 2100; */
        if (found == TRUE) {
            if (longValue < 0) {
                longValue = -longValue;
                if (longValue < 0) {
                    longValue++;
                    longValue = -longValue;
                }
            }
            ulongValue = (c_ulong)longValue;
            setAction(configuration, ulongValue);
        }
        u_cfDataFree(data);
        data = u_cfData(c_iterTakeFirst(iter));
    }
    c_iterFree(iter);
}
Esempio n. 2
0
static c_bool
cfgGetArguments(
    sr_serviceInfo si,
    u_cfElement info)
{
    c_iter iter;
    int    iterLength;
    c_bool r;
    u_cfData d;

    r = TRUE;
    iter = u_cfElementXPath(info, "Arguments/#text");
    iterLength = c_iterLength(iter);
    d = u_cfData(c_iterTakeFirst(iter));
    if (iterLength == 1) {
        r = u_cfDataStringValue(d, &si->args);
        u_cfDataFree(d);
    } else if (iterLength == 0) {
        OS_REPORT_1(OS_INFO, OSRPT_CNTXT_SPLICED, 
            0, "Taking default for <Arguments> parameter service %s", si->name);
        si->args = os_strdup("");
    } else {
        OS_REPORT_1(OS_ERROR, OSRPT_CNTXT_SPLICED, 
            0, "One <Arguments> parameter expected for service %s", si->name);
        si->args = os_strdup("");
        while (d != NULL) {
            u_cfDataFree(d);
            d = u_cfData(c_iterTakeFirst(iter));
        }
        r = FALSE;
    }
    c_iterFree(iter);

    return r;
}
Esempio n. 3
0
c_iter
u_cfElementGetAttributes(
    u_cfElement element)
{
    u_result      r;
    v_cfElement   ke;
    v_cfAttribute attr;
    c_iter        ka;
    c_iter        attributes;
    u_participant p;


    attributes = c_iterNew(NULL);
    if (element != NULL) {
        r = u_cfNodeReadClaim(u_cfNode(element), (v_cfNode*)(&ke));
        if (r == U_RESULT_OK) {
            p = u_cfNodeParticipant(u_cfNode(element));
            ka = v_cfElementGetAttributes(ke);
            attr = c_iterTakeFirst(ka);
            while (attr != NULL) {
                c_iterInsert(attributes, u_cfAttributeNew(p, attr));
                attr = c_iterTakeFirst(ka);
            }
            c_iterFree(ka);
            u_cfNodeRelease(u_cfNode(element));
        }
    }
    return attributes;
}
Esempio n. 4
0
/**************************************************************
 * Private functions
 **************************************************************/
static c_bool
cfgGetCommand(
    sr_serviceInfo si,
    u_cfElement info)
{
    c_iter iter;
    int      iterLength;
    c_bool r;
    u_cfData d;

    r = TRUE;

    iter = u_cfElementXPath(info, "Command/#text");
    iterLength = c_iterLength(iter);
    d = u_cfData(c_iterTakeFirst(iter));
    if (iterLength == 1) {
        r = u_cfDataStringValue(d, &si->command);
        u_cfDataFree(d);
    } else {
        OS_REPORT_1(OS_ERROR, OSRPT_CNTXT_SPLICED, 
            0, "One <Command> parameter expected for service %s", si->name);
        while (d != NULL) {
            u_cfDataFree(d);
            d = u_cfData(c_iterTakeFirst(iter));
        }
        r = FALSE;
    }
    c_iterFree(iter);

    return r;
}
Esempio n. 5
0
static void
s_configurationAttrValueBoolean(
    s_configuration configuration,
    u_cfElement     element,
    const char      *tag,
    const char      *attr,
    void            (* const setAction)(s_configuration config, c_bool boolValue))
{
    c_iter   iter;
    u_cfElement e;
    u_cfAttribute a;
    c_bool   boolValue, found;

    iter = u_cfElementXPath(element, tag);
    e = u_cfElement(c_iterTakeFirst(iter));

    while (e != NULL) {
        a = u_cfElementAttribute(e, attr);

        if (a) {
            found = u_cfAttributeBoolValue(a, &boolValue);
            /* QAC EXPECT 2100; */
            if (found == TRUE) {
                setAction(configuration, boolValue);
            }
            u_cfAttributeFree(a);
        }
        u_cfElementFree(e);
        e = u_cfElement(c_iterTakeFirst(iter));
    }
    c_iterFree(iter);
}
Esempio n. 6
0
void
cmx_readerSnapshotFreeAll()
{
    cmx_readerSnapshot s;
    c_char* sample;
    os_mutex m;

    m = cmx_getReaderSnapshotMutex();
    os_mutexLock(&m);
    s = cmx_readerSnapshot(c_iterTakeFirst(readerSnapshots));

    while(s != NULL){
        if(s->samples != NULL){
            sample = (c_char*)(c_iterTakeFirst(s->samples));

            while(sample != NULL){
                os_free(sample);
                sample = (c_char*)(c_iterTakeFirst(s->samples));
            }
            c_iterFree(s->samples);
        }
        os_free(s);
        s = cmx_readerSnapshot(c_iterTakeFirst(readerSnapshots));
    }
    os_mutexUnlock(&m);
}
Esempio n. 7
0
void
v_subscriberUnSubscribe(
    v_subscriber s,
    const c_char *partitionExpr)
{
    v_partition d;
    v_dataReaderConnectionChanges arg;
    v_partitionPolicy old;

    assert(s != NULL);
    assert(C_TYPECHECK(s,v_subscriber));

    arg.addedPartitions = NULL;

    c_lockWrite(&s->lock);

    arg.removedPartitions = v_partitionAdminRemove(s->partitions, partitionExpr);
    old = s->qos->partition;
    s->qos->partition = v_partitionPolicyRemove(old, partitionExpr,
                                                c_getBase(c_object(s)));
    c_free(old);
    c_setWalk(s->readers, qosChangedAction, &arg);

    d = v_partition(c_iterTakeFirst(arg.removedPartitions));
    while (d != NULL) {
        c_free(d);
        d = v_partition(c_iterTakeFirst(arg.removedPartitions));
    }
    c_iterFree(arg.removedPartitions);

    c_lockUnlock(&s->lock);
}
Esempio n. 8
0
static void
s_configurationValueString(
    s_configuration configuration,
    u_cfElement     element,
    const char      *tag,
    void            (* const setAction)(s_configuration config, const c_char * str) )
{
    c_iter   iter;
    u_cfData data;
    c_bool   found;
    c_char *   str;

    iter = u_cfElementXPath(element, tag);
    data = u_cfData(c_iterTakeFirst(iter));

    while (data) {
        found = u_cfDataStringValue(data, &str);
        /* QAC EXPECT 2100; */
        if (found == TRUE) {
            setAction(configuration, str);
            os_free(str);
        }
        u_cfDataFree(data);
        data = u_cfData(c_iterTakeFirst(iter));
    }
    c_iterFree(iter);
}
Esempio n. 9
0
static void
s_configurationValueSize(
    s_configuration configuration,
    u_cfElement     element,
    const char      *tag,
    void            (* const setAction)(s_configuration config, c_ulong ulongValue))
{
    c_iter   iter;
    u_cfData data;
    c_ulong  ulongValue;
    c_bool   found;

    iter = u_cfElementXPath(element, tag);
    data = u_cfData(c_iterTakeFirst(iter));
    while (data != NULL) {
        found = u_cfDataSizeValue(data, &ulongValue);
        /* QAC EXPECT 2100; */
        if (found == TRUE) {
            setAction(configuration, ulongValue);
        }
        u_cfDataFree(data);
        data = u_cfData(c_iterTakeFirst(iter));
    }
    c_iterFree(iter);
}
Esempio n. 10
0
static void
s_configurationValueFloat(
    s_configuration configuration,
    u_cfElement     element,
    const c_char    *tag,
    void            (* const setAction)(s_configuration config, c_float floatValue))
{
    c_iter   iter;
    u_cfData data;
    c_bool   found;
    c_float  floatValue;

    iter = u_cfElementXPath(element, tag);
    data = u_cfData(c_iterTakeFirst(iter));

    while (data != NULL) {
        found = u_cfDataFloatValue(data, &floatValue);

        if (found == TRUE) {
            setAction(configuration, floatValue);
        }
        u_cfDataFree(data);
        data = u_cfData(c_iterTakeFirst(iter));
    }
    c_iterFree(iter);
}
Esempio n. 11
0
jni_topic
jni_lookupTopic(
    jni_participant p,
    const char* name)
{
    c_iter topics;
    jni_topic topic, temp;
    int found;
    
    topic = NULL;
    
    if((name != NULL) && (p != NULL)){
        topics = c_iterCopy(p->topics);
        found = 0;
        temp = jni_topic(c_iterTakeFirst(topics));
        
        while( (temp != NULL) && (!found)){
            
            if(strcmp(jni_topicDescription(temp)->name, name) == 0){
                topic = temp;
                found = 1;
            }
            temp = jni_topic(c_iterTakeFirst(topics));
        }
        c_iterFree(topics);
    }
    return topic;
}
Esempio n. 12
0
void
cmx_readerSnapshotFree(
    c_char* snapshot)
{
    cmx_readerSnapshot s;
    c_char* sample;
    os_mutex m;

    s = cmx_readerSnapshotLookup(snapshot);

    if(s != NULL){
        m = cmx_getReaderSnapshotMutex();
        os_mutexLock(&m);
        c_iterTake(readerSnapshots, s);
        os_mutexUnlock(&m);

        if(s->samples != NULL){
            sample = (c_char*)(c_iterTakeFirst(s->samples));

            while(sample != NULL){
                os_free(sample);
                sample = (c_char*)(c_iterTakeFirst(s->samples));
            }
            c_iterFree(s->samples);
        }
        os_free(s);
        os_free(snapshot);
    }
}
Esempio n. 13
0
u_result
u_subscriberDeleteContainedEntities (
    u_subscriber _this)
{
    u_result result;
    u_reader reader;
    c_iter list;

    if (_this != NULL) {
        result = u_entityLock(u_entity(_this));
        if (result == U_RESULT_OK) {
            list = _this->readers;
            _this->readers = NULL;
            /* Unlock here because following code will take this lock. */
            u_entityUnlock(u_entity(_this));
            reader = c_iterTakeFirst(list);
            while (reader) {
                switch (u_entityKind(u_entity(reader))) {
                case U_READER:
                    result = u_dataReaderDeleteContainedEntities(u_dataReader(reader));
                    result = u_dataReaderFree(u_dataReader(reader));
                break;
                case U_GROUPQUEUE:
                    result = u_groupQueueFree(u_groupQueue(reader));
                break;
                case U_DATAVIEW:
                    result = u_dataViewFree(u_dataView(reader));
                break;
                case U_NETWORKREADER:
                    result = u_networkReaderFree(u_networkReader(reader));
                break;
                default:
                    OS_REPORT_2(OS_WARNING,
                                "u_subscriberDeleteContainedEntities",0,
                                "invalid object type: "
                                "For Subscriber = 0x%x, found Reader type = %s.",
                                _this, u_kindImage(u_entityKind(u_entity(reader))));
                    assert(0);
                break;
                }
                u_entityDereference(u_entity(_this));
                reader = c_iterTakeFirst(list);
            }
            c_iterFree(list);
        } else {
            OS_REPORT_2(OS_WARNING,
                        "u_subscriberDeleteContainedEntities",0,
                        "Operation u_entityLock failed: "
                        "Subscriber = 0x%x, result = %s.",
                        _this, u_resultImage(result));
        }
    } else {
        OS_REPORT(OS_WARNING,
                  "u_subscriberDeleteContainedEntities",0,
                  "Invalid Subscriber <NULL>.");
        result = U_RESULT_ILL_PARAM;
    }
    return result;
}
Esempio n. 14
0
static c_bool
cfgGetSchedule(
    sr_serviceInfo si,
    u_cfElement info)
{
    c_iter iter;
    int      iterLength;
    c_bool r;
    u_cfData d;
    c_char *str;

    r = TRUE;
    iter = u_cfElementXPath(info, "Scheduling/Class/#text");
    iterLength = c_iterLength(iter);
    d = u_cfData(c_iterTakeFirst(iter));
    if (iterLength == 1) {
        r = u_cfDataStringValue(d, &str);

        if (r == TRUE) {
            if (strncmp(str, SCHED_RT, strlen(SCHED_RT)) == 0) {
                si->procAttr.schedClass = OS_SCHED_REALTIME;
            } else {
                if (strncmp(str, SCHED_TS, strlen(SCHED_TS)) == 0) {
                    si->procAttr.schedClass = OS_SCHED_TIMESHARE;
                } else {
                    if (strcmp(str, SCHED_DEF)==0) {
                        si->procAttr.schedClass = OS_SCHED_DEFAULT;
                    } else {
                        si->procAttr.schedClass = OS_SCHED_DEFAULT;
                        OS_REPORT_1(OS_WARNING, OSRPT_CNTXT_SPLICED, 
                             0, "Incorrect <Scheduling/Class> parameter for service %s -> default",
                             si->name);
                         r = TRUE;
                    }
                }
            }
            os_free(str);
        }
        u_cfDataFree(d);
    } else {
        si->procAttr.schedClass = OS_SCHED_DEFAULT;
        if (iterLength == 0) {
            OS_REPORT_1(OS_INFO, OSRPT_CNTXT_SPLICED, 
                0, "Taking default for <Scheduling/Class> parameter service %s", si->name);
        } else {
            OS_REPORT_1(OS_ERROR, OSRPT_CNTXT_SPLICED, 
                0, "One <Scheduling/Class> parameter expected for service %s", si->name);
            r = FALSE;
        }
        while (d != NULL) {
            u_cfDataFree(d);
            d = u_cfData(c_iterTakeFirst(iter));
        }
    }
    c_iterFree(iter);

    return r;
}
Esempio n. 15
0
jni_result
jni_participantFree(
    jni_participant p)
{
    jni_result r;
    jni_partition partition;
    
    r = JNI_RESULT_OK;
    
    if(p != NULL){
        if((p->publishers != NULL) && (c_iterLength(p->publishers) != 0)){
            r = JNI_RESULT_PRECONDITION_NOT_MET;
        }
        else if((p->subscribers != NULL) && (c_iterLength(p->subscribers) != 0)){
            r = JNI_RESULT_PRECONDITION_NOT_MET;
        }
        else if((p->topics != NULL) && (c_iterLength(p->topics) != 0)){
            r = JNI_RESULT_PRECONDITION_NOT_MET;
        }
        else if((p->partitions != NULL) && (c_iterLength(p->partitions) != 0)){
            partition = jni_partition(c_iterTakeFirst(p->partitions));
            
            while((partition != NULL) && (r == JNI_RESULT_OK)){
                r = jni_partitionFree(partition);
                partition = jni_partition(c_iterTakeFirst(p->partitions));
            }
        }
        else{
          /*DO NOTHING.*/
        }
        
        if(r == JNI_RESULT_OK){
            if(p->publishers != NULL){
                c_iterFree(p->publishers);
            }
            if(p->subscribers != NULL){
                c_iterFree(p->subscribers);
            }
            if(p->topics != NULL){
                c_iterFree(p->topics);
            }
            if(p->partitions != NULL){
                c_iterFree(p->partitions);
            }
            if(p->uparticipant != NULL){
                r = jni_convertResult(u_participantFree(p->uparticipant));
            }
            else{
                r = JNI_RESULT_OK;
            }
            os_free(p);
        }        
    }
    else{
        r = JNI_RESULT_BAD_PARAMETER;
    }
    return r;
}
Esempio n. 16
0
void
d_waitsetDeinit(
    d_object object)
{
    d_waitset waitset;
    d_waitsetEntity we;
    d_waitsetHelper helper;

    assert(d_objectIsValid(object, D_WAITSET) == TRUE);

    if(object){
        waitset = d_waitset(object);
        waitset->terminate = TRUE;

        if(waitset->runToCompletion == TRUE){
            if(os_threadIdToInteger(waitset->thread)) {
                u_waitsetNotify(waitset->uwaitset, NULL);
                os_threadWaitExit(waitset->thread, NULL);
            }
        } else {
            if(waitset->threads){
                helper = d_waitsetHelper(c_iterTakeFirst(waitset->threads));

                while(helper){
                    helper->terminate = TRUE;
                    u_waitsetNotify(helper->userWaitset, NULL);
                    os_threadWaitExit(helper->tid, NULL);
                    u_waitsetDetach(helper->userWaitset, u_entity(helper->entity->dispatcher));
                    u_waitsetFree(helper->userWaitset);
                    os_free(helper);
                    helper = d_waitsetHelper(c_iterTakeFirst(waitset->threads));
                }
                c_iterFree(waitset->threads);
                waitset->threads = NULL;
            }
        }
        d_lockLock(d_lock(waitset));

        if(waitset->entities) {
            we = d_waitsetEntity(c_iterTakeFirst(waitset->entities));

            while(we) {
                if(waitset->runToCompletion == TRUE){
                    u_waitsetDetach(waitset->uwaitset, u_entity(we->dispatcher));
                }
                d_waitsetEntityFree(we);
                we = d_waitsetEntity(c_iterTakeFirst(waitset->entities));
            }
            c_iterFree(waitset->entities);
        }
        if(waitset->runToCompletion == TRUE){
            if(waitset->uwaitset) {
                u_waitsetFree(waitset->uwaitset);
            }
        }
        d_lockUnlock(d_lock(waitset));
    }
}
Esempio n. 17
0
void
cms_clientFree(
    cms_client client)
{
    struct soap* soap;
    cms_soapThread soapThread;

    cms_thread(client)->terminate = TRUE;

    os_mutexLock(&client->conditionMutex);
    os_condSignal(&client->condition);
    os_mutexUnlock(&client->conditionMutex);

    cms_threadDeinit(cms_thread(client));

    if(client->soapEnvs){
        os_mutexLock(&client->soapMutex);
        soap = (struct soap*)(c_iterTakeFirst(client->soapEnvs));

        while(soap){
            soap->error = soap_receiver_fault(soap, "Service is terminating.", NULL);
            soap_send_fault(soap);
            soap_destroy(soap);
            soap_end(soap);
            soap_done(soap);
            os_free(soap);
            soap = (struct soap*)(c_iterTakeFirst(client->soapEnvs));
        }
        c_iterFree(client->soapEnvs);
        client->soapEnvs = NULL;
        os_mutexUnlock(&client->soapMutex);
    }

    if(client->threads){
        soapThread = cms_soapThread(c_iterTakeFirst(client->threads));

        while(soapThread){
            cms_soapThreadFree(soapThread);
            (void)u_observableAction(u_observable(client->service->uservice), cms_clientStatisticsThreadRemove, client->service);
            soapThread = cms_soapThread(c_iterTakeFirst(client->threads));
        }
        c_iterFree(client->threads);
        client->threads = NULL;
    }
    os_mutexDestroy(&client->soapMutex);
    os_mutexDestroy(&client->threadMutex);
    os_mutexDestroy(&client->conditionMutex);
    os_condDestroy(&client->condition);
    client->initCount = 0;

    if(client->service->configuration->verbosity >= 5){
        OS_REPORT(OS_INFO, CMS_CONTEXT, 0,
                        "Client thread stopped for IP: %d.%d.%d.%d",
                        (int)(client->ip>>24)&0xFF,
                        (int)(client->ip>>16)&0xFF,
                        (int)(client->ip>>8)&0xFF,
                        (int)(client->ip&0xFF));
    }
Esempio n. 18
0
static void*
d_waitsetEventHandler(
    void* userData)
{
    d_subscriber subscriber;
    d_durability durability;
    d_admin admin;
    c_iter events;
    d_waitsetEntity we;
    c_time time;
    d_waitsetHelper helper;
    u_waitset userWaitset;
    u_waitsetEvent event;
    u_result ur;

    helper           = d_waitsetHelper(userData);
    we               = helper->entity;
    subscriber       = d_waitsetGetSubscriber(helper->waitset);
    admin            = d_subscriberGetAdmin(subscriber);
    durability       = d_adminGetDurability(admin);
    time.seconds     = 1;
    time.nanoseconds = 0;
    userWaitset      = helper->userWaitset;
    ur               = U_RESULT_OK;

    while((helper->terminate == FALSE) && (ur == U_RESULT_OK)) {
        events = NULL;
        if(helper->waitset->timedWait == TRUE){
            ur = u_waitsetTimedWaitEvents(userWaitset, time,&events);
        } else {
            ur = u_waitsetWaitEvents(userWaitset,&events);
        }
        if(events  && (ur == U_RESULT_OK)){/* events may be null if waitset was deleted*/
            event = u_waitsetEvent(c_iterTakeFirst(events));

            while(event){
                /* Only dispatch event when durability is not terminating */
                if (d_durabilityGetState(durability) != D_STATE_TERMINATING){
                    we->action(we->dispatcher, event, we->usrData);
                }
                u_waitsetEventFree(event);
                event = u_waitsetEvent(c_iterTakeFirst(events));
            }
            c_iterFree(events);
        }
    }
    if(ur != U_RESULT_OK){
        d_printTimedEvent(durability, D_LEVEL_SEVERE,
            we->name,
            "Waitset no longer available (result: %d). Fatal error, terminating now...\n",
            ur);
        OS_REPORT_1(OS_ERROR, D_CONTEXT_DURABILITY, 0,
            "Waitset no longer available (result: %d). Fatal error, terminating now...\n",
            ur);
        d_durabilityTerminate(durability);
    }
    return NULL;
}
Esempio n. 19
0
v_partitionPolicyI
v_partitionPolicyAdd(
    v_partitionPolicyI p,
    const c_char* expr,
    c_base base)
{
    c_iter list;
    c_char *str, *partition;
    os_size_t size;
    c_bool isIn;
    v_partitionPolicyI newPolicy;

    newPolicy.v = NULL;

    assert(expr);

    if(p.v){
        isIn = FALSE;

        list = v_partitionPolicySplit(p);
        partition = c_iterTakeFirst(list);

        while(partition){
            if(strcmp(partition, expr) == 0){
               isIn = TRUE;
           }
           os_free(partition);
           partition = c_iterTakeFirst(list);
        }
        c_iterFree(list);

        if(isIn){
            /* It's already in there, so return the current value */
            newPolicy.v = c_stringNew(base, p.v);
        } else {
            /* It's not in there, so add it to the existing one */
            size = strlen(p.v) + 1 + strlen(expr) + 1;
            str = os_malloc(size);

            if (str) {
                os_strncpy(str, p.v, size);
                str = os_strcat(str, ",");
                str = os_strcat(str, expr);
                newPolicy.v = c_stringNew(base, str);
                os_free(str);
            } else {
                /* failed to allocate, so report error and return NULL */
                OS_REPORT(OS_FATAL, "v_partitionPolicyAdd", V_RESULT_OUT_OF_MEMORY, "Failed to allocate partitionPolicy");
            }
        }
    } else {
        /* No policy exists yet, so make the expr the new policy */
        newPolicy.v = c_stringNew(base, expr);
    }
    return newPolicy;
}
Esempio n. 20
0
/*     ReturnCode_t
 *     delete_contained_entities();
 */
gapi_returnCode_t
gapi_dataReaderView_delete_contained_entities (
    gapi_dataReaderView _this)
{
    gapi_returnCode_t result = GAPI_RETCODE_OK;
    _DataReaderView datareaderview;
    gapi_context context;
    _Condition condition = NULL;
    c_iter entities;
    u_entity e;
    u_result ur;

    GAPI_CONTEXT_SET(context, _this, GAPI_METHOD_DELETE_CONTAINED_ENTITIES);

    if ( _this != NULL ) {
        datareaderview = gapi_dataReaderViewClaim(_this, &result);
        if ( datareaderview != NULL ) {
            if (!gapi_loanRegistry_is_empty(datareaderview->loanRegistry)) {
                result = GAPI_RETCODE_PRECONDITION_NOT_MET;
            } else {
                entities = u_readerLookupQueries(U_READER_GET(datareaderview));
                e = c_iterTakeFirst(entities);
                while (e) {
                    condition = u_entityGetUserData(e);
                    if (condition) {
                        _ObjectReadClaimNotBusy(_Object(condition));
                        _ConditionFree(condition);
                    } else {
                        if (e == u_entity(datareaderview->uQuery)) {
                            datareaderview->uQuery = NULL;
                            ur = u_queryFree(u_query(e));
                            if (ur == U_RESULT_OK) {
                                result = GAPI_RETCODE_OK;
                            } else {
                                result = GAPI_RETCODE_BAD_PARAMETER;
                            }
                        } else {
                            assert(condition);
                            result = GAPI_RETCODE_BAD_PARAMETER;
                        }
                    }
                    e = c_iterTakeFirst(entities);
                }
                c_iterFree(entities);
            }
            _EntityRelease(datareaderview);
        } else {
            result = GAPI_RETCODE_ALREADY_DELETED;
        }
    } else {
        result = GAPI_RETCODE_BAD_PARAMETER;
    }

    return result;
}
Esempio n. 21
0
static c_bool
cfgGetPriorityKind(
    sr_serviceInfo si,
    u_cfElement info)
{
    c_iter iter;
    int      iterLength;
    c_bool r;
    u_cfElement d;
    c_char * str;

    r = TRUE;
    iter = u_cfElementXPath(info, "Scheduling/Priority");
    iterLength = c_iterLength(iter);
    d = u_cfElement(c_iterTakeFirst(iter));
    if (iterLength == 1) {
        r = u_cfElementAttributeStringValue(d, ATTR_PRIOKIND, &str);

        if (r == TRUE) {
            if (strcmp(str, PRIOKIND_REL) == 0) {
                si->priorityKind = V_SCHED_PRIO_RELATIVE;
            } else {
                if (strcmp(str, PRIOKIND_ABS) == 0) {
                    si->priorityKind = V_SCHED_PRIO_ABSOLUTE;
                } else {
                    si->priorityKind = V_SCHED_PRIO_RELATIVE;
                    OS_REPORT_1(OS_WARNING, OSRPT_CNTXT_SPLICED, 
                         0, "Incorrect <Scheduling/Priority[@priority_kind]> attribute for service %s -> default",
                         si->name);
                     r = TRUE;
                }
            }
            os_free(str);
        }
        u_cfElementFree(d);
    } else {
        if (iterLength == 0) {
            si->priorityKind = V_SCHED_PRIO_RELATIVE;
            OS_REPORT_1(OS_INFO, OSRPT_CNTXT_SPLICED, 
                0, "Taking default for <Scheduling/Priority[@priority_kind]> parameter for  service %s", si->name);
        } else {
            OS_REPORT_1(OS_ERROR, OSRPT_CNTXT_SPLICED, 
                0, "One <Scheduling/Priority[@priority_kind]> parameter expected for service %s", si->name);
            r = FALSE;
        }
        while (d != NULL) {
            u_cfElementFree(d);
            d = u_cfElement(c_iterTakeFirst(iter));
        }
    }
    c_iterFree(iter);

    return r;
}
Esempio n. 22
0
static void*
cms_serviceCollectGarbage(
    void* arg)
{
    cms_service cms;
    os_time update;
    cms_thread client;
    c_bool garbagePresent;

    cms = cms_service(arg);
    update.tv_sec = 2;
    update.tv_nsec = 0;

    garbagePresent = FALSE;

    /*
     * Keep going until service terminates AND all garbage has been collected.
     */
    while((cms->terminate == FALSE) || (c_iterLength(cms->clientGarbage) != 0)) {
        os_mutexLock(&cms->clientMutex);
        client = cms_thread(c_iterTakeFirst(cms->clientGarbage));
        os_mutexUnlock(&cms->clientMutex);

        while(client != NULL) {
            /*
             * Call threadFree and NOT clientFree on purpose.
             */
            cms_threadFree(client);
            os_mutexLock(&cms->clientMutex);
            client = cms_thread(c_iterTakeFirst(cms->clientGarbage));
            os_mutexUnlock(&cms->clientMutex);
            garbagePresent = TRUE;
        }

        if((c_iterLength(cms->clients) == 0) && (garbagePresent == TRUE)) {
            if(cms->configuration->verbosity >= 3) {
                OS_REPORT(OS_INFO, CMS_CONTEXT, 0,
                          "No clients connected. Performing some garbage collecting...");
            }
            cmx_deregisterAllEntities();
            garbagePresent = FALSE;
        }


        if(cms->terminate == FALSE) {
            os_nanoSleep(update);
        }
    }
    c_iterFree(cms->clientGarbage);

    return NULL;
}
Esempio n. 23
0
u_result
u_dispatcherDeinit(
    u_dispatcher _this)
{
    v_observer ko;
    u_listener listener;
    os_threadId tid;
    u_result result = U_RESULT_OK;

    if (_this != NULL) {
        os_mutexLock(&_this->mutex);
        listener = u_listener(c_iterTakeFirst(_this->listeners));
        while (listener != NULL) {
            u_listenerFree(listener);
            listener = u_listener(c_iterTakeFirst(_this->listeners));
        }
        c_iterFree(_this->listeners);
        _this->listeners = NULL; /* Flags the dispatch thread to stop */
        if (os_threadIdToInteger(_this->threadId) != 0U) {
            tid = _this->threadId;
            result = u_entityReadClaim(u_entity(_this), (v_entity*)(&ko));
            if(result != U_RESULT_OK) {
                /* This is a valid situation when a participant has been
                 * freed prior to the freeing of a dispatcher within the
                 * participant.
                 */
                os_mutexUnlock(&_this->mutex);
                os_threadWaitExit(tid, NULL);
                os_mutexDestroy(&_this->mutex);
                /*return U_RESULT_INTERNAL_ERROR;*/
            } else {
                /* Wakeup the dispatch thread */
                v_observerLock(ko);
                v_observerNotify(ko, NULL, NULL);
                v_observerUnlock(ko);
                u_entityRelease(u_entity(_this));
                os_mutexUnlock(&_this->mutex);
                os_threadWaitExit(tid, NULL);
                os_mutexDestroy(&_this->mutex);
            }
        } else {
            os_mutexUnlock(&_this->mutex);
            os_mutexDestroy(&_this->mutex);
        }
        result = u_entityDeinit(u_entity(_this));
    } else {
        OS_REPORT(OS_ERROR,"u_dispatcherDeinit",0,
                  "Illegal parameter.");
        result = U_RESULT_ILL_PARAM;
    }
    return result;
}
Esempio n. 24
0
static void*
d_waitsetEventHandlerRunToCompletion(
    void* userData)
{
    d_subscriber subscriber;
    d_durability durability;
    d_admin admin;
    d_waitset waitset;
    c_iter events = NULL;
    d_waitsetEntity we;
    c_time time;
    u_waitsetEvent event;

    waitset          = d_waitset(userData);
    subscriber       = d_waitsetGetSubscriber(waitset);
    admin            = d_subscriberGetAdmin(subscriber);
    durability       = d_adminGetDurability(admin);
    time.seconds     = 1;
    time.nanoseconds = 0;

    while(waitset->terminate == FALSE) {
        if(waitset->timedWait == TRUE){
            u_waitsetTimedWaitEvents(waitset->uwaitset, time,&events);
        } else {
            u_waitsetWaitEvents(waitset->uwaitset,&events);
        }
        if(d_durabilityGetState(durability) != D_STATE_TERMINATING){
            if(waitset->terminate == FALSE){
                d_lockLock(d_lock(waitset));

                event = u_waitsetEvent(c_iterTakeFirst(events));

                while(event){
                    we = c_iterResolve(waitset->entities, d_waitsetEntityFind, event->entity);

                    if(we){
                        we->action(we->dispatcher, event, we->usrData);
                    }
                    u_waitsetEventFree(event);
                    event = u_waitsetEvent(c_iterTakeFirst(events));
                }
            }
            d_lockUnlock(d_lock(waitset));
        }
        if(events){/* events may be null if waitset was deleted */
            c_iterFree(events);
        }
    }
    return NULL;
}
Esempio n. 25
0
static u_result
u__waitsetDeinitW(
    void *_vthis)
{
    u_waitset _this;
    u_waitsetEntry entry;
    u_result result = U_RESULT_OK;

    _this = u_waitset(_vthis);
    os_mutexLock(&_this->mutex);

    _this->alive = FALSE;
    while (_this->waitBusy) {
        waitset_notify(_this, NULL);
        os_condWait(&_this->waitCv, &_this->mutex);
    }
    entry = c_iterTakeFirst(_this->entries);
    while (entry != NULL) {
        u_domain domain = u_observableDomain(u_observable(entry));
        result = u_domainRemoveWaitset(domain, _this);
        if (result != U_RESULT_OK) {
            OS_REPORT(OS_ERROR,
                      "u__waitsetDeinitW", result,
                      "Operation u_domainRemoveWaitset failed: "
                      "Waitset = 0x%"PA_PRIxADDR", result = %s",
                      (os_address)_this, u_resultImage(result));
            assert(FALSE);
        }
        result = u_objectFree_s(entry);
        if (result == U_RESULT_ALREADY_DELETED) {
            result = U_RESULT_OK;
        } else if (result != U_RESULT_OK) {
            OS_REPORT(OS_ERROR,
                      "u__waitsetDeinitW", result,
                      "Operation u_waitsetEntryFree failed: "
                      "Waitset = 0x%"PA_PRIxADDR", result = %s",
                      (os_address)_this, u_resultImage(result));
            result = U_RESULT_OK;
            (void)result;
            assert(FALSE);
        }
        entry = c_iterTakeFirst(_this->entries);
    }
    c_iterFree(_this->entries);
    _this->entries = NULL;

    os_mutexUnlock(&_this->mutex);
    u__objectDeinitW(_this);
    return result;
}
Esempio n. 26
0
/* Free the specified file object without releasing all contained elements */
static void
idl_fileFree(
    /* QAC EXPECT 3673; No solution to the message here, but no problem either */
    const idl_file file)
{
    void *listElement;

    listElement = c_iterTakeFirst(file->contains);
    while (listElement != NULL) {
        listElement = c_iterTakeFirst(file->contains);
    }
    /* QAC EXPECT 5007; will not use wrapper */
    os_free(file->fileName);
}
Esempio n. 27
0
/* Free a file map releasing all files associated with it */
void
idl_fileMapFree(
    const idl_fileMap fileMap)
{
    idl_file file;

    file = c_iterTakeFirst(fileMap->files);
    while (file) {
        idl_fileFree (file);
        file = c_iterTakeFirst(fileMap->files);
    }
    /* QAC EXPECT 5007; will not use wrapper */
    os_free (fileMap);
}
Esempio n. 28
0
d_storeResult
d_storeMMFKernelBackupRestore(
    d_storeMMFKernel kernel,
    const d_store store,
    const d_nameSpace nameSpace)
{
    c_iter groups;
    d_groupInfo group;
    d_groupInfo restore, found;
    d_storeResult result;

    OS_UNUSED_ARG(store);

    if(kernel && nameSpace){
        groups = ospl_c_select(kernel->backup, 0);
        group = d_groupInfo(c_iterTakeFirst(groups));
        result = D_STORE_RESULT_OK;

        while(group && (result == D_STORE_RESULT_OK)){
            if(d_nameSpaceIsIn(nameSpace, group->partition, group->topic->name)){
                restore = c_remove(kernel->backup, group, NULL, NULL);
                assert(restore);

                if(restore){
                    found = d_groupInfo(c_tableInsert(kernel->groups, restore));

                    if(found != restore){
                        c_remove(kernel->groups, found, NULL, NULL);
                        c_free(found);
                        found = d_groupInfo(c_tableInsert(kernel->groups, restore));
                        assert(found == restore);

                        if(found != restore){
                            result = D_STORE_RESULT_ERROR;
                        }
                    }
                } else {
                    result = D_STORE_RESULT_ERROR;
                }
            }
            c_free(group);
            group = d_groupInfo(c_iterTakeFirst(groups));
        }
        c_iterFree(groups);
    } else {
        result = D_STORE_RESULT_ILL_PARAM;
    }
    return result;
}
Esempio n. 29
0
void
v_participantDeleteHistoricalData(
    v_participant participant,
    const c_char* partitionExpr,
    const c_char* topicExpr)
{
    c_iter matchingGroups;
    v_group group;
    c_time t;
    c_value params[2];
    C_STRUCT(v_event) event;
    C_STRUCT(v_historyDeleteEventData) hde;

    assert(participant != NULL);
    assert(C_TYPECHECK(participant, v_participant));
    assert(partitionExpr);
    assert(topicExpr);

    if(partitionExpr && topicExpr){
        params[0]  = c_stringValue((c_string)partitionExpr);
        params[1]  = c_stringValue((c_string)topicExpr);

        c_lockRead(&participant->lock);
        t = v_timeGet();
        matchingGroups = v_groupSetSelect(
                                v_objectKernel(participant)->groupSet,
                                "partition.name like %0 AND topic.name like %1",
                                params);
        c_lockUnlock(&participant->lock);

        group = v_group(c_iterTakeFirst(matchingGroups));
        while(group){
            v_groupDeleteHistoricalData(group, t);
            c_free(group);
            group = v_group(c_iterTakeFirst(matchingGroups));
        }
        c_iterFree(matchingGroups);


        hde.partitionExpression = (c_char *)partitionExpr;
        hde.topicExpression = (c_char *)topicExpr;
        hde.deleteTime = t;
        event.kind = V_EVENT_HISTORY_DELETE;
        event.source = v_publicHandle(v_public(participant));
        event.userData = &hde;
        v_observableNotify(v_observable(v_objectKernel(participant)),&event);
    }
    return;
}
Esempio n. 30
0
static c_iter
getKnownServices(cf_element root)
{
   c_iter services;
   cf_element domain;
   cf_element el;
   cf_element cmd;
   cf_data data;
   c_iter children;
   cf_attribute attr;
   struct serviceInfo *si;

   assert(root);

   services = NULL;
   if (root
       && (domain = (cf_element)cf_elementChild(root, "Domain")) )
   {
      children = cf_elementGetChilds(domain);
      while ( (el = c_iterTakeFirst(children)) != NULL)
      {
         if ( strcmp(cf_nodeGetName(cf_node(el)), "Service") == 0
              && (cmd = (cf_element)cf_elementChild(el, "Command"))
              && (data = cf_data(cf_elementChild(cmd, "#text")))
              && (si = os_malloc(sizeof(struct serviceInfo))))
         {

            si->command = cf_dataValue(data).is.String;

            attr = cf_elementAttribute(el, "name");
            if (attr)
            {
               si->name = cf_attributeValue(attr).is.String;
            }
            else
            {
               si->name = si->command;
            }

            if (!si->name || !si->command)
            {
               /* detected an invalid service configuration, report and skip */
               fprintf(stderr,
                       "Warning: detected invalid 'Service'"
                       " element (name = %s; command = %s) -> skip\n",
                       (si->name?si->name:"<null>"),
                       (si->command?si->command:"<null>"));
               os_free(si);
               si = NULL;
            }
            else
            {
               services = c_iterInsert(services, si);
            }
         }
      }
      c_iterFree(children);
   }
   return services;
}