Exemplo n.º 1
0
TEST_F(MamaFieldCacheIteratorTestC, iteratorLoop)
{
    mamaFieldCache fieldCache = NULL;
    mama_status ret = mamaFieldCache_create(&fieldCache);
    ASSERT_EQ(MAMA_STATUS_OK, ret);

    mamaMsg message;
    mamaMsg_create(&message);
    mamaMsg_addBool(message, "test_bool", 10, 1);
    mamaMsg_addF64(message, "test_f32", 25, 12.3);
    mamaMsg_addI32(message, "test_i32", 66, -101);
    mamaMsg_addString(message, "test_string", 90, "hello world");
    mamaMsg_addString(message, "test_string_empty", 88, "");
    mamaFieldCache_applyMessage(fieldCache, message, NULL);

    mamaFieldCacheIterator iterator;
    mamaFieldCacheIterator_create(&iterator, fieldCache);
    
    int counter = 0;
    mamaFieldCacheField current = NULL;
    while (mamaFieldCacheIterator_hasNext(iterator))
    {
        current = mamaFieldCacheIterator_next(iterator);
        ASSERT_TRUE(current);
        counter++;
    }
    ASSERT_EQ(5, counter);

    mamaFieldCacheIterator_destroy(iterator);
    mamaMsg_destroy(message);

    ret = mamaFieldCache_destroy(fieldCache);
}
Exemplo n.º 2
0
TEST_F(MamaFieldCacheIteratorTestC, iteratorBegin)
{
    mamaFieldCache fieldCache = NULL;
    mama_status ret = mamaFieldCache_create(&fieldCache);
    ASSERT_EQ(MAMA_STATUS_OK, ret);
    
    mamaMsg message;
    mamaMsg_create(&message);
    mamaMsg_addBool(message, "test_bool", 10, 1);
    mamaMsg_addF64(message, "test_f32", 25, 12.3);
    mamaMsg_addI32(message, "test_i32", 66, -101);
    mamaMsg_addString(message, "test_string", 90, "hello world");
    mamaFieldCache_applyMessage(fieldCache, message, NULL);

    mamaFieldCacheIterator iterator;
    mamaFieldCacheIterator_create(&iterator, fieldCache);
    
    mamaFieldCacheField field = NULL;
    
    mama_fid_t fid = 0;
    field = mamaFieldCacheIterator_begin(iterator);
    ASSERT_TRUE(field);
    mamaFieldCacheField_getFid(field, &fid);
    ASSERT_EQ(10, fid);
    
    mamaFieldCacheIterator_destroy(iterator);
    mamaMsg_destroy(message);

    ret = mamaFieldCache_destroy(fieldCache);
    ASSERT_EQ(MAMA_STATUS_OK, ret);
}
Exemplo n.º 3
0
/*  Description: Populate a mamaMsg with a number of fields, including the
 *  mdMsgNum field. Call msgUtils_getNum and ensure it a) returns
 *  MAMA_STATUS_OK, and b) populates the result with the correct value.
 *
 *  Expected Result: MAMA_STATUS_OK and 128
 */
TEST_F (MamaMsgUtilsTestC, msgNum)
{
    short result = 0;

    ASSERT_EQ (MAMA_STATUS_OK, mamaMsg_addI32 (msg,
                                               MamaFieldMsgTotal.mName,
                                               MamaFieldMsgTotal.mFid,
                                               64));

    ASSERT_EQ (MAMA_STATUS_OK, mamaMsg_addI32 (msg,
                                               MamaFieldMsgNum.mName,
                                               MamaFieldMsgNum.mFid,
                                               128));

    EXPECT_EQ (MAMA_STATUS_OK, msgUtils_msgNum (msg, &result));
    EXPECT_EQ (128, result);
}
Exemplo n.º 4
0
TEST_F(MamaFieldCacheIteratorTestC, iteratorNext)
{
    mamaFieldCache fieldCache = NULL;
    mama_status ret = mamaFieldCache_create(&fieldCache);
    ASSERT_EQ(MAMA_STATUS_OK, ret);
    
    mamaMsg message;
    mamaMsg_create(&message);
    mamaMsg_addBool(message, "test_bool", 10, 1);
    mamaMsg_addF64(message, "test_f32", 25, 12.3);
    mamaMsg_addI32(message, "test_i32", 66, -101);
    mamaMsg_addString(message, "test_string", 90, "hello world");
    mamaFieldCache_applyMessage(fieldCache, message, NULL);

    mamaFieldCacheIterator iterator;
    mamaFieldCacheIterator_create(&iterator, fieldCache);
    
    mamaFieldCacheField begin = NULL;
    begin = mamaFieldCacheIterator_begin(iterator);
    
    ASSERT_TRUE(mamaFieldCacheIterator_hasNext(iterator));

    mamaFieldCacheField current = NULL;
    current = mamaFieldCacheIterator_next(iterator);
    ASSERT_TRUE(current);
    ASSERT_TRUE(current == begin);

    mama_fid_t fid = 0;
    ASSERT_TRUE(mamaFieldCacheIterator_hasNext(iterator));
    current = mamaFieldCacheIterator_next(iterator);
    ASSERT_TRUE(current);
    mamaFieldCacheField_getFid(current, &fid);
    ASSERT_EQ(25, fid);
    
    ASSERT_TRUE(mamaFieldCacheIterator_hasNext(iterator));
    current = mamaFieldCacheIterator_next(iterator);
    ASSERT_TRUE(current);
    mamaFieldCacheField_getFid(current, &fid);
    ASSERT_EQ(66, fid);
    
    ASSERT_TRUE(mamaFieldCacheIterator_hasNext(iterator));
    current = mamaFieldCacheIterator_next(iterator);
    mamaFieldCacheField_getFid(current, &fid);
    ASSERT_EQ(90, fid);
    
    ASSERT_FALSE(mamaFieldCacheIterator_hasNext(iterator));
    
    current = mamaFieldCacheIterator_next(iterator);
    ASSERT_FALSE(current);

    mamaFieldCacheIterator_destroy(iterator);
    mamaMsg_destroy(message);

    ret = mamaFieldCache_destroy(fieldCache);
}
Exemplo n.º 5
0
/*  Description: Populate a mamaMsg with a number of fields, but not the
 *  mdMsgNum field. Call msgUtils_getNum and ensure it a) returns
 *  MAMA_STATUS_NOT_FOUND and b) doesn't attempt the populate the result.
 *
 *  Expected Result: MAMA_STATUS_NOT_FOUND and 0.
 */
