当前位置: 首页>>代码示例>>C++>>正文


C++ CallbackInfo::dataTemplateCallbackFunction方法代码示例

本文整理汇总了C++中CallbackInfo::dataTemplateCallbackFunction方法的典型用法代码示例。如果您正苦于以下问题:C++ CallbackInfo::dataTemplateCallbackFunction方法的具体用法?C++ CallbackInfo::dataTemplateCallbackFunction怎么用?C++ CallbackInfo::dataTemplateCallbackFunction使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在CallbackInfo的用法示例。


在下文中一共展示了CallbackInfo::dataTemplateCallbackFunction方法的2个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C++代码示例。

示例1: dbReaderSendNewTemplate

/**
 * Constructs a template from the table data and sends it to all connected
 * modules.
 */
int dbReaderSendNewTemplate(IpfixDbReader* ipfixDbReader,DataTemplateInfo* dataTemplateInfo, int table_index)
{
    int i,n;
    int fieldLength  = 0;

    DbReader* dbReader = ipfixDbReader->dbReader;
    DbData* dbData = dbReader->dbData;
    
    dataTemplateInfo->id =0;
    dataTemplateInfo->preceding= 0;	
    dataTemplateInfo->fieldCount = 0;
    dataTemplateInfo->fieldInfo = NULL;
    dataTemplateInfo->dataCount = 0;
    dataTemplateInfo->dataInfo = NULL;
    dataTemplateInfo->data = NULL;
    dataTemplateInfo->userData = NULL;
        
    /**get columnsname of the table*/
    if(getColumns(ipfixDbReader, table_index) != 0) {
        msg(MSG_ERROR,"IpfixDbReader: Could not get columns for template");
        return 1;
    }

    for(i = 0; i < dbData->colCount; i++) {			
        dataTemplateInfo->fieldCount++;
        dataTemplateInfo->fieldInfo = realloc(dataTemplateInfo->fieldInfo,
                              sizeof(FieldInfo)*dataTemplateInfo->fieldCount);
        FieldInfo* fi = &dataTemplateInfo->fieldInfo[dataTemplateInfo->fieldCount - 1];	
        fi->type.id = dbData->columns[i]->ipfixId;
        fi->type.length = dbData->columns[i]->length;
        fi->type.eid = 0;
        fi->offset = fieldLength;
        fieldLength = fieldLength + fi->type.length; 
    }

    for (n = 0; n != dbReader->callbackCount; n++) {
        CallbackInfo* ci = &dbReader->callbackInfo[n];
        if (ci->dataTemplateCallbackFunction) {
            ci->dataTemplateCallbackFunction(ci->handle, &ipfixDbReader->srcId,
                             dataTemplateInfo);
            msg(MSG_DEBUG,"IpfixDbReader sent template for table %s", dbData->tableNames[table_index]);
        }
    }
    return 0;
}
开发者ID:BackupTheBerlios,项目名称:vermont-svn,代码行数:49,代码来源:IpfixDbReader.c

示例2: processDataTemplateSet

/**
 * Processes an IPFIX DataTemplate set.
 * Called by processMessage
 */
