--------------------------------------------------------
--  This file was automatically generated by Ocarina  --
--  Do NOT hand-modify this file, as your             --
--  changes will be lost when you re-run Ocarina      --
--------------------------------------------------------
pragma Style_Checks
 ("NM32766");

with Interfaces;
with PolyORB_HI.Port_Type_Marshallers;
with PolyORB_HI.Utils;
with PolyORB_HI.Transport_Low_Level;
with PolyORB_HI_Generated.Activity;
use PolyORB_HI_Generated.Activity;
with Ada.Real_Time;
with PolyORB_HI.Time_Marshallers;
with PolyORB_HI_Generated.Marshallers;

package body PolyORB_HI_Generated.Transport is

  procedure Producer_Consumer_Result_Consumer_Deliver
   (Port : PolyORB_HI_Generated.Deployment.Port_Type;
    From : PolyORB_HI_Generated.Deployment.Entity_Type;
    Msg : in out PolyORB_HI.Messages.Message_Type);

  -------------
  -- Deliver --
  -------------

  procedure Deliver
   (Entity : PolyORB_HI_Generated.Deployment.Entity_Type;
    Message : PolyORB_HI.Streams.Stream_Element_Array)
  is
    use PolyORB_HI_Generated.Deployment;
    Msg : PolyORB_HI.Messages.Message_Type;
    Value : Interfaces.Unsigned_16;
    Port : PolyORB_HI_Generated.Deployment.Port_Type;
    use type PolyORB_HI.Streams.Stream_Element_Offset;
  begin
    PolyORB_HI.Messages.Write
     (Msg,
      Message
       ((Message'First
          + PolyORB_HI.Messages.Header_Size) .. Message'Last));
    PolyORB_HI.Port_Type_Marshallers.Unmarshall
     (Value,
      Msg);
    Port :=
     PolyORB_HI.Utils.Corresponding_Port
       (Value);
    if (Entity
      = PolyORB_HI_Generated.Deployment.pr_A_Result_Consumer_K)
    then
      Producer_Consumer_Result_Consumer_Deliver
       (Port,
        PolyORB_HI.Messages.Sender
         (Message),
        Msg);
    end if;
  end Deliver;

  function Producer_Consumer_Producer_Send
   (Entity : PolyORB_HI_Generated.Deployment.Entity_Type;
    Message : PolyORB_HI.Streams.Stream_Element_Array)
   return PolyORB_HI.Errors.Error_Kind;

  ----------
  -- Send --
  ----------

  function Send
   (From : PolyORB_HI_Generated.Deployment.Entity_Type;
    Entity : PolyORB_HI_Generated.Deployment.Entity_Type;
    Message : PolyORB_HI.Messages.Message_Type)
   return PolyORB_HI.Errors.Error_Kind
  is
    use PolyORB_HI_Generated.Deployment;
    Msg : constant PolyORB_HI.Streams.Stream_Element_Array :=
     PolyORB_HI.Messages.Encapsulate
       (Message,
        From,
        Entity);
  begin
    if (From
      = PolyORB_HI_Generated.Deployment.pr_A_Producer_K)
    then
      return Producer_Consumer_Producer_Send
       (Entity,
        Msg);
    else
      return PolyORB_HI.Errors.Error_Kind'
       (PolyORB_HI.Errors.Error_Transport);
    end if;
  end Send;

  -------------------------------------
  -- Producer_Consumer_Producer_Send --
  -------------------------------------

  function Producer_Consumer_Producer_Send
   (Entity : PolyORB_HI_Generated.Deployment.Entity_Type;
    Message : PolyORB_HI.Streams.Stream_Element_Array)
   return PolyORB_HI.Errors.Error_Kind
  is
    pragma Warnings
     (Off,
      Message);
    pragma Warnings
     (Off,
      Entity);
    use PolyORB_HI_Generated.Deployment;
  begin
    if (Entity
      = PolyORB_HI_Generated.Deployment.pr_B_Consumer_K)
    then
      --  Default transport mechanism
      return PolyORB_HI.Transport_Low_Level.Send
       (PolyORB_HI_Generated.Deployment.Entity_Table
         (Entity),
        Message);
    else
      return PolyORB_HI.Errors.Error_Kind'
       (PolyORB_HI.Errors.Error_Transport);
    end if;
  end Producer_Consumer_Producer_Send;

  -----------------------------------------------
  -- Producer_Consumer_Result_Consumer_Deliver --
  -----------------------------------------------

  procedure Producer_Consumer_Result_Consumer_Deliver
   (Port : PolyORB_HI_Generated.Deployment.Port_Type;
    From : PolyORB_HI_Generated.Deployment.Entity_Type;
    Msg : in out PolyORB_HI.Messages.Message_Type)
  is
    use PolyORB_HI_Generated.Deployment;
    Thread_Interface_Ü : Software_Q_Impl_Interface;
    Time_Stamp_Ü : Ada.Real_Time.Time;
  begin
    if (Port
      = PolyORB_HI_Generated.Deployment.pr_A_Result_Consumer_Data_Sink_K)
    then
      PolyORB_HI.Time_Marshallers.Unmarshall
       (Time_Stamp_Ü,
        Msg);
      PolyORB_HI_Generated.Marshallers.Unmarshall
       (Data_Sink,
        Thread_Interface_Ü,
        Msg);
      PolyORB_HI_Generated.Activity.Store_Received_Message
       (PolyORB_HI_Generated.Deployment.pr_A_Result_Consumer_K,
        Thread_Interface_Ü,
        From,
        Time_Stamp_Ü);
    end if;
  end Producer_Consumer_Result_Consumer_Deliver;

end PolyORB_HI_Generated.Transport;
