1. -- 
  2. -- Copyright (c) 2012 Kevin Wellwood 
  3. -- All rights reserved. 
  4. -- 
  5. -- This source code is distributed under the Modified BSD License. For terms and 
  6. -- conditions, see license.txt. 
  7. -- 
  8.  
  9. with Objects;                           use Objects; 
  10.  
  11. private with Ada.Real_Time; 
  12.  
  13. package Input_Handlers is 
  14.  
  15.     -- An Input_Handler object runs an internal task to listen from mouse and 
  16.     -- keyboard input from the OS and queue input events. Input_Handler objects 
  17.     -- may not be copied. Only one instance per application is necessary. 
  18.     type Input_Handler is new Limited_Object with private; 
  19.     type A_Input_Handler is access all Input_Handler'Class; 
  20.  
  21.     -- Creates a new Input_Handler to receive mouse and keyboard input from the 
  22.     -- OS and generate appropriate events. 
  23.     function Create_Input_Handler( mouseEnabled : Boolean ) return A_Input_Handler; 
  24.     pragma Postcondition( Create_Input_Handler'Result /= null ); 
  25.  
  26.     -- Starts the Input_Handler's internal task. Input events will begin 
  27.     -- queueing after this is called. This can only be called once during the 
  28.     -- life of the object. 
  29.     procedure Start( this : not null access Input_Handler'Class ); 
  30.  
  31.     -- Stops the Input_Handler's task. It is called automatically during 
  32.     -- deletion. 
  33.     procedure Stop( this : not null access Input_Handler'Class ); 
  34.  
  35.     -- Deletes the Input_Handler. It will be stopped if it is currently running. 
  36.     procedure Delete( this : in out A_Input_Handler ); 
  37.     pragma Postcondition( this = null ); 
  38.  
  39. private 
  40.  
  41.     use Ada.Real_Time; 
  42.  
  43.     -- The life cycle of Input_Task is the following: 
  44.     -- "Init, Start, Stop" or "Init, Stop" 
  45.     task type Input_Task is 
  46.  
  47.         -- Input_Task must be initialized after creation and before stopping. 
  48.         entry Init( this : A_Input_Handler ); 
  49.  
  50.         -- Starts polling hardware and sending events. 
  51.         entry Start; 
  52.  
  53.         -- Stops operation and ends the task. 
  54.         entry Stop; 
  55.  
  56.     end Input_Task; 
  57.     type A_Input_Task is access all Input_Task; 
  58.  
  59.     -- Deletes the Input_Task. 
  60.     procedure Delete( intask : in out A_Input_Task ); 
  61.  
  62.     ---------------------------------------------------------------------------- 
  63.  
  64.     type Input_Handler is new Limited_Object with 
  65.         record 
  66.             mouseEnabled : Boolean := False; 
  67.             tickDelta    : Time_Span := Time_Span_Zero; 
  68.             process      : A_Input_Task := null; 
  69.             started      : Boolean := False; 
  70.             stopped      : Boolean := False; 
  71.         end record; 
  72.  
  73.     procedure Construct( this         : access Input_Handler; 
  74.                          mouseEnabled : Boolean ); 
  75.  
  76.     procedure Delete( this : in out Input_Handler ); 
  77.  
  78. end Input_Handlers;