package Ada_Store.PoST.Input_Queue

package Ada_Store.PoST.Input_Queue is

   type Input_Action is ( Unknown,
			  Enter, Cancel, 
			  Sign_On, Sign_Off, Close_Down,
			  Item_Sale, Department_Sale, Price_Enquiry, Subtract_Line, 
			  Sub_Total, 
			  Cash_Payment, Cheque_Payment, Card_Payment );

   Max_Input_Text : constant Positive := 40;

   type Message is 
      record
	 Action : Input_Action := Unknown;
	 Input  : String(1 .. Max_Input_Text);
	 Length : Natural := 0;
      end record;

   type Message_Ptr is access all Message;

   procedure Append
     (Message : in Message_Ptr);

   function  Get
     (Wait : in Boolean	:= False)
      return Message_Ptr;

   function  Peek
     (Wait : in Boolean	:= False)
     return Message_Ptr;

end Ada_Store.PoST.Input_Queue;

with Ada_Store.Support.Trace;
with Ada_Store.Support.List;
with Ada_Store.Support.IPC;

package body Ada_Store.PoST.Input_Queue is
   
   package Unsafe_List is new Support.List(Message_Ptr);

   type List_Ptr is access Unsafe_List.Instance;

   Real_List : List_Ptr := new Unsafe_List.Instance;
   Semaphore : Support.IPC.Semaphore(False);
   Mutex     : Support.IPC.Mutex;

   procedure Append
     (Message : in     Message_Ptr) is
   begin
      Support.Trace.Put("CIQ.Append (" &
			Input_Action'Image(Message.Action) & ", " &
			Message.Input & ", " &
			Integer'Image(Message.Length) & ")");

      Mutex.Acquire;
      Unsafe_List.Append(Real_List, Message);
      Mutex.Release;
      
      Semaphore.Signal;
   end Append;
   
   function  Get
     (Wait    : in     Boolean	    := False) return Message_Ptr is

      Message : Message_Ptr;
   begin
      Semaphore.Wait;
      Semaphore.Reset;

      Mutex.Acquire;
      Message := Unsafe_List.Get(Real_List);
      Mutex.Release;
      
      Support.Trace.Put("CIQ.Get (" &
			Input_Action'Image(Message.Action) & ", " &
			Message.Input(1 .. Message.Length + 1) & ", " &
			Integer'Image(Message.Length) & ")");
      return Message;
   end Get;
   
   function  Peek
     (Wait    : in     Boolean	    := False) return Message_Ptr is

      Message : Message_Ptr;
   begin
      Semaphore.Wait;

      Mutex.Acquire;
      Message := Unsafe_List.Peek(Real_List);
      Mutex.Release;
      
      Support.Trace.Put("CIQ.Peek (" &
			Input_Action'Image(Message.Action) & ", " &
			Message.Input(1 .. Message.Length + 1) & ", " &
			Integer'Image(Message.Length) & ")");
      return Message;
   end Peek;
   
end Ada_Store.PoST.Input_Queue;

Contents Page

Copyright © 1996 Simon Johnston &
Addison Wesley Longman