Esempio n. 1
0
mama_status
mamaDictionary_populateFromFile (
        mamaDictionary       dictionary,
        const char*          fileName)
{
    char                lineBuffer[256];
    FILE*               infile =   NULL;
    mamaDictionaryImpl* impl    =   (mamaDictionaryImpl*)dictionary;
    if (!impl) return MAMA_STATUS_NULL_ARG;

    if (MAMA_STATUS_OK!=openWombatFile (fileName, "r", &infile))
    {
        mama_log (MAMA_LOG_LEVEL_FINE, "Could not open file for reading [%s]",
                                        fileName);
        return MAMA_STATUS_IO_ERROR;
    }

    while (fgets (lineBuffer, 255, infile) != NULL)
    {
        mama_status status      = MAMA_STATUS_OK;
        char*       c           = lineBuffer;
        char*       fidStr      = NULL;
        char*       fieldName   = NULL;
        char*       typeStr     = NULL;

        /*Get rid of any newline characters*/
        stripTrailingWhiteSpace (lineBuffer);

        /*Validate the line - continue if invalid*/
        if (MAMA_STATUS_OK!=validateDelimLine (c))
            continue;

        /*First field is the fid*/
        fidStr = c;

        /*Second field is the field name*/
        fieldName = getNextDelimStr (c);

        /*Third field is the field type*/
        typeStr = getNextDelimStr (c);

        /*Add the descriptor to the dictionary*/
        if (MAMA_STATUS_OK!=(status=mamaDictionary_createFieldDescriptor
                                     (dictionary,
                                     atoi (fidStr),
                                     fieldName,
                                     atoi (typeStr),
                                     NULL)))
         {
            mama_log (MAMA_LOG_LEVEL_FINE, "Could not create field descriptor"
                    "from file. [%s] [%s]",fileName, lineBuffer);
            return status;
         }
    
    }
    fclose (infile);
    return MAMA_STATUS_OK;
}
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. 3
-1
static void MAMACALLTYPE
dictMsgIterator (const mamaMsg       msg,
                 const mamaMsgField  field,
                 void*               closure)
{
    mamaDictionaryImpl*  impl           = (mamaDictionaryImpl*) closure;
    const char*          fieldName      = NULL;
    mama_fid_t           fid            = 0;
    mamaFieldType        type           = 0;
    const char*          val            = NULL;

    mamaMsgField_getType(field,&type);
    mamaMsgField_getFid(field,&fid);
    mamaMsgField_getName(field,&fieldName);
    
    if (MamaFieldFeedName.mFid == fid)
    {
        if (MAMA_STATUS_OK == mamaMsg_getString (msg, fieldName, fid, &val))
        {
            checkFree(&impl->mFeedName);
            impl->mFeedName = copyString(val);
            mama_log ( MAMA_LOG_LEVEL_FINE,
                       "Dictionary source feed name: %s",
                       val);
        }
    }
    else if (MamaFieldFeedHost.mFid == fid)
    {
        if (MAMA_STATUS_OK == mamaMsg_getString (msg, fieldName, fid, &val))
        {
            checkFree(&impl->mFeedHost);
            impl->mFeedHost = copyString(val);
            mama_log ( MAMA_LOG_LEVEL_FINE,
                       "Dictionary source hostname: %s",
                       val);
        }
    }
    
    mamaDictionary_createFieldDescriptor (impl,
                                       fid,
                                       fieldName,
                                       type,
                                       NULL);
}