1. with Objects;                           use Objects; 
  2.  
  3. private with Ada.Real_Time; 
  4.  
  5. package Input_Handlers is 
  6.  
  7.     -- An Input_Handler object runs an internal task to asynchronously poll 
  8.     -- input hardware and queue input events. Input_Handler objects may not be 
  9.     -- copied. 
  10.     type Input_Handler is new Limited_Object with private; 
  11.     type A_Input_Handler is access all Input_Handler'Class; 
  12.  
  13.     -- Creates a new Input_Handler that will poll input devices at the given 
  14.     -- rate in hertz. 
  15.     function Create_Input_Handler( hertz : Positive ) return A_Input_Handler; 
  16.     pragma Postcondition( Create_Input_Handler'Result /= null ); 
  17.  
  18.     -- Starts the Input_Handler's listening task. Input events will begin 
  19.     -- queueing after this is called. This can only be called once during the 
  20.     -- life of the object. 
  21.     procedure Start( this : not null access Input_Handler'Class ); 
  22.  
  23.     -- Stops the Input_Handler's task. This is called automatically as part of 
  24.     -- deletion, or it can be called sooner if Start has already been called. 
  25.     procedure Stop( this : not null access Input_Handler'Class ); 
  26.  
  27.     -- Deletes the Input_Handler. 
  28.     procedure Delete( this : in out A_Input_Handler ); 
  29.     pragma Postcondition( this = null ); 
  30.  
  31. private 
  32.  
  33.     use Ada.Real_Time; 
  34.  
  35.     -- The life cycle of Input_Task is the following: 
  36.     -- "Init, Start, Stop" or "Init, Stop" 
  37.     task type Input_Task is 
  38.  
  39.         -- Input_Task must be initialized after creation and before stopping. 
  40.         entry Init( this : A_Input_Handler ); 
  41.  
  42.         -- Starts polling hardware and sending events. 
  43.         entry Start; 
  44.  
  45.         -- Stops operation and ends the task. 
  46.         entry Stop; 
  47.  
  48.     end Input_Task; 
  49.     type A_Input_Task is access all Input_Task; 
  50.  
  51.     -- Deletes the Input_Task. 
  52.     procedure Delete( intask : in out A_Input_Task ); 
  53.  
  54.     ---------------------------------------------------------------------------- 
  55.  
  56.     type Input_Handler is new Limited_Object with 
  57.         record 
  58.             tickDelta : Time_Span := Time_Span_Zero; 
  59.             process   : A_Input_Task := null; 
  60.             started   : Boolean := False; 
  61.             stopped   : Boolean := False; 
  62.         end record; 
  63.  
  64.     procedure Construct( this : access Input_Handler; hertz : Positive ); 
  65.  
  66.     procedure Delete( this : in out Input_Handler ); 
  67.  
  68. end Input_Handlers;