polyorb_hi-utils.ads 5.72 KB
Newer Older
1 2 3 4 5 6 7 8
------------------------------------------------------------------------------
--                                                                          --
--                          PolyORB HI COMPONENTS                           --
--                                                                          --
--                     P O L Y O R B _ H I . U T I L S                      --
--                                                                          --
--                                 S p e c                                  --
--                                                                          --
9
--    Copyright (C) 2007-2009 Telecom ParisTech, 2010-2014 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
--                                                                          --
------------------------------------------------------------------------------

--  This package contains some utility routines used by PolyORB-HI

36
with Ada.Unchecked_Conversion;
37
with Interfaces;
38
with System;
39

40
with PolyORB_HI_Generated.Deployment;
41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64

package PolyORB_HI.Utils is

   pragma Preelaborate;

   use Interfaces;
   use PolyORB_HI_Generated.Deployment;

   ---------------------------
   -- Low-level marshallers --
   ---------------------------

   --  These subprograms allow to get the proper enumerator depending
   --  on their internal codes specified as representation clause in
   --  the deployment package.
   --
   --  Note:
   --  1) these converters require that the size of the various
   --  enumerators be fixed to either 8 or 16 bits. This requirement
   --  is enforced in the PolyORB_HI_Generated.Deployment package
   --  spec.
   --  2) these converters must be endianness-independent

   function Internal_Code is new Ada.Unchecked_Conversion
65
     (Entity_Type, Unsigned_8);
66
   function Corresponding_Entity is new Ada.Unchecked_Conversion
67
     (Unsigned_8, Entity_Type);
68 69

   function Internal_Code is new Ada.Unchecked_Conversion
70
     (Node_Type, Unsigned_8);
71
   function Corresponding_Node is new Ada.Unchecked_Conversion
72
     (Unsigned_8, Node_Type);
73

74
   function Internal_Code (P : Port_Type) return Unsigned_16;
75
   function Corresponding_Port (I : Unsigned_16) return Port_Type;
76

77 78
   function Swap_Bytes (B : Interfaces.Unsigned_16)
                       return Interfaces.Unsigned_16;
79 80 81 82 83 84 85
   --  Swap bytes iff the host is little endian. This function is
   --  notionnally equivalent to htons().

   ------------
   -- String --
   ------------

86 87
   HI_String_Size : constant := 80;

88
   type HI_String is private;
89

90 91 92 93 94 95 96 97 98 99
   function To_Hi_String (S : String) return HI_String
     with Post => (Valid (To_Hi_String'Result));

   function To_String (H : HI_String) return String
     with Pre => (Valid (H));

   function Length (H : HI_String) return Natural
     with Pre => (Valid (H));

   function Valid (H : HI_String) return Boolean;
100

101
   function Parse_String (S : String; First : Integer; Delimiter : Character)
102 103 104 105 106 107 108 109
                         return Integer
     with Pre => (First >= S'First and First <= S'Last);
   --  XXX GNATProve GPL2014 cannot prove this, TBI
   --            Post => ((Parse_String'Result = S'Last)
   --                     or (Parse_String'Result in S'Range
   --                           and then Parse_String'Result > S'First
   --                           and then S (Parse_String'Result - 1) = Delimiter));
   --  Return index of the character just before Delimiter, or return S'last
110

111 112 113 114 115 116
   ------------------
   -- Naming Table --
   ------------------

   type Naming_Entry is record
      Location : PolyORB_HI.Utils.HI_String;
117 118
      Port     : Natural;
      Variable : System.Address;
119 120 121 122 123
   end record;

   type Naming_Table_Type is array (Node_Type'Range)
     of PolyORB_HI.Utils.Naming_Entry;

124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141
private

   type HI_String is record
      S : String (1 ..HI_String_Size);
      L : Natural;
      --  It is exepected L <= HI_String_Size
      --  XXX Todo add a type invariant
   end record;

   function Length (H : HI_String) return Natural is
      (H.L);

   function Valid (H : HI_String) return Boolean is
      (H.L <= HI_String_Size);

   function To_String (H : HI_String) return String is
      (H.S (1 .. H.L));

142
end PolyORB_HI.Utils;