この関数は、名前付きパーサー・ファクトリーの単一のインスタンスをブローカーに作成します。
これは、ブローカーによって LIL ファイルがロードされる際に呼び出される初期化関数 bipGetParserFactory の中でしか呼び出すことができません。 後で cpiCreateParserFactory が呼び出されても、結果は予測不可能です。
CciFactory* cpiCreateParserFactory(
int* returnCode,
CciChar* name);
成功した場合、パーサー・ファクトリー・オブジェクトのアドレスが戻されます。 正常に実行されない場合は、ゼロの値 (CCI_NULL_ADDR) が戻され、 returnCode がエラーの理由を示します。
この例は、サンプル・パーサー・ファイル BipSampPluginParser.c から取られています。
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);
}