 |
» |
|
|
|
The program RECV1S and its counterpart SEND1S use the AIF:OS
system calls to send and receive the data.
This is the source code for program RECV1S:
#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 RECV1s and its counterpart SEND1S 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] = "PORT1 ";
char port_password[16] = "PORT1_PASS ";
int access_mode = 1;
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 = 1;
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 */
|
/***************************************************************************/
/* receive_stng */
/***************************************************************************/
int receive_stng (int *port_id,
char *stng,
int stng_len,
int msg_pri)
{
int time_out = -1;
itemnum_array[0] = 11002;
item_array[0] = &time_out;
itemnum_array[1] = 11001;
item_array[1] = &msg_pri;
itemnum_array[2] = 0;
GETPRIVMODE ();
printf ("\nChecking for msg at pri: %d\n", msg_pri);
AIFPORTRECEIVE (&overall_status, port_id, stng, &stng_len
, ,, itemnum_array, item_array, itemstatus_array);
GETUSERMODE ();
if (( (overall_status.decode.error_num == -111) ||
(overall_status.decode.error_num == -129)) &&&
(overall_status.decode.subsys_num == 516)) {
printf ("No message found at that priority\n");
return FALSE;
}
else if (overall_status.word) {
strcpy (error_stng, "AIFPORTRECEIVE intrinsic error");
fatal_aif_error (&overall_status, error_stng, itemstatus_array);
}
else
stng[stng_len] = '\0';
return TRUE;
} /* receive_stng */
|
/***************************************************************************/
/* MAIN */
/***************************************************************************/
int main(int argc, char *argv[], char *envp[], int parm)
{
char stng[80];
int msg_pri;
open_port (&port_id);
printf ("\n\nEnter message priority (0 to quit) : ");
scanf ("%d", &msg_pri);
printf ("portid is %d\n", port_id);
while (msg_pri) {
if (receive_stng (&port_id, stng, sizeof (stng), msg_pri)) {
printf ("\nReceived msg: %s at pri: %d\n", stng, msg_pri);
}
printf ("\n\nEnter message priority : ");
scanf ("%d", &msg_pri);
}
close_port (&port_id);
}
|
|