在消息代理中创建指定的解析器工厂的单个实例。只有在初始化函数 bipGetParserFactory 中才必须对它进行调用,当消息代理装入“lil”时会调用此初始化函数。如果在任何其他时间调用 cpiCreateParserFactory,则结果是不可预测的。
CciFactory* cpiCreateParserFactory( int* returnCode, CciChar* name);
如果成功,返回解析器工厂对象的地址。否则,返回零值(CCI_NULL_ADDR),并且 returnCode 参数表明错误的原因。
此示例取自样本解析器文件 BipSampPluginParser.c(862 行到 901 行):
void LilFactoryExportPrefix * LilFactoryExportSuffix bipGetParserFactory() { /* Declare variables */ CciFactory* factoryObject; int rc; static CPI_VFT vftable = {CPI_VFT_DEFAULT}; /* Before we proceed we need to initialise all the static constants */ /* that may be used by the plug-in. */ initParserConstants(); /* Setup function table with pointers to parser implementation functions */ vftable.iFpCreateContext = cpiCreateContext; vftable.iFpParseBufferEncoded = cpiParseBufferEncoded; vftable.iFpParseFirstChild = cpiParseFirstChild; vftable.iFpParseLastChild = cpiParseLastChild; vftable.iFpParsePreviousSibling = cpiParsePreviousSibling; vftable.iFpParseNextSibling = cpiParseNextSibling; vftable.iFpWriteBufferEncoded = cpiWriteBufferEncoded; vftable.iFpDeleteContext = cpiDeleteContext; vftable.iFpSetElementValue = cpiSetElementValue; vftable.iFpElementValue = cpiElementValue; vftable.iFpNextParserClassName = cpiNextParserClassName; vftable.iFpSetNextParserClassName = cpiSetNextParserClassName; vftable.iFpNextParserEncoding = cpiNextParserEncoding; vftable.iFpNextParserCodedCharSetId = cpiNextParserCodedCharSetId; /* Create the parser factory for this plugin */ factoryObject = cpiCreateParserFactory(&rc, constParserFactory); if (factoryObject) { /* Define the classes of message supported by the factory */ cpiDefineParserClass(&rc, factoryObject, constPXML, &vftable); } else { /* Error: Unable to create parser factory */ } /* Return address of this factory object to the broker */ return(factoryObject); }