polyorb_hi-output.adb 6 KB
Newer Older
1 2 3 4 5 6 7 8
------------------------------------------------------------------------------
--                                                                          --
--                          PolyORB HI COMPONENTS                           --
--                                                                          --
--                    P O L Y O R B _ H I . O U T P U T                     --
--                                                                          --
--                                 B o d y                                  --
--                                                                          --
jhugues's avatar
jhugues committed
9
--    Copyright (C) 2006-2009 Telecom ParisTech, 2010-2012 ESA & ISAE.      --
10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28
--                                                                          --
-- PolyORB HI is free software; you  can  redistribute  it and/or modify it --
-- under terms of the GNU General Public License as published by the Free   --
-- Software Foundation; either version 2, or (at your option) any later.    --
-- PolyORB HI 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 General --
-- Public License for more details. You should have received  a copy of the --
-- GNU General Public  License  distributed with PolyORB HI; see file       --
-- COPYING. If not, write  to the Free  Software Foundation, 51 Franklin    --
-- Street, Fifth Floor, Boston, MA 02111-1301, USA.                         --
--                                                                          --
-- As a special exception,  if other files  instantiate  generics from this --
-- unit, or you link  this unit with other files  to produce an executable, --
-- this  unit  does not  by itself cause  the resulting  executable  to  be --
-- covered  by the  GNU  General  Public  License.  This exception does not --
-- however invalidate  any other reasons why  the executable file  might be --
-- covered by the  GNU Public License.                                      --
--                                                                          --
jhugues's avatar
jhugues committed
29 30
--              PolyORB-HI/Ada is maintained by the TASTE project           --
--                      (taste-users@lists.tuxfamily.org)                   --
31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150
--                                                                          --
------------------------------------------------------------------------------

with PolyORB_HI.Output_Low_Level;
with PolyORB_HI.Suspenders;
with Ada.Real_Time;
with System;

package body PolyORB_HI.Output is
   use Ada.Real_Time;

   protected Lock is
      procedure Put (Text : in String);
      --  To guarantee thread-safe output display

      procedure Put_Line (Text : in String);
      --  To guarantee thread-safe output display

   private
      pragma Priority (System.Priority'Last);
   end Lock;

   protected body Lock is

      --------------
      -- Put_Line --
      --------------

      procedure Put_Line (Text : in String) is
      begin
         Unprotected_Put_Line (Text);
      end Put_Line;

      ---------
      -- Put --
      ---------

      procedure Put (Text : in String) is
      begin
         Unprotected_Put (Text);
      end Put;
   end Lock;

   --------------
   -- Put_Line --
   --------------

   procedure Put_Line (Mode : in Verbosity := Normal; Text : in String) is
   begin
      pragma Warnings (Off);
      --  Disable warnings on "Condition always true/false" because
      --  Current_Mode is a constant.

      if Mode >= Current_Mode then
         pragma Warnings (On);
         Put_Line (Text);
      end if;

   end Put_Line;

   --------------
   -- Put_Line --
   --------------

   procedure Put_Line (Text : in String) is
   begin
      Lock.Put_Line (Text);
   end Put_Line;

   ---------
   -- Put --
   ---------

   procedure Put (Mode : in Verbosity := Normal; Text : in String) is
   begin
      pragma Warnings (Off);
      --  Disable warnings on "Condition always true/false" because
      --  Current_Mode is a constant.

      if Mode >= Current_Mode then
         pragma Warnings (On);
         Put (Text);
      end if;

   end Put;

   ---------
   -- Put --
   ---------

   procedure Put (Text : in String) is
   begin
      Lock.Put (Text);
   end Put;

   --------------------------
   -- Unprotected_Put_Line --
   --------------------------

   procedure Unprotected_Put_Line (Text : in String) is
   begin
      Unprotected_Put (Text);
      PolyORB_HI.Output_Low_Level.New_Line;
   end Unprotected_Put_Line;

   ---------------------
   -- Unprotected_Put --
   ---------------------

   procedure Unprotected_Put (Text : in String) is
      Start_Time : Time renames  PolyORB_HI.Suspenders.System_Startup_Time;
      Elapsed    : Time_Span;
   begin
      if Start_Time = Time_First then
         Elapsed := To_Time_Span (0.0);
      else
         Elapsed := Clock - Start_Time;
      end if;

      PolyORB_HI.Output_Low_Level.Put ("[");
151 152
      PolyORB_HI.Output_Low_Level.Put
        (Duration'Image (To_Duration (Elapsed * 1000)));
153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 175 176 177 178 179 180 181 182 183 184 185 186 187 188 189
      PolyORB_HI.Output_Low_Level.Put ("] ");
      PolyORB_HI.Output_Low_Level.Put (Text);
   end Unprotected_Put;

   ----------
   -- Dump --
   ----------

   subtype Output_Line is String (1 .. 48);

   Hex : constant String := "0123456789ABCDEF";
   Nil : constant Output_Line := (Output_Line'Range => ' ');

   procedure Dump
     (Stream : Stream_Element_Array;
      Mode   : Verbosity            := Verbose)
   is
      Index   : Natural := 1;
      Output  : Output_Line := Nil;
   begin
      for J in Stream'Range loop
         Output (Index)     := ' ';
         Output (Index + 1) := Hex (Natural (Stream (J) / 16) + 1);
         Output (Index + 2) := Hex (Natural (Stream (J) mod 16) + 1);
         Index := Index + 3;

         if Index > Output'Length then
            Put_Line (Mode, Output);
            Index := 1;
            Output := Nil;
         end if;
      end loop;

      Put_Line (Mode, "DUMP" & Output);
   end Dump;

end PolyORB_HI.Output;