Esempio n. 1
0
/*  Description: Create a mamaDictionary from a file and write to a msg.
 *  The dictionary file includes a field type of UNKNOWN, which is logged with name and fid.
 *                   
 *  Expected Result: MAMA_STATUS_OK
 */
TEST_F (MamaDictionaryTestC, LoadFromFileAndWriteToMsg)
{
    mamaDictionary dictionary;
    mamaMsg msg;
    char buf[1024];
    const char* path = getenv("WOMBAT_PATH");
    size_t dictionarySize;
    size_t msgSize;
    
    ASSERT_EQ (MAMA_STATUS_OK, mamaDictionary_create(&dictionary));

    ASSERT_NE (path, (const char*) NULL);
    snprintf(buf, sizeof(buf), "%s/dictionary1.txt", path);
    ASSERT_EQ (MAMA_STATUS_OK, mamaDictionary_populateFromFile(dictionary, buf));

    ASSERT_EQ (MAMA_STATUS_OK, mamaDictionary_getDictionaryMessage(dictionary, &msg));

    ASSERT_EQ (MAMA_STATUS_OK, mamaDictionary_getSize(dictionary, &dictionarySize));

    ASSERT_EQ (MAMA_STATUS_OK, mamaMsg_getNumFields(msg, &msgSize));

    /* Expect one less in msg since there is an unknown in the dictionary */
    ASSERT_EQ (dictionarySize-1, msgSize);

    ASSERT_EQ (MAMA_STATUS_OK, mamaMsg_destroy(msg));

    ASSERT_EQ (MAMA_STATUS_OK, mamaDictionary_destroy(dictionary));
}
void DictionaryImpl::populateFromFile (const char* fileName)
{
    if (!mDictionary)
    {
        mamaTry(mamaDictionary_create(&mDictionary));
    }
    
    mamaTry (mamaDictionary_populateFromFile (mDictionary, fileName));
}
void DictionaryImpl::setMaxFid (
        mama_size_t          maxFid)
{
    /*Create the underlying dictionary if required.*/
    if (!mDictionary)
        mamaTry(mamaDictionary_create(&mDictionary));

    mamaTry (mamaDictionary_setMaxFid (mDictionary, maxFid));
}
void DictionaryImpl::buildDictionaryFromMessage(MamaMsg& msg)
{
    if (!mDictionary)
    {
        mamaTry(mamaDictionary_create(&mDictionary));
        
        mamaTry(mamaDictionary_buildDictionaryFromMessage(
             mDictionary,msg.getUnderlyingMsg()));
    }
    return;
}
MamaFieldDescriptor* DictionaryImpl::createFieldDescriptor (
        mama_fid_t             fid,
        const char*            name,
        mamaFieldType          type)
{
    mamaFieldDescriptor newDescriptor = NULL;

    /*Create the underlying dictionary if required.*/
    if (!mDictionary)
        mamaTry(mamaDictionary_create(&mDictionary));

    mamaTry(mamaDictionary_createFieldDescriptor (mDictionary,
                                       fid,
                                       name,
                                       type,
                                       &newDescriptor));
    
    return getCppFieldDescriptor (newDescriptor);
}
Esempio n. 6
0
void MsgNewIteratorTestC::SetUp(void)
{
    mama_loadBridge (&mBridge, getMiddleware());
    mama_open();

    /* add a fields to the message. */
    mamaMsg_create    (&msg);
    mamaMsg_addU8     (msg, "u8", 101, 8);
    mamaMsg_addString (msg, "string", 102, "This is an iteration test.");
    mamaMsg_addU16    (msg, "u16", 103, 16);
    mamaMsg_addU32    (msg, "u32", 104, 32);
    mamaMsg_addU64    (msg, "u64", 105, 64);

    /* Build the MAMA Dictionary from our test message. */
    mamaDictionary_create (&dict);
    mamaDictionary_buildDictionaryFromMessage (dict, msg);

    /* Create the message iterator */
    mamaMsgIterator_create (&iterator, dict);
    mamaMsgIterator_associate (iterator, msg);
}
Esempio n. 7
0
void MsgNewIteratorTestC::SetUp(void)
{
    mama_loadBridge (&mBridge, getMiddleware());
    mama_open();

    /* add a fields to the message. */
    mamaMsg_create    (&msg);
    for (mama_fid_t f = 101; f < 106; f++)
    {
        char buf[64];
        sprintf (buf, "field_%u", f);
        int val = rand();
        mamaMsg_addU64 (msg, buf, f, val);
        values.insert(std::pair<mama_fid_t, uint64_t>(f, val));
    }

    /* Build the MAMA Dictionary from our test message. */
    mamaDictionary_create (&dict);
    mamaDictionary_buildDictionaryFromMessage (dict, msg);

    /* Create the message iterator */
    mamaMsgIterator_create (&iterator, dict);
    mamaMsgIterator_associate (iterator, msg);
}
Esempio n. 8
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);
    }
}