Beispiel #1
0
static void MAMACALLTYPE
sendRecap     (mamaQueue queue, void* closure)
{
    recapInfo* info = (recapInfo*) closure;


    mamaMsg_updateU8(gSubscriptionList[info->index].cachedMsg, NULL, MamaFieldMsgType.mFid, MAMA_MSG_TYPE_INITIAL);

    if (info->msg)
    {
        mamaDQPublisher_sendReply(gSubscriptionList[info->index].pub, info->msg, gSubscriptionList[info->index].cachedMsg);
        mamaMsg_destroy( info->msg);

    }
    else
        mamaDQPublisher_send(gSubscriptionList[info->index].pub, gSubscriptionList[info->index].cachedMsg);


    free (info);
}
Beispiel #2
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;
}
Beispiel #3
0
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;
        }
    }

}
Beispiel #4
0
static void prepareDictionaryListener (void)
{
    mama_status      status                     = MAMA_STATUS_OK;
    mamaMsgCallbacks dictionarySubCallbacks;

    dictionarySubCallbacks.onCreate       = dictionarySubOnCreate;
    dictionarySubCallbacks.onDestroy      = dictionarySubOnDestroy;
    dictionarySubCallbacks.onError        = dictionarySubOnError;
    dictionarySubCallbacks.onMsg          = dictionarySubOnMsg;

    /* Basic subscription so these are set to NULL */
    dictionarySubCallbacks.onQuality      = NULL;
    dictionarySubCallbacks.onGap          = NULL;
    dictionarySubCallbacks.onRecapRequest = NULL;

    status = mamaSubscription_allocate (&gDictionarySubscription);
    if (MAMA_STATUS_OK != status) 
    {
        mama_log (MAMA_LOG_LEVEL_ERROR,
                  "Could not allocate dictionary subscription.");
        exit (1);
    }

    status = mamaSubscription_createBasic (gDictionarySubscription, 
                                           gPubTransport,
                                           gPubDefaultQueue, 
                                           &dictionarySubCallbacks,
                                           "_MDDD.WOMBAT.DATA_DICT", 
                                           NULL);
    if (status != MAMA_STATUS_OK) 
    {
        mama_log (MAMA_LOG_LEVEL_ERROR, 
                  "Could not create dictionary subscription");
        exit (1);
    }

    /* Create the Dictionary Object */
    mamaDictionary_create           (&gDictionary);
    mamaDictionary_populateFromFile (gDictionary, gDictionaryFile);

    /* Create Dictionary Response Message */
    status = mamaDictionary_getDictionaryMessage (gDictionary,
                                                  &gDictionaryMessage);
    if (MAMA_STATUS_OK != status)
    {
        mama_log (MAMA_LOG_LEVEL_ERROR,
                  "Failed to allocate dictionary message.");
        exit (1);
    }

    /* Build dictionary publisher */
    status = mamaPublisher_create (&gDictionaryPublisher,
                                   gPubTransport,
                                   "WOMBAT.DATA_DICT",
                                   NULL, 
                                   NULL);

    if (MAMA_STATUS_OK != status)
    {
        mama_log (MAMA_LOG_LEVEL_ERROR,
                  "Failed to create dictionary publisher.");
        exit (1);
    }

    status = mamaMsg_updateU8 (gDictionaryMessage,
                               MamaFieldMsgType.mName,
                               MamaFieldMsgType.mFid,
                               MAMA_MSG_TYPE_INITIAL);

    if (MAMA_STATUS_OK != status)
    {
        mama_log (MAMA_LOG_LEVEL_ERROR,
                  "Failed to update dictionary message.");
        exit (1);
    }
}