FTAM/9000 Programmer's Guide
Chapter 4 189
Using Support Functions
Responding to Asynchronous Calls
/*
** Sample program for em_hp_sigio()
**
** This program is designed with three primary components:
**
** * a central control/dispatch component
** * a MAP event processing component
** * a Non-MAP event processing component
**
** The central control/dispatch component makes use of an array of semaphores
** to manage program suspension and resumption, and to keep track of which
** components (MAP or Non-MAP) have work to do. Additionally, a signal
** handler is installed for the MAP and Non-MAP generated signals which
** manipulates the semaphore array. The SIGIO signal is used to notify the
** control/dispatch component that a MAP event needs to be processed, and the
** SIGUSR1 signal is used for Non-MAP events.
**
** The MAP and Non-MAP processing components are referenced as external
** functions. Details of these components are specific to each application
** and are, therefore, not included here. Note, calling em_wait() to obtain
** the MAP event would normally be included in the MAP specific processing
** component, but em_wait() is pulled out into the main component here to
** demonstrate the relationship between em_hp_sigio() and em_wait().
*/
#include %<stdio.h>
#include %<errno.h>
#include %<signal.h>
#include %<sys/types.h>
#include %<sys/ipc.h>
#include %<sys/sem.h>
#include %</opt/ftam/include/map.h>
/*
** Functions and variables not provided by the demonstration program.
*/
extern Bool operations_to_wait_on_and_process;
extern void initiate_MAP_operation();
extern void process_MAP_operation();
extern void initiate_NON_MAP_operation();
extern void process_NON_MAP_operation();
/*
** Semaphores used to manage suspend/resume activity
**
** Three semaphores are used to manage the MAP and Non-MAP asynchronous
** activity. One semaphore is used to control the suspension and resumption
** of process. Another semaphore is used to keep track of the number of
** pending events for each event type, MAP and Non-MAP in this case.
**
** The semaphores are operated on by a set of functions included following
** the main program. The functions provide logical P and V operations on a
** set of semaphores, based on HP-UX semaphore operations (system calls).
*/
#define NUM_SEMAPHORES 3
#define SEM_CONTROL 1 /* Used for suspend & resume control */
#define SEM_MAP 2 /* Used to track pending MAP events */
#define SEM_NON_MAP 4 /* Used to track pending Non-MAP events */