Copyright © TIBCO Software Inc. All Rights Reserved
Copyright © TIBCO Software Inc. All Rights Reserved


Chapter 10 Accessing External Routines : Making a C Program Compatible with TIBCO Object Service Broker

Making a C Program Compatible with TIBCO Object Service Broker
Requirements
Your C program should be written and receive arguments according to standard C coding conventions.
Syntax Mapping
The following table shows how TIBCO Object Service Broker syntax is mapped to C syntax.

C Syntax Declaration
n = 2
n = 4
n = 4
n = 8
n = 16

1
The first part of the C syntax for V describes the length of the argument and the second part contains the data.

2
TIBCO Object Service Broker supports packed decimal and IBM hexadecimal floating point. The C declarations are valid only for IBM’s mainframe C compiler.

3
An RD field consists of a four-byte inclusive binary length followed by the data.

See Also
TIBCO Object Service Broker Programming in Rules about TIBCO Object Service Broker syntax.
Sample
C Program
The following routine shows how to define the arguments in C. The routine must be identified to TIBCO Object Service Broker as described in Identifying Your External Routine to TIBCO Object Service Broker. In the ROUTINES table, for routines written in IBM C, the Language specified in the ROUTINES table should be LEPERSIST.

 
/* dayXmasC - concatenate a number to a string */
static void join(
char * * ptptr,
char * sptr
)
{
char c;
char * tptr = *ptptr;
do {
*tptr++ = c = *sptr++;
} while ( c );
*ptptr = tptr; /* update pointer for caller */
*(tptr-1) = ' '; /* change null to a blank */
}
void DAYXMAS(
char * result,
int * count,
char * item
)
{
int len;
char *p, *p0;
short *p2;
char temp[80];
static char * numbers[14] = { "no", "a", "two", "three", "four", "five",
"six", "seven", "eight", "nine", "ten", "eleven", "twelve", "many" };
static char * minus = "minus";
int itemlen = (short) *((short *) item);
int i = *count;
p = p0 = result + 2;
p2 = (short *) result;
/* Make a C-format string from the input string. */
for (len=0; len<itemlen; len++)
temp[len] = item[len+2];
temp[itemlen] = 0;
/* Adjust the count so that it is between 0 and 13 inclusive. */
if ( i < 0 ) {
join(&p,minus);
i = -i;
}
if ( i > 12 ) i = 13;
join(&p,numbers[i]);
join(&p,temp);
len = (int) (p-p0-1); /* length of output string */
*p2 = (short) len;
}

 
Table ROUTINES
The table ROUTINES should contain:

 
EDITING TABLE : ROUTINES
TABLE TYPE : TDS
COMMAND ==>
------------------------------------------------------------------------------
 
NAME : DAYOFCHRISTMAS
LANGUAGE : LEPERSIST
FUNCTION : Y
TYPE :
SYNTAX : V
LENGTH : 80
DECIMAL : 0
LOADNAME : DAYXMAS
SCOPE :
NODENAME :
:
:
LIBNAME :
:
:

 
Table ARGUMENTS(DAYOFCHRISTMAS)
The table ARGUMENT(DAYOFCHRISTMAS) should contain:

 
BROWSING TABLE : ARGUMENTS(DAYOFCHRISTMAS)
COMMAND ==>
NUMBER NAME INOUT TYPE SYNTAX LENGTH DECIMAL
_ ------ ---------------- - - - ------ ------
_ 1 COUNT N C B 4 0
_ 2 ITEM N S V 32 0

 
Rule That Calls the C Program
The first rule calls the second one, which calls the C routine.

 
RULE EDITOR ===> SCROLL: P
TWELVE;
_
_ ---------------------------------------------------------------------------
_ ------------------------------------------------------------+--------------
_ CALL XDAY(12, 'drummers drumming'); ¦ 1
_ CALL XDAY(11, 'lords a-leaping'); ¦ 2
_ CALL XDAY(10, 'pipers piping'); ¦ 3
_ CALL XDAY(9, 'ladies dancing'); ¦ 4
_ CALL XDAY(8, 'maids a-milking'); ¦ 5
_ CALL XDAY(7, 'swans a-swimming'); ¦ 6
_ CALL XDAY(6, 'geese a-laying'); ¦ 7
_ CALL XDAY(5, 'gold rings'); ¦ 8
_ CALL XDAY(4, 'calling birds'); ¦ 9
_ CALL XDAY(3, 'French hens'); ¦ A
_ CALL XDAY(2, 'turtle doves'); ¦ B
_ CALL XDAY(1, 'partridge in a pear tree'); ¦ C
_ ---------------------------------------------------------------------------
PFKEYS: 1=HELP 3=END 12=CANCEL 13=PRINT 14=EXPAND 2=DOCUMENT 22=DELETE

 
 
RULE EDITOR ===> SCROLL: P
XDAY(N, X);
_
_ ---------------------------------------------------------------------------
_ ------------------------------------------------------------+--------------
_ CALL MSGLOG(DAYOFCHRISTMAS(N, X)); ¦ 1
_ ---------------------------------------------------------------------------
PFKEYS: 1=HELP 3=END 12=CANCEL 13=PRINT 14=EXPAND 2=DOCUMENT 22=DELETE

 
JCL to compile and link the sample
//CMP6000 EXEC PROC=EDCCB,
// CPARM='RENT,SHOW,SO,XREF',
// INFILE='S6B.TST.C(DAYXMAS)',
// OUTFILE='S6B.TST.LOAD(DAYXMAS),DISP=SHR'
//BIND.SYSIN DD *
ENTRY DAYXMAS
NAME DAYXMAS(R)
/*

Copyright © TIBCO Software Inc. All Rights Reserved
Copyright © TIBCO Software Inc. All Rights Reserved