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

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

        ---------
package RESOURCES is
        ---------

   type ALLOC_TYPE is (FIRST_REQUEST, WAITING, ALLOCATED);
   subtype POINTER is natural;

   package STORAGES is

      --===================================
      --VISIBLE DATA STRUCTURE DECLARATIONS
      --===================================

      type STORAGE is limited private;
      type STORAGE_UNIT is limited private;


      --=====================================
      -- OPERATORS FOR STORAGE_TYPE RESOURCES
      --=====================================

      --Provides the capability to instantiate an AdaSim STORAGE_TYPE resource
      procedure CREATE_STORAGE (STORAGE_REF : in out STORAGE;
                                STORAGE_NAME : in STRING;
                                CAPACITY : in integer;
                                NO_OF_SERVERS : in integer);

      --Provides the capability to REQUEST a STORAGE_TYPE resource
      procedure REQUEST_STORAGE (STORAGE_REF : in out STORAGE;
                                 AMOUNT_REQUESTED : in integer;
                                 UNIT_ALLOCATED : in out STORAGE_UNIT);

      --Provides the capability to RELEASE a STORAGE_TYPE resource
      procedure RELEASE_STORAGE (UNIT_ALLOCATED : in out STORAGE_UNIT);

      --Provides the capability to DESTROY a STORAGE_TYPE resource
      procedure DESTROY_STORAGE (STORAGE_REF : in out STORAGE);

      --Provides the capability to MODIFY the configuration 
      --of a STORAGE_TYPE resource
      procedure MODIFY_STORAGE (STORAGE_REF : in out STORAGE;
                                ENABLE_FLAG : in boolean;
                                CAPACITY : in integer;
                                SERVER_LIMIT : in integer);

      --Allows the user to query the STORAGE_TYPE resource to 
      --determine whether it is on line (i.e. useable)
      function STORAGE_ENABLED (STORAGE_REF : in STORAGE) return boolean;

      --Allows the user to query the STORAGE_TYPE resource for the 
      --number of servers
      function STORAGE_SERVERS (STORAGE_REF : in STORAGE) return integer;

      --Allows the user to query the STORAGE_TYPE resource for its capacity
      function STORAGE_CAPACITY (STORAGE_REF : in STORAGE) return integer;

      --Allows the user to perform output control
      procedure SET_STORAGE_REPORT_OPTION (REPORT_OPTION : in UTILITY.OPTION);
      procedure SET_STORAGE_TRACE_OPTION (TRACE_OPTION : in UTILITY.OPTION);
      procedure SET_STORAGE_DUMP_OPTION (DUMP_OPTION : in UTILITY.OPTION);
      procedure OUTPUT_STORAGE_REPORT;
      procedure OUTPUT_STORAGE_DUMP;


   --=============================
   --STORAGES PRIVATE DECLARATIONS
   --=============================

   private

      task type STORAGE_RESOURCE is
         entry SETUP       (SERVER_LIMIT: in integer;
                            AMT_OF_RES : in integer;
                            STORAGE_NAME : in STRING;
                            RES_REFER : in STORAGE);
         entry RES_REQUEST (UNIT_ALLOCATED : in out STORAGE_UNIT;
                            AMOUNT_REQUESTED : in integer;
                            ALLOC_RESPONSE : in out ALLOC_TYPE);
         entry RES_RELEASE (UNIT_ALLOCATED : in out STORAGE_UNIT);
         entry ENABLED     (FLAG : out boolean);
         entry SERVERS     (NUMBER_OF_AVAILABLE_SERVERS : out integer);
         entry CAP_AVAIL   (AMOUNT_AVAILABLE : out integer);
         entry ALTER       (FLAG : in boolean; 
                            SERVER_LIMIT, AMT_RES : in integer);
         entry REPORT;
         entry DUMP;
      end STORAGE_RESOURCE;

      type STORAGE is access STORAGE_RESOURCE;

      type STORAGE_ALLOCATION_LIST is
         record
            BUSY_START_TIME : float;
            AMOUNT : integer;
            RES_UNIT : STORAGE := null;
            JOB_NAME : UTILITY.CHAR_STRING;
         end record;
      type STORAGE_UNIT is access STORAGE_ALLOCATION_LIST;

   end STORAGES;


   package FACILITIES is
      type FACILITY is limited private;

       --======================================--
       -- OPERATORS FOR FACILITY_TYPE RESOURCES:
       --======================================--

