Exemplo n.º 1
0
static c_char *
createInstanceKeyExpr (
    c_base base,
    v_topic topic)
{
    c_char fieldName[16];
    c_char *keyExpr;
    c_long i,nrOfKeys,totalSize;
    c_array keyList;

    assert(C_TYPECHECK(topic,v_topic));
    keyList = v_topicMessageKeyList(topic);
    nrOfKeys = c_arraySize(keyList);
    if (nrOfKeys>0) {
        totalSize = nrOfKeys * strlen("key.field0,");
        if (nrOfKeys > 9) {
            totalSize += (nrOfKeys-9);
            if (nrOfKeys > 99) {
                totalSize += (nrOfKeys-99);
            }
        }
        keyExpr = c_stringMalloc(base, totalSize);
        keyExpr[0] = 0;
        for (i=0;i<nrOfKeys;i++) {
            os_sprintf(fieldName,"key.field%d",i);
            os_strcat(keyExpr,fieldName);
            if (i<(nrOfKeys-1)) { os_strcat(keyExpr,","); }
        }
    } else {
        keyExpr = NULL;
    }
    return keyExpr;
}
Exemplo n.º 2
0
u_bool
u_topicContentFilterValidate2 (
    const u_topic _this,
    const q_expr expr,
    const c_value params[],
    os_uint32 nrOfParams)
{
    v_topic topic;
    u_bool result;
    v_filter filter;
    u_result uResult;

    assert(_this);
    assert(expr);

    result = FALSE;
    filter = NULL;
    uResult = u_topicReadClaim(_this, &topic, C_MM_RESERVATION_LOW);
    if (uResult == U_RESULT_OK) {
        assert(topic);
        filter = v_filterNew(v_topicMessageType(topic), v_topicMessageKeyList(topic), expr, params, nrOfParams);
        u_topicRelease(_this, C_MM_RESERVATION_LOW);
    }
    if (filter != NULL) {
        result = TRUE;
        c_free(filter);
    }
    return result;
}
Exemplo n.º 3
0
void
jni_getTopicKeyExpression(
    v_entity entity,
    c_voidp args)
{
    v_kernel vk;
    c_iter vtopics;
    c_array keyList;
    c_char* keyExpr;
    c_long nrOfKeys, totalSize, i;
    c_string fieldName, actualFieldName;
    struct jni_topicArg *arg;
    
    arg = (struct jni_topicArg *)args;
    vk = v_objectKernel(entity);
    
    if(vk != NULL){
        vtopics = v_resolveTopics(vk, arg->topicName);
            
        if(c_iterLength(vtopics) == 0){
            c_iterFree(vtopics);
        }
        else{
            keyList = v_topicMessageKeyList(c_iterTakeFirst(vtopics));
            c_iterFree(vtopics);                
            nrOfKeys = c_arraySize(keyList);

            if (nrOfKeys>0) {
                totalSize = 0;
                
                for (i=0;i<nrOfKeys;i++) {
                    fieldName = c_fieldName(keyList[i]);
                    totalSize += (strlen(fieldName)+1-9/*skip 'userdata.'*/);
                }
                keyExpr = (c_char *)os_malloc((size_t)(totalSize+1));
                keyExpr[0] = 0;
                
                for (i=0;i<nrOfKeys;i++) {
                    fieldName = c_fieldName(keyList[i]);
                    actualFieldName = c_skipUntil(fieldName, ".");
                    actualFieldName++; /*skip '.' */
                    os_strcat(keyExpr,actualFieldName);
                    
                    if (i<(nrOfKeys-1)) { 
                        os_strcat(keyExpr,","); 
                    }
                }
                arg->keyExpr = keyExpr;
            } else{
                /*No keys, do nothing.*/
            }
            arg->result = U_RESULT_OK;
        }
    }
}
Exemplo n.º 4
0
static d_instance
d_instanceNew(
    d_groupInfo groupInfo,
    const v_groupAction action)
{
    d_instance instance;
    c_type type;
    c_long nrOfKeys, i;
    c_array messageKeyList, instanceKeyList;

    instanceKeyList = c_tableKeyList(groupInfo->instances);
    type = c_subType(groupInfo->instances);
    instance = d_instance(c_new(type));
    c_free(type);

    if(instance){
        /*
         * copy the key value of the message into the newly created instance.
         */
        messageKeyList = v_topicMessageKeyList(v_groupTopic(action->group));
        nrOfKeys = c_arraySize(messageKeyList);
        assert(nrOfKeys == c_arraySize(instanceKeyList));

        for (i=0;i<nrOfKeys;i++) {
            c_fieldCopy(messageKeyList[i],action->message,
                        instanceKeyList[i], instance);
        }
        c_free(instanceKeyList);

        d_instanceSetHead(instance, NULL);
        d_instanceSetTail(instance, NULL);

        instance->messageCount = 0;
        instance->count = 0;
        instance->state = 0;

        v_stateSet(instance->state, L_EMPTY);
    } else {
        OS_REPORT(OS_ERROR,
                  "d_instanceNew",0,
                  "Failed to allocate instance.");
        assert(FALSE);
    }
    return instance;
}
Exemplo n.º 5
0
static v_message
createUnregisterMessage(
    v_group group,
    v_message message)
{
    c_array            messageKeyList;
    c_long                i, nrOfKeys;
    v_message            unregisterMessage;

    assert(!v_stateTest(v_nodeState(message), L_UNREGISTER));

    /* Create new message objec */
    unregisterMessage = v_topicMessageNew
                                (group->topic);

    /* Copy keyvalues to unregistermessage */
    messageKeyList = v_topicMessageKeyList(v_groupTopic(group));
    nrOfKeys = c_arraySize(messageKeyList);
    for (i=0;i<nrOfKeys;i++) {
        c_fieldAssign (messageKeyList[i],
                unregisterMessage,
                c_fieldValue(messageKeyList[i],message));
    }

    /* Set instance & writer GID */
    unregisterMessage->writerGID =
            message->writerGID;
    unregisterMessage->writerInstanceGID =
            message->writerInstanceGID;

    /* Copy messageQos */
    c_keep (message->qos);
    unregisterMessage->qos = message->qos;

    /* Set nodestate to unregister */
    v_nodeState(unregisterMessage) = L_UNREGISTER;

    unregisterMessage->writeTime = v_timeGet();
#ifndef _NAT_
    unregisterMessage->allocTime = unregisterMessage->writeTime;
#endif

    return unregisterMessage;
}
Exemplo n.º 6
0
static void
checkTopicKeyList (
    v_entity e,
    c_voidp arg)
{
    c_array keyList = v_topicMessageKeyList(e);
    checkTopicKeyListArg *info  = (checkTopicKeyListArg *) arg;
    c_long i;
    gapi_char *name;
    c_long size;
    c_iter iter;
    gapi_boolean equal = TRUE;

    iter = c_splitString(info->keyList, " \t,");

    if ( iter ) {
        size = c_arraySize(keyList);

        for ( i = 0; equal && (i < size); i++ ) {
            name = (gapi_char *)c_iterResolve(iter,
                                              topicKeyCompare,
                                              keyNameFromField(keyList[i]));
            if ( !name ) {
                equal = FALSE;
                OS_REPORT_2(OS_API_INFO,
                            "gapi::kernelCheckTopicKeyList", 0,
                            "incompatible key <%s> found for topic <%s>",
                            keyNameFromField(keyList[i]),
                            v_entityName(e));
            }
        }
        name = c_iterTakeFirst(iter);
        while ( name ) {
            os_free(name);
            name = c_iterTakeFirst(iter);
        }
        c_iterFree(iter);
    }
    info->equal = equal;
}
Exemplo n.º 7
0
static void
topicGetKeys(
    v_entity e,
    c_voidp arg)
{
    c_array keyList = v_topicMessageKeyList(e);
    gapi_char     **keys  = (gapi_char **) arg;
    gapi_char      *ptr;
    c_ulong i;
    c_ulong size;
    c_ulong total = 0;
    c_ulong len = 0;

    size = c_arraySize(keyList);

    for ( i = 0; i < size; i++ ) {
        total += strlen(c_fieldName(keyList[i])) + 1;
    }

    if ( total > 0 ) {
        *keys = (gapi_char *)os_malloc(total);
        memset(*keys, 0, total);
    } else {
        *keys = (gapi_char *)os_malloc(1);
        **keys = '\0';
    }

    ptr = *keys;
    for ( i = 0; i < size; i++ ) {
        if ( i == 0 ) {
            len = os_sprintf(ptr, "%s", keyNameFromField(keyList[i]));
        } else {
            len = os_sprintf(ptr, ",%s", keyNameFromField(keyList[i]));
        }
        ptr = &(ptr[len]);
    }
}
Exemplo n.º 8
0
u_bool
u_topicContentFilterValidate (
    const u_topic _this,
    const q_expr expr,
    const c_value params[],
    os_uint32 nrOfParams)
{
    v_topic topic;
    u_bool result;
    q_expr subexpr, term;
    int i;
    v_filter filter;
    u_result uResult;

    assert(_this);
    assert(expr);

    result = FALSE;
    filter = NULL;
    uResult = u_topicReadClaim(_this, &topic, C_MM_RESERVATION_LOW);
    if (uResult == U_RESULT_OK) {
        assert(topic);
        i = 0;
        subexpr = q_getPar(expr, i); /* get rid of Q_EXPR_PROGRAM */
        while ((term = q_getPar(subexpr, i++)) != NULL) {
            if (q_getTag(term) == Q_EXPR_WHERE) {
                filter = v_filterNew(v_topicMessageType(topic), v_topicMessageKeyList(topic), term, params, nrOfParams);
            }
        }
        u_topicRelease(_this, C_MM_RESERVATION_LOW);
    }
    if (filter != NULL) {
        result = TRUE;
        c_free(filter);
    }
    return result;
}
Exemplo n.º 9
0
static d_instance
d_groupInfoLookupInstance (
    d_groupInfo _this,
    const v_groupAction action)
{
    c_long i, nrOfKeys;
    c_value keyValues[32];
    d_instance instance;
    c_array messageKeyList;

    assert(C_TYPECHECK(action->message,v_message));

    messageKeyList = v_topicMessageKeyList(action->group->topic);
    nrOfKeys = c_arraySize(messageKeyList);

    if (nrOfKeys > 32) {
        OS_REPORT_1(OS_ERROR,
                    "d_groupInfoGetInstance",0,
                    "too many keys %d exceeds limit of 32",
                    nrOfKeys);
        instance = NULL;
    } else {
        for (i=0;i<nrOfKeys;i++) {
            keyValues[i] = c_fieldValue(messageKeyList[i],action->message);
        }
        instance = c_tableFind(_this->instances, &keyValues[0]);
        c_keep(instance);



        for (i=0;i<nrOfKeys;i++) {
            c_valueFreeRef(keyValues[i]);
        }
    }
    return instance;
}
Exemplo n.º 10
0
static c_type
createInstanceType (
    v_topic topic,
    c_char *keyExpr,
    c_array *keyListRef)
{
    c_metaObject o;
    c_type instanceType, baseType, foundType;
    c_type sampleType, keyType, keyInstanceType;
    c_base base;
    c_char *name;
    os_size_t length;
    int sres;

    assert(C_TYPECHECK(topic,v_topic));

    foundType = NULL;
    if (keyExpr) {
        keyType = v_topicKeyTypeCreate(topic,keyExpr,keyListRef);
    } else {
        keyExpr = v_topicKeyExpr(topic);
        keyType = v_topicKeyType(topic);
        *keyListRef = c_keep(v_topicMessageKeyList(topic));
    }
    sampleType = sampleTypeNew(topic);
    if (sampleType) {
        base = c_getBase(topic);
        baseType = v_dataReaderInstance_t(base);
        instanceType = c_type(c_metaDefine(c_metaObject(base),M_CLASS));
        if (instanceType != NULL) {
            c_class(instanceType)->extends = c_keep(c_class(baseType));
            o = c_metaDeclare(c_metaObject(instanceType),
                              "sample",M_ATTRIBUTE);
            c_property(o)->type = c_keep(sampleType);
            c_free(o);
            o = c_metaDeclare(c_metaObject(instanceType),
                              "oldest",M_ATTRIBUTE);
            c_property(o)->type = (c_type)c_metaResolveType(c_metaObject(base),
                                                    "c_voidp");
            assert(c_property(o)->type);
            c_free(o);
            c_metaFinalize(c_metaObject(instanceType));
#define INSTANCE_NAME   "v_indexInstance<v_indexSample<>>"
#define INSTANCE_FORMAT "v_indexInstance<v_indexSample<%s>>"
            /* The sizeof contains \0 */
            length = sizeof(INSTANCE_NAME) + strlen(v_topicName(topic));
            name = os_alloca(length);
            sres = snprintf(name,length,INSTANCE_FORMAT,v_topicName(topic));
            assert(sres >= 0 && (os_size_t) sres == (length-1));
            OS_UNUSED_ARG(sres);
#undef INSTANCE_NAME
#undef INSTANCE_FORMAT
            foundType = c_type(c_metaBind(c_metaObject(base),
                                          name,
                                          c_metaObject(instanceType)));
            if (foundType == NULL) {
                OS_REPORT(OS_ERROR,
                        "v_index::createInstanceType",V_RESULT_INTERNAL_ERROR,
                        "Could not create instance type");
            }

            os_freea(name);

            if (keyType != NULL) {
                keyInstanceType = c_type(c_metaDefine(c_metaObject(base),M_CLASS));
                if (keyInstanceType) {
                    c_class(keyInstanceType)->extends = c_keep(c_class(instanceType));
                    o = c_metaDeclare(c_metaObject(keyInstanceType),
                                      "key",M_ATTRIBUTE);
                    c_property(o)->type = c_keep(keyType);
                    c_free(o);
                    c_metaFinalize(c_metaObject(keyInstanceType));
#define INSTANCE_NAME   "v_indexKeyInstance<v_indexSample<>,>"
#define INSTANCE_FORMAT "v_indexKeyInstance<v_indexSample<%s>,%s>"
                    /* The sizeof contains \0 */
                    length = sizeof(INSTANCE_NAME) +
                             strlen(v_topicName(topic)) +
                             strlen(keyExpr);
                    name = os_alloca(length);
                    sres = snprintf(name,
                                    length,
                                    INSTANCE_FORMAT,
                                    v_topicName(topic),
                                    keyExpr);
                    assert(sres >= 0 && (os_size_t) sres == (length-1));
                    OS_UNUSED_ARG(sres);
#undef INSTANCE_NAME
#undef INSTANCE_FORMAT
                    c_free(foundType); /* Will be overwritten, so free */
                    foundType = c_type(c_metaBind(c_metaObject(base),
                                                  name,
                                                  c_metaObject(keyInstanceType)));
                    if (foundType == NULL) {
                        OS_REPORT(OS_ERROR,
                                  "v_index::createInstanceType",V_RESULT_INTERNAL_ERROR,
                                  "Could not create key instance type");
                    }
                    os_freea(name);
                    c_free(keyInstanceType);
                }
                c_free(keyType);
            }
            c_free(instanceType);
            c_free(baseType);
        } else {
            foundType = baseType; /* transfer refCount to caller */
        }
        c_free(sampleType);
    }

    return foundType;
}
Exemplo n.º 11
0
static in_result
in_ddsiStreamReaderImplDerializePayloadByKeyHash(
	in_ddsiStreamReaderImpl _this,
	in_ddsiSubmessageData submessage,
	in_connectivityPeerWriter peerWriter,
	v_topic topic,
	v_message *messageObject,
	c_octet* keyHash)
{
	in_result result;
	c_long nrOfKeys, i, bytesCopied;
	c_array messageKeyList;
	c_value value;
	c_base base;

	assert(_this);
	assert(submessage);
	assert(peerWriter);
	assert(topic);
	assert(*messageObject);

	messageKeyList = v_topicMessageKeyList(topic);
	nrOfKeys = c_arraySize(messageKeyList);
	bytesCopied = 0;
	base = c_getBase(topic);
	result = IN_RESULT_OK;

	/*TODO: In case key is larger then 16 bytes, MD5 must be used*/
	for (i=0;(i<nrOfKeys) && (result == IN_RESULT_OK);i++)
	{
		switch(c_fieldValueKind(messageKeyList[i]))
		{
		case V_BOOLEAN:
			value = c_boolValue(*((c_bool*)&(keyHash[bytesCopied])));
			bytesCopied += sizeof(c_bool);
		break;
		case V_OCTET:
			value = c_octetValue(*((c_octet*)&(keyHash[bytesCopied])));
			bytesCopied += sizeof(c_octet);
		break;
		case V_SHORT:
#ifdef PA_BIG_ENDIAN
			value = c_shortValue(*((c_short*)&(keyHash[bytesCopied])));
#else
			value = c_shortValue(IN_UINT16_SWAP_LE_BE(*((c_short*)&(keyHash[bytesCopied]))));
#endif
			bytesCopied += sizeof(c_short);
		break;
		case V_USHORT:
#ifdef PA_BIG_ENDIAN
			value = c_ushortValue(*((c_ushort*)&(keyHash[bytesCopied])));
#else
			value = c_ushortValue(IN_UINT16_SWAP_LE_BE(*((c_ushort*)&(keyHash[bytesCopied]))));
#endif
			bytesCopied += sizeof(c_ushort);
		break;
		case V_LONG:
#ifdef PA_BIG_ENDIAN
			value = c_longValue(*((c_long*)&(keyHash[bytesCopied])));
#else
			value = c_longValue(IN_UINT32_SWAP_LE_BE(*((c_long*)&(keyHash[bytesCopied]))));
#endif
			bytesCopied += sizeof(c_long);
		break;

		case V_ULONG:
#ifdef PA_BIG_ENDIAN
			value = c_ulongValue(*((c_ulong*)&(keyHash[bytesCopied])));
#else
			value = c_ulongValue(IN_UINT32_SWAP_LE_BE(*((c_ulong*)&(keyHash[bytesCopied]))));
#endif
			bytesCopied += sizeof(c_long);
		break;
		case V_CHAR:
			value = c_charValue(*((c_char*)&(keyHash[bytesCopied])));
			bytesCopied += sizeof(c_char);
		break;
		case V_STRING:
#ifdef PA_BIG_ENDIAN
			value = c_ulongValue(*((c_ulong*)&(keyHash[bytesCopied])));
#else
			value = c_ulongValue(IN_UINT32_SWAP_LE_BE(*((c_ulong*)&(keyHash[bytesCopied]))));
#endif
			bytesCopied += 4;
			/*TODO: validate the string copy algorithm*/
			if(value.is.ULong != 0)
			{
				value = c_stringValue(
					c_stringNew(base,((c_string)(&(keyHash[bytesCopied])))));
				bytesCopied += strlen(value.is.String) + 1;
			} else
			{
				value = c_stringValue(c_stringNew(base, ""));
				bytesCopied += 1;
			}
		break;
		case V_DOUBLE:
			value = c_undefinedValue();
			bytesCopied += sizeof(c_double);
			result = IN_RESULT_PRECONDITION_NOT_MET;
		break;
		case V_FLOAT:
			value = c_undefinedValue();
			bytesCopied += sizeof(c_float);
			result = IN_RESULT_PRECONDITION_NOT_MET;
		break;
		case V_ULONGLONG:
			value = c_undefinedValue();
			bytesCopied += sizeof(c_ulonglong);
			result = IN_RESULT_PRECONDITION_NOT_MET;
		break;
		case V_LONGLONG:
			value = c_undefinedValue();
			bytesCopied += sizeof(c_longlong);
			result = IN_RESULT_PRECONDITION_NOT_MET;
		break;
		default:
			value = c_undefinedValue();
			assert(FALSE);
			result = IN_RESULT_ERROR;
		break;
		}
		c_fieldAssign(messageKeyList[i],*messageObject, value);
		c_valueFreeRef(value);
	}

	return result;
}