예제 #1
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);
}
예제 #2
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);
}