--Provides the capability to instantiate an AdaSim FACILITY_TYPE resource.
      procedure CREATE_FACILITY (FACILITY_REF : in out FACILITY;
                                 FACILITY_NAME : in STRING);

--Provides the capability to REQUEST a FACILITY_TYPE  resource.
      procedure REQUEST_FACILITY (FACILITY_REF : in out FACILITY);

--Provides the capability to RELEASE a FACILITY_TYPE  resource.
      procedure RELEASE_FACILITY (FACILITY_REF : in out FACILITY);

--Provides the capability to DESTROY a FACILITY_TYPE  resource.
      procedure DESTROY_FACILITY (FACILITY_REF : in out FACILITY);

--Provides the capability to MODIFY the configuration of a 
--FACILITY_TYPE resource.
      procedure MODIFY_FACILITY (FACILITY_REF : in out FACILITY;
                                 ENABLE_FLAG : in boolean);

--Allows the user to query the FACILITY_TYPE resource to 
--determine whether it is on line (i.e. useable).
      function FACILITY_ENABLED (FACILITY_REF : in FACILITY) return boolean;

--Allows the user to query the FACILITY_TYPE resource to
--determine whether it is allocated (busy).
      function FACILITY_ALLOCATED (FACILITY_REF : in FACILITY) return boolean;

--Allows the user to perform output control
      procedure SET_FACILITY_REPORT_OPTION (REPORT_OPTION : in UTILITY.OPTION);
      procedure SET_FACILITY_TRACE_OPTION (TRACE_OPTION : in UTILITY.OPTION);
      procedure SET_FACILITY_DUMP_OPTION (DUMP_OPTION : in UTILITY.OPTION);
      procedure OUTPUT_FACILITY_REPORT;
      procedure OUTPUT_FACILITY_DUMP;

   private
      task type FACILITY_RESOURCE is
         entry SETUP       (FACILITY_NAME : in STRING);
         entry RES_REQUEST (ALLOC_RESPONSE : in out ALLOC_TYPE);
         entry RES_RELEASE;
         entry ENABLED     (FLAG : out boolean);
         entry ALLOCATED   (FLAG : out boolean);
         entry ALTER       (FLAG : in boolean);
         entry REPORT;
         entry DUMP;
      end FACILITY_RESOURCE;

      type FACILITY is access FACILITY_RESOURCE;

   end FACILITIES;

           --------
   package MESSAGES is
           --------

      type MESSAGE is limited private;

      --=====================================
      -- OPERATORS FOR MESSAGE_TYPE RESOURCES
      --=====================================

      --Creates a resource of type MESSAGE_TYPE
      procedure CREATE_MESSAGE (MESSAGE_REF : in out MESSAGE;
                                NAME : in STRING);

      --Destroys a message resource.
      procedure DESTROY_MESSAGE (MESSAGE_REF : in out MESSAGE);

      --Modifies the STATUS of a MESSAGE_TYPE resource.
      procedure MODIFY_MESSAGE (MESSAGE_REF : in out MESSAGE;
                                ENABLE_FLAG : in boolean);

      --Queries the enable status of a MESSAGE_TYPE resource.
      function MESSAGE_ENABLED (MESSAGE_REF : in MESSAGE) return boolean;

      --Provides the number of messages sent but not received.
      function CURRENT_MESSAGE_COUNT (MESSAGE_REF : in MESSAGE) return natural;

      --Provides the number of calls waiting for a message to be sent
      function NUMBER_WAITING_FOR_MESSAGE (MESSAGE_REF : in MESSAGE) 
         return natural;

      --Allows the user to perform output control
      procedure SET_MESSAGE_REPORT_OPTION (REPORT_OPTION : in UTILITY.OPTION);
      procedure SET_MESSAGE_TRACE_OPTION (TRACE_OPTION : in UTILITY.OPTION);
      procedure SET_MESSAGE_DUMP_OPTION (DUMP_OPTION : in UTILITY.OPTION );
      procedure OUTPUT_MESSAGE_REPORT;
      procedure OUTPUT_MESSAGE_DUMP;


   generic

      type MESSAGE_TYPE is private;

      package MESSAGE_CREATOR is
         --RECEIVES a message from a specified source.
         procedure RECEIVE_MESSAGE (MESSAGE_REF : in out MESSAGE;
                                    DATA : out MESSAGE_TYPE);
         --SENDs a message using a specified message resource
         procedure SEND_MESSAGE (MESSAGE_REF: in out MESSAGE;
                                 DATA : in MESSAGE_TYPE);
      end MESSAGE_CREATOR;

   private
      task type MESSAGE_RESOURCE is
         entry SETUP (NAME : in STRING);
         entry RECEIVE (DATA : in out POINTER;
                        RESPONSE : in out ALLOC_TYPE);
         entry SEND (DATA : in POINTER);
         entry STATUS (STATE : out boolean);
         entry SEND_COUNT (NUMBER : out natural);
         entry RECEIVE_COUNT (NUMBER : out natural);
         entry ALTER (FLAG : in boolean);
         entry REPORT;
         entry DUMP;
      end MESSAGE_RESOURCE;

      type MESSAGE is access MESSAGE_RESOURCE;

   end MESSAGES;



   package EVENTS is

      type EVENT is limited private;

       --======================================--
       -- OPERATORS FOR EVENT_TYPE RESOURCES:
       --======================================--

