C 框架代码

以下是 C 用户定义的节点的框架代码。它具有成功编译用户定义的节点所需的最少内容。
#ifdef __WIN32__
#include <windows.h>
#endif
#include <BipCos.h>
#include <BipCci.h>
#include <BipCni.h>
#include <cstring>
#include <malloc.h>
#include <stdlib.h>
#include <stdio.h>
#define BIP_DEF_COMP_CCSID 437
CciChar* constNodeFactory = 0;
CciChar* constNodeName    = 0;
CciChar* constTerminalName    = 0;
CciChar* constOutTerminalName    = 0;
CciChar* CciString(
const char* source,
int         codepage
){
/* Maximum number of characters in Unicode representation */
int maxChars = strlen(source) + 1 ;
CciChar* buffer = (CciChar*)malloc(maxChars * sizeof(CciChar)) ;
int rc;
cciMbsToUcs(&rc, source, buffer, maxChars, codepage) ;
return buffer ;
}
void initNodeConstants(){
constNodeFactory       = CciString("myNodeFactory", BIP_DEF_COMP_CCSID);  
constNodeName          = CciString("myNode",BIP_DEF_COMP_CCSID);  
constTerminalName      = CciString("in",BIP_DEF_COMP_CCSID);  
constOutTerminalName   = CciString("out",BIP_DEF_COMP_CCSID);  
}
struct MyNodeContext {
CciTerminal* iOutTerminal;
};
CciContext* createNodeContext(
  CciFactory* factoryObject,
  CciChar*    nodeName,
  CciNode*    nodeObject
){
MyNodeContext * p = (MyNodeContext *)malloc(sizeof(MyNodeContext));
/*here we would create an instance of some data structure
where we could store context about this node instance. 
We would return a pointer to this struct and that pointer 
will be passed to our other implementation functions */
/* now we create an input terminal for the node*/
cniCreateInputTerminal(NULL, nodeObject, (CciChar*)constTerminalName);
p->iOutTerminal = cniCreateOutputTerminal(NULL, nodeObject, (CciChar*)constOutTerminalName);
return((CciContext*)p);
}
/****************************************************************/
/* */
/* Plugin Node Implementation Function:           cniEvaluate() */
/* */
/****************************************************************/
void evaluate(
  CciContext* context,                
  CciMessage* destinationList,        
  CciMessage* exceptionList,          
  CciMessage* message                 
){
/* we would place our node's processing logic in here*/
  return;
}
int run(
  CciContext* context,                
  CciMessage* destinationList,        
  CciMessage* exceptionList,          
  CciMessage* message                 
)
{
char* buffer="<doc><test>hello</test></doc>";
CciChar* wBuffer=CciString(buffer,BIP_DEF_COMP_CCSID);
//cniSetInputBuffer(NULL,message,(void*)wBuffer,strlen(buffer) * sizeof(CciChar));
cniSetInputBuffer(NULL,message,(void*)buffer,strlen(buffer));
cniFinalize(NULL,message,0);
cniPropagate(NULL,((MyNodeContext*)context)->iOutTerminal,destinationList,exceptionList,message);
  return CCI_SUCCESS_CONTINUE;                                    
}
#ifdef __cplusplus
extern "C"{
#endif
CciFactory LilFactoryExportPrefix * LilFactoryExportSuffix bipGetMessageflowNodeFactory()
{
	CciFactory* factoryObject;
/* Before we proceed we need to initialize all the static constants */
  /* that may be used by the plug-in.                                 */
initNodeConstants();
/* Create the Node Factory for this plug-in */
/* If any errors/exceptions    */
/* occur during the execution of this utility function, then as we have not */
/* supplied the returnCode argument, the exception will bypass the plugin   */
/* and be directly handled by the broker. */
factoryObject = cniCreateNodeFactory(0, (unsigned short *)constNodeFactory);
	if (factoryObject == CCI_NULL_ADDR) {
		/* Any further local error handling can go here */
}
else {
/* Define the node supported by this factory */
static CNI_VFT vftable = {CNI_VFT_DEFAULT};
	/* Setup function table with pointers to node implementation functions */
vftable.iFpCreateNodeContext = createNodeContext;
vftable.iFpEvaluate          = evaluate;
vftable.iFpRun               = run;
/* Define a node type supported by our factory. If any errors/exceptions    */
/* occur during the execution of this utility function, then as we have not */
/* supplied the returnCode argument, the exception will bypass the plugin   */
/* and be directly handled by the broker. */
cniDefineNodeClass(NULL, factoryObject, (CciChar*)constNodeName, &vftable);
}
  /* Return address of this factory object to the broker */
	return(factoryObject);
}
#ifdef __cplusplus
}
#endif

GNU makefile

以下是列出文件、依赖性和编译 C 用户定义的节点所依据的规则的 Makefile。

.SUFFIXES : .so .a .o .c
R1INC = .
R1LIB = .
# WMQI
MQSIDIR = /cmvc/back/inst.images/x86_linux_2/shipdata/opt/mqsi
MQSIINC		= $(MQSIDIR)/include
MQSILIB		= $(MQSIDIR)/lib
# WMQ 
MQIDIR = /usr/mqm
CC = /usr/bin/g++
LD = ${CC}
OBJ = .o
LIL = .lil
THINGSTOCLEAN = *${OBJ}
CFLAGS		= -fpic -c #-pedantic -x c -Wall
CFLAGSADD	= -I${R1INC} -I${MQSIINC} -I${MQSIINC}/plugin ${DEFINES}
DEFINES = -DLINUX
LIBADD		= -L${MQSILIB} -limbdfplg 
LDFLAG		= -shared ${LIBADD}
#CC = /usr/bin/gcc
#LD = ${CC}
OBJECTS = skeleton${OBJ}
.c.o : ; ${CC} ${CFLAGS} ${CFLAGSADD} $<
ALL : ${OBJECTS} Samples${LIL}
clean: 
	rm *${OBJ} *${LIL}
skeleton${OBJ}:	skeleton.c
Samples${LIL}: ${OBJECTS}
${LD} -o $@ ${OBJECTS} ${LDFLAG}
相关任务
使用 C 创建用户定义的扩展
相关参考
C 语言用户定义的解析器 API
C 语言用户定义的节点 API
C 通用实施函数
C 通用实用程序函数
声明 | 商标 | 下载 | | 支持 | 反馈
Copyright IBM Corporation 1999, 2006 最后更新:2006/05/19
as24982_