コード例 #1
0
ファイル: capturereplayc.c プロジェクト: OpenMAMA/OpenMAMA
static void MAMACALLTYPE 
subscriptionHandlerOnNewRequestCb (mamaDQPublisherManager manager,
                                   const char*            symbol,
                                   short                  subType,
                                   short                  msgType,
                                   mamaMsg                msg)
{
    int index = 0;
    char* headerString;
    char *temp;
    char * source;
    mamaMsg newMessage;

    for (index=0; index < gNumSymbols; index++)
    {
       if (strcmp (gSubscriptionList[index].symbol, symbol) == 0)
            break;
    }

    if (index == gNumSymbols)
    {
       mama_log  (MAMA_LOG_LEVEL_WARN, 
                  "Received request for unknown symbol: %s", 
                  symbol);
        return;
    }

    mama_log (MAMA_LOG_LEVEL_NORMAL, 
              "Received new request: %s", 
              symbol);

    mamaDQPublisherManager_createPublisher (manager, symbol, (void*)&gSubscriptionList[index], &gSubscriptionList[index].pub);
    mamaPlaybackFileParser_allocate (&gSubscriptionList[index].fileParser);
    mamaPlaybackFileParser_openFile(gSubscriptionList[index].fileParser, (char*)gFilename);
    mamaMsg_create(&gSubscriptionList[index].cachedMsg);

    while (mamaPlaybackFileParser_getNextHeader(gSubscriptionList[index].fileParser, &headerString))
    {
        /* skip source and transport name */
        temp = strchr (headerString,DELIM);
        temp++;
        source = strchr (temp,DELIM);
        source++; /* skip : */

        temp = strchr (source,DELIM);
        if ((strncmp (gSubscriptionList[index].symbol, source, temp-source) == 0) && (strlen(gSubscriptionList[index].symbol) == temp-source))
                break;
        mamaPlaybackFileParser_getNextMsg (gSubscriptionList[index].fileParser,
                                                    &newMessage);
    }

    if (mamaPlaybackFileParser_getNextMsg (gSubscriptionList[index].fileParser,
                                            &newMessage))
    {
        mamaMsg_applyMsg (gSubscriptionList[index].cachedMsg, newMessage);

        switch (msgType)
        {
        case MAMA_SUBSC_SUBSCRIBE:
        case MAMA_SUBSC_SNAPSHOT:
            if (subType == MAMA_SUBSC_TYPE_BOOK)
            {
                mamaMsg_updateU8 (gSubscriptionList[index].cachedMsg, 
                                  NULL,
                                  MamaFieldMsgType.mFid, 
                                  MAMA_MSG_TYPE_BOOK_INITIAL);
            } else {
                mamaMsg_updateU8 (gSubscriptionList[index].cachedMsg, 
                                  NULL,
                                  MamaFieldMsgType.mFid, 
                                  MAMA_MSG_TYPE_INITIAL);
            }
            mamaDQPublisher_sendReply (gSubscriptionList[index].pub, msg,
                                       gSubscriptionList[index].cachedMsg);
            break;
        default:
            mama_log (MAMA_LOG_LEVEL_NORMAL, "Publishing MAMA_MSG_TYPE_RECAP");
            mamaMsg_updateU8 (gSubscriptionList[index].cachedMsg, 
                              NULL,
                              MamaFieldMsgType.mFid, 
                              MAMA_MSG_TYPE_RECAP);

            mamaDQPublisher_send (gSubscriptionList[index].pub,
                                  gSubscriptionList[index].cachedMsg);
            break;
        }
    }

}
コード例 #2
0
ファイル: capturereplayc.c プロジェクト: OpenMAMA/OpenMAMA
static void readSymbolsFromFile (void)
{
    mamaPlaybackFileParser  fileParser;
    char*                   headerString    = NULL;
    char*                   temp            = NULL;
    char*                   source          = NULL;
    int                     symbolIndex     = 0;
    int                     i               = 0;
    int                     iterations      = 0;
    mamaMsg                 newMessage;

    gSubscriptionList = (pubCache*)calloc (MAX_SUBSCRIPTIONS,
                                                   sizeof (pubCache));

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

    mama_log (MAMA_LOG_LEVEL_NORMAL, "Continuing.");
    while (mamaPlaybackFileParser_getNextHeader (fileParser, &headerString))
    {
        if (mamaPlaybackFileParser_getNextMsg (fileParser,
                                                &newMessage))
        {
            temp = strchr (headerString,DELIM);
            temp++;
            source = strchr (temp,DELIM);
            source++;

            temp = strchr (source,DELIM);

            for (i=0;i<symbolIndex;i++)
            {
                int res = strncmp (gSubscriptionList[i].symbol, source, temp-source);

                 if (( res == 0)  && (strlen(gSubscriptionList[i].symbol) == temp-source))
                   break;
            }
            if (i==symbolIndex)
            {
                gSubscriptionList[symbolIndex].symbol = (char*)calloc (temp-source+1,
                                                       sizeof (char));
                gSubscriptionList[symbolIndex].index = symbolIndex;
                strncpy (gSubscriptionList[symbolIndex].symbol, source, temp-source);
                symbolIndex++;

                if (0 == (symbolIndex % 20))
                {
                    mama_log (MAMA_LOG_LEVEL_NORMAL, 
                              "Read %d symbols from playback file.",
                              symbolIndex);
                    mama_log (MAMA_LOG_LEVEL_NORMAL,
                              "Continuing.");
                }
            }

            /*
             * Just some additional logging to help make it clear the application
             * hasn't frozen when processing large files.
             */
            iterations++;
            if (0 == (iterations % 5000))
            {
                printf (".");
                fflush (stdout);

                if (0 == (iterations % 50000))
                {
                    printf(".\n");
                    mama_log (MAMA_LOG_LEVEL_NORMAL, "Continuing.");
                }
            }
        }
    }
    gNumSymbols = symbolIndex;

    /* End logging. */
    mama_log (MAMA_LOG_LEVEL_NORMAL, 
              "Symbols read from playback file. Total symbols:\t%d", 
              gNumSymbols);

    mamaPlaybackFileParser_closeFile  (fileParser);
    mamaPlaybackFileParser_deallocate (fileParser);
}
コード例 #3
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);
}