package Ada_Store.Log

with Ada.Calendar;
with Ada_Store.Station;

package Ada_Store.Log is

  type Element		is tagged private;
  
  function To_String
    (Log_Element : in Element)
     return String;
	   
  procedure Open_Log;

  procedure Put
    (Element_In	: in out Element'Class);

private
  type Sequence_Number 	is new Long_Integer range 1 .. Long_Integer'Last;

  type Element 		is tagged 
    record
      Sequence 	    : Sequence_Number;
      Calendar_Time : Ada.Calendar.Time;
      Station_ID    : Station.Identifier;
    end record;

end Ada_Store.Log;

with Ada.Streams.Stream_IO; use Ada.Streams.Stream_IO; with Ada.IO_Exceptions; package body Ada_Store.Log is -- internal Current_Sequence : Sequence_Number := 1; type Log_File is record Open : Boolean := False; As_File : File_Type; As_Stream : Stream_Access; end record; Current_Log : Log_File; -- public function To_String (Log_Element : in Element) return String is Sequence_Str : String := Sequence_Number'Image(Log_Element.Sequence); Station_Str : String := Station.Identifier'Image(Log_Element.Station_ID); begin return Sequence_Str & Station_Str; end To_String; procedure Open_Log is Log_File_Name : constant String := "Ada_Store.log"; begin begin Open(File => Current_Log.As_File, Mode => Append_File, Name => Log_File_Name); exception when Ada.IO_Exceptions.Name_Error => Create(File => Current_Log.As_File, Mode => Append_File, Name => Log_File_Name); end; Current_Log.As_Stream := Stream(Current_Log.As_File); end Open_Log; procedure Put (Element_In : in out Element'Class) is begin Current_Sequence := Current_Sequence + 1; Element(Element_In).Sequence := Current_Sequence; Element(Element_In).Calendar_Time := Ada.Calendar.Clock; Element(Element_In).Station_ID := Ada_Store.Station.This_Station; Element'Class'Output(Current_Log.As_Stream, Element_In); Flush(Current_Log.As_File); end Put; end Ada_Store.Log;

Contents Page

Copyright © 1996 Simon Johnston &
Addison Wesley Longman