Ejemplo n.º 1
0
static void
collect_readers(
    c_voidp object,
    c_voidp arg)
{
    struct collect_readers_arg *a = (struct collect_readers_arg *)arg;
    u_reader r = (u_reader)object;
    c_char *name;

    if (a->topic_name == NULL) {
        a->readers = c_iterInsert(a->readers, r);
    } else {
        name = NULL;
        u_dataReaderTopicName(u_dataReader(r),&name);
        if (name) {
            if (strcmp(name, a->topic_name) == 0)
            {
                /* Expect to have a u_entityKeep(r); at this point as
                 * soon as GAPI redesign is finished.
                */
                a->readers = c_iterInsert(a->readers, r);
            }
            os_free(name);
        }
    }
}
Ejemplo n.º 2
0
/**This function only works if the topic already exists.
 * In the future this must be extended.
 */
jni_topic
jni_createTopic(
    jni_participant p,
    const char* name,
    const char* typeName,
    v_topicQos qos)
{
    jni_topic topic;
    u_result result;
    struct jni_topicArg arg;
    
    topic = NULL;
    
    if((p != NULL) && (jni_lookupTopic(p, name) == NULL)){
        arg.topicName = name;
        arg.keyExpr = NULL;
        arg.result = U_RESULT_ILL_PARAM;
        result = u_entityAction(u_entity(p->uparticipant), jni_getTopicKeyExpression, &arg);       
                
        if((result == U_RESULT_OK) && (arg.result == U_RESULT_OK)){
            topic = jni_topicNew(p, name, typeName, arg.keyExpr, qos);
            
            if(arg.keyExpr != NULL){
                os_free(arg.keyExpr);
            }
            
            if(topic != NULL){
                p->topics = c_iterInsert(p->topics, topic);
            }
        }
       
    }
    return topic;
}
Ejemplo n.º 3
0
c_char*
cmx_readerSnapshotNew(
    const c_char* reader)
{
    u_entity e;
    c_char* result;
    struct cmx_readerSnapshotArg arg;
    os_mutex m;
    
    arg.success = FALSE;
    result = NULL;
    e = cmx_entityUserEntity(reader);
    
    if(e != NULL){    
        u_entityAction(e, cmx_readerSnapshotNewAction, &arg);
        
        if(arg.success == TRUE){
            m = cmx_getReaderSnapshotMutex();
            os_mutexLock(&m);
            readerSnapshots = c_iterInsert(readerSnapshots, arg.snapshot);
            os_mutexUnlock(&m);
            
            result = (c_char*)(os_malloc(60));
            os_sprintf(result, "<readerSnapshot><id>"PA_ADDRFMT"</id></readerSnapshot>", (c_address)(arg.snapshot));
        }
    }
    return result;
}
Ejemplo n.º 4
0
c_iter
v_serviceTakeNewGroups(
    v_service service)
{
    c_iter result;
    v_group group;
    c_set newGroups;

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

    result = c_iterNew(NULL);

    v_observerLock(v_observer(service));
    newGroups = (c_set)v_observer(service)->eventData;
    if (newGroups != NULL) {
        group = v_group(c_take(newGroups));
        while (group != NULL) {
            c_iterInsert(result, group);
            group = v_group(c_take(newGroups));
        }
    }
    v_observerUnlock(v_observer(service));

    return result;
}
Ejemplo n.º 5
0
static void
q_countVarWalk(
    q_expr e,
    c_iter list)
{
    q_list l;
    q_expr found;

    if (e != NULL) {
        switch(e->kind) {
        case T_VAR:
            found = c_iterResolve(list,compareVar,e);
            if (found == NULL) {
                list = c_iterInsert(list,e);
            }
        break;
        case T_FNC:
            if (e->info.function->tag == Q_EXPR_CALLBACK) {
                q_countVarWalk(q_getPar(e,2),list);
            } else {
                l = e->info.function->params;
                while (l != NULL) {
                    q_countVarWalk(l->expr,list);
                    l = l->next;
                }
            }
        break;
        default:
        break;
        }
    }
}
Ejemplo n.º 6
0
/* This method registers a database object to be managed by the user-layer.
 * Once a process has registered an object it can free its reference.
 * The user-layer will keep the registered object alive until it is deregistered
 * using the u_userFree method.
 * The user-layer will free all references of registered objects on process
 * termination via the installed exit handler (u_userExit).
 */
c_object
u_userKeep(
    c_object o)
{
    u_user u;
    u_domainAdmin ka;
    c_long i;

    if (o) {
        u = u__userLock();
        if (u) {
            /* the user-layer object exists so now find the domain that holds
             * the given object.
             */
            for (i=1; i <= u->domainCount; i++) {
                ka = &u->domainList[i];
                if (ka->domain) {
                    /* A valid domain admin exists, now check if the objects
                     * address is in the domains address range.
                     */
                    if (((c_address)o >= ka->lowerBound) &&
                        ((c_address)o <= ka->upperBound))
                    {
                        c_keep(o);
                        ka->keepList = c_iterInsert(ka->keepList,o);
                        i = u->domainCount + 1; /* jump out of the loop */
                    }
                }
            }
            u__userUnlock();
        }
    }
    return o;
}
Ejemplo n.º 7
0
c_char*
cmx_readerSnapshotNew(
    const c_char* reader)
{
    cmx_entity ce;
    c_char* result;
    struct cmx_readerSnapshotArg arg;
    os_mutex m;

    arg.success = FALSE;
    result = NULL;

    ce = cmx_entityClaim(reader);
    if(ce != NULL){
        if (u_observableAction(u_observable(ce->uentity),
                               cmx_readerSnapshotNewAction,
                               &arg) == U_RESULT_OK)
        {
            if(arg.success == TRUE){
                m = cmx_getReaderSnapshotMutex();
                os_mutexLock(&m);
                readerSnapshots = c_iterInsert(readerSnapshots, arg.snapshot);
                os_mutexUnlock(&m);

                result = (c_char*)(os_malloc(60));
                os_sprintf(result,
                           "<readerSnapshot><id>"PA_ADDRFMT"</id></readerSnapshot>",
                           (c_address)(arg.snapshot));
            }
        }
        cmx_entityRelease(ce);
    }
    return result;
}
Ejemplo n.º 8
0
c_iter
c_bindAttributes(
    c_metaObject scope,
    c_iter declarations,
    c_type type,
    c_bool isReadOnly)
{
    c_iter attributes;
    c_declarator d;
    c_metaObject o;

    if (isReadOnly) {
        /* suppress warnings */
    }
    attributes = NULL;
    d = (c_declarator)c_iterTakeFirst(declarations);
    while (d != NULL) {
        o = c_metaDefine(scope,M_ATTRIBUTE);
        c_property(o)->type = c_declaratorType(d,type);
        c_metaFinalize(o);
        c_metaBind(scope,d->name,o);
        attributes = c_iterInsert(attributes,o);
        os_free(d);
        d = (c_declarator)c_iterTakeFirst(declarations);
    }
    c_iterFree(declarations);
    return attributes;
}
Ejemplo n.º 9
0
void
cmx_participantFindTopicAction(
    v_public p,
    c_voidp args)
{
    cmx_walkEntityArg arg;
    c_iter topics;
    v_entity topic;
    c_bool proceed;
    c_char* xmlEntity;

    arg = cmx_walkEntityArg(args);
    topics = v_resolveTopics(v_objectKernel(p), cmx_walkParticipantArg(arg)->topicName);
    topic = v_entity(c_iterTakeFirst(topics));

    while(topic != NULL){
        proceed = cmx_entityNewFromWalk(v_public(topic), &arg->entityArg);

        if(proceed == TRUE){
            xmlEntity = arg->entityArg.result;
            arg->list = c_iterInsert(arg->list, xmlEntity);
            arg->length += strlen(xmlEntity);
        }
        c_free(topic);
        topic = v_entity(c_iterTakeFirst(topics));
    }
    c_iterFree(topics);
}
Ejemplo n.º 10
0
c_iter
v_serviceTakeNewGroups(
    v_service service)
{
    c_iter result;
    v_group group;
    c_set newGroups;

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

    result = c_iterNew(NULL);

    OSPL_BLOCK_EVENTS(service);
    newGroups = service->newGroups;
    if (newGroups != NULL) {
        group = v_group(c_take(newGroups));
        while (group != NULL) {
            c_iterInsert(result, group);
            group = v_group(c_take(newGroups));
        }
    }
    OSPL_UNBLOCK_EVENTS(service);

    return result;
}
Ejemplo n.º 11
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;
}
Ejemplo n.º 12
0
void
cmx_participantDomainsAction(
    v_public p,
    c_voidp args)
{
    cmx_walkEntityArg arg;
    c_iter partitions;
    v_entity partition;
    c_bool proceed;
    c_char* xmlEntity;

    arg = cmx_walkEntityArg(args);
    partitions = v_resolvePartitions(v_objectKernel(p), "*");
    partition = v_entity(c_iterTakeFirst(partitions));

    while(partition != NULL){
        proceed = cmx_entityNewFromWalk(v_public(partition), &arg->entityArg);

        if(proceed == TRUE){
            xmlEntity = arg->entityArg.result;
            arg->list = c_iterInsert(arg->list, xmlEntity);
            arg->length += strlen(xmlEntity);
        }
        c_free(partition);
        partition = v_entity(c_iterTakeFirst(partitions));
    }
    c_iterFree(partitions);
}
Ejemplo n.º 13
0
u_result
u_readerAddQuery(
    u_reader _this,
    u_query query)
{
    os_result r;
    u_result result = U_RESULT_PRECONDITION_NOT_MET;

    if (_this && query) {
        if(u_entityOwner(u_entity(_this))) {
            r = os_mutexLock(&_this->mutex);
            if (r == os_resultSuccess) {
                _this->queries = c_iterInsert(_this->queries, query);
                os_mutexUnlock(&_this->mutex);
                result = U_RESULT_OK;
            } else {
                OS_REPORT(OS_WARNING,
                          "u_readerAddQuery",0,
                          "Failed to lock Reader.");
                result = U_RESULT_ILL_PARAM;
            }
        } else {
            result = U_RESULT_OK;
        }
    } else {
        OS_REPORT(OS_WARNING,
                  "u_readerAddQuery",0,
                  "Illegal parameter.");
        result = U_RESULT_ILL_PARAM;
    }
    return result;
}
Ejemplo n.º 14
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;
}
Ejemplo n.º 15
0
static unsigned int
childsToIterator(
    c_object o,
    c_iter *c)
{
    *c = c_iterInsert(*c, o);
    return 1;
}
Ejemplo n.º 16
0
/* Add a key definition to the specified key definition list */
void
idl_keyDefAdd (
    idl_keyDef keyDef,
    c_metaObject scope,
    const char *typeName,
    const char *keyList)
{
    c_iterInsert (keyDef->keyList, idl_keyMapNew (scope, typeName, keyList));
}
Ejemplo n.º 17
0
static c_bool
childsToIterator(
    c_object o,
    c_voidp arg)
{
    c_iter *c = (c_iter *)arg;
    *c = c_iterInsert(*c, o);
    return TRUE;
}
Ejemplo n.º 18
0
c_bool
v_leaseCollectObservers(
    c_object o,
    c_voidp arg)
{
    c_iter *observers = (c_iter*)arg;
    *observers = c_iterInsert(*observers, c_keep(o));
    return TRUE;
}
Ejemplo n.º 19
0
static void
collect_queries(
    c_voidp object,
    c_voidp arg)
{
    c_iter *queries = (c_iter *)arg;
    u_query q = (u_query)object;

    *queries = c_iterInsert(*queries, q);
}
Ejemplo n.º 20
0
static void
collectNsWalk(
    d_nameSpace ns, void* userData)
{
    c_iter nameSpaces = (c_iter)userData;
    if (ns)
    {
        d_objectKeep(d_object(ns));
        c_iterInsert (nameSpaces, ns);
    }
}
Ejemplo n.º 21
0
static c_bool
collectPartitions(
    c_object o,
    c_voidp arg)
{
    v_partition d = (v_partition)o;
    c_iter iter = (c_iter)arg;

    iter = c_iterInsert(iter,c_keep(d));
    return TRUE;
}
Ejemplo n.º 22
0
/* Add a stac definition to the specified stac definition list */
void
idl_stacDefAdd (
    idl_stacDef stacDef,
    c_metaObject scope,
    const char *typeName,
    const char *stacList)
{
    if(stacDef)
    {
        c_iterInsert (stacDef->stacList, idl_stacMapNew (scope, typeName, stacList));
    }
}
Ejemplo n.º 23
0
c_iter
v_partitionLookupSubscribers(
    v_partition partition)
{
    c_iter participants;
    c_iter result;
    c_iter entities;
    c_iter partitions;
    v_participant participant;
    v_entity entity;
    v_entity partition2;

    result = NULL;
    participants = v_resolveParticipants(v_objectKernel(partition), "*");
    participant = v_participant(c_iterTakeFirst(participants));

    while (participant != NULL) {
        c_lockRead(&participant->lock);
        entities = c_select(participant->entities, 0);
        c_lockUnlock(&participant->lock);
        entity = v_entity(c_iterTakeFirst(entities));

        while (entity != NULL) {
            if(v_objectKind(entity) == K_SUBSCRIBER) {
                partitions = v_subscriberLookupPartitions(v_subscriber(entity),
                                                    v_partitionName(partition));

                if (c_iterLength(partitions) > 0) {
                    result = c_iterInsert(result, entity); /* transfer refcount */
                } else {
                    c_free(entity);
                }
                partition2 = v_entity(c_iterTakeFirst(partitions));

                while (partition2 != NULL) {
                    c_free(partition2);
                    partition2 = v_entity(c_iterTakeFirst(partitions));
                }
                c_iterFree(partitions);
            }
            /* entity is already free or refcount transferred to result */
            entity = v_entity(c_iterTakeFirst(entities));
        }
        c_iterFree(entities);
        c_free(participant);
        participant = v_participant(c_iterTakeFirst(participants));
    }
    c_iterFree(participants);
    return result;
}
Ejemplo n.º 24
0
u_result
u_dispatcherInsertListener(
    u_dispatcher _this,
    u_dispatcherListener listener,
    c_voidp userData)
{
    u_listener ul;
    os_threadAttr attr;
    v_observer ke;
    u_result result = U_RESULT_OK;
    c_char *name;

    if ((_this != NULL) && (listener != NULL)) {
        os_mutexLock(&_this->mutex);
        ul = u_listenerNew(listener,userData);
        _this->listeners = c_iterInsert(_this->listeners,ul);

        if (os_threadIdToInteger(_this->threadId) == 0U) {
            result = u_entityReadClaim(u_entity(_this), (v_entity*)(&ke));
            if(result == U_RESULT_OK) {
                assert(ke);
                name = v_entityName(ke);
                if (name == NULL) {
                    name = "NoName";
                }
                os_threadAttrInit(&attr);
                os_threadCreate(&_this->threadId,
                                name,
                                &attr,dispatch,
                                (void *)_this);
                result = u_entityRelease(u_entity(_this));
                if (result != U_RESULT_OK) {
                    OS_REPORT(OS_ERROR, "u_dispatcherInsertListener", 0,
                              "Release observer failed.");
                }
            } else {
                OS_REPORT(OS_WARNING, "u_dispatcherInsertListener", 0,
                          "Failed to claim Dispatcher.");
            }
        }
        u_entityEnable(u_entity(_this));
        os_mutexUnlock(&_this->mutex);
    } else {
        OS_REPORT(OS_ERROR,"u_dispatcherInsertListener",0,
                  "Illegal parameter.");
        result = U_RESULT_ILL_PARAM;
    }

    return result;
}
Ejemplo n.º 25
0
static c_bool
getChildren(
    c_object o,
    c_voidp arg)
{
    struct getChildrenArg *a = (struct getChildrenArg *)arg;
    c_value value;
    c_bool isEqual;

    if (a->tagName == NULL) {
        a->children = c_iterInsert(a->children, o);
    } else {
        if (strcmp(v_cfNodeGetName(v_cfNode(o)), a->tagName) == 0) {
            if (a->attribName == NULL) {
                a->children = c_iterInsert(a->children, o);
            } else {
                value = v_cfElementAttributeValue(v_cfElement(o), a->attribName);
                if (value.kind == V_STRING) {
                    isEqual = (strcmp(a->attribValue, value.is.String) == 0);
                    if (isEqual != a->attribNegate) {
                        /* Add if isEqual && !a->attribNegate or
                               if !isEqual && a->attribNegate (XOR) */
                        a->children = c_iterInsert(a->children, o);
                    }
                } else {
                    assert(value.kind == V_UNDEFINED);
                    /* If this is a not-relationship,
                       add the element to the result */
                    if (a->attribNegate) {
                        a->children = c_iterInsert(a->children, o);
                    }
                }
            }
        }
    }
    return TRUE; /* always finish the walk */
}
Ejemplo n.º 26
0
/* Add the specified meta object to the specified file */
static void
idl_fileObjectAdd(
    /* QAC EXPECT 3673; No solution to the message here, but no problem either */
    const idl_file file,
    const c_baseObject object)
{
    c_baseObject o;

    /* find the meta object in the specified file */
    o = c_iterResolve(file->contains, idl_objectCompare, object);
    if (o == NULL) {
        /* if not found, add it to the file */
        c_iterInsert (file->contains, object);
    }
}
Ejemplo n.º 27
0
/* Add object to source */
void idl_fileMapFillList(
    c_baseObject object,
    c_iter objects)
{
    switch(object->kind) {
    case M_LITERAL:
    case M_EXPRESSION:
    case M_EXCEPTION:
    case M_PARAMETER:
        break;
    default:
        c_iterInsert(objects, object);
        break;
    }
}
Ejemplo n.º 28
0
c_bool
collectExpired(
    c_object o,
    c_voidp arg)
{
    v_leaseAction leaseAction = v_leaseAction(o);
    struct collectExpiredArg *a = (struct collectExpiredArg *)arg;
    c_time headExpTime;
    c_time leaseExpTime;
    c_bool setHead;
    c_equality cmp;

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

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

    return TRUE;
}
Ejemplo n.º 29
0
c_iter
v_deadLineInstanceListCheckDeadlineMissed(
    v_deadLineInstanceList list,
    v_duration deadlineTime,
    c_time now)
{
    c_time expiryTime;
    v_instance listItem;
    c_iter missed;

    assert(C_TYPECHECK(list,v_deadLineInstanceList));

    missed = NULL;
    if (v_instanceAlone(v_instance(list))) { /* list is empty */
        assert (list->deadlineLease != NULL);
        v_leaseManagerDeregister(list->leaseManager, list->deadlineLease);
        c_free(list->deadlineLease);
        list->deadlineLease = NULL;
    } else {
        listItem = v_instance(list)->prev;
        expiryTime = c_timeSub(now, deadlineTime);
        while ((listItem != NULL) &&
                (v_objectKind(listItem) != K_DEADLINEINSTANCE)  &&
                (c_timeCompare(expiryTime, listItem->lastCheckTime) != C_LT)) {
            missed = c_iterInsert(missed, listItem);
            listItem->lastCheckTime = now;
            listItem = listItem->prev;
        }
        /* determine next wake-up time */
        if (v_objectKind(listItem) == K_DEADLINEINSTANCE) {
            /* listItem is the deadline list itself, so if there
             * were instances all instances have been missed. Just
             * set the new check to be in 'deadlineTime'.
             */
            expiryTime = deadlineTime;
        } else {
            /*
             * The new lease duration can be calculated:
             * lastCheckTime + deadlineTime = next expiry time
             * next expiry time - now = lease duration
             */
            expiryTime = c_timeAdd(listItem->lastCheckTime, deadlineTime);
            expiryTime = c_timeSub(expiryTime, now);
            v_leaseRenew(list->deadlineLease, expiryTime);
        }
    }
    return missed;
}
Ejemplo n.º 30
0
jni_result
jni_participantAddPartition(
    jni_participant p,
    const c_char* partitionName)
{
    jni_result r;
    c_iter partCopy;
    jni_partition partition, partNew;
    int found;
    
    r = JNI_RESULT_OK;
    
    if((p == NULL) || (partitionName == NULL)){
        r = JNI_RESULT_BAD_PARAMETER;
    }
    else if((strcmp(partitionName, "*") == 0) ||
            (strcmp(partitionName, "") == 0)){
        /*DO NOTHING*/
    } 
    else{
        /*Check if the partitionName already exists.*/
        partCopy = c_iterCopy(p->partitions);
        partition = jni_partition(c_iterTakeFirst(partCopy));
        found = 0;
        
        while((partition != NULL) && (!found)){
            if(strcmp(partition->name, partitionName) == 0){
                found = 1;
            }
            partition = jni_partition(c_iterTakeFirst(partCopy));
        }    
        c_iterFree(partCopy);
        
        if(!found){
            partNew = jni_partitionNew(p, partitionName, NULL);
            
            if(partNew == NULL){
                r = JNI_RESULT_ERROR;
            }
            else{
                p->partitions = c_iterInsert(p->partitions, partNew);
            }
        }
    }
    return r;
}