----------------------------------------- --------------------------------------- -- -- -- OCARINA COMPONENTS -- -- -- -- O C A R I N A . D I A . P A R S E R . C O R E . P O R T S -- -- -- -- B o d y -- -- -- -- Copyright (C) 2005-2006, GET-Telecom Paris. -- -- -- -- Ocarina 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 version. Ocarina 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 Ocarina; 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. -- -- -- -- Ocarina is maintained by the Ocarina team -- -- (ocarina-users@listes.enst.fr) -- -- -- ------------------------------------------------------------------------------ with Ada.Text_IO; use Ada.Text_IO; with DOM.Core.Nodes; with Ocarina.Dia.Parser.Core.Attributes; with Ocarina.Dia.Parser.Translate.Misc; package body Ocarina.Dia.Parser.Core.Ports is ---------------- -- Print_Port -- ---------------- procedure Print_Port (P : Port) is begin case P.Port_Type_Arg is when Access_Provider => Put_Line ("Access Provider"); when Access_Requirer => Put_Line ("Access Requirer"); when In_Data_Port => Put_Line ("In Data Port"); when In_Event_Port => Put_Line ("In Event Port"); when In_Event_Data_Port => Put_Line ("In Event Data Port"); when Out_Data_Port => Put_Line ("Out Data Port"); when Out_Event_Port => Put_Line ("Out Event Port"); when Out_Event_Data_Port => Put_Line ("Out Event Data Port"); when In_Out_Data_Port => Put_Line ("In Out Data Port"); when In_Out_Event_Port => Put_Line ("In Out Event Port"); when In_Out_Event_Data_Port => Put_Line ("In Out Event Data Port"); when Port_Group => Put_Line ("Port Group"); when Point => Put_Line ("Connection Point"); end case; end Print_Port; ----------------- -- Print_Ports -- ----------------- procedure Print_Ports (PL : Port_List) is L : Port_List := PL; P : Port := null; begin while L /= null loop P := L.Hd; Put (">> "); Print_Port (P); case P.Port_Type_Arg is when Real_Port => Put_Line (">> Declaration : " & To_String (P.Declaration)); when Point => Put_Line (">> Position : " & To_String (P.Position)); end case; L := L.Tl; end loop; end Print_Ports; ---------------- -- Match_Port -- ---------------- function Match_Port (S : Unbounded_String) return Port_Type is S2 : constant String := To_String (S); begin if S2 = "9" then return Access_Provider; elsif S2 = "10" then return Access_Requirer; elsif S2 = "11" then return In_Data_Port; elsif S2 = "12" then return In_Event_Port; elsif S2 = "13" then return In_Event_Data_Port; elsif S2 = "14" then return Out_Data_Port; elsif S2 = "15" then return Out_Event_Port; elsif S2 = "16" then return Out_Event_Data_Port; elsif S2 = "17" then return In_Out_Data_Port; elsif S2 = "18" then return In_Out_Event_Port; elsif S2 = "19" then return In_Out_Event_Data_Port; elsif S2 = "20" then return Port_Group; else raise Unknown_Port; end if; end Match_Port; -------------- -- Get_Port -- -------------- function Get_Port (N : DOM.Core.Node) return Port is use DOM.Core; use Ocarina.Dia.Parser.Core.Attributes; P : Port := null; NL : constant DOM.Core.Node_List := DOM.Core.Nodes.Child_Nodes (N); E : DOM.Core.Node; begin E := Get_Attribute_Node (NL, "port_type"); P := new Port_Record (Match_Port (Get_Val_Attribute (E))); E := Get_Attribute_Node (NL, "port_declaration"); P.Declaration := Get_String_Attribute (E); return P; end Get_Port; --------------- -- Get_Ports -- --------------- function Get_Ports (Children : DOM.Core.Node_List) return Port_List is use DOM.Core; use Ocarina.Dia.Parser.Core.Attributes; L : Port_List := null; E : DOM.Core.Node; begin -- First the real ports E := Get_Attribute_Node (Children, "aadlbox_ports"); E := DOM.Core.Nodes.First_Child (E); while E /= null loop declare Q : constant Port_List := L; begin if E.Node_Type = Element_Node and then DOM.Core.Nodes.Node_Name (E) = "dia:composite" then L := new Port_List_Record; L.Hd := Get_Port (E); L.Tl := Q; end if; E := DOM.Core.Nodes.Next_Sibling (E); end; end loop; -- Then the connection points E := Get_Attribute_Node (Children, "aadlbox_connections"); E := DOM.Core.Nodes.First_Child (E); while E /= null loop declare Q : constant Port_List := L; CP : Port; EAS : DOM.Core.Named_Node_Map; begin if E.Node_Type = Element_Node and then DOM.Core.Nodes.Node_Name (E) = "dia:point" then L := new Port_List_Record; CP := new Port_Record (Point); EAS := DOM.Core.Nodes.Attributes (E); CP.Position := To_Unbounded_String (Get_Required_Attribute (EAS, "val")); L.Hd := CP; L.Tl := Q; end if; E := DOM.Core.Nodes.Next_Sibling (E); end; end loop; return L; end Get_Ports; --------------- -- Has_Ports -- --------------- function Has_Ports (N : Ocarina.Dia.Parser.Core.Node) return Boolean is begin if N.Ports /= null then return True; else return False; end if; end Has_Ports; -------------- -- Get_Port -- -------------- function Get_Port (N : Ocarina.Dia.Parser.Core.Node; I : Integer) return Port is L : Port_List := N.Ports; P : Port := null; begin for J in 1 .. I loop if L = null then return null; else P := L.Hd; L := L.Tl; end if; end loop; return P; end Get_Port; -------------------------- -- Get_Port_Declaration -- -------------------------- function Get_Port_Declaration (P : Port) return String is begin return Ocarina.Dia.Parser.Translate.Misc.Node_Name (To_String (P.Declaration)); end Get_Port_Declaration; end Ocarina.Dia.Parser.Core.Ports;