------------------------------------------------------------------ -- -- NAME: WSR_EVENT_SYNCHRONIZER - BODY -- DISCREPANCY REPORTS: -- ------------------------------------------------------------------ -- file: wsr_event_synch_b.ada -- level: mc, 0c, 1c, 2c with GKS_TYPES; package body WSR_EVENT_SYNCHRONIZER is -- This package defines a task type for which every INPUT or -- OUTIN workstation should declare an object of for coordinating -- the entry of one or more (simultaneous) events into the GKS -- EVENT QUEUE. -- Function rename in order for comparisons. function "=" (A,B : GKS_TYPES.INPUT_QUEUE_CLASS) return BOOLEAN renames GKS_TYPES."="; task body SYNCHRONIZER is begin -- Loop until program termination loop select -- request to synchronize a fixed number of events accept SIMULTANEOUS_EVENTS(NUM_EVENTS: in POSITIVE) do declare EVENTS : GKS_EVENT_QUEUE.EVENT_RECORD_ARRAY (1..NUM_EVENTS); -- Array to hold current number of simultaneous events VALID_EVENTS : NATURAL; -- Number of events that are not of class NONE (breaks -- or no values) OVERFLOW : BOOLEAN; -- Indicates an overflow in the GKS event queue begin VALID_EVENTS := 0; -- Once a request to synchronize is received, wait -- for the given number of events from the event -- reporters for I in 1..NUM_EVENTS loop accept QUEUE_EVENT (EVENT: in EVENT_TYPE) do -- Keep a count of the number of valid events if EVENT.CLASS /= GKS_TYPES.NONE then VALID_EVENTS := VALID_EVENTS + 1; -- Store only valid events into an array for -- the GKS event queue EVENTS(VALID_EVENTS) := EVENT; end if; end QUEUE_EVENT; end loop; -- Transmit valid events, if any, to GKS event queue. -- Overflow indicates if there was room for all events if VALID_EVENTS /= 0 then GKS_EVENT_QUEUE.QUEUE_EVENTS(EVENTS(1..VALID_EVENTS ),OVERFLOW); else OVERFLOW := FALSE; end if; -- Tell event reporters the overflow result. If -- overflow occurred the event is not acknowledged. for I in 1..NUM_EVENTS loop accept QUEUE_RESULT(RESULT: out BOOLEAN) do -- Result is true if event is queued successfully RESULT := not OVERFLOW; end QUEUE_RESULT; end loop; end; end SIMULTANEOUS_EVENTS; or -- allows termination of task with program completion terminate; end select; end loop; end SYNCHRONIZER; end WSR_EVENT_SYNCHRONIZER;