------------------------------------------------------------------------------
------------------------------------------------------------------------------
-- Cheddar is a GNU GPL real-time scheduling analysis tool.
-- This program provides services to automatically check schedulability and
-- other performance criteria of real-time architecture models.
--
-- Copyright (C) 2002-2023, Frank Singhoff, Alain Plantec, Jerome Legrand,
-- Hai Nam Tran, Stephane Rubini
--
-- The Cheddar project was started in 2002 by
-- Frank Singhoff, Lab-STICC UMR CNRS 6285, Universite de Bretagne Occidentale
--
-- Cheddar has been published in the "Agence de Protection des Programmes/France" in 2008.
-- Since 2008, Ellidiss technologies also contributes to the development of
-- Cheddar and provides industrial support.
--
-- The full list of contributors and sponsors can be found in README.md
--
-- This program is free software; you can redistribute it and/or modify
-- it under the terms of the GNU General Public License as published by
-- the Free Software Foundation; either version 2 of the License, or
-- (at your option) any later version.
--
-- This program 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
-- along with this program; if not, write to the Free Software
-- Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
--
--
-- Contact : cheddar@listes.univ-brest.fr
--
------------------------------------------------------------------------------
-- Last update :
-- $Rev: 4589 $
-- $Date: 2023-09-29 16:02:19 +0200 (ven. 29 sept. 2023) $
-- $Author: singhoff $
------------------------------------------------------------------------------
------------------------------------------------------------------------------
with sets;
with task_set; use task_set;
with unbounded_strings; use unbounded_strings;
with Ada.Strings.Unbounded; use Ada.Strings.Unbounded;
with Ada.Strings.Unbounded.Text_IO; use Ada.Strings.Unbounded.Text_IO;
use type task_set.tasks_range;
--#[debug]
with debug; use debug;
---------------------------------------------------------------------
-- Package Marzhin_Utils
-- Purpose: Contain types definitions, functions and procedures
-- usefull for sockets manipulations such as IO and configuration.
-- Used mainly to translate Cheddar events to Marzhin event format
-- as well as parsing specific xml event related data.
-- Extra: Documentations on methods are in the specification file.
---------------------------------------------------------------------
package body Marzhin_Utils is
--------------
-- Add_Port --
--------------
-- procedure Add_Port (
-- Task_Name : in Unbounded_String;
-- Resource_Name : in Unbounded_String;
-- State_Value : in Unbounded_String)
-- is
-- begin
-- Ports.Port_Array(Ports.Port_Nb).Task_Data := Task_Name;
-- Ports.Port_Array(Ports.Port_Nb).Resource_Data := Resource_Name;
-- Ports.Port_Array(Ports.Port_Nb).State_Data := State_Value;
-- Ports.Port_Nb := Ports.Port_Nb + 1;
-- end Add_Port;
----------------------------
-- Encode_Task_Capacities --
----------------------------
function Encode_Task_Capacities
(Si : scheduling_information) return Unbounded_String
is
Output : Unbounded_String;
begin
for curr_task in 0 .. Si.number_of_tasks - 1 loop
put_debug
("__INFO__ :: Task -> " &
Si.tcbs (curr_task).tsk.name &
" || Capacity -> " &
Si.tcbs (curr_task).tsk.capacity'img);
end loop;
Output := To_Unbounded_String ("");
return Output;
end Encode_Task_Capacities;
-------------------------------
-- Get_Event_String_From_XML --
-------------------------------
procedure Get_Event_String_From_XML
(XML_String : in Unbounded_String;
Event_String : in out Unbounded_String)
is
XML_Start_Tag_Time_Unit_Event : constant String := "";
XML_End_Tag_Time_Unit_Event : constant String := "";
XML_Start_Tag_Type_Event : constant String := "";
XML_End_Tag_Type_Event : constant String := "";
XML_Start_Tag_Position : Natural;
XML_End_Tag_Position : Natural;
XML_Substring : Unbounded_String;
begin
-- Get time_unit_event tag start and end positions in the string
XML_Start_Tag_Position :=
Index (XML_String, XML_Start_Tag_Time_Unit_Event) +
XML_Start_Tag_Time_Unit_Event'length;
XML_End_Tag_Position :=
Index (XML_String, XML_End_Tag_Time_Unit_Event) - 1;
-- Get substring without time_unit_event tag
XML_Substring :=
substring (XML_String, XML_Start_Tag_Position, XML_End_Tag_Position);
-- Get type_of_event tag start and end positions in the substring
XML_Start_Tag_Position :=
Index (XML_Substring, XML_Start_Tag_Type_Event) +
XML_Start_Tag_Type_Event'length;
XML_End_Tag_Position :=
Index (XML_Substring, XML_End_Tag_Type_Event) - 1;
-- Get the type of event string
Event_String :=
substring
(XML_Substring,
XML_Start_Tag_Position,
XML_End_Tag_Position);
end Get_Event_String_From_XML;
------------------------------
-- Get_Resource_Id_From_XML --
------------------------------
procedure Get_Resource_Id_From_XML
(XML_String : in Unbounded_String;
Event_String : in Unbounded_String;
Resource_Id_String : in out Unbounded_String)
is
XML_Start_Tag : Unbounded_String := To_Unbounded_String ("ref=""");
XML_End_Tag : constant String := """ />";
XML_Start_Tag_Position : Natural;
XML_End_Tag_Position : Natural;
begin
if Event_String = To_Unbounded_String ("WAIT_FOR_RESOURCE") then
XML_Start_Tag := To_Unbounded_String ("";
XML_Start_Tag_Position : Natural;
XML_End_Tag_Position : Natural;
begin
if Event_String = To_Unbounded_String ("PREEMPTION") then
XML_Start_Tag := To_Unbounded_String ("[unlock]");
elsif Event_String = To_Unbounded_String ("THREAD_GET_RESOURCE") then
Event_String := To_Unbounded_String ("RESOURCE [unlock]->[lock]");
end if;
end Set_To_Marzhin_Resource_Event;
------------------------------
-- To_Marzhin_Output_Format --
------------------------------
function To_Marzhin_Output_Format
(Tick : Natural;
Event : Unbounded_String;
Data : Unbounded_String) return Unbounded_String
is
Return_String : Unbounded_String;
begin
Return_String := To_Unbounded_String (Tick'img);
Return_String := Trim (Return_String, Ada.Strings.Left);
Return_String :=
"tick=" & Return_String & " " & Event & " " & "root." & Data;
return Return_String;
end To_Marzhin_Output_Format;
end Marzhin_Utils;