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 rate. 
  14.     function Create_Input_Handler( hertz : Positive ) return A_Input_Handler; 
  15.     pragma Postcondition( Create_Input_Handler'Result /= null ); 
  16.  
  17.     -- Starts the Input_Handler's listening task. Input events will begin 
  18.     -- queueing after this is called. 
  19.     procedure Start( this : not null access Input_Handler'Class ); 
  20.  
  21.     -- Stops the Input_Handler's task. This must be called after Start and 
  22.     -- before the object is deleted. 
  23.     procedure Stop( this : not null access Input_Handler'Class ); 
  24.  
  25.     -- Deletes the Input_Handler. 
  26.     procedure Delete( this : in out A_Input_Handler ); 
  27.     pragma Postcondition( this = null ); 
  28.  
  29. private 
  30.  
  31.     use Ada.Real_Time; 
  32.  
  33.     -- The life cycle of Input_Task is the following: 
  34.     -- "Init, Start, Stop" or "Init, Stop" 
  35.     task type Input_Task is 
  36.  
  37.         -- Input_Task must be initialized after creation and before stopping. 
  38.         entry Init( in_handler : A_Input_Handler ); 
  39.  
  40.         -- Starts polling hardware and sending events. 
  41.         entry Start; 
  42.  
  43.         -- Stops operation and ends the task. 
  44.         entry Stop; 
  45.     end Input_Task; 
  46.     type A_Input_Task is access all Input_Task; 
  47.  
  48.     -- Deletes the Input_Task. 
  49.     procedure Delete( intask : in out A_Input_Task ); 
  50.  
  51.     ---------------------------------------------------------------------------- 
  52.  
  53.     type Input_Handler is new Limited_Object with 
  54.         record 
  55.             tickDelta : Time_Span := Time_Span_Zero; 
  56.             process   : A_Input_Task := null; 
  57.             started   : Boolean := False; 
  58.             stopped   : Boolean := False; 
  59.         end record; 
  60.  
  61.     procedure Construct( this : access Input_Handler; hertz : Positive ); 
  62.  
  63.     procedure Delete( this : in out Input_Handler ); 
  64.  
  65. end Input_Handlers;