static void processDataTemplateSet(IpfixReceiver* ipfixReceiver, SourceID sourceId, IpfixSetHeader* set) {
    IpfixDataTemplateHeader* th = (IpfixDataTemplateHeader*)&set->data;
    byte* endOfSet = (byte*)set + ntohs(set->length);
    byte* record = (byte*)&th->data;

    /* DataTemplateSets are >= 4 byte, so we stop processing when only 3 bytes are left */
    while (record < endOfSet - 3) {
        BufferedTemplate* bt = (BufferedTemplate*)malloc(sizeof(BufferedTemplate));
        DataTemplateInfo* ti = (DataTemplateInfo*)malloc(sizeof(DataTemplateInfo));
        bt->sourceID = sourceId;
        bt->templateID = ntohs(th->templateId);
        bt->recordLength = 0;
        bt->setID = ntohs(set->id);
        bt->dataTemplateInfo = ti;
        ti->userData = 0;
        ti->fieldCount = ntohs(th->fieldCount);
        ti->dataCount = ntohs(th->dataCount);
        ti->fieldInfo = (FieldInfo*)malloc(ti->fieldCount * sizeof(FieldInfo));
        int isLengthVarying = 0;
        uint16_t fieldNo;
        for (fieldNo = 0; fieldNo < ti->fieldCount; fieldNo++) {
            ti->fieldInfo[fieldNo].type.id = ntohs(*(uint16_t*)((byte*)record+0));
            ti->fieldInfo[fieldNo].type.length = ntohs(*(uint16_t*)((byte*)record+2));
            ti->fieldInfo[fieldNo].offset = bt->recordLength; bt->recordLength+=ti->fieldInfo[fieldNo].type.length;
            if (ti->fieldInfo[fieldNo].type.length == 65535) isLengthVarying=1;
            if (ti->fieldInfo[fieldNo].type.id & 0x80) {
                ti->fieldInfo[fieldNo].type.eid = ntohl(*(uint32_t*)((byte*)record+4));
                record = (byte*)((byte*)record+8);
                } else {
                ti->fieldInfo[fieldNo].type.eid = 0;
                record = (byte*)((byte*)record+4);
                }
            }
        if (isLengthVarying) {
            bt->recordLength = 65535;
            for (fieldNo = 0; fieldNo < ti->fieldCount; fieldNo++) ti->fieldInfo[fieldNo].offset = 65535;
            }

        ti->dataInfo = (FieldInfo*)malloc(ti->fieldCount * sizeof(FieldInfo));
        for (fieldNo = 0; fieldNo < ti->dataCount; fieldNo++) {
            ti->dataInfo[fieldNo].type.id = ntohs(*(uint16_t*)((byte*)record+0));
            ti->dataInfo[fieldNo].type.length = ntohs(*(uint16_t*)((byte*)record+2));
            if (ti->dataInfo[fieldNo].type.id & 0x80) {
                ti->dataInfo[fieldNo].type.eid = ntohl(*(uint32_t*)((byte*)record+4));
                record = (byte*)((byte*)record+8);
                } else {
                ti->dataInfo[fieldNo].type.eid = 0;
                record = (byte*)((byte*)record+4);
                }
            }
        
        /* done with reading dataInfo, @c record now points to the fixed data block */
        byte* dataStart = record;
        
        int dataLength = 0;
        for (fieldNo = 0; fieldNo < ti->dataCount; fieldNo++) {
            ti->dataInfo[fieldNo].offset = dataLength;
            if (ti->dataInfo[fieldNo].type.length == 65535) {
                /* This is a variable-length field, get length from first byte and advance offset */
                ti->dataInfo[fieldNo].type.length = *(uint8_t*)(dataStart + ti->dataInfo[fieldNo].offset);
                ti->dataInfo[fieldNo].offset += 1;
                if (ti->dataInfo[fieldNo].type.length == 255) {
                    /* First byte did not suffice, length is stored in next two bytes. Advance offset */
                    ti->dataInfo[fieldNo].type.length = *(uint16_t*)(dataStart + ti->dataInfo[fieldNo].offset);
                    ti->dataInfo[fieldNo].offset += 2;
                    }
                }
            dataLength += ti->dataInfo[fieldNo].type.length;
            }
            
        /* Copy fixed data block */
        ti->data = (byte*)malloc(dataLength);
        memcpy(ti->data,dataStart,dataLength);

        /* Advance record to end of fixed data block, i.e. start of next template*/
        record += dataLength;
        
        bufferTemplate(ipfixReceiver->templateBuffer, bt); 
        // FIXME: Template expiration disabled for debugging
        // bt->expires = time(0) + TEMPLATE_EXPIRE_SECS;

        int n;		
        for (n = 0; n < ipfixReceiver->callbackCount; n++) {
            CallbackInfo* ci = &ipfixReceiver->callbackInfo[n];
            if (ci->dataTemplateCallbackFunction) ci->dataTemplateCallbackFunction(ci->handle, sourceId, ti);
            }
  		}
    }
开发者ID:BackupTheBerlios,项目名称:vermont-svn,代码行数:92,代码来源:rcvIpfix.c


注:本文中的CallbackInfo::dataTemplateCallbackFunction方法示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。