polyorb_hi-messages.ads 5.71 KB
Newer Older
1 2 3 4 5 6 7 8
------------------------------------------------------------------------------
--                                                                          --
--                          PolyORB HI COMPONENTS                           --
--                                                                          --
--                  P O L Y O R B _ H I . M E S S A G E S                   --
--                                                                          --
--                                 S p e c                                  --
--                                                                          --
9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25
--    Copyright (C) 2006-2009 Telecom ParisTech, 2010-2015 ESA & ISAE.      --
--                                                                          --
-- PolyORB-HI is free software; you can redistribute it and/or modify under --
-- terms of the  GNU General Public License as published  by the Free Soft- --
-- ware  Foundation;  either version 3,  or (at your option) any later ver- --
-- sion. 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.                     --
--                                                                          --
-- As a special exception under Section 7 of GPL version 3, you are granted --
-- additional permissions described in the GCC Runtime Library Exception,   --
-- version 3.1, as published by the Free Software Foundation.               --
--                                                                          --
-- You should have received a copy of the GNU General Public License and    --
-- a copy of the GCC Runtime Library Exception along with this program;     --
-- see the files COPYING3 and COPYING.RUNTIME respectively.  If not, see    --
-- <http://www.gnu.org/licenses/>.                                          --
26
--                                                                          --
jhugues's avatar
jhugues committed
27 28
--              PolyORB-HI/Ada is maintained by the TASTE project           --
--                      (taste-users@lists.tuxfamily.org)                   --
29 30 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
--                                                                          --
------------------------------------------------------------------------------

--  Definition of the messages exchanged by PolyORB HI partitions

with PolyORB_HI.Streams;
with PolyORB_HI_Generated.Deployment;

package PolyORB_HI.Messages is

   pragma Preelaborate;

   use PolyORB_HI.Streams;
   use PolyORB_HI_Generated.Deployment;

   type Message_Type is private;
   --  Base type of messages exchanged between nodes

   Message_Length_Size : constant := 2;
   --  Number of bytes to store a message size

   Header_Size : constant := Message_Length_Size + 2;
   --  Size of the header (see the documentation in the body for
   --  details on the header internal structure).

   PDU_Size : constant := Header_Size + (Max_Payload_Size / 8) + 1;
   --  Maximum size of a request

   subtype Message_Size_Buffer is Stream_Element_Array
     (1 .. Message_Length_Size);
   --  The sub-buffer that holds the message length

   function To_Length (B : Message_Size_Buffer) return Stream_Element_Count;
62 63
   function To_Buffer (L : Stream_Element_Count) return Message_Size_Buffer
     with Pre => (L < 2**16 -1); -- XXX Provide a better bound for L
64 65 66 67 68
   --  Conversion functions to store/extract a length in/from a sub-buffer.

   procedure Read
     (Stream : in out Message_Type;
      Item   :    out Stream_Element_Array;
69 70
      Last   :    out Stream_Element_Offset)
     with Pre => (Valid (Stream));
71 72 73 74 75 76 77
   --  Move Item'Length stream elements from the specified stream to
   --  fill the array Item. The index of the last stream element
   --  transferred is returned in Last. Last is less than Item'Last
   --  only if the end of the stream is reached.

   procedure Write
     (Stream : in out Message_Type;
78 79
      Item   :        Stream_Element_Array)
     with Pre => (Valid (Stream));
80 81 82 83 84
   --  Append Item to the specified stream

   procedure Reallocate (M : in out Message_Type);
   --  Reset M

85 86
   function Payload (M : Message_Type) return Stream_Element_Array
      with Pre => (Valid (M));
87 88
   --  Return the remaining payload of message M

89 90
   function Sender (M : Message_Type) return Entity_Type
       with Pre => (Valid (M));
91 92 93 94 95 96 97
   function Sender (M : Stream_Element_Array) return Entity_Type;
   --  Return the sender of the message M

   function Encapsulate
     (Message : Message_Type;
      From    : Entity_Type;
      Entity  : Entity_Type)
98 99
     return Stream_Element_Array
     with Pre => (Valid (Message));
100 101 102
   --  Return a byte array including a two byte header (length and
   --  originator entity) and Message payload.

103 104
   function Valid (Message : Message_Type) return Boolean;

105 106
private

107 108 109
   subtype PDU_Index is Stream_Element_Count range 0 .. PDU_Size;
   subtype PDU is Stream_Element_Array (1 .. PDU_Index'Last);

110 111
   Empty_PDU : constant PDU := (others => 0);

112
   type Message_Type is record
113
      Content : PDU := Empty_PDU;
114 115
      First   : PDU_Index := 1;
      Last    : PDU_Index := 0;
116 117
   end record;

118
   function Valid (Message : Message_Type) return Boolean is
119 120
      (Message.First >= Message.Content'First
         and then Message.Last <= Message.Content'Last);
yoogx's avatar
yoogx committed
121 122 123
      --  The following part cannot be correct in the case Message is
      --  not initialized, see defaults for Message_Type
      --    and then Message.First <= Message.Last
124 125 126 127 128 129 130

   function Payload (M : Message_Type) return Stream_Element_Array is
      (M.Content (M.First .. M.Last));

   function Sender (M : Message_Type) return Entity_Type is
      (Sender (Payload (M)));

131 132 133 134
   pragma Inline (To_Length);
   pragma Inline (To_Buffer);

end PolyORB_HI.Messages;