FTAM/9000 Programmer's Guide
Chapter 4 191
Using Support Functions
Responding to Asynchronous Calls
/*
** Activate MAP 3.0 Application Entity for FTAM or FTAM, then initiate
** asynchronous MAP 3.0 operations.
*/
initiate_MAP_operation();
/*
** Initialize and initiate Non-MAP asynchronous operations.
*/
initiate_NON_MAP_operation();
while (operations_to_wait_on_and_process)
{
/*
** Suspend processing until an asynchronous event occurs.
*/
printf(“\nSuspending processing until an event occurs.\n”);
sem_p(sem_id, SEM_CONTROL, WAIT);
/*
** Processing has resumed. Determine the event type that occurred.
*/
printf(“Resuming processing after semaphore popped.\n”);
/*
** Process MAP 3.0 (FTAM or FTAM) event if one is pending.
**
** A non-blocking sem_p() operation is used to atomically test and
** decrement the pending MAP event count. If a MAP event is pending,
** sem_p() returns zero; otherwise, it returns non-zero.
**
** Note, calling em_hp_sigio() earlier merely put the MAP interface
** into SIGIO notification mode. You must still call em_wait() to
** obtain the event name for the MAP 3.0 operation that triggered
** the signal notification. Furthermore, the operation may only be
** partially complete. Calling em_wait() processes the MAP event as
** much as possible, but returns EME005_TIMEOUT if the event is not
** completely processed.
*/
if (sem_p(sem_id, SEM_MAP, NO_WAIT) == 0)
{
printf(“Calling em_wait() to obtain MAP event.\n”);
map_rc = em_wait(0, & map_event_name, & map_result);
if (map_rc == SUCCESS)
process_MAP_operation(map_event_name);
else if (map_rc == EME005_TIMEOUT)
printf(“em_wait timeout: operation partially complete\n”);
else
fprintf(stderr, “ERROR: em_wait() failed, %d\n”, map_rc);
}