C skeleton code

Use the skeleton code that is supplied as guidance for your C user-defined node. The code has the minimum content that is required to compile a user-defined node successfully.

#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* localEnvironment,
  CciMessage* exceptionList,
  CciMessage* message
){
  /* we would place our node's processing logic in here*/
  return;
}

int run(
  CciContext* context,
  CciMessage* localEnvironment,
  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,localEnvironment,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 might 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 integration node.                                   */
  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 integration node.                                   */
    cniDefineNodeClass(NULL, factoryObject, (CciChar*)constNodeName, &vftable);
    
  }

  /* Return address of this factory object to the integration node */
  return(factoryObject);
}
#ifdef __cplusplus
}
#endif


GNU makefile

The following file is a makefile that lists the files, dependencies, and rules by which the C user-defined node is compiled.

.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}