--CREATEs an EVENT_TYPE resource.
      procedure CREATE_EVENT (EVENT_REF : in out EVENT;
                              EVENT_NAME : in STRING);

--WAITs for the occurence of a specified event.
      procedure WAIT_EVENT (EVENT_REF : in out EVENT);

--SIGNALs the occurence of a specified event.
      procedure SIGNAL_EVENT (EVENT_REF : in out EVENT);

--DESTROYs an EVENT_TYPE resource.
      procedure DESTROY_EVENT (EVENT_REF : in out EVENT);

--MODIFies an EVENT_TYPE.
      procedure MODIFY_EVENT (EVENT_REF : in out EVENT; 
                              ENABLE_FLAG : in boolean);

--Queries the enable status of an EVENT.
      function EVENT_ENABLED (EVENT_REF : in EVENT) return boolean;

--Provides the number of events signaled but not waiting.
      function CURRENT_EVENT_COUNT (EVENT_REF : in EVENT) return natural;

--Provides the number of calls waiting for an event to be signalled
      function NUMBER_WAITING_FOR_EVENT (EVENT_REF : in EVENT) 
         return natural;

--Allows the user to perform output control
      procedure SET_EVENT_REPORT_OPTION (REPORT_OPTION : in UTILITY.OPTION);
      procedure SET_EVENT_TRACE_OPTION (TRACE_OPTION : in UTILITY.OPTION);
      procedure SET_EVENT_DUMP_OPTION (DUMP_OPTION : in UTILITY.OPTION);
      procedure OUTPUT_EVENT_REPORT;
      procedure OUTPUT_EVENT_DUMP;

   private
      task type EVENT_RESOURCE is
         entry SETUP (NAME : in STRING);
         entry WAIT (PTR : in out POINTER; 
                     RESPONSE : in out ALLOC_TYPE);
         entry SIGNAL (PTR : in POINTER);
         entry STATUS (STATE : out boolean);
         entry SIGNAL_COUNT (NUMBER : out natural);
         entry WAIT_COUNT (NUMBER : out natural);
         entry ALTER (FLAG : in boolean);
         entry REPORT;
         entry DUMP;
      end EVENT_RESOURCE;

      type EVENT is access EVENT_RESOURCE;

   end EVENTS;



   --=========================
   --OUTPUT CONTROL PROCEDURES
   --=========================

   procedure OUTPUT_RESOURCE_REPORTS;
   procedure OUTPUT_RESOURCE_DUMPS;


   --==========
   --EXCEPTIONS
   --==========

   STORAGE_DOES_NOT_EXIST : exception;
   STORAGE_IS_DISABLED : exception;
   STORAGE_UNIT_NOT_ALLOCATED : exception;
   FACILITY_DOES_NOT_EXIST : exception;
   FACILITY_IS_DISABLED : exception;
   FACILITY_NOT_ALLOCATED : exception;
   MESSAGE_DOES_NOT_EXIST : exception;  
   MESSAGE_IS_DISABLED : exception;
   EVENT_DOES_NOT_EXIST : exception;
   EVENT_IS_DISABLED : exception;

end RESOURCES;
