 |
» |
|
|
|
Examples one and two illustrate using the AIF:OS system calls to send and
receive data. These two examples are written in HP C/iX.
To compile the source code for SEND1S:
ccxl send1s,,$null;info="-Aa +e"
link from=$oldpass,xdbend.lib.sys;to=send1p;&
cap=ia,pm;rl=libcinit.lib.sys
|
This is the source code for program SEND1S:
#pragma list off
#include <stdio.h>
#include <string.h>
#include <time.h>
#include <mpe.h>
#pragma list on
#pragma intrinsic_file "aifintr.pub.sys"
#pragma intrinsic AIFPORTOPEN
#pragma intrinsic AIFPORTCLOSE
#pragma intrinsic AIFPORTSEND
#pragma intrinsic_file "sysintr.pub.sys"
#pragma intrinsic GETPRIVMODE
#pragma intrinsic GETUSERMODE
#define num_items 50
typedef int^ item_array_type[num_items];
typedef int itemnum_array_type[num_items];
typedef t_mpe_status item_status_array_type[num_items];
/*
This program SEND1S and its counterpart RECV1S will use AIF:OS intrinsics
to send and receive data.
*/
static item_array_type item_array;
static itemnum_array_type itemnum_array;
static item_status_array_type itemstatus_array;
static t_mpe_status overall_status;
static char error_stng[80];
static int user_id = 123456789; /* Your valid user_id */
static int port_id = 0;
|
/***************************************************************************/
/* fatal_aif_error */
/***************************************************************************/
void fatal_aif_error (t_mpe_status *overall status
char
item_status_array_type
item_status_array)
{
int i;
printf ("**** %s\n", error_stng);
printf ("**** error: Info=%d Subsystem=%d\n",
overall_status->decode.error_num
overall_status->decode.subsys_num
for (i=0; i, num_items; i++|) {
if (item_status_array[i].decode.error.num) {
printf("\n Loop: %d error: Info=%d Subsystem=%d\n",
i, item_status_array[i].decode.error_num,
item_status_array[i].decode.subsys_num);
} /* if */
} /* for loop */
QUIT (1);
} /* fatal_aif_error */
|
/***************************************************************************/
/* open_port */
/***************************************************************************/
void open_port (int *port_id)
{
char port_name[16] = "PORT2 ";
char port_password[16] = "PORT2_PASS ";
int access_mode = 2;
int create_option = 1; /* default, but we're showing an example */
itemnum_array[0] = 11201;
item_array[0] = &create_option;
itemnum_array[1] = 0;
GETPRIVMODE ();
*port_id = AIFPORTOPEN (&overall_status, port_name, port_password,
access_mode, user_id,
itemnum_array, item_array, itemstatus_array);
GETUSERMODE ();
if (overall_status.word) {
strcpy (error_stng, "AIFPORTOPEN intrinsic error");
fatal_aif_error (&overall_status, error_stng, itemstatus_array);
}
} /* open_port */
/***************************************************************************/
/* close_port */
/***************************************************************************/
void close_port (int *port_id)
{
int access_mode = 2;
GETPRIVMODE ();
AIFPORTCLOSE (&overall_status, port_id, access_mode);
GETUSERMODE ();
if (overall_status.word) {
strcpy (error_stng, "AIFPORTCLOSE intrinsic error");
fatal_aif_error (&overall_status, error_stng, itemstatus_array);
}
} /* close_port */
|
/***************************************************************************/
/* send_stng */
/***************************************************************************/
void send_stng (int *port_id,
char *stng,
int msg_pri)
{
int stng_len;
stng_len = strlen (stng);
itemnum_array[0] = 11102;
item_array[0] = &msg_pri; /* set the pri*/
itemnum_array[1] = 0;
printf ("\nSending msg: %s: to port: %d at priority %d\n",
stng, *port_id, msg_pri);
GETPRIVMODE ();
AIFPORTSEND (&overall_status, port_id, stng, stng_len
, ,, itemnum_array, item_array, itemstatus_array);
GETUSERMODE ();
if (overall_status.word) {
strcpy (error_stng, "AIFPORTSEND intrinsic error");
fatal_aif_error (&overall_status, error_stng, itemstatus_array);
}
} /* send_stng */
/***************************************************************************/
/* MAIN */
/***************************************************************************/
int main(int argc, char *argv[], char *envp[], int parm)
{
char stng[80];
char pri_stng[20];
int msg_pri;
open_port (&port_id);
printf ("\n\nEnter message to be sent (Q to quit) : ");
gets (stng);
while (strncmp (stng, "Q", 1) != 0) {
printf ("\n\nEnter message priority : ");
gets (pri_stng);
msg_pri = atoi (pri_stng);
send_stng (&port_id, stng, msg_pri);
printf ("\n\nEnter message to be sent (Q to quit) : ");
gets (stng);
}
close_port (&port_id);
}
|
|