TEST_F (MamaMsgUtilsTestC, msgNumEmptyField)
{
    short result = 0;

    ASSERT_EQ (MAMA_STATUS_OK, mamaMsg_addI32 (msg,
                                               MamaFieldMsgTotal.mName,
                                               MamaFieldMsgTotal.mFid,
                                               64));

    EXPECT_EQ (MAMA_STATUS_NOT_FOUND, msgUtils_msgNum (msg, &result));
    EXPECT_EQ (0, result);
}
Exemplo n.º 6
0
TEST_F(MamaFieldCacheTestC, applyMsgUsingNames)
{
    mamaFieldCache fieldCache = NULL;
    mama_size_t size = 0;
    const char* name = "";
    mama_status ret = mamaFieldCache_create(&fieldCache);
    mamaFieldCache_setUseFieldNames(fieldCache, 1);

    mamaMsg message;
    mamaMsg_create(&message);
    mamaMsg_addBool(message, "test_bool", 10, 1);
    mamaMsg_addF64(message, "test_f64", 25, 12.3);
    mamaMsg_addI32(message, "test_i32", 66, -101);
    mamaMsg_addString(message, "test_string", 90, "hello world");

    ret = mamaFieldCache_applyMessage(fieldCache, message, NULL);

    ASSERT_EQ(MAMA_STATUS_OK, ret);
    ret = mamaFieldCache_getSize(fieldCache, &size);
    ASSERT_EQ(4, size);

    mamaFieldCacheField field = NULL;
    ret = mamaFieldCache_find(fieldCache, 10, NULL, &field);
    ASSERT_EQ(MAMA_STATUS_OK, ret);
    ASSERT_EQ(10, field->mFid);
    mamaFieldCacheField_getName(field, &name);
    ASSERT_STREQ("test_bool", name);

    field = NULL;
    ret = mamaFieldCache_find(fieldCache, 25, NULL, &field);
    ASSERT_EQ(MAMA_STATUS_OK, ret);
    ASSERT_EQ(25, field->mFid);
    mamaFieldCacheField_getName(field, &name);
    ASSERT_STREQ("test_f64", name);

    field = NULL;
    ret = mamaFieldCache_find(fieldCache, 66, NULL, &field);
    ASSERT_EQ(MAMA_STATUS_OK, ret);
    ASSERT_EQ(66, field->mFid);
    mamaFieldCacheField_getName(field, &name);
    ASSERT_STREQ("test_i32", name);

    field = NULL;
    ret = mamaFieldCache_find(fieldCache, 90, NULL, &field);
    ASSERT_EQ(MAMA_STATUS_OK, ret);
    ASSERT_EQ(90, field->mFid);
    mamaFieldCacheField_getName(field, &name);
    ASSERT_STREQ("test_string", name);

    mamaMsg_destroy (message);

    ret = mamaFieldCache_destroy(fieldCache);
}
void RMDSBridgeSubscription::SendStatusMessage( mamaMsgStatus secStatus )
{
	if (isShutdown_)
	{
		// just don't bother making the callback
		return;
	}
	// create and send a message containing the (failed) status
	mamaMsg msg;
	mamaMsg_createForPayload(&msg, MAMA_PAYLOAD_TICK42RMDS);

	mamaMsg_addI32(msg, MamaFieldMsgType.mName, MamaFieldMsgType.mFid, MAMA_MSG_TYPE_SEC_STATUS);
	mamaMsg_addI32(msg, MamaFieldMsgStatus.mName, MamaFieldMsgStatus.mFid, secStatus);

    const CommonFields &commonFields = UpaMamaCommonFields::CommonFields();
	mamaMsg_addString(msg, commonFields.wIssueSymbol.mama_field_name.c_str(),commonFields.wIssueSymbol.mama_fid, symbol_.c_str());
	mamaMsg_addString(msg, commonFields.wSymbol.mama_field_name.c_str(), commonFields.wSymbol.mama_fid, symbol_.c_str());

	mama_status status = MAMA_STATUS_OK;
	try
	{
		status = mamaSubscription_processMsg(subscription_, msg);
	}
	catch (...)
	{
		mamaMsg_destroy(msg);	
		t42log_error("RMDSBridgeSubscription::OnMessage - caught exception calling mamaSubscription_processMsg for %s", symbol_.c_str());
	}


	if (MAMA_STATUS_OK != status)
	{
		mama_log (MAMA_LOG_LEVEL_ERROR,
			"RMDSBridgeSubscription::OnMessage: "
			"mamaSubscription_processMsg() failed. [%d]",
			status);
	}

	mamaMsg_destroy(msg);	
}
Exemplo n.º 8
0
mama_status
msgUtils_createEndOfInitialsMsg (mamaMsg *msg)
{
    mamaMsg_create (msg);
    mamaMsg_addU8 (*msg,
                    MamaFieldMsgType.mName,
                    MamaFieldMsgType.mFid,
                    MAMA_MSG_TYPE_END_OF_INITIALS);
    mamaMsg_addI32 (*msg,
                    MamaFieldMsgStatus.mName,
                    MamaFieldMsgStatus.mFid,
                    MAMA_MSG_STATUS_OK);
    return MAMA_STATUS_OK;
}
Exemplo n.º 9
0
mama_status
msgUtils_createTimeoutMsg (mamaMsg *msg)
{
    mamaMsg_create (msg);

    mamaMsg_addU8 (*msg,
                    MamaFieldMsgType.mName,
                    MamaFieldMsgType.mFid,
                    MAMA_MSG_TYPE_INITIAL);

    mamaMsg_addI32 (*msg,
                    MamaFieldMsgStatus.mName,
                    MamaFieldMsgStatus.mFid,
                    MAMA_MSG_STATUS_TIMEOUT);

    return MAMA_STATUS_OK;
}
Exemplo n.º 10
0
mama_status mamaFieldCache_updateMsgField(mamaFieldCache fieldCache,
                                          mamaFieldCacheField field,
                                          mamaMsg message,
                                          mama_bool_t useUpdate)
{
    mama_status status = MAMA_STATUS_OK;
    mama_fid_t fid;
    mamaFieldType type;
    const char* name = NULL;

    mamaFieldCacheField_getFid(field, &fid);
    mamaFieldCacheField_getType(field, &type);
    if (fieldCache->mUseFieldNames)
    {
        mamaFieldCacheField_getName(field, &name);
    }

    switch (type)
    {
        case MAMA_FIELD_TYPE_BOOL:
        {
            mama_bool_t value;
            mamaFieldCacheField_getBool(field, &value);
            status = useUpdate ? mamaMsg_updateBool(message, name, fid, value)
                               : mamaMsg_addBool(message, name, fid, value);
            break;
        }
        case MAMA_FIELD_TYPE_CHAR:
        {
            char value;
            mamaFieldCacheField_getChar(field, &value);
            status = useUpdate ? mamaMsg_updateChar(message, name, fid, value)
                               : mamaMsg_addChar(message, name, fid, value);
            break;
        }
        case MAMA_FIELD_TYPE_I8:
        {
            mama_i8_t value;
            mamaFieldCacheField_getI8(field, &value);
            status = useUpdate ? mamaMsg_updateI8(message, name, fid, value)
                               : mamaMsg_addI8(message, name, fid, value);
            break;
        }
        case MAMA_FIELD_TYPE_U8:
        {
            mama_u8_t value;
            mamaFieldCacheField_getU8(field, &value);
            status = useUpdate ? mamaMsg_updateU8(message, name, fid, value)
                               : mamaMsg_addU8(message, name, fid, value);
            break;
        }
        case MAMA_FIELD_TYPE_I16:
        {
            mama_i16_t value;
            mamaFieldCacheField_getI16(field, &value);
            status = useUpdate ? mamaMsg_updateI16(message, name, fid, value)
                               : mamaMsg_addI16(message, name, fid, value);
            break;
        }
        case MAMA_FIELD_TYPE_U16:
        {
            mama_u16_t value;
            mamaFieldCacheField_getU16(field, &value);
            status = useUpdate ? mamaMsg_updateU16(message, name, fid, value)
                               : mamaMsg_addU16(message, name, fid, value);
            break;
        }
        case MAMA_FIELD_TYPE_I32:
        {
            mama_i32_t value;
            mamaFieldCacheField_getI32(field, &value);
            status = useUpdate ? mamaMsg_updateI32(message, name, fid, value)
                               : mamaMsg_addI32(message, name, fid, value);
            break;
        }
        case MAMA_FIELD_TYPE_U32:
        {
            mama_u32_t value;
            mamaFieldCacheField_getU32(field, &value);
            status = useUpdate ? mamaMsg_updateU32(message, name, fid, value)
                               : mamaMsg_addU32(message, name, fid, value);
            break;
        }
        case MAMA_FIELD_TYPE_I64:
        {
            mama_i64_t value;
            mamaFieldCacheField_getI64(field, &value);
            status = useUpdate ? mamaMsg_updateI64(message, name, fid, value)
                               : mamaMsg_addI64(message, name, fid, value);
            break;
        }
        case MAMA_FIELD_TYPE_U64:
        {
            mama_u64_t value;
            mamaFieldCacheField_getU64(field, &value);
            status = useUpdate ? mamaMsg_updateU64(message, name, fid, value)
                               : mamaMsg_addU64(message, name, fid, value);
            break;
        }
        case MAMA_FIELD_TYPE_F32:
        {
            mama_f32_t value;
            mamaFieldCacheField_getF32(field, &value);
            status = useUpdate ? mamaMsg_updateF32(message, name, fid, value)
                               : mamaMsg_addF32(message, name, fid, value);
            break;
        }
        case MAMA_FIELD_TYPE_QUANTITY:
        case MAMA_FIELD_TYPE_F64:
        {
            mama_f64_t value;
            mamaFieldCacheField_getF64(field, &value);
            status = useUpdate ? mamaMsg_updateF64(message, name, fid, value)
                               : mamaMsg_addF64(message, name, fid, value);
            break;
        }
        case MAMA_FIELD_TYPE_STRING:
        {
            const char* value = NULL;
            mama_size_t len;
            mamaFieldCacheField_getString(field, &value, &len);
            if (!value)
            {
                return MAMA_STATUS_INVALID_ARG;
            }
            status = useUpdate ? mamaMsg_updateString(message, name, fid, value)
                                : mamaMsg_addString(message, name, fid, value);
            break;
        }
        case MAMA_FIELD_TYPE_PRICE:
        {
            const mamaPrice value = NULL;
            mamaFieldCacheField_getPrice(field, &value);
            if (!value)
            {
                return MAMA_STATUS_INVALID_ARG;
            }
            status = useUpdate ? mamaMsg_updatePrice(message, name, fid, value)
                               : mamaMsg_addPrice(message, name, fid, value);
            break;
        }
        case MAMA_FIELD_TYPE_TIME:
        {
            const mamaDateTime value = NULL;
            mamaFieldCacheField_getDateTime(field, &value);
            if (!value)
            {
                return MAMA_STATUS_INVALID_ARG;
            }
            status = useUpdate ? mamaMsg_updateDateTime(message, name, fid, value)
                               : mamaMsg_addDateTime(message, name, fid, value);
            break;
        }
        case MAMA_FIELD_TYPE_VECTOR_I8:
        {
            const mama_i8_t* values = NULL;
            mama_size_t size = 0;
            mamaFieldCacheField_getI8Vector(field, &values, &size);
            if (!values)
            {
                return MAMA_STATUS_INVALID_ARG;
            }
            status = useUpdate ? mamaMsg_updateVectorI8(message, name, fid, values, size)
                               : mamaMsg_addVectorI8(message, name, fid, values, size);
            break;
        }
        case MAMA_FIELD_TYPE_VECTOR_U8:
        {
            const mama_u8_t* values = NULL;
            mama_size_t size = 0;
            mamaFieldCacheField_getU8Vector(field, &values, &size);
            if (!values)
            {
                return MAMA_STATUS_INVALID_ARG;
            }
            status = useUpdate ? mamaMsg_updateVectorU8(message, name, fid, values, size)
                               : mamaMsg_addVectorU8(message, name, fid, values, size);
            break;
        }
        case MAMA_FIELD_TYPE_VECTOR_I16:
        {
            const mama_i16_t* values = NULL;
            mama_size_t size = 0;
            mamaFieldCacheField_getI16Vector(field, &values, &size);
            if (!values)
            {
                return MAMA_STATUS_INVALID_ARG;
            }
            status = useUpdate ? mamaMsg_updateVectorI16(message, name, fid, values, size)
                               : mamaMsg_addVectorI16(message, name, fid, values, size);
            break;
        }
        case MAMA_FIELD_TYPE_VECTOR_U16:
        {
            const mama_u16_t* values = NULL;
            mama_size_t size = 0;
            mamaFieldCacheField_getU16Vector(field, &values, &size);
            if (!values)
            {
                return MAMA_STATUS_INVALID_ARG;
            }
            status = useUpdate ? mamaMsg_updateVectorU16(message, name, fid, values, size)
                               : mamaMsg_addVectorU16(message, name, fid, values, size);
            break;
        }
        case MAMA_FIELD_TYPE_VECTOR_I32:
        {
            const mama_i32_t* values = NULL;
            mama_size_t size = 0;
            mamaFieldCacheField_getI32Vector(field, &values, &size);
            if (!values)
            {
                return MAMA_STATUS_INVALID_ARG;
            }
            status = useUpdate ? mamaMsg_updateVectorI32(message, name, fid, values, size)
                               : mamaMsg_addVectorI32(message, name, fid, values, size);
            break;
        }
        case MAMA_FIELD_TYPE_VECTOR_U32:
        {
            const mama_u32_t* values = NULL;
            mama_size_t size = 0;
            mamaFieldCacheField_getU32Vector(field, &values, &size);
            if (!values)
            {
                return MAMA_STATUS_INVALID_ARG;
            }
            status = useUpdate ? mamaMsg_updateVectorU32(message, name, fid, values, size)
                               : mamaMsg_addVectorU32(message, name, fid, values, size);
            break;
        }
        case MAMA_FIELD_TYPE_VECTOR_I64:
        {
            const mama_i64_t* values = NULL;
            mama_size_t size = 0;
            mamaFieldCacheField_getI64Vector(field, &values, &size);
            if (!values)
            {
                return MAMA_STATUS_INVALID_ARG;
            }
            status = useUpdate ? mamaMsg_updateVectorI64(message, name, fid, values, size)
                               : mamaMsg_addVectorI64(message, name, fid, values, size);
            break;
        }
        case MAMA_FIELD_TYPE_VECTOR_U64:
        {
            const mama_u64_t* values = NULL;
            mama_size_t size = 0;
            mamaFieldCacheField_getU64Vector(field, &values, &size);
            if (!values)
            {
                return MAMA_STATUS_INVALID_ARG;
            }
            status = useUpdate ? mamaMsg_updateVectorU64(message, name, fid, values, size)
                               : mamaMsg_addVectorU64(message, name, fid, values, size);
            break;
        }
        case MAMA_FIELD_TYPE_VECTOR_F32:
        {
            const mama_f32_t* values = NULL;
            mama_size_t size = 0;
            mamaFieldCacheField_getF32Vector(field, &values, &size);
            if (!values)
            {
                return MAMA_STATUS_INVALID_ARG;
            }
            status = useUpdate ? mamaMsg_updateVectorF32(message, name, fid, values, size)
                               : mamaMsg_addVectorF32(message, name, fid, values, size);
            break;
        }
        case MAMA_FIELD_TYPE_VECTOR_F64:
        {
            const mama_f64_t* values = NULL;
            mama_size_t size = 0;
            mamaFieldCacheField_getF64Vector(field, &values, &size);
            if (!values)
            {
                return MAMA_STATUS_INVALID_ARG;
            }
            status = useUpdate ? mamaMsg_updateVectorF64(message, name, fid, values, size)
                               : mamaMsg_addVectorF64(message, name, fid, values, size);
            break;
        }
        case MAMA_FIELD_TYPE_VECTOR_STRING:
        {
            const char** values = NULL;
            mama_size_t size = 0;
            mamaFieldCacheField_getStringVector(field, &values, &size);
            if (!values)
            {
                return MAMA_STATUS_INVALID_ARG;
            }
            status = useUpdate ? mamaMsg_updateVectorString(message, name, fid, values, size)
                               : mamaMsg_addVectorString(message, name, fid, values, size);
            break;
        }
        case MAMA_FIELD_TYPE_VECTOR_PRICE:
        {
            const mamaPrice* values = NULL;
            mama_size_t size = 0;
            mamaFieldCacheField_getPriceVector(field, &values, &size);
            if (!values)
            {
                return MAMA_STATUS_INVALID_ARG;
            }
            status = /*useUpdate ? mamaMsg_updateVectorPrice(message, name, fid, values, size)
                               : */mamaMsg_addVectorPrice(message, name, fid, values, size);
            break;
        }
        case MAMA_FIELD_TYPE_VECTOR_TIME:
        {
            const mamaDateTime* values = NULL;
            mama_size_t size = 0;
            mamaFieldCacheField_getDateTimeVector(field, &values, &size);
            if (!values)
            {
                return MAMA_STATUS_INVALID_ARG;
            }
            status = /*useUpdate ? mamaMsg_updateVectorTime(message, name, fid, values, size)
                               : */mamaMsg_addVectorDateTime(message, name, fid, values, size);
            break;
        }
        default:
            status = MAMA_STATUS_NOT_FOUND;
            break;
    }
    return status;
}
Exemplo n.º 11
0
int main (int argc, const char **argv)
{

	mamaPlaybackFileParser	fileParser		= NULL;
	mamaPlaybackCapture		fileCapture		= NULL;
	char*           		headerString	= NULL;
	mamaMsg        			sourceMsg		= NULL;
	mamaMsg					targetMsg		= NULL;
	mamaMsgField			aField 			= NULL;
	mamaBridge        		gMamaBridge     = NULL;
    mamaMsgIterator 		iterator 		= NULL;
    mamaFieldType 			fieldType		= MAMA_FIELD_TYPE_UNKNOWN;
    parseCommandLine (argc, argv);

     mama_loadBridge (&gMamaBridge, "wmw");
     mama_loadBridge (&gMamaBridge, "avis");
     mama_open ();

    mamaPlaybackFileParser_allocate (&fileParser);
    mamaPlaybackFileParser_openFile(fileParser, (char*)gInputFilename);

    mamaCapture_allocate(&fileCapture);
    mamaCapture_openFile (&fileCapture, gOutputFilename);

    mamaMsgIterator_create(&iterator, NULL);

    mamaMsg_createForPayload(&targetMsg, 'A');

    while (mamaPlaybackFileParser_getNextHeader(fileParser, &headerString))
    {
        if (mamaPlaybackFileParser_getNextMsg (fileParser,
                                                &sourceMsg))
        {
            char 	temp[64];
            char*	start = headerString;
            char*	end = strchr (headerString,':');

            strncpy (temp,start, end-start); temp[end-start]='\0';
            mamaCapture_setFeedSource (&fileCapture, temp);
            end++;
            start=end;
            end = strchr (start,':');
            strncpy (temp,start, end-start);temp[end-start]='\0';
            mamaCapture_setTransportName (&fileCapture, temp);
            end++;
            start=end;
            end = strchr (start,'\0');
            strncpy (temp,start, end-start);temp[end-start]='\0';
            mamaCapture_setSymbol (&fileCapture, temp);

			mamaMsgIterator_associate(iterator, sourceMsg);
			mamaMsg_clear(targetMsg);

			while ((aField = mamaMsgIterator_next(iterator)) != NULL)
			{
				uint16_t        fid             = 0;
				mamaMsgField_getFid(aField, &fid);
				mamaMsgField_getType(aField, &fieldType);
				switch (fieldType)
				{

					case  MAMA_FIELD_TYPE_BOOL:
		               { mama_bool_t result;
		                mamaMsgField_getBool (aField, &result);
						mamaMsg_addBool(targetMsg, NULL, fid, result);
						}break;
					case MAMA_FIELD_TYPE_CHAR:
						{char result;
		                mamaMsgField_getChar (aField, &result);
						mamaMsg_addChar(targetMsg, NULL, fid, result);
						}break;
					case  MAMA_FIELD_TYPE_I8:
		                {mama_i8_t result;
		                mamaMsgField_getI8 (aField, &result);
						mamaMsg_addI8(targetMsg, NULL, fid, result);
						}break;
					case  MAMA_FIELD_TYPE_U8:
		                {mama_u8_t result;
		                mamaMsgField_getU8 (aField, &result);
						mamaMsg_addU8(targetMsg, NULL, fid, result);
						}break;
					case MAMA_FIELD_TYPE_I16:
		                {mama_i16_t result;
		                mamaMsgField_getI16 (aField, &result);
						mamaMsg_addI16(targetMsg, NULL, fid, result);
						}break;
					case MAMA_FIELD_TYPE_U16:
		                {mama_u16_t result;
		                mamaMsgField_getU16 (aField, &result);
						mamaMsg_addU16(targetMsg, NULL, fid, result);
						}break;
					case  MAMA_FIELD_TYPE_I32:
		                {mama_i32_t result;
		                mamaMsgField_getI32 (aField, &result);
						mamaMsg_addI32(targetMsg, NULL, fid, result);
						}break;
					case  MAMA_FIELD_TYPE_U32:
		                {mama_u32_t result;
		                mamaMsgField_getU32 (aField, &result);
						mamaMsg_addU32(targetMsg, NULL, fid, result);
						}break;
					case MAMA_FIELD_TYPE_I64:
		                {mama_i64_t result;
		                mamaMsgField_getI64 (aField, &result);
						mamaMsg_addI64(targetMsg, NULL, fid, result);
						}break;
					case  MAMA_FIELD_TYPE_U64:
		                {mama_u64_t result;
		                mamaMsgField_getU64 (aField, &result);
						mamaMsg_addU64(targetMsg, NULL, fid, result);
						}break;
					case  MAMA_FIELD_TYPE_F32:
		                {mama_f32_t result;
		                mamaMsgField_getF32 (aField, &result);
						mamaMsg_addF32(targetMsg, NULL, fid, result);
						}break;
					case MAMA_FIELD_TYPE_F64:
		                {mama_f64_t result;
		                mamaMsgField_getF64 (aField, &result);
						mamaMsg_addF64(targetMsg, NULL, fid, result);
						}break;
					case MAMA_FIELD_TYPE_STRING:
						{const char* result;
		                mamaMsgField_getString (aField, &result);
						mamaMsg_addString(targetMsg, NULL, fid, result);
						}break;
					case  MAMA_FIELD_TYPE_TIME:
						{
							mamaDateTime result;
							mamaMsgField_getDateTime (aField, result);
							mamaMsg_addDateTime(targetMsg, NULL, fid, result);
						}break;
					case MAMA_FIELD_TYPE_PRICE:
						{
							mamaPrice result;
							mamaMsgField_getPrice(aField, result);
							mamaMsg_addPrice(targetMsg, NULL, fid, result);
						}break;
					default:
						case MAMA_FIELD_TYPE_VECTOR_I8:
						case MAMA_FIELD_TYPE_VECTOR_U8:
						case MAMA_FIELD_TYPE_VECTOR_I16:
						case MAMA_FIELD_TYPE_VECTOR_U16:
						case MAMA_FIELD_TYPE_VECTOR_I32:
						case MAMA_FIELD_TYPE_VECTOR_U32:
						case MAMA_FIELD_TYPE_VECTOR_I64:
						case MAMA_FIELD_TYPE_VECTOR_U64:
						case MAMA_FIELD_TYPE_VECTOR_F32:
						case MAMA_FIELD_TYPE_VECTOR_F64:
						case MAMA_FIELD_TYPE_VECTOR_STRING:
						case MAMA_FIELD_TYPE_VECTOR_MSG:
						case MAMA_FIELD_TYPE_VECTOR_TIME:
						case MAMA_FIELD_TYPE_VECTOR_PRICE:
						case MAMA_FIELD_TYPE_QUANTITY:
						case MAMA_FIELD_TYPE_COLLECTION :
						case MAMA_FIELD_TYPE_UNKNOWN:
						case MAMA_FIELD_TYPE_OPAQUE:
						case MAMA_FIELD_TYPE_MSG:
							break;
				}
			}
            mamaCapture_saveMamaMsg (&fileCapture, &targetMsg);
        }
    }

    mamaMsgIterator_destroy(iterator);
    mamaCapture_closeFile(fileCapture);
    mamaCapture_deallocate (fileCapture);
    mamaPlaybackFileParser_closeFile(fileParser);
    mamaPlaybackFileParser_deallocate (fileParser);
    return (0);
}
Exemplo n.º 12
0
TEST_F(MamaFieldCacheTestC, applyMsgUpdate)
{
    mamaFieldCache fieldCache = NULL;
    mama_bool_t modified = 0;
    mama_size_t size = 0;
    mama_size_t len = 0;
    mama_status ret = mamaFieldCache_create(&fieldCache);

    mamaMsg message;
    mamaMsg_create(&message);
    mamaMsg_addBool(message, "test_bool", 10, 1);
    mamaMsg_addF64(message, "test_f64", 25, 12.3);
    mamaMsg_addString(message, "test_string", 90, "hello world");

    mamaFieldCache_applyMessage(fieldCache, message, NULL);

    ret = mamaFieldCache_getSize(fieldCache, &size);
    ASSERT_EQ(3, size);

    mamaFieldCacheField field = NULL;
    ret = mamaFieldCache_find(fieldCache, 10, NULL, &field);
    ASSERT_EQ(MAMA_STATUS_OK, ret);
    ASSERT_EQ(10, field->mFid);
    mama_bool_t resultBool = 0;
    mamaFieldCacheField_getBool(field, &resultBool);
    ASSERT_EQ(1, resultBool);
    mamaFieldCacheField_isModified(field, &modified);
    ASSERT_TRUE(modified);

    field = NULL;
    ret = mamaFieldCache_find(fieldCache, 25, NULL, &field);
    ASSERT_EQ(MAMA_STATUS_OK, ret);
    ASSERT_EQ(25, field->mFid);
    mama_f64_t resultF64 = 0;
    mamaFieldCacheField_getF64(field, &resultF64);
    ASSERT_DOUBLE_EQ(12.3, resultF64);
    mamaFieldCacheField_isModified(field, &modified);
    ASSERT_TRUE(modified);

    field = NULL;
    ret = mamaFieldCache_find(fieldCache, 90, NULL, &field);
    ASSERT_EQ(MAMA_STATUS_OK, ret);
    ASSERT_EQ(90, field->mFid);
    const char* resultString = NULL;
    mamaFieldCacheField_getString(field, &resultString, &len);
    ASSERT_STREQ("hello world", resultString);
    mamaFieldCacheField_isModified(field, &modified);
    ASSERT_TRUE(modified);

    size = 0;
    mamaFieldCacheList_getSize(fieldCache->mModifiedFields, &size);
    ASSERT_EQ(3, size);

    mamaMsg_clear(message);

    mamaMsg_addF64(message, "test_f32", 25, 10.9);
    mamaMsg_addI32(message, "test_i32", 60, -123);

    mamaFieldCache_applyMessage(fieldCache, message, NULL);

    ret = mamaFieldCache_getSize(fieldCache, &size);
    ASSERT_EQ(4, size);

    mamaFieldCacheList_getSize(fieldCache->mModifiedFields, &size);
    ASSERT_EQ(4, size);

    ret = mamaFieldCache_find(fieldCache, 10, NULL, &field);
    ASSERT_EQ(MAMA_STATUS_OK, ret);
    ASSERT_EQ(10, field->mFid);
    resultBool = 0;
    mamaFieldCacheField_getBool(field, &resultBool);
    ASSERT_EQ(1, resultBool);
    mamaFieldCacheField_isModified(field, &modified);
    ASSERT_TRUE(modified);

    ret = mamaFieldCache_find(fieldCache, 60, NULL, &field);
    ASSERT_EQ(MAMA_STATUS_OK, ret);
    ASSERT_EQ(60, field->mFid);
    mama_i32_t resultI32 = 0;
    mamaFieldCacheField_getI32(field, &resultI32);
    ASSERT_DOUBLE_EQ(-123, resultI32);
    mamaFieldCacheField_isModified(field, &modified);
    ASSERT_TRUE(modified);

    ret = mamaFieldCache_find(fieldCache, 25, NULL, &field);
    ASSERT_EQ(MAMA_STATUS_OK, ret);
    ASSERT_EQ(25, field->mFid);
    resultF64 = 0;
    mamaFieldCacheField_getF64(field, &resultF64);
    ASSERT_DOUBLE_EQ(10.9, resultF64);
    mamaFieldCacheField_isModified(field, &modified);
    ASSERT_TRUE(modified);

    ret = mamaFieldCache_find(fieldCache, 90, NULL, &field);
    ASSERT_EQ(MAMA_STATUS_OK, ret);
    ASSERT_EQ(90, field->mFid);
    resultString = NULL;
    mamaFieldCacheField_getString(field, &resultString, &len);
    ASSERT_STREQ("hello world", resultString);
    mamaFieldCacheField_isModified(field, &modified);
    ASSERT_TRUE(modified);

    ret = mamaFieldCache_destroy(fieldCache);
    mamaMsg_destroy(message);
}
Exemplo n.º 13
0
mama_status
msgUtils_createSubscriptionMessage(
    mamaSubscription  subscription,
    mamaSubscMsgType  subscMsgType,
    mamaMsg*          msg,
    const char*       issueSymbol)
{
    uint8_t appDataType = 0;
    char*   ipaddr;

    mama_status status = mamaMsg_create (msg);
    if (status != MAMA_STATUS_OK)
    {
        return status;
    }

    if (subscription != NULL)
    {
        mamaBridgeImpl* bridge = mamaSubscription_getBridgeImpl (subscription);
        const char* source = NULL;
        const char* symbol = NULL;
        mamaSubscriptionType type = MAMA_SUBSC_TYPE_NORMAL;

        mamaMsgImpl_useBridgePayload    (*msg, bridge);

        mamaSubscription_getSource      (subscription, &source);

        /* For group subs the issue symbol needs to be passed in as it
           is not the same as the subscribe symbol */
        if (issueSymbol)
        {
            symbol = issueSymbol;
        }
        else
        {
            mamaSubscription_getSubscSymbol (subscription, &symbol);
        }

        mamaSubscription_getSubscriptionType (subscription, &type);
        mamaSubscription_getAppDataType      (subscription, &appDataType);

        status = mamaMsgImpl_setSubscInfo (
            *msg,
            mamaSubscription_getSubscRoot (subscription),
            source,
            symbol,
            1);
        if (status != MAMA_STATUS_OK)
            return status;


        status = mamaMsg_addI32 (
            *msg,
            MamaFieldSubscriptionType.mName,
            MamaFieldSubscriptionType.mFid,
            type);
        if (status != MAMA_STATUS_OK)
            return status;
    }

    status = mamaMsg_addI32 (
        *msg,
        MamaFieldSubscMsgType.mName,
        MamaFieldSubscMsgType.mFid,
        subscMsgType);
    if (status != MAMA_STATUS_OK)
    {
        return status;
    }

    status = mamaMsg_addU8 (
        *msg,
        MamaFieldAppDataType.mName,
        MamaFieldAppDataType.mFid,
        appDataType);
    if (status != MAMA_STATUS_OK)
    {
        return status;
    }

#ifndef IGNORE_DEPRECATED_FIELDS
    status = mamaMsg_addI32 (
        *msg,
        MamaFieldSubscMsgTypeOld.mName,
        MamaFieldSubscMsgTypeOld.mFid,
        subscMsgType);
    if (status != MAMA_STATUS_OK)
        return status;
#endif

    mama_getIpAddress ((const char**)&ipaddr);

    if (ipaddr != NULL && strlen( ipaddr ) > 0)
    {
        status = mamaMsg_addString (
            *msg,
            MamaFieldSubscSourceHost.mName,
            MamaFieldSubscSourceHost.mFid,
            ipaddr);
        if (status != MAMA_STATUS_OK)
            return status;
    }

    return MAMA_STATUS_OK;
}
Exemplo n.º 14
0
void populateMessageFromDictionary (mamaDictionaryImpl* impl,
                                    mamaMsg             msg)
{
    int         i      = 0;
    mama_status status = MAMA_STATUS_OK;

    const mama_bool_t bool_vector[] = {0};
    const char char_vector[] = {' '};
    const mama_i8_t i8_vector[] = {1};
    const mama_u8_t u8_vector[] = {1};
    const mama_i16_t i16_vector[] = {1};
    const mama_u16_t u16_vector[] = {1};
    const mama_i32_t i32_vector[] = {1};
    const mama_u32_t u32_vector[] = {1};
    const mama_i64_t i64_vector[] = {1};
    const mama_u64_t u64_vector[] = {1};
    const mama_f32_t f32_vector[] = {1.0f};
    const mama_f64_t f64_vector[] = {1.0};
    const char*      string_vector[] = {" "};

    mamaMsg msgArray[1];
    mamaMsg tempMsg   =   NULL;

    mamaPrice price_vector[1];
    mamaPrice price = NULL;

    mamaDateTime dateTime_vector[1];
    mamaDateTime dateTime = NULL;


    mamaMsg_create (&tempMsg);
    mamaMsg_addI32 (tempMsg, NULL, 1, 0);
    msgArray[0] = tempMsg;

    mamaPrice_create (&price);
    mamaPrice_setValue (price,123.45);
    price_vector[0] = price;

    mamaDateTime_create (&dateTime);
    mamaDateTime_setToNow (dateTime);
    dateTime_vector[0] = dateTime;
    
    for (i=0;i<impl->mDictSize;i++)
    {
        if (impl->mDict[i])
        {
            mamaFieldDescriptor fd = impl->mDict[i];
            mama_fid_t      fid     = mamaFieldDescriptor_getFid  (fd);
            const char*     name    = mamaFieldDescriptor_getName (fd);
            mamaFieldType   type    = mamaFieldDescriptor_getType (fd);

            switch (type)
            {
                case MAMA_FIELD_TYPE_MSG:
                    ADD_TO_DICT (Msg, tempMsg);
                    break;
                case MAMA_FIELD_TYPE_OPAQUE:
                    mamaMsg_addOpaque (msg, name, fid, (void*)" ", 2);
                    break;
                case MAMA_FIELD_TYPE_STRING:
                    ADD_TO_DICT (String, "");
                    break;
                case MAMA_FIELD_TYPE_BOOL:
                    ADD_TO_DICT (Bool, 0);
                    break;
                case MAMA_FIELD_TYPE_CHAR:
                    ADD_TO_DICT (Char, ' ');
                    break;
                case MAMA_FIELD_TYPE_I8:
                    ADD_TO_DICT (I8, 0);
                    break;
                case MAMA_FIELD_TYPE_U8:
                    ADD_TO_DICT (U8, 0);
                    break;
                case MAMA_FIELD_TYPE_I16:
                    ADD_TO_DICT (I16, 0);
                    break;
                case MAMA_FIELD_TYPE_U16:
                    ADD_TO_DICT (U16, 0);
                    break;
                case MAMA_FIELD_TYPE_I32:
                    ADD_TO_DICT (I32, 0);
                    break;
                case MAMA_FIELD_TYPE_U32:
                    ADD_TO_DICT (U32, 0);
                    break;
                case MAMA_FIELD_TYPE_I64:
                    ADD_TO_DICT (I64, 0);
                    break;
                case MAMA_FIELD_TYPE_U64:
                    ADD_TO_DICT (U64, 0);
                    break;
                case MAMA_FIELD_TYPE_F32:
                    ADD_TO_DICT (F32, 0.0f);
                    break;
                case MAMA_FIELD_TYPE_F64:
                    ADD_TO_DICT (F64, 0.0);
                    break;
                case MAMA_FIELD_TYPE_TIME:
                    ADD_TO_DICT (DateTime, dateTime);
                    break;
                case MAMA_FIELD_TYPE_PRICE:
                    ADD_TO_DICT (Price, price);
                    break;
                case MAMA_FIELD_TYPE_VECTOR_BOOL:
                    ADD_VECTOR_TO_DICT (Bool, bool_vector);
                    break;
                case MAMA_FIELD_TYPE_VECTOR_CHAR:
                    ADD_VECTOR_TO_DICT (Char, char_vector);
                    break;
                case MAMA_FIELD_TYPE_VECTOR_I8:
                    ADD_VECTOR_TO_DICT (I8, i8_vector);
                    break;
                case MAMA_FIELD_TYPE_VECTOR_U8:
                    ADD_VECTOR_TO_DICT (U8, u8_vector);
                    break;
                case MAMA_FIELD_TYPE_VECTOR_I16:
                    ADD_VECTOR_TO_DICT (I16, i16_vector);
                    break;
                case MAMA_FIELD_TYPE_VECTOR_U16:
                    ADD_VECTOR_TO_DICT (U16, u16_vector);
                    break;
                case MAMA_FIELD_TYPE_VECTOR_I32:
                    ADD_VECTOR_TO_DICT (I32, i32_vector);
                    break;
                case MAMA_FIELD_TYPE_VECTOR_U32:
                    ADD_VECTOR_TO_DICT (U32, u32_vector);
                    break;
                case MAMA_FIELD_TYPE_VECTOR_I64:
                    ADD_VECTOR_TO_DICT (I64, i64_vector);
                    break;
                case MAMA_FIELD_TYPE_VECTOR_U64:
                    ADD_VECTOR_TO_DICT (U64, u64_vector);
                    break;
                case MAMA_FIELD_TYPE_VECTOR_F32:
                    ADD_VECTOR_TO_DICT (F32, f32_vector);
                    break;
                case MAMA_FIELD_TYPE_VECTOR_F64:
                    ADD_VECTOR_TO_DICT (F64, f64_vector);
                    break;
                case MAMA_FIELD_TYPE_VECTOR_STRING:
                    ADD_VECTOR_TO_DICT (String, string_vector);
                    break;
                case MAMA_FIELD_TYPE_VECTOR_MSG:
                    ADD_VECTOR_TO_DICT (Msg, msgArray);
                    break;
                case MAMA_FIELD_TYPE_VECTOR_TIME:
                    ADD_VECTOR_TO_DICT (DateTime, dateTime_vector);
                    break;
                case MAMA_FIELD_TYPE_VECTOR_PRICE:
                    ADD_VECTOR_TO_DICT (Price, price_vector);
                    break;
                default:
					/* error with unknown type */
                    mama_log (MAMA_LOG_LEVEL_NORMAL, "Could not add type to "
                              "dict message - not supported. [%s] fid=%d name=%s",
                              mamaFieldTypeToString (type), fid, name);
                    break;
            }
        }
    }

    mamaPrice_destroy (price);
    mamaDateTime_destroy (dateTime);
    mamaMsg_destroy (tempMsg);
}