---------------------------------- --------- --------------------------------------- -- -- -- 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;