C のスケルトン・コード

変更の始まりC ユーザー定義ノードのスケルトン・コードを以下に示します。これは、ユーザー定義ノードを正常にコンパイルするために必要な最小限の内容しか含まれていません。
#ifdef __WIN32
#include <windows.h>
#endif
#include <BipCos.h>
#include <BipCci.h>
#include <BipCni.h>
#include <malloc.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);
}

typedef struct {
  CciTerminal* iOutTerminal;
}MyNodeContext;

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 Make ファイル

C ユーザー定義ノードをコンパイルするために使用されるファイル、依存関係、および規則をリストする Make ファイルを以下に示します。

.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 最終更新: 08/21/2006
as24982_