polyorb_hi-output.adb 6.52 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                                  --
--                                                                          --
9
--    Copyright (C) 2006-2009 Telecom ParisTech, 2010-2013 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
--                                                                          --
------------------------------------------------------------------------------

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;

42 43 44 45 46 47 48 49 50 51
   procedure Unprotected_Put_Line (Text : in String);
   --  Not thread-safe Put_Line function

   procedure Unprotected_Put (Text : in String);
   --  Not thread-safe Put function

   ----------
   -- Lock --
   ----------

52
   protected Lock is
53 54 55
      --  This lock has been defined to guarantee thread-safe output
      --  display

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 151 152 153
      procedure Put (Text : in String);

      procedure Put_Line (Text : in String);

   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;

   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;

   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 ("[");
154 155
      PolyORB_HI.Output_Low_Level.Put
        (Duration'Image (To_Duration (Elapsed * 1000)));
156 157 158 159 160 161 162 163
      PolyORB_HI.Output_Low_Level.Put ("] ");
      PolyORB_HI.Output_Low_Level.Put (Text);
   end Unprotected_Put;

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

164 165 166
   subtype Output_Position is Positive range 1 .. 48;

   subtype Output_Line is String (Output_Position);
167 168 169 170 171 172 173 174

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

   procedure Dump
     (Stream : Stream_Element_Array;
      Mode   : Verbosity            := Verbose)
   is
175
      Index   : Output_Position := Output_Position'First;
176 177 178
      Output  : Output_Line := Nil;
   begin
      for J in Stream'Range loop
179
         if Index + 3 <= Output'Last then
180 181 182 183 184
            Output (Index)     := ' ';
            Output (Index + 1) := Hex (Natural (Stream (J) / 16) + 1);
            Output (Index + 2) := Hex (Natural (Stream (J) mod 16) + 1);
            Index := Index + 3;
         else
185 186 187 188 189 190
            Put_Line (Mode, Output);
            Index := 1;
            Output := Nil;
         end if;
      end loop;

191
      Put_Line (Mode,  Output);
192 193
   end Dump;

194 195 196 197 198 199 200 201 202 203 204 205 206
   ---------
   -- "+" --
   ---------

   function "+" (S1 : String; S2 : String) return String is
      S : String (1 .. S1'Length + S2'Length);
   begin
      S (1 .. S1'Length) := S1 (S1'First .. S1'Last);
      S (S1'Length + 1 .. S'Last) := S2 (S2'First .. S2'Last);

      return S;
   end "+";

207
end PolyORB_HI.Output;