Avaya Logo

Previous Topic

Next Topic

Book Contents

Book Index

Sample DIP

The following is an example of a DIP.

#include <stdio.h>
#include
<sys/types.h>
#include
<sys/ipc.h>
#include
<sys/mesg.h>
#include
"/usr/spool/log/head/log.h"
#include
"/usr/spool/log/head/systemLog.h"
#include "/usr/spool/log/head/logAPPL.h"

#include
"shmemtab.h"
#include
"spp.h"
#include
"mesg.h"
#include "VS.h"

/* Define all messages that can be received

* For example, caller_info_msg is a message that is sent by
* the TSM
script giving the caller's social security number.
* Also
define the message ids for each messages received.
* These
message ids should be in a header file instead of
* here.

*/

#define ACCOUNT_REQUEST 8500
struct callerMsg {

struct mbhdr hd;
char
socialSecurityNo[10];
char accountNo[7];

};

/* Define Message Receive structure
* Should be
large enough to hold largest message.
* Add all received message
structures in the following
* union.

*/

union rcvMsg {
struct ms_univ u; /* the
standard message (mesg.h) */
struct
callerMsg c; /* caller's info */
};

/* Define Message structures to be Sent.
* Also
define the message id for each message.
* The message id should go
in a header file but
* it's shown
here for convenience.
* The
message ids should all be unique across all
* applications.
* Only
one message is sent in this example but usually you'll
* lots more.
*/


#define ACCOUNT_INFO 8090 /* message id */

struct accountMsg {
struct mbhdr
hd;
int balance;
};

static char *Myname="bankMgrDip"; /* Name of this DIP */
static short
Myinstance=1; /* Instance of DIP */

/* Names of other processes you talk to */
#define DBDIPPER "bankTellerDip"

main()
{
int myQkey;
int noBytesRead;

int accountBalance;
int
retCode;
union rcvMsg rcvbuf;

struct accountMsg acctbuf;

/* initialize DIP */


/* Logger Initialization */

/* Sleep if necessary to wait for the voice system
/* to finish diagnosing the cards
*/

logInit(Myname);

/* Get your dynamically-assigned Qkey */
myQkey
= VSstartup(Myname, Myinstance, DIP_PROC);
if (myQkey <= 0
) {
db_pr("%s: Can't get qkey:
VSstartup: %s\n");
VSerror(myQkey);

logMsg(APPL_INITFAIL,EL_FL,*Myname,"Can't get

qkey");
sleep(5); /* to slow down
continuous respawning */
exit(1);
}


/* Clear out my message queue */

noBytesRead = mesgrcv(myQkey,
&rcvbuf, sizeof(rcvbuf),
0, IPC_NOWAIT,NULL);
while
(noBytesRead >= 0) {
noBytesRead =
mesgrcv(myQkey, &rcvbuf, sizeof(rcvbuf),
0,
IPC_NOWAIT,NULL);
}

/*
Main processing Loop:
* Read and process
message for ever
*/
while
(1) {
/* wait for a message to
arrive */
noBytesRead =
mesgrcv(myQkey, &rcvbuf, sizeof(rcvbuf),
0, 0);

if (noBytesRead
< 0) {
/* Something went
wrong with the read
* Could be that
the reading was interrupted (EINTR).
* There should be some error
processing here but
* for brevity I'll
just try to read again.
*/

continue;
}

/* Got a
message! Get to work */
db_pr("%s:
got message: chan =%d, id=%d, senderQkey=%d\n",
*Myname,rcvbuf.c.hd.mchan,
rcvbuf.c.hd.mcont,
rcvbuf.c.hd.morig);

/*
Typically, the DIP will have a case for each
* possible message id.

* In this
example, we only have one possible message
* that can be received.

*/

switch (rcvbuf.c.hd.mcont) {

case ACCOUNT_REQUEST:
/* TSM
script wants account balance info */
db_pr("%s: request for
account info for SS#=%s\n",
*Myname,
rcvbuf.c.socialSecurityNo);
db_pr("%s: and
account#=%s\n",
rcvbuf.c.accountNo);
/* Go out and
get the account information
* and return it in
accountBalance.
* This balance (for
simplicity) is generated from
* the
last 4 digits of the SSN
*/

accountBalance =
atoi(rcvbuf.c.socialSecurityNo+5);
db_pr("%s: the
balance = %d\n",, *Myname,
accountBalance );

/* Now
package and send respond back */
acctbuf.hd.mchan =
rcvbuf.c.hd.mchan;
acctbuf.hd.mtype
= 1;
acctbuf.hd.morig =
myQkey;
acctbuf.hd.mcont = ACCOUNT_INFO;

acctbuf.hd.mseqno = 0;
acctbuf.balance =
accountBalance;
retCode =
mesgsnd(TSM, &acctbuf, sizeof(acctbuf), 0);
if (retCode < 0) {

/* Message
send failed; log message
* Note that before this will work you

* must add your DIP errors into
the logger system.
*/

logMsg(APPL_MSGSNDERR, EL_FL,
acctbuf.hd.mchan,
*Myname);
}
break;
default:

/* Notify logget that an unknown
message was
* received.
*/

logMsg(APPL_UNKNOWNMSG, EL_FL,
rcvbuf.c.hd.mchan,
*Myname );
break;
} /* switch on
message id */
} /* while loop
that reads forever */

} /* Main program */

int Fcn_APPLMSG_START()

{
static int
startLoc = -1 ;
static int readID
;

/* Have the
message classes been read again? If so, */
/* make sure we get
the new value */

if (logClassReadCnt
!= readID)
{
readID = logClassReadCnt
;
startLoc = -1 ;
}
if (startLoc < 0)
startLoc =
logStartClass("APPL") ;
return(startLoc) ;
}

© 2004 Avaya Inc. All Rights Reserved.