with Objects; use Objects;
private with Ada.Real_Time;
package Input_Handlers is
-- An Input_Handler object runs an internal task to asynchronously poll
-- input hardware and queue input events. Input_Handler objects may not be
-- copied.
type Input_Handler is new Limited_Object with private;
type A_Input_Handler is access all Input_Handler'Class;
-- Creates a new Input_Handler that will poll input devices at the given
-- rate in hertz.
function Create_Input_Handler( hertz : Positive ) return A_Input_Handler;
pragma Postcondition( Create_Input_Handler'Result /= null );
-- Starts the Input_Handler's listening task. Input events will begin
-- queueing after this is called. This can only be called once during the
-- life of the object.
procedure Start( this : not null access Input_Handler'Class );
-- Stops the Input_Handler's task. This is called automatically as part of
-- deletion, or it can be called sooner if Start has already been called.
procedure Stop( this : not null access Input_Handler'Class );
-- Deletes the Input_Handler.
procedure Delete( this : in out A_Input_Handler );
pragma Postcondition( this = null );
private
use Ada.Real_Time;
-- The life cycle of Input_Task is the following:
-- "Init, Start, Stop" or "Init, Stop"
task type Input_Task is
-- Input_Task must be initialized after creation and before stopping.
entry Init( this : A_Input_Handler );
-- Starts polling hardware and sending events.
entry Start;
-- Stops operation and ends the task.
entry Stop;
end Input_Task;
type A_Input_Task is access all Input_Task;
-- Deletes the Input_Task.
procedure Delete( intask : in out A_Input_Task );
----------------------------------------------------------------------------
type Input_Handler is new Limited_Object with
record
tickDelta : Time_Span := Time_Span_Zero;
process : A_Input_Task := null;
started : Boolean := False;
stopped : Boolean := False;
end record;
procedure Construct( this : access Input_Handler; hertz : Positive );
procedure Delete( this : in out Input_Handler );
end Input_Handlers;