ibm-information-center/dist/eclipse/plugins/i5OS.ic.apiref_5.4.0.1/apiexustra.htm

832 lines
45 KiB
HTML
Raw Normal View History

2024-04-02 14:02:31 +00:00
<?xml version="1.0" encoding="UTF-8"?>
<!DOCTYPE html
PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html lang="en-us" xml:lang="en-us">
<head>
<meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
<meta name="security" content="public" />
<meta name="Robots" content="index,follow" />
<meta http-equiv="PICS-Label" content='(PICS-1.1 "http://www.icra.org/ratingsv02.html" l gen true r (cz 1 lz 1 nz 1 oz 1 vz 1) "http://www.rsac.org/ratingsv01.html" l gen true r (n 0 s 0 v 0 l 0) "http://www.classify.org/safesurf/" l gen true r (SS~~000 1))' />
<meta name="DC.Type" content="reference" />
<meta name="DC.Title" content="Example: Using SNA/Management services transport APIs" />
<meta name="abstract" content="This example shows a source and target application using network management transport APIs to send and receive management services data. The example compiles in ILE C." />
<meta name="description" content="This example shows a source and target application using network management transport APIs to send and receive management services data. The example compiles in ILE C." />
<meta name="DC.Relation" scheme="URI" content="apiexmp.htm" />
<meta name="copyright" content="(C) Copyright IBM Corporation 1998, 2006" />
<meta name="DC.Rights.Owner" content="(C) Copyright IBM Corporation 1998, 2006" />
<meta name="DC.Format" content="XHTML" />
<meta name="DC.Identifier" content="apiexustra" />
<meta name="DC.Language" content="en-us" />
<!-- All rights reserved. Licensed Materials Property of IBM -->
<!-- US Government Users Restricted Rights -->
<!-- Use, duplication or disclosure restricted by -->
<!-- GSA ADP Schedule Contract with IBM Corp. -->
<link rel="stylesheet" type="text/css" href="./ibmdita.css" />
<link rel="stylesheet" type="text/css" href="./ic.css" />
<title>Example: Using SNA/Management services transport APIs</title>
</head>
<body id="apiexustra"><a name="apiexustra"><!-- --></a>
<!-- Java sync-link --><script language="Javascript" src="../rzahg/synch.js" type="text/javascript"></script>
<h1 class="topictitle1">Example: Using SNA/Management services transport APIs</h1>
<div><p>This example shows a source and target application using network
management transport APIs to send and receive management services data. The
example compiles in ILE C.</p>
<div class="section"><div class="note"><span class="notetitle">Note:</span> Read the <a href="codedisclaimer.htm">Code license and disclaimer information</a> for important
legal information.</div>
</div>
<div class="section"><h4 class="sectiontitle">Source application program</h4><p>This source application
program sends a request to a target application.</p>
<pre>/*********************************************************************/
/*********************************************************************/
/* */
/* FUNCTION: */
/* This is a source application that uses the management services */
/* transport APIs. It does the following: */
/* 1. Prompts for the network ID and CP name of the remote system */
/* where target application MSTTARG has been started. */
/* 2. Prompts for data to be sent to MSTTARG. */
/* 3. Prompts for whether or not a reply is required. */
/* 4. Sends a management services transport request to MSTTARG. */
/* 5. Repeats steps 2-4 until QUIT is entered. */
/* */
/* Note: MSTTARG may be ended by this application by sending it the */
/* string "ENDRMTAPP". */
/* */
/* LANGUAGE: ILE C */
/* */
/* APIs USED: QNMSTRAP, QNMENDAP, QNMRCVDT, */
/* QNMSNDRQ, QNMCHGMN, QNMENDAP */
/* */
/*********************************************************************/
/*********************************************************************/
/* Includes */
/*********************************************************************/
#include &lt;stdio.h&gt;
#include &lt;string.h&gt;
#include &lt;stdlib.h&gt;
#define NOERROR "NOERROR"
#define RQSONLY "*RQS "
#define RQSRPY "*RQSRPY "
/*-------------------------------------------------------------------*/
/* Type definitions */
/*-------------------------------------------------------------------*/
typedef int HANDLE; /* typedef for handle */
typedef char APPLNAME[8]; /* typedef for application name */
typedef char NETID[8]; /* typedef for network ID */
typedef char CPNAME[8]; /* typedef for control point name*/
typedef char MODENAME[8]; /* typedef for mode name */
typedef char SENSECODE[8]; /* typedef for SNA sense code (in
character format) */
typedef char LIBNAME[10]; /* typedef for library name */
typedef char QNAME[10]; /* typedef for data queue name */
typedef char MSGID[7]; /* typedef for message ID */
typedef char EXCPDATA[48]; /* typedef for exception data */
typedef char CATEGORY[8]; /* typedef for category */
typedef char APPLTYPE[10]; /* typedef for application type */
typedef char REPLREG[10]; /* typedef for replace
registration */
typedef char DATARCVD[10]; /* typedef for data received */
typedef char REQTYPE[10]; /* typedef for request type */
typedef char POSTRPL[10]; /* typedef for post reply */
typedef char REQUESTID[53]; /* typedef for request ID */
typedef char SRBUFFER[500]; /* typedef for send/receive
buffer. This program limits
the amount of data to be sent
or received to 500 bytes. The
maximum size of a management
services transport buffer is
31739. */
typedef struct { /* Library-qualified data queue
name */
QNAME data_queue_name; /* data queue name */
LIBNAME library_name; /* library name */
} QUALQNAME;
typedef struct { /* Error code structure */
int bytes_provided; /* number of bytes provided */
int bytes_available; /* number of bytes available */
MSGID exception_ID; /* exception ID */
char reserved_area; /* reserved */
EXCPDATA exception_data; /* exception data */
} ERRORCODE;
typedef struct { /* Notification record structure */
char record_type[10]; /* Record type */
char function[2]; /* Function */
HANDLE handle; /* Handle */
REQUESTID req_id; /* Request ID */
char reserved[11]; /* Reserved area */
} NOTIFRCD;
typedef struct { /* Receiver variable structure */
int bytes_provided; /* number of bytes provided */
int bytes_available; /* number of bytes available */
SRBUFFER received_data; /* received data */
} RECEIVERVAR;
typedef struct { /* Qualified application name */
NETID network_id; /* Network ID */
CPNAME cp_name; /* Control point name */
APPLNAME app_name; /* Application name */
} QUALAPPL;
/*-------------------------------------------------------------------*/
/* External program declarations */
/*-------------------------------------------------------------------*/
#pragma linkage(QNMSTRAP, OS) /* Start application API */
extern void QNMSTRAP (HANDLE *handle, /* pointer to handle */
APPLNAME *applname, /* pointer to appl name */
QUALQNAME *qualqname, /* pointer to data queue
name */
ERRORCODE *errorcode); /* pointer to error code
parameter */
#pragma linkage(QNMENDAP, OS) /* End application API */
extern void QNMENDAP (HANDLE *handle, /* pointer to handle */
ERRORCODE *errorcode); /* pointer to error code
parameter */
#pragma linkage(QNMRCVDT, OS) /* Receive data API */
extern void QNMRCVDT (HANDLE *handle, /* pointer to handle */
RECEIVERVAR *rcvvar, /* pointer to receiver
variable */
int *rcvvarln, /* pointer to receiver variable
length */
REQUESTID *reqid, /* pointer to request ID */
QUALAPPL *qualappl, /* pointer to remote
application name */
DATARCVD *datarcvd, /* pointer to type of data
received */
int *waittim, /* pointer to wait time */
ERRORCODE *errorcode); /* pointer to error code
parameter */
#pragma linkage(QNMSNDRQ, OS) /* Send request API */
extern void QNMSNDRQ (HANDLE *handle, /* pointer to handle */
QUALAPPL *qualappl, /* pointer to remote
application name */
REQUESTID *reqid, /* pointer to request ID */
SRBUFFER *sndbuf, /* pointer to send buffer */
int *sndbufln, /* pointer to send buffer length*/
REQTYPE *reqtype, /* pointer to request type */
POSTRPL *postrpl, /* pointer to post reply */
int *waittim, /* pointer to wait time */
ERRORCODE *errorcode); /* pointer to error code
parameter */
#pragma linkage(QNMCHGMN, OS) /* Change mode name API */
extern void QNMCHGMN (HANDLE *handle, /* pointer to handle */
MODENAME *modename, /* pointer to mode name */
ERRORCODE *errorcode); /* pointer to error code
parameter */
void check_error_code (char func_name[8]); /* Used to check error code
*/
void get_network_id (void); /* Get network ID of destination
node */
void get_cp_name (void); /* Get CP name of destination
node */
void process_replies(void); /* Process replies received from
destination application */
/*-------------------------------------------------------------------*/
/* Global declarations */
/*-------------------------------------------------------------------*/
HANDLE appl_handle; /* Handle of application */
ERRORCODE error_code_struc = /* Error code parameter */
{sizeof(error_code_struc), /* Initialize bytes provided */
0, /* initialize bytes available */
NOERROR}; /* initialize error code */
char input_line[80]; /* Input data */
QUALAPPL qual_appl = /* Qualified application name */
{" "," "," "};
REQUESTID req_id; /* Returned request ID */
int wait_time = -1; /* Wait time = wait forever */
/*-------------------------------------------------------------------*/
/* Start of main. */
/*-------------------------------------------------------------------*/
int main ()
{
APPLNAME appl_name = "MSTSOURC"; /* Application name to be used */
QUALQNAME data_queue_parm = /* Data queue name to be used */
{"*NONE ", " "}; /* Initialize structure */
NOTIFRCD notif_record; /* Area to contain notification
record */
CATEGORY category = "*NONE "; /* SNA/Management Services function
set group */
APPLTYPE appl_type = "*FPAPP "; /* Application type */
REPLREG replace_reg = "*YES "; /* Replace registration = *YES */
int sys_result; /* Result of system function */
char end_msg[] = "ENDRMTAPPL"; /* If this data is received then
the application will end */
char incoming_data[] = "01"; /* Incoming data constant */
SRBUFFER send_buffer; /* Send buffer */
int data_length; /* Length of send data */
char input_char; /* Input character */
REQTYPE req_type; /* Request type */
POSTRPL post_reply = "*NO "; /* Don't post any received replies
*/
MODENAME mode_name = "#INTER "; /* Mode name = #INTER */
/*-------------------------------------------------------------------*/
/* Start of code */
/*-------------------------------------------------------------------*/
QNMSTRAP (&amp;appl_handle,
&amp;appl_name,
&amp;data_queue_parm,
&amp;error_code_struc); /* Start application */
check_error_code("QNMSTRAP"); /* Check error code */
QNMCHGMN (&amp;appl_handle,
&amp;mode_name,
&amp;error_code_struc); /* Change mode name */
check_error_code("QNMCHGMN"); /* Check error code */
get_network_id(); /* Get network ID */
get_cp_name(); /* Get CP name */
memcpy(qual_appl.app_name,
"MSTTARG ",
sizeof(qual_appl.app_name)); /* Copy application name */
printf ("Enter message to send to remote application or "
"QUIT to end\n");
gets(input_line);
while (memcmp(input_line,
"QUIT",
sizeof("QUIT")) != 0) /* While an ending string
has not been entered */
{
data_length = strlen(input_line); /* Get length of message */
memcpy(send_buffer,
input_line,
data_length); /* Put message in send buffer */
printf("Reply necessary? (Y or N)\n"); /* Prompt for reply
indicator */
gets(input_line); /* Get reply character */
input_char = toupper(input_line[0]); /* Convert character to
uppercase */
while (strlen(input_line) != 1 ||
(input_char != 'Y' &amp;&amp;
input_char != 'N'))
{
printf("Please type Y or N\n");
gets(input_line); /* Get reply character */
input_char = toupper(input_line[0]); /* Convert character to
uppercase */
}
if (input_char == 'Y')
{
memcpy(req_type,
RQSRPY,
sizeof(req_type)); /* Indicate request should have
a reply */
}
else
{
memcpy(req_type,
RQSONLY,
sizeof(req_type)); /* Indicate request should not have
a reply */
}
QNMSNDRQ (&amp;appl_handle,
&amp;qual_appl,
&amp;req_id,
&amp;send_buffer,
&amp;data_length,
&amp;req_type,
&amp;post_reply,
&amp;wait_time,
&amp;error_code_struc); /* Send request to remote
application */
check_error_code("QNMSNDRQ"); /* Check error code */
if (input_char == 'Y')
{
process_replies(); /* Process one or more received
replies */
}
printf ("Enter message to send to remote application or "
"QUIT to end\n");
gets(input_line);
}
QNMENDAP (&amp;appl_handle,
&amp;error_code_struc); /* End the application */
return 0;
}
/*-------------------------------------------------------------------*/
/* process_replies function */
/*-------------------------------------------------------------------*/
void process_replies ()
{
RECEIVERVAR receiver_var = /* Receiver variable */
{sizeof(receiver_var)}; /* Initialize bytes provided */
int rcv_var_len = sizeof(receiver_var); /* Length of receiver
variable */
DATARCVD data_rcvd = "*NODATA "; /* Type of data received */
QUALAPPL qual_appl; /* Sender of reply */
printf ("Received reply(s):\n");
while (memcmp(data_rcvd,
"*RPYCPL ",
sizeof(data_rcvd)) != 0) /* While final reply has not
been received */
{
strncpy(receiver_var.received_data,
"\0",
sizeof(receiver_var.received_data)); /* Null out
data buffer */
QNMRCVDT (&amp;appl_handle,
&amp;receiver_var,
&amp;rcv_var_len,
&amp;req_id,
&amp;qual_appl,
&amp;data_rcvd,
&amp;wait_time,
&amp;error_code_struc); /* Receive reply */
check_error_code("QNMRCVDT"); /* Check error code */
printf("%1.500s\n",receiver_var.received_data); /* Print out
reply */
}
}
/*-------------------------------------------------------------------*/
/* get_network_id function. */
/*-------------------------------------------------------------------*/
void get_network_id ()
{
int count;
printf("Enter network ID of remote system where MSTTARG "
"application has been started\n"); /* Prompt for network
ID */
gets(input_line); /* Get network ID */
while (strlen(input_line) &lt;= 0 ||
strlen(input_line) &gt; 8) /* While network ID is not valid */
{
printf("Network ID is too long or too short - try again\n");
gets(input_line); /* Get network ID */
}
memcpy(qual_appl.network_id,
input_line,
strlen(input_line)); /* Copy network ID */
for (count=0; count &lt; strlen(input_line); count++)
qual_appl.network_id[count] =
toupper(qual_appl.network_id[count]); /* Convert
input to uppercase */
}
/*-------------------------------------------------------------------*/
/* get_cp_name function. */
/*-------------------------------------------------------------------*/
void get_cp_name ()
{
int count;
printf("Enter CP name of remote system where MSTTARG application "
"has been started\n"); /* Prompt for CP name */
gets(input_line); /* Get CP name */
while (strlen(input_line) &lt;= 0 ||
strlen(input_line) &gt; 8) /* While CP name is not valid */
{
printf("CP name is too long or too short - try again\n");
gets(input_line); /* Get CP name */
}
memcpy(qual_appl.cp_name,
input_line,
strlen(input_line)); /* Copy CP name */
for (count=0; count &lt; strlen(input_line); count++)
qual_appl.cp_name[count] =
toupper(qual_appl.cp_name[count]); /* Convert
input to uppercase */
}
/*-------------------------------------------------------------------*/
/* check_error_code - */
/*-------------------------------------------------------------------*/
void check_error_code (char func_name[8])
{
char *sense_ptr = error_code_struc.exception_data + 36; /*
Pointer to sense code in
exception data */
SENSECODE sense_code; /* SNA sense code */
if (error_code_struc.bytes_available != 0) /* Error occurred? */
{
printf("\n\nError occurred calling %1.8s.\n",func_name);
memcpy(sense_code,
sense_ptr,
sizeof(sense_code)); /* Copy sense code from exception
data */
printf("Error code is %1.7s, SNA sense code is %1.8s.\n",
error_code_struc.exception_ID,
sense_code);
if (memcmp(func_name,
"QNMSTRAP",
sizeof(func_name)) != 0) /* Error did not occur on
start application? */
{
QNMENDAP (&amp;appl_handle,
&amp;error_code_struc); /* End the application */
}
exit(EXIT_FAILURE); /* Exit this program */
}
}
</pre>
</div>
<div class="section"><h4 class="sectiontitle">Target application program</h4><p>This target application
receives requests from and returns replies to source applications.</p>
<pre>/*********************************************************************/
/*********************************************************************/
/* */
/* FUNCTION: */
/* This is a target application that uses the management services */
/* transport APIs. It receives management services transport */
/* requests from source application MSTSOURC and displays the data */
/* contained in the request. If the request specifies that a */
/* reply needs to be sent, this program accepts input from the */
/* keyboard and sends one or more replies to the source application. */
/* */
/* LANGUAGE: ILE C */
/* */
/* APIs USED: QNMSTRAP, QNMENDAP, QNMREGAP, QNMDRGAP, */
/* QNMRCVDT, QNMSNDRP, QNMRCVOC, QRCVDTAQ, */
/* QNMENDAP */
/* */
/*********************************************************************/
/*********************************************************************/
/* Includes */
/*********************************************************************/
#include &lt;stdio.h&gt;
#include &lt;string.h&gt;
#include &lt;stdlib.h&gt;
#define NOERROR "NOERROR"
#define REQUEST "*RQS "
#define REQREPLY "*RQSRPY "
#define REPLYINC "*RPYINCPL "
#define REPLYCMP "*RPYCPL "
/*-------------------------------------------------------------------*/
/* Type definitions */
/*-------------------------------------------------------------------*/
typedef int HANDLE; /* typedef for handle */
typedef char APPLNAME[8]; /* typedef for application name */
typedef char NETID[8]; /* typedef for network ID */
typedef char CPNAME[8]; /* typedef for control point name*/
typedef char SENSECODE[8]; /* typedef for SNA sense code
(in character format) */
typedef char LIBNAME[10]; /* typedef for library name */
typedef char QNAME[10]; /* typedef for data queue name */
typedef char MSGID[7]; /* typedef for message ID */
typedef char EXCPDATA[48]; /* typedef for exception data */
typedef char CATEGORY[8]; /* typedef for category */
typedef char APPLTYPE[10]; /* typedef for application type */
typedef char REPLREG[10]; /* typedef for replace
registration */
typedef char DATARCVD[10]; /* typedef for data received */
typedef char REPLYTYPE[10]; /* typedef for reply type */
typedef char REQUESTID[53]; /* typedef for request ID */
typedef char PACKED5[3]; /* typedef for PACKED(5,0) field */
typedef char SRBUFFER[500]; /* typedef for send/receive
buffer. This program limits
the amount of data to be sent
or received to 500 bytes. The
maximum size of a management
services transport buffer is
31739. */
typedef struct { /* Library-qualified data queue
name */
QNAME data_queue_name; /* data queue name */
LIBNAME library_name; /* library name */
} QUALQNAME;
typedef struct { /* Error code structure */
int bytes_provided; /* number of bytes provided */
int bytes_available; /* number of bytes available */
MSGID exception_ID; /* exception ID */
char reserved_area; /* reserved */
EXCPDATA exception_data; /* exception data */
} ERRORCODE;
typedef struct { /* Notification record structure */
char record_type[10]; /* Record type */
char function[2]; /* Function */
HANDLE handle; /* Handle */
REQUESTID req_id; /* Request ID */
char reserved[11]; /* Reserved area */
} NOTIFRCD;
typedef struct { /* Receiver variable structure */
int bytes_provided; /* number of bytes provided */
int bytes_available; /* number of bytes available */
SRBUFFER received_data; /* received data */
} RECEIVERVAR;
typedef struct { /* Qualified application name */
NETID network_id; /* Network ID */
CPNAME cp_name; /* Control point name */
APPLNAME app_name; /* Application name */
} QUALAPPL;
/*-------------------------------------------------------------------*/
/* External program declarations */
/*-------------------------------------------------------------------*/
#pragma linkage(QNMSTRAP, OS) /* Start application API */
extern void QNMSTRAP (HANDLE *handle, /* pointer to handle */
APPLNAME *applname, /* pointer to application
name */
QUALQNAME *qualqname,/* pointer to data queue
name */
ERRORCODE *errorcode); /* pointer to error code
parameter */
#pragma linkage(QNMENDAP, OS) /* End application API */
extern void QNMENDAP (HANDLE *handle, /* pointer to handle */
ERRORCODE *errorcode); /* pointer to error code
parameter */
#pragma linkage(QNMREGAP, OS) /* Register application API */
extern void QNMREGAP (HANDLE *handle, /* pointer to handle */
CATEGORY *category, /* pointer to category */
APPLTYPE *appltype, /* pointer to application
type */
REPLREG *replreg, /* pointer to replace
registration parameter */
ERRORCODE *errorcode); /* pointer to error code
parameter */
#pragma linkage(QNMDRGAP, OS) /* Deregister application API */
extern void QNMDRGAP (HANDLE *handle, /* pointer to handle */
ERRORCODE *errorcode); /* pointer to error code
set group */
#pragma linkage(QNMRCVDT, OS) /* Receive data API */
extern void QNMRCVDT (HANDLE *handle, /* pointer to handle */
RECEIVERVAR *rcvvar, /* pointer to receiver
variable */
int *rcvvarln, /* pointer to receiver variable
length */
REQUESTID *reqid, /* pointer to request ID */
QUALAPPL *qualappl, /* pointer to remote
application name */
DATARCVD *datarcvd, /* pointer to type of data
received */
int *waittim, /* pointer to wait time */
ERRORCODE *errorcode); /* pointer to error code
parameter */
#pragma linkage(QNMSNDRP, OS) /* Send reply API */
extern void QNMSNDRP (HANDLE *handle, /* pointer to handle */
REQUESTID *reqid, /* pointer to request ID */
SRBUFFER *sndbuf, /* pointer to send buffer */
int *sndbufln, /* pointer to send buffer length*/
REPLYTYPE *rpltype, /* pointer to reply type */
int *waittim, /* pointer to wait time */
ERRORCODE *errorcode); /* pointer to error code
parameter */
#pragma linkage(QNMRCVOC, OS) /* Receive operation completion API
*/
extern void QNMRCVOC (HANDLE *handle, /* pointer to handle */
REQUESTID *reqid, /* pointer to request ID */
QUALAPPL *qualappl, /* pointer to remote
application name */
ERRORCODE *errorcode); /* pointer to error code
parameter */
#pragma linkage(QRCVDTAQ, OS) /* Receive data queue */
extern void QRCVDTAQ (QNAME *queue_name, /* pointer to queue name */
LIBNAME *lib_name, /* pointer to library name */
PACKED5 *rcd_len, /* pointer to record length */
NOTIFRCD *notifrcd, /* pointer to notification
record */
PACKED5 *waittime); /* pointer to wait time */
void check_error_code (char func_name[8]); /* Used to check error
code */
/*-------------------------------------------------------------------*/
/* Global declarations */
/*-------------------------------------------------------------------*/
HANDLE appl_handle; /* Handle of application */
ERRORCODE error_code_struc = /* Error code parameter */
{sizeof(error_code_struc), /* Initialize bytes provided */
0, /* initialize bytes available */
NOERROR}; /* initialize error code */
/*-------------------------------------------------------------------*/
/* Start of main function */
/*-------------------------------------------------------------------*/
int main ()
{
/*-------------------------------------------------------------------*/
/* Local declarations */
/*-------------------------------------------------------------------*/
APPLNAME appl_name = "MSTTARG "; /* Application name to be used */
QUALQNAME data_queue_parm = /* Data queue name to be used */
{"MSTDTAQ ", "QTEMP "}; /* Initialize structure */
NOTIFRCD notif_record; /* Area to contain notification
record */
RECEIVERVAR receiver_var = /* Receiver variable */
{sizeof(receiver_var)}; /* Initialize bytes provided */
QUALAPPL qual_appl; /* Qualified application name */
DATARCVD data_rcvd; /* Type of data received */
CATEGORY category = "*NONE "; /* SNA/Management Services function
set group */
APPLTYPE appl_type = "*FPAPP "; /* Application type */
REPLREG replace_reg = "*YES "; /* Replace registration = *NO */
REPLYTYPE reply_cmp = REPLYCMP; /* Complete reply */
REPLYTYPE reply_inc = REPLYINC; /* Incomplete reply */
int sys_result; /* Result of system function */
int rcv_var_len = sizeof(receiver_var); /* Length of receiver
variable */
PACKED5 wait_time_p = "\x00\x00\x1D"; /* Packed value for wait time
= -1, that is, wait forever */
PACKED5 record_len; /* Length of received data queue
record */
int wait_forever = -1; /* Integer value for wait time =
-1, that is, wait forever */
int no_wait = 0; /* Do not wait for I/O to
complete */
char end_msg[] = "ENDRMTAPPL"; /* If this data is received then
the application will end */
char incoming_data[] = "01"; /* Incoming data constant */
char inbuf[85]; /* Input buffer */
SRBUFFER send_buffer; /* Send buffer for sending
replies */
int reply_len; /* Length of reply data */
/*-------------------------------------------------------------------*/
/* Start of executable code */
/*-------------------------------------------------------------------*/
sys_result = system("DLTDTAQ DTAQ(QTEMP/MSTDTAQ)"); /* Delete
previous data queue (if any) */
sys_result = system("CRTDTAQ DTAQ(QTEMP/MSTDTAQ) MAXLEN(80)"); /*
Create data queue */
QNMSTRAP (&amp;appl_handle,
&amp;appl_name,
&amp;data_queue_parm,
&amp;error_code_struc); /* Start application */
check_error_code("QNMSTRAP"); /* Check error code */
QNMREGAP (&amp;appl_handle,
&amp;category,
&amp;appl_type,
&amp;replace_reg,
&amp;error_code_struc); /* Register the application */
check_error_code("QNMREGAP"); /* Check error code */
while (memcmp(receiver_var.received_data,
end_msg,
sizeof(end_msg)) != 0)
{ /* Loop until an ending string
has been sent by the requesting
application */
QRCVDTAQ (&amp;data_queue_parm.data_queue_name,
&amp;data_queue_parm.library_name,
&amp;record_len,
&amp;notif_record,
&amp;wait_time_p); /* Receive indication from data
queue */
if (memcmp(notif_record.function,
incoming_data,
sizeof(incoming_data)) == 0) /* Incoming data was
received? */
{
strncpy(receiver_var.received_data,
"\0",
sizeof(receiver_var.received_data)); /* Null out the
receive buffer */
QNMRCVDT (&amp;appl_handle,
&amp;receiver_var,
&amp;rcv_var_len,
&amp;notif_record.req_id,
&amp;qual_appl,
&amp;data_rcvd,
&amp;wait_forever,
&amp;error_code_struc); /* Receive data using the
request ID in the notification*/
check_error_code("QNMRCVDT"); /* Check error code */
printf("%1.500s\n",receiver_var.received_data); /* Display
the received data */
if (memcmp(data_rcvd,
REQREPLY,
sizeof(data_rcvd)) == 0) /* Request requires
a reply? */
{
printf("Please enter your replies (a null line "
"indicates that you are finished)\n"); /* Display
a prompt message */
gets(inbuf); /* Get the reply data */
reply_len = strlen(inbuf); /* Get length of reply */
while (reply_len != 0) /* While no null string was input
*/
{
memcpy(send_buffer,inbuf,strlen(inbuf)); /* Copy
data to send buffer */
QNMSNDRP (&amp;appl_handle,
&amp;notif_record.req_id,
&amp;send_buffer,
&amp;reply_len,
&amp;reply_inc,
&amp;no_wait,
&amp;error_code_struc); /* Send a reply to the
source application (specify
"not last" reply). The results
of this operation will be
obtained later using the
receive operation completion
API. */
gets(inbuf); /* Get the next reply */
reply_len = strlen(inbuf); /* Get length of reply */
}
QNMSNDRP (&amp;appl_handle,
&amp;notif_record.req_id,
&amp;send_buffer,
&amp;reply_len,
&amp;reply_cmp,
&amp;no_wait,
&amp;error_code_struc); /* Send final reply (this
contains no data). The results
of this operation will be
obtained later using the
receive operation completion
API. */
}
else
{ /* A reply is not required */
if (memcmp(data_rcvd,
REQUEST,
sizeof(data_rcvd)) != 0) /* Something other than a
request was received? */
{
printf("Incorrect data was received, "
"data_rcvd = %1.10s\n", data_rcvd); /* Print
value of data_rcvd */
}
}
}
else
{ /* A send completion was received
for a previous send reply
operation */
QNMRCVOC (&amp;appl_handle,
&amp;notif_record.req_id,
&amp;qual_appl,
&amp;error_code_struc);/* Receive operation completion*/
check_error_code("QNMRCVOC"); /* Check error code */
printf("Reply was sent successfully.\n"); /* Error code was
OK */
}
}
QNMDRGAP (&amp;appl_handle,
&amp;error_code_struc); /* Deregister the application */
QNMENDAP (&amp;appl_handle,
&amp;error_code_struc); /* End the application */
return 0;
}
/*-------------------------------------------------------------------*/
/* check_error_code - */
/* */
/* This function validates the error code parameter returned on */
/* the call to a management services transport API program. If */
/* an error occurred, it displays the error that occurred and */
/* ends this program. */
/*-------------------------------------------------------------------*/
void check_error_code (char func_name[8])
{
char *sense_ptr = error_code_struc.exception_data + 36; /*
Pointer to sense code in
exception data */
SENSECODE sense_code; /* SNA sense code */
if (error_code_struc.bytes_available != 0) /* Error occurred? */
{
printf("\nError occurred calling %1.8s.\n",func_name);
memcpy(sense_code,
sense_ptr,
sizeof(sense_code)); /* Copy sense code from exception
data */
printf("Error code is %1.7s, SNA sense code is %1.8s.\n",
error_code_struc.exception_ID,
sense_code);
if (memcmp(func_name,
"QNMSTRAP",
sizeof("QNMSTRAP")) != 0) /* Error did not occur on
start application? */
{
QNMENDAP (&amp;appl_handle,
&amp;error_code_struc); /* End the application */
}
exit(EXIT_FAILURE); /* Exit this program */
}
}
</pre>
</div>
</div>
<div>
<div class="familylinks">
<div class="parentlink"><strong>Parent topic:</strong> <a href="apiexmp.htm" title="Contains example programs that use APIs and exit programs.">Examples: APIs</a></div>
</div>
</div>
</body>
</html>