From:	SCOVCB::GALVIN_FX    31-JAN-1989 09:03
To:	ARISIA::EVERHART
Subj:	

with text_io; use text_io;
with UTILITY; use UTILITY; 
with MATH; use MATH; 
with QUEUES; 
with UNCHECKED_DEALLOCATION; 
pragma ELABORATE (text_io, UTILITY, MATH, QUEUES);

        ----------
package SIMULATION is
        ----------

-- Type Declarations :
-- -------------------

   type PROCESS is private;



-- Simulator Control Operators :
-- -----------------------------

   procedure START_SIMULATION (SIMULATION_DURATION : in float 
                               := float'last);
      -- This allows the user to specify that the AdaSim simulation scheduler 
      -- is to run a simulation for the specified time, SIMULATION_DURATION.


   procedure STOP_SIMULATION;
      -- This procedure allows the user to signal to the simulation scheduler 
      -- to return control to the program module which called START_SIMULATION


-- Status Operators :
-- ------------------

   function CURRENT_SIMULATION_TIME return float;

   function CURRENT_PROCESS_PRIORITY return float;

   function CURRENT_PROCESS_NAME return UTILITY.CHAR_STRING;

   function CURRENT_PROCESS return PROCESS;


-- Process Control Operators :
-- ---------------------------

   procedure DELAY_PROCESS (DELAY_TIME : in float);
      -- Delay a process for length of time specified by DELAY_TIME.

   procedure BLOCK;
      -- Block the specified process.

   procedure UNBLOCK (BLOCK_JOB : in PROCESS);
      -- Unblock the specified process and enter job in simulation queue.

   procedure SUSPEND_PROCESS;
      -- Suspend the current process for an indefinte length of time.

   procedure RESUME_PROCESS (JOB_RESUME : in PROCESS;
                             RESUME_TIME, PRIORITY : in float);
      -- Resume a previously SUSPENDED process at the specified time with the 
      -- given priority.


-- Report/Trace/Dump Output Operators :
-- ------------------------------------

   procedure OUTPUT_PROCESS_REPORT;
      -- This procedure allows the user to request that the simulation report 
      -- be generated.

   procedure OUTPUT_PROCESS_DUMP;
      -- This procedure allows the user to request that the simulation dump 
      -- be generated.

   procedure SET_PROCESS_REPORT_OPTION (REPORT_OPTION : in UTILITY.OPTION);
      -- This procedure allows the user to select reporting options for 
      -- standard statistics report generation.

   procedure SET_PROCESS_TRACE_OPTION (TRACE_OPTION : in UTILITY.OPTION);
      -- This allows the user to invoke the trace option for standard trace 
      -- output.

   procedure SET_PROCESS_DUMP_OPTION (DUMP_OPTION : in UTILITY.OPTION);
      -- This allows the user to invoke the dump option for AdaSim internal 
      -- data structures to be output upon occurence of errors during a 
      -- simulation run.

   procedure SIMULATOR_ERROR (ERROR_MESSAGE : in string;
                              SEVERITY : in UTILITY.ERROR_SEVERITY);
      -- This procedure allows the user to invoke an AdaSim error termination 
      -- to occur.  AdaSim internal data structures will be dumped according 
      -- to the dump options set.


-- Exception Declarations :
-- ------------------------

   ACTIVATION_TIME_ERROR, DURATION_TIME_ERROR, 
   PROCESS_DOES_NOT_EXIST : exception;
     -- Raise an exception when any of the above error conditions occur.


-- Process Create Operators :
-- --------------------------

   generic
      PROCESS_GROUP_NAME : string;
      type PROCESS_KIND is limited private;
      type ATTRIBUTE_TYPE is private;

      package PROCESS_CREATOR is

      -- This package allows the declaration of two types, 
      -- PROCESS_KIND and ATTRIBUTE_TYPE, which describe the 
      -- behavior of a modeled process and its attributes.  
      -- The package is used in specifying a generic 
      -- instantiation of a PROCESS_CREATOR package and a
      -- CREATE_PROCESS procedure for a specified process type 
      -- and set of attributes.


   -- Process Operators :
   -- -------------------

         procedure CREATE_PROCESS
                  (PROCESS_REF : out PROCESS;
                   PROCESS_NAME : in string;
                   START_TIME,
                   PRIORITY : in float;
                   PROCESS_ATTRIBUTES : in ATTRIBUTE_TYPE);

         procedure GET_ATTRIBUTES (ATTRIBUTES : out ATTRIBUTE_TYPE);
            -- Get attributes of current process.

         procedure DESTROY_PROCESS;
         -- This procedure is used within an AdaSim process to terminate 
         -- itself.  It should be the last call in every ADASIM process task.


      end PROCESS_CREATOR;


-- Private Simulation Declarations :
-- ---------------------------------

   private

      type PROCESS_STATUS_TYPE is (ACTIVE, INACTIVE, DORMANT, TERMINATED);

      -- Synchronization task type :
      task type SYNCH is
         entry CONTINUE;
         entry WAIT;
      end;
      type SYNCH_PTR is access SYNCH;

   -- Data Structure consisting of process info. :
      type PROCESS_REC;
      type PROCESS is access PROCESS_REC;

      type GROUP_RECORD is
         record
            GROUP_NAME              : UTILITY.CHAR_STRING;
            NUMBER_TERMINATED       : natural := 0;
            SUM_OF_GROUP_EXEC_TIMES : float := 0.0;
            SUM_OF_GROUP_SQUARED    : float := 0.0;
            MIN_GROUP_EXEC_TIME     : float := float'last;
            MAX_GROUP_EXEC_TIME     : float := 0.0;
         end record;
      type GROUP is access GROUP_RECORD;

      type PROCESS_REC is
         record
            NAME : UTILITY.CHAR_STRING;
            STATUS : PROCESS_STATUS_TYPE;
            ACTIVATION_TIME, PRIORITY : float;
            SIGNAL : SYNCH_PTR;
            GROUP_ID : GROUP;
            PROCESS_ID : natural;
            START_TIME, TERMINATION_TIME : float;
         end record;

end SIMULATION;
