Esempio n. 1
0
void
idl_constExpressionAdd (
    idl_constExpression constExpression, 
    idl_operand operand)
{
    constExpression->operands = c_iterAppend (constExpression->operands, operand);
}
Esempio n. 2
0
c_iter
c_splitString(
    const c_char *str,
    const c_char *delimiters)
{
    const c_char *head, *tail;
    c_char *nibble;
    c_iter iter = NULL;
    c_long length;

    if (str == NULL) return NULL;

    tail = str;
    while (*tail != '\0') {
        head = c_skipUntil(tail,delimiters);
        length = abs((c_address)head - (c_address)tail);
        if (length != 0) {
            length++;
            nibble = (c_string)os_malloc(length);
            os_strncpy(nibble,tail,length);
            nibble[length-1]=0;
            iter = c_iterAppend(iter,nibble);
        }
        tail = head;
        if (c_isOneOf(*tail,delimiters)) tail++;
    }
    return iter;
}
Esempio n. 3
0
v_actionResult
nb_topicObjectReaderAction(
    c_object o,
    c_voidp copyArg, /* c_iter<nb_topicObject> * */
    nb_topicObjectAllocFunc allocFunc)
{
    nb_topicObject to;
    v_actionResult result = 0;

    assert(allocFunc);

    if(o != NULL){
        c_iter *iter;
        v_dataReaderSample s = v_dataReaderSample(o);
        v_message message = v_dataReaderSampleMessage(s);
        const void * from = C_DISPLACE (message, C_MAXALIGNSIZE(sizeof(*message)));

        iter = (c_iter*)copyArg;
        assert(iter);

        v_actionResultSet(result, V_PROCEED);
        to = allocFunc();
        to->state = v_nodeState(message);
        to->writeTime = message->writeTime;

        nb_topicObjectCopyOut(to, from);

        *iter = c_iterAppend(*iter, to);
    }
    return result;
}
Esempio n. 4
0
static c_bool
collectFellowNsWalk(
    d_nameSpace nameSpace,
    c_voidp userData)
{
    c_iter nsList = (c_iter)userData;
    c_iterAppend (nsList, d_nameSpaceCopy(nameSpace));
    return TRUE;
}
Esempio n. 5
0
c_iter
v_partitionPolicySplit(
    v_partitionPolicyI p)
{
    const c_char *head, *tail;
    c_char *nibble;
    c_iter iter = NULL;
    os_size_t length;
    const c_char *delimiters = ",";

    if (p.v == NULL) return NULL;

    head = p.v;
    do {
        tail = c_skipUntil(head,delimiters);
        length = (os_size_t) (tail - head);
        if (length != 0) {
            length++;
            nibble = (c_string)os_malloc(length);
            os_strncpy(nibble, head, length);
            nibble[length-1]=0;
            iter = c_iterAppend(iter, nibble);
        } else {
            /* head points to one of the delimiters, so we add an empty string */
            length = 1;
            nibble = (c_string)os_malloc(length);
            nibble[length - 1 ] = 0;
            iter = c_iterAppend(iter, nibble);
        }
        head = tail;
        if (c_isOneOf(*head, delimiters)) {
            /* if the string ends with a delimiter, we also add an empty string */
            head++;
            if (*head == '\0') {
                length = 1;
                nibble = (c_string)os_malloc(length);
                nibble[length - 1 ] = 0;
                iter = c_iterAppend(iter, nibble);
            }
        }
    } while (*head != '\0');

    return iter;
}
Esempio n. 6
0
/* Add a file to the file map */
void
idl_fileMapAdd(
    /* QAC EXPECT 3673; No solution to the message here, but no problem either */
    const idl_fileMap fileMap,
    const char *fileName)
{
    idl_file file;

    /* Find the file in the file map based on the file name */
    file = c_iterResolve(fileMap->files, idl_fileCompare, (c_iterResolveCompareArg)fileName);
    if (file == NULL) {
        /* If not found, then add it now */
        file = idl_fileNew(fileName);
        c_iterAppend(fileMap->files, file);
    }
}
Esempio n. 7
0
u_result
u_dispatcherAppendListener(
    u_dispatcher _this,
    u_dispatcherListener listener,
    c_voidp userData)
{
    u_listener ul;
    os_threadAttr attr;
    v_observer ko;
    u_result result = U_RESULT_OK;

    if ((_this != NULL) && (listener != NULL)) {
        os_mutexLock(&_this->mutex);
        ul = u_listenerNew(listener,userData);
        _this->listeners = c_iterAppend(_this->listeners,ul);
        if (os_threadIdToInteger(_this->threadId) == 0U) {
            result = u_entityReadClaim(u_entity(_this), (v_entity*)(&ko));
            if(result == U_RESULT_OK) {
                assert(ko);
                os_threadAttrInit(&attr);
                os_threadCreate(&_this->threadId,
                                v_entityName(ko),
                                &attr,
                                dispatch,
                                (void *)_this);
                result = u_entityRelease(u_entity(_this));
                if (result != U_RESULT_OK) {
                    OS_REPORT(OS_ERROR, "u_dispatcherAppendListener", 0,
                              "Release observer failed.");
                }
            } else {
                OS_REPORT(OS_WARNING, "u_dispatcherAppendListener", 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;
}
static void
updateNameSpacesWalk (
    d_nameSpace n,
    c_iterActionArg userData)
{
    d_nameSpacesRequestListener listener;
    d_admin admin;
    d_nameSpaces ns;
    d_networkAddress master;
    struct updateNsWalkData* walkData;

    walkData = (struct updateNsWalkData*)userData;
    listener = walkData->listener;
    admin = d_listenerGetAdmin(d_listener(listener));

    /* Create nameSpaces object from namespace, update total later */
    ns = d_nameSpacesNew(admin, n, d_nameSpaceGetInitialQuality(n), 0);
    master = d_nameSpaceGetMaster(n);
    d_nameSpacesSetMaster(ns, master);
    d_networkAddressFree(master);

    /* Add namespaces object to listener */
    walkData->nameSpaces = c_iterAppend (walkData->nameSpaces, ns);
}
Esempio n. 9
0
static c_bool
d_instanceInject(
   c_object o,
   c_voidp arg)
{
    d_instance instance;
    d_sample sample;
    v_message message, storeMessage, unregisterMsg;
    struct d_instanceInjectArg* inj;
    v_writeResult wr;
    os_time oneSec;
    c_iter unregisterMessagesToInject;
    c_bool success;

    assert(o != NULL);
    assert(C_TYPECHECK(o, d_instance));

    instance = d_instance(o);
    inj = (struct d_instanceInjectArg*)(arg);
    unregisterMessagesToInject = c_iterNew(NULL);

    sample = d_sample(instance->oldest);

    while ((sample != NULL) && (inj->result == D_STORE_RESULT_OK)) {
        storeMessage = d_sampleGetMessage(sample);

        /* copy message */
        c_cloneIn(inj->messageType, storeMessage, (c_voidp*)&(message));

        /* inject message */
        wr = v_groupWriteNoStream(inj->vgroup, message, NULL, V_NETWORKID_LOCAL);
        oneSec.tv_sec  = 1;
        oneSec.tv_nsec = 0;

        while(wr == V_WRITE_REJECTED){
            wr = v_groupWriteNoStream(inj->vgroup, message, NULL, V_NETWORKID_LOCAL);
            os_nanoSleep(oneSec);
        }

        if((wr != V_WRITE_SUCCESS) &&
           (wr != V_WRITE_REGISTERED) &&
           (wr != V_WRITE_UNREGISTERED)) {
            OS_REPORT_1(OS_ERROR, D_CONTEXT, 0,
                "Unable to write persistent data to group. (result: '%d')\n",
                wr);
            inj->result = D_STORE_RESULT_ERROR;
        } else {
            /* If a sample is written or registered, add unregister action */
            unregisterMsg = findUnregisterMessage(unregisterMessagesToInject, message);

            if(!unregisterMsg){
                unregisterMsg = createUnregisterMessage (inj->vgroup, message);

                /* Add the newly created unregister message to the list of extra messages to inject */
                unregisterMessagesToInject = c_iterAppend (
                        unregisterMessagesToInject, unregisterMsg);
            }
            /* Set valid sequence number */
            if (message->sequenceNumber >= unregisterMsg->sequenceNumber) {
                unregisterMsg->sequenceNumber = message->sequenceNumber + 1;
            }
        }
        sample = sample->newer;
    }
    if(inj->result == D_STORE_RESULT_OK){
        oneSec.tv_sec  = 1;
        oneSec.tv_nsec = 0;
        /* inject the extra unregister messages */
        unregisterMsg = v_message(c_iterTakeFirst(unregisterMessagesToInject));

        while (unregisterMsg) {
            wr = v_groupWriteNoStream(inj->vgroup, unregisterMsg, NULL, V_NETWORKID_LOCAL);

            while(wr == V_WRITE_REJECTED){
                wr = v_groupWriteNoStream(inj->vgroup, unregisterMsg, NULL, V_NETWORKID_LOCAL);
                os_nanoSleep(oneSec);
            }
            unregisterMsg = v_message(c_iterTakeFirst(unregisterMessagesToInject));
        }
        c_iterFree(unregisterMessagesToInject);
    }

    if(inj->result == D_STORE_RESULT_OK){
        success = TRUE;
    } else {
        success = FALSE;
    }
    return success;
}
Esempio n. 10
0
c_iter
v_cfElementXPath(
    v_cfElement element,
    const c_char *xpathExpr)
{
    c_iter result;
    const c_char *posInExpr;
    const c_char *slash;
    char *attribEnd;
    c_ulong length;
    struct getChildrenArg arg;
    c_long nrToProcess;
    v_cfNode node;

    assert(C_TYPECHECK(element, v_cfElement));
    assert(xpathExpr != NULL);
 
    result = c_iterNew(element);
    nrToProcess = 1;
    posInExpr = xpathExpr;
    slash = strchr(posInExpr, XPATH_SEPERATOR);
    while (nrToProcess > 0) {
        node = c_iterTakeFirst(result);
        nrToProcess--;
        if (node->kind == V_CFELEMENT) { /* do not process data elements */
            if (slash) {

            	length = C_ADDRESS(slash) - C_ADDRESS(posInExpr);
            } else {
                length = strlen(posInExpr);
            }
            arg.children = c_iterNew(NULL);
            arg.tagName = (c_char *)os_malloc(length + 1U);
            os_strncpy(arg.tagName, posInExpr, length);
            arg.tagName[length] = 0;
            
            /* Look for selection criteria based on attribute value
             * Example XPath expression:
             * /aaa/bbb[@name='value']/ccc or /aaa/bbb[@name!='value']/ccc */
            arg.attribName = strchr(arg.tagName, '[');
            if (arg.attribName != NULL) {
                *arg.attribName = '\0';
                arg.attribName = &(arg.attribName[1]);
                assert(*arg.attribName == '@');
                arg.attribName = &(arg.attribName[1]);
                arg.attribValue = strchr(arg.attribName, '!');
                if (arg.attribValue != NULL) {
                    arg.attribNegate = TRUE;
                    *arg.attribValue = '\0';
                    arg.attribValue = &arg.attribValue[1];
                    assert(*arg.attribValue == '=');
                } else {
                    arg.attribNegate = FALSE;
                    arg.attribValue = strchr(arg.attribName, '=');
                }
                assert(arg.attribValue != NULL);
                *arg.attribValue = '\0';
                arg.attribValue = &arg.attribValue[1];
                assert(*arg.attribValue == '\'');
                arg.attribValue = &(arg.attribValue[1]);
                attribEnd = strchr(arg.attribValue, '\'');
                assert(attribEnd != NULL);
                *attribEnd = '\0';
                assert(attribEnd[1] == ']');
            }
        
            c_walk(v_cfElement(node)->children, getChildren, &arg);
            os_free(arg.tagName);
            if (slash) { 
                nrToProcess += c_iterLength(arg.children);
            }
            /* now append */
            node = v_cfNode(c_iterTakeFirst(arg.children));
            while (node != NULL) {
                c_iterAppend(result, node);
                node = v_cfNode(c_iterTakeFirst(arg.children));
            }
            c_iterFree(arg.children);

            if (slash) {

                posInExpr = (const c_char *)(C_ADDRESS(slash) + 1U);
                slash = strchr(posInExpr, XPATH_SEPERATOR);
            }
        }
    }

    return result;
}
Esempio n. 11
0
static c_bool
createMessageKeyList(
    c_type messageType,
    const c_char *topicKeyExpr,
    c_array *keyListRef)
{
    c_array keyList;
    c_type fieldType;
    c_field field;
    c_iter splitNames, newNames;
    c_char *name, *newName;
    c_long i,length,sres;

    assert(keyListRef != NULL);

    *keyListRef = NULL;
    if (topicKeyExpr == NULL) {
        return TRUE;
    }
    newNames = NULL;
    splitNames = c_splitString(topicKeyExpr,", \t");
    while ((name = c_iterTakeFirst(splitNames)) != NULL) {
#define PATH_SEPARATOR "."
#define PREFIX "userData"
        length = strlen(PREFIX) + sizeof(PATH_SEPARATOR) + strlen(name);
        newName = (char *)os_malloc(length);
        sres = snprintf(newName,length,"%s"PATH_SEPARATOR"%s",PREFIX, name);
        assert(sres == (length-1));
#undef PREFIX
#undef PATH_SEPARATOR

        os_free(name);
        newNames = c_iterAppend(newNames,newName);
    }
    c_iterFree(splitNames);
    length = c_iterLength(newNames);
    if (length == 0) {
        return TRUE;
    }

    fieldType = c_field_t(c_getBase(messageType));
    keyList = c_arrayNew(fieldType,length);
    c_free(fieldType);
    i=0;
    while ((name = c_iterTakeFirst(newNames)) != NULL) {
        field = c_fieldNew(messageType,name);
        if (field == NULL) {
            OS_REPORT_1(OS_API_INFO,
                        "create message key list failed", 21,
                        "specified key field name %s not found",
                        name);
            os_free(name);
            c_iterFree(newNames);
            c_free(keyList);

            return FALSE;
        }
        keyList[i++] = field;
        os_free(name);
    }
    c_iterFree(newNames);
    *keyListRef = keyList;
    return TRUE;
}
Esempio n. 12
0
v_index
v__indexNew(
    v_dataReader reader,
    q_expr _from,
    c_iter indexList,
    v_indexNewAction action,
    c_voidp arg)
{
    v_kernel kernel;
    v_index index;
    v_topic topic;
    c_type instanceType;
    c_iter list;
    c_char *keyExpr;
    c_array keyList;
    c_ulong nrOfTopics;

    assert(C_TYPECHECK(reader,v_dataReader));
    kernel = v_objectKernel(reader);

    if (q_isId(_from)) {
        list = v_resolveTopics(kernel,q_getId(_from));
        nrOfTopics = c_iterLength(list);
        if (nrOfTopics == 0) {
            OS_REPORT(OS_ERROR,
                        "v__indexNew", V_RESULT_ILL_PARAM,
                        "Unknown topic %s",
                        q_getId(_from));
            c_iterFree(list);
            return NULL;
        }
        if (nrOfTopics > 1) {
            OS_REPORT(OS_ERROR,
                        "v__indexNew", V_RESULT_ILL_PARAM,
                        "Multiple topic definitions of: %s",
                        q_getId(_from));
            topic = v_topic(c_iterTakeFirst(list));
            while (topic != NULL) {
                c_free(topic);
                topic = v_topic(c_iterTakeFirst(list));
            }
            c_iterFree(list);
            return NULL;
        }
        topic = c_iterTakeFirst(list);
        c_iterFree(list);
        index = v_index(c_iterReadAction(indexList, indexCompare, topic));
        if (index == NULL) {
            /* If the userKey is enabled then the instance type key field type
             * will be determined from the user key expression and topic.
             * Otherwise when no user key is specified the default Topic key
             * type will be used.
             */
            if (v_reader(reader)->qos->userKey.v.enable) {
                keyExpr = v_reader(reader)->qos->userKey.v.expression;
            } else {
                keyExpr = NULL;
            }
            instanceType = createInstanceType(topic,keyExpr,&keyList);
            if (instanceType) {
                index = v_index(v_objectNew(kernel,K_INDEX));
                v_indexInit(index, instanceType, keyList, v_reader(reader));
            }
            c_free(keyList);
            c_free(instanceType);

            if (index != NULL) {
                if (action != NULL && !action(index, topic, arg)) {
                    OS_REPORT(OS_ERROR,
                        "v_indexNew", V_RESULT_INTERNAL_ERROR,
                        "v_indexNewAction failed!");
                    c_free(index);
                    index = NULL;
                } else {
                    (void)c_iterAppend(indexList, index);
                }
            }
        }
    } else {
        OS_REPORT(OS_ERROR,
                  "v_indexNew failed",V_RESULT_ILL_PARAM,
                  "illegal from clause specified");
        assert(FALSE);
        index = NULL;
    }
    return index;
}