--------------------------------------------------------------------------------
--                                                                            --
-- Copyright (C) 2004, RISC OS Ada Library (RASCAL) developers.               --
--                                                                            --
-- This library is free software; you can redistribute it and/or              --
-- modify it under the terms of the GNU Lesser General Public                 --
-- License as published by the Free Software Foundation; either               --
-- version 2.1 of the License, or (at your option) any later version.         --
--                                                                            --
-- This library is distributed in the hope that it will be useful,            --
-- but WITHOUT ANY WARRANTY; without even the implied warranty of             --
-- MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU           --
-- Lesser General Public License for more details.                            --
--                                                                            --
-- You should have received a copy of the GNU Lesser General Public           --
-- License along with this library; if not, write to the Free Software        --
-- Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA    --
--                                                                            --
--------------------------------------------------------------------------------

-- @brief Event definitions to handle messages from !Alarm.
-- $Author$
-- $Date$
-- $Revision$


with RASCAL.OS;                use RASCAL.OS;

with Ada.Unchecked_Conversion;

package RASCAL.Alarm is

   --
   -- This message is broadcast by !Alarm when an application alarm goes off.
   --If the message is not acknowledged !Alarm 'prompts' the user to start the application, and defers the alarm for 1 minute, before restarting this message broadcast procedure.
   --
   type Message_AlarmGoneOff is
   record
   Header         : Message_Event_Header;
   Sender         : Char_Array (1..40);
   Alarm_Name     : Char_Array (1..40);
   end record;
   pragma Convention (C, Message_AlarmGoneOff);

   type Message_AlarmGoneOff_Pointer is access Message_AlarmGoneOff;

   type AMEL_Message_AlarmGoneOff is abstract new
        Message_EventListener(Message_Event_AlarmGoneOff) with
   record
   Event : Message_AlarmGoneOff_Pointer;
   end record;


   type Alarm_Reason_Type is (Set_Local,Set_UTC,Cancel);

   type OS_Date_And_Time is
   record
   Time : Char_Array(1..5);
   end record;
   pragma Convention (C, OS_Date_And_Time);

   type Alarm_Date_And_Time is
   record
   Year   : Short_Integer;
   Month  : Byte;
   Date   : Byte;
   Hour   : Byte;
   Minute : Byte;
   end record;
   pragma Convention (C, Alarm_Date_And_Time);
   
   type Time_Type (Time : Alarm_Reason_Type := Set_Local) is
   record
   case Time is
   when Set_UTC   => UTC   : OS_Date_And_Time;
   when Set_Local => Local : Alarm_Date_And_Time;
   when Cancel    => null;
   end case;
   end record;
   --pragma Unchecked_Union(Time_Type);
   pragma Convention (C, Time_Type);

   --
   -- This message can be used to set/cancel alarms.
   --If the message is sent recorded then !Alarm acknowledges with 0 if successful or a null terminated error string.
   --
   type Message_AlarmSet is
   record
   Header         : Message_Event_Header;
   Set_Reason     : Alarm_Reason_Type;
   Time           : Time_Type;
   Sender         : Char_Array (1..40);
   Alarm_Name     : Char_Array (1..40);
   end record;
   pragma Convention (C, Message_AlarmSet);
   
   type Message_AlarmSet_Pointer is access Message_AlarmSet;

   type AMEL_Message_AlarmSet is abstract new
        Message_EventListener(Message_Event_AlarmSet) with
   record
   Event : Message_AlarmSet_Pointer;
   end record;

   function To_Wimp_Block is
      new Ada.Unchecked_Conversion (Source => Message_AlarmSet_Pointer,
                                    Target => Wimp_Block_Pointer);

end RASCAL.Alarm;
