------------------------------------------------------------------------------ ------------------------------------------------------------------------------ -- 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-2020, Frank Singhoff, Alain Plantec, Jerome Legrand, -- Hai Nam Tran, Stephane Rubini -- -- The Cheddar project was started in 2002 by -- Frank Singhoff, Lab-STICC UMR 6285, Université 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 AUTHORS.txt and SPONSORS.txt -- -- 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$ -- $Date$ -- $Author: singhoff $ ------------------------------------------------------------------------------ ------------------------------------------------------------------------------ with Translate; use Translate; with unbounded_strings; use unbounded_strings; with Ada.Exceptions; use Ada.Exceptions; with Processors; use Processors; with core_units; use core_units; use core_units.Core_Units_Table_Package; with Objects; use Objects; use Objects.Generic_Object_Set_Package; with Objects.extended; use Objects.extended; with text_io; use text_io; with Ada.Strings.Unbounded; use Ada.Strings.Unbounded; with Unbounded_Strings; use Unbounded_Strings; use Unbounded_Strings.Strings_Table_Package; use Unbounded_Strings.Unbounded_String_List_Package; with initialize_framework; use initialize_framework; package body deployment_Set is procedure Check_deployment (My_deployments : in deployments_Set; Name : in Unbounded_String; resource_entities : in Generic_Objects_Set; consumer_entities : in Generic_Objects_Set; allocation_file : in Unbounded_String; capacity : in Integer; period : in Integer; priority : in Integer; Is_Preemptive : in Preemptives_Type; Quantum : in Integer; File_Name : in Unbounded_String; A_Scheduler : in Schedulers_Type; automaton_name : in Unbounded_String) is begin if Name = "" then Raise_Exception (Invalid_Parameter'Identity, To_String (Lb_deployment_Name (Current_Language) & Lb_Mandatory (Current_Language))); end if; if not Is_A_Valid_Identifier (Name) then Raise_Exception (Invalid_Parameter'Identity, To_String (Lb_deployment (Current_Language) & " " & Name & " : " & Lb_deployment_Name (Current_Language) & Lb_Colon & Lb_Invalid_Identifier (Current_Language))); end if; if not Is_A_Valid_Identifier (allocation_file) then Raise_Exception (Invalid_Parameter'Identity, To_String (Lb_deployment (Current_Language) & " " & Name & " : allocation file " & Lb_Colon & Lb_Invalid_Identifier (Current_Language))); end if; if not Is_A_Valid_Identifier (file_name) then Raise_Exception (Invalid_Parameter'Identity, To_String (Lb_deployment (Current_Language) & " " & Name & " : " & Lb_file_Name (Current_Language) & Lb_Colon & Lb_Invalid_Identifier (Current_Language))); end if; if (allocation_file = empty_string) then if (A_Scheduler = pipeline_User_Defined_Protocol) and (File_Name = "") then Raise_Exception (Invalid_Parameter'Identity, To_String (Lb_deployment (Current_Language) & Name & " : " & Lb_File_Name (Current_Language) & Lb_Mandatory (Current_Language))); end if; if (File_Name /= "") and (A_Scheduler /= pipeline_User_Defined_Protocol) and (A_Scheduler /= Automata_User_Defined_Protocol) then Raise_Exception (Invalid_Parameter'Identity, To_String (Lb_deployment (Current_Language) & Name & " : " & Lb_File_Name_Control (Current_Language))); end if; if period < 0 then Raise_Exception (Invalid_Parameter'Identity, To_String (Lb_deployment (Current_Language) & " " & Name & " : " & Lb_Period (Current_Language) & Lb_Must_Be (Current_Language) & Lb_greater_or_equal_than (Current_Language) & To_Unbounded_String ("0"))); end if; if capacity < 0 then Raise_Exception (Invalid_Parameter'Identity, To_String (Lb_deployment (Current_Language) & " " & Name & " : " & Lb_Capacity (Current_Language) & Lb_Must_Be (Current_Language) & Lb_greater_or_equal_than (Current_Language) & To_Unbounded_String ("0"))); end if; if (priority < Integer (Priority_Range'First)) or (priority > Integer (Priority_Range'Last)) then Raise_Exception (Invalid_Parameter'Identity, To_String (Lb_deployment (Current_Language) & " " & Name & " : " & Lb_Invalid_Priority (Current_Language))); end if; if (Quantum /= 0) and (A_Scheduler /= Posix_1003_Highest_Priority_First_Protocol) and (A_Scheduler /= Round_Robin_Protocol) and (A_Scheduler /= Hierarchical_Round_Robin_Protocol) and (A_Scheduler /= Hierarchical_Cyclic_Protocol) then Raise_Exception (Invalid_Parameter'Identity, To_String (Lb_deployment (Current_Language) & Name & " : " & Lb_Quantum_Control (Current_Language))); end if; if (Quantum < 0) then Raise_Exception (Invalid_Parameter'Identity, To_String (Lb_deployment (Current_Language) & Name & " : " & "Quantum" & Lb_Must_Be (Current_Language) & Lb_greater_or_equal_than (Current_Language) & To_Unbounded_String ("0"))); end if; if (A_Scheduler = No_Scheduling_Protocol) then Raise_Exception (Invalid_Parameter'Identity, To_String (Lb_deployment (Current_Language) & " " & Name & " : " & Lb_Invalid_Scheduler (Current_Language))); end if; end if; if (get_number_of_elements (consumer_entities) = 0) then Raise_Exception (Invalid_Parameter'Identity, To_String (Lb_deployment (Current_Language) & " " & Name & " : " & Lb_source_set(Current_Language) & Lb_can_not_be_empty(Current_Language))); end if; if (get_number_of_elements (resource_entities) = 0) then Raise_Exception (Invalid_Parameter'Identity, To_String (Lb_deployment (Current_Language) & " " & Name & " : " & Lb_sink_set(Current_Language) & Lb_can_not_be_empty(Current_Language))); end if; end Check_deployment; procedure Add_deployment (My_deployments : in out deployments_set; Name : in Unbounded_String; resource_entities : in Generic_Objects_Set; consumer_entities : in Generic_Objects_Set; allocation_description : in Unbounded_String; capacity : in Integer :=0; period : in Integer :=0; priority : in Integer :=0; Is_Preemptive : in Preemptives_Type := preemptive; Quantum : in Integer := 0; File_Name : in Unbounded_String := empty_string; A_Scheduler : in Schedulers_Type := No_Scheduling_Protocol; automaton_name : in Unbounded_String := empty_string) is Dummy : generic_deployment_Ptr; begin Add_deployment (My_deployments, Dummy, Name, resource_entities, consumer_entities, allocation_description, capacity, period, priority, is_preemptive, quantum, file_name, a_scheduler, automaton_name); end Add_deployment; procedure Add_deployment (My_deployments : in out deployments_set; A_deployment : in out generic_deployment_Ptr; Name : in Unbounded_String; resource_entities : in Generic_Objects_Set; consumer_entities : in Generic_Objects_Set; allocation_description : in Unbounded_String ; capacity : in Integer :=0; period : in Integer :=0; priority : in Integer :=0; Is_Preemptive : in Preemptives_Type := preemptive; Quantum : in Integer := 0; File_Name : in Unbounded_String := empty_string; A_Scheduler : in Schedulers_Type := No_Scheduling_Protocol; automaton_name : in Unbounded_String := empty_string) is My_Iterator : deployments_iterator; begin check_initialize; Check_deployment (My_deployments, Name, resource_entities, consumer_entities, allocation_description, capacity, period, priority, Is_Preemptive, Quantum, File_Name, A_Scheduler, automaton_name); if (get_number_of_elements (My_deployments) > 0) then reset_iterator (My_deployments, My_Iterator); loop current_element (My_deployments, A_deployment, My_Iterator); if (Name = A_deployment.name) then Raise_Exception (Invalid_Parameter'Identity, To_String (Lb_deployment (Current_Language) & " " & Name & " : " & Lb_deployment_Name (Current_Language) & Lb_Already_Defined (Current_Language))); end if; exit when is_last_element (My_deployments, My_Iterator); next_element (My_deployments, My_Iterator); end loop; end if; if allocation_description /= empty_string then A_deployment := new static_deployment; a_deployment.deployment_type := static_deployment_type; static_deployment_ptr(a_deployment).allocation_description := allocation_description; else A_deployment := new dynamic_deployment; a_deployment.deployment_type := dynamic_deployment_type; dynamic_deployment_ptr(a_deployment).allocation_parameters.scheduler_type := a_scheduler; dynamic_deployment_ptr(a_deployment).allocation_parameters.capacity := capacity; dynamic_deployment_ptr(a_deployment).allocation_parameters.period := period; dynamic_deployment_ptr(a_deployment).allocation_parameters.priority := Priority_Range (priority); dynamic_deployment_ptr(a_deployment).allocation_parameters.quantum:=quantum; dynamic_deployment_ptr(a_deployment).allocation_parameters.preemptive_type:=is_preemptive; dynamic_deployment_ptr(a_deployment).allocation_parameters.automaton_name:=automaton_name; dynamic_deployment_ptr(a_deployment).allocation_parameters.user_defined_scheduler_source_file_name:=file_name; end if; A_deployment.name := Name; A_deployment.consumer_entities:= consumer_entities; A_deployment.resource_entities:= resource_entities; add (My_deployments, A_deployment); exception when Generic_deployment_Set.full_set => Raise_Exception (Invalid_Parameter'Identity, To_String (Lb_Can_Not_Define_More_deployments (Current_Language))); end Add_deployment; function Search_deployment (My_deployments : in deployments_Set; Name : in Unbounded_String) return Generic_deployment_Ptr is My_Iterator : deployments_Iterator; A_deployment : Generic_deployment_Ptr; Result : Generic_deployment_Ptr; Found : Boolean := False; begin if not is_empty(My_deployments) then reset_iterator (My_deployments, My_Iterator); loop current_element (My_deployments, A_deployment, My_Iterator); if (A_deployment.name = Name) then Found := True; Result := A_deployment; end if; exit when is_last_element (My_deployments, My_Iterator); next_element (My_deployments, My_Iterator); end loop; end if; if not Found then Raise_Exception (deployment_Not_Found'Identity, To_String (Lb_deployment_Name (Current_Language) & "=" & Name)); end if; return Result; end Search_deployment; function Search_deployment_By_Processor_Name (My_deployments : in deployments_Set; Name : in Unbounded_String) return Generic_deployment_Ptr is My_Iterator : deployments_Iterator; A_deployment : Generic_deployment_Ptr; Result : Generic_deployment_Ptr; resource_Iterator : Generic_Object_Set_Package.Iterator; resource_Object : Generic_Object_Ptr; Found : Boolean := False; begin if not is_empty(My_deployments) then reset_iterator (My_deployments, My_Iterator); loop current_element (My_deployments, A_deployment, My_Iterator); reset_iterator (A_deployment.resource_entities, resource_Iterator); loop current_element (A_deployment.resource_entities, resource_Object, resource_Iterator); if (resource_Object.object_type = Processor_Object_Type) and (named_object_ptr(resource_object).name = Name) then Found := True; Result := A_deployment; end if; exit when is_last_element (A_deployment.resource_entities, resource_Iterator); next_element (A_deployment.resource_entities, resource_Iterator); end loop; exit when is_last_element (My_deployments, My_Iterator); next_element (My_deployments, My_Iterator); end loop; end if; if not Found then Raise_Exception (deployment_Not_Found'Identity, To_String (Lb_deployment_Name (Current_Language) & "=" & Name)); end if; return Result; end Search_deployment_By_Processor_Name; function Search_deployment_By_resource_Task_Name (My_deployments : in deployments_Set; Name : in Unbounded_String) return Generic_deployment_Ptr is My_Iterator : deployments_Iterator; A_deployment : Generic_deployment_Ptr; Result : Generic_deployment_Ptr; resource_Iterator : Generic_Object_Set_Package.Iterator; resource_Object : Generic_Object_Ptr; Found : Boolean := False; begin if not is_empty(My_deployments) then reset_iterator (My_deployments, My_Iterator); loop current_element (My_deployments, A_deployment, My_Iterator); reset_iterator (A_deployment.resource_entities, resource_Iterator); loop current_element (A_deployment.resource_entities, resource_Object, resource_Iterator); if (resource_Object.object_type = Task_Object_Type) and (named_object_ptr(resource_object).name = Name) then Found := True; Result := A_deployment; end if; exit when is_last_element (A_deployment.resource_entities, resource_Iterator); next_element(A_deployment.resource_entities, resource_Iterator); end loop; exit when is_last_element (My_deployments, My_Iterator); next_element (My_deployments, My_Iterator); end loop; end if; if not Found then Raise_Exception (deployment_Not_Found'Identity, To_String (Lb_deployment_Name (Current_Language) & "=" & Name)); end if; return Result; end Search_deployment_By_resource_Task_Name; function Search_deployment_By_consumer_Task_Name (My_deployments : in deployments_Set; Name : in Unbounded_String) return Generic_deployment_Ptr is My_Iterator : deployments_Iterator; A_deployment : Generic_deployment_Ptr; Result : Generic_deployment_Ptr; consumer_Iterator : Generic_Object_Set_Package.Iterator; consumer_Object : Generic_Object_Ptr; Found : Boolean := False; begin if not is_empty(My_deployments) then reset_iterator (My_deployments, My_Iterator); loop current_element (My_deployments, A_deployment, My_Iterator); reset_iterator (A_deployment.consumer_entities, consumer_Iterator); loop current_element (A_deployment.consumer_entities, consumer_Object, consumer_Iterator); if (consumer_Object.object_type = Task_Object_Type) and (named_object_ptr(consumer_object).name = Name) then Found := True; Result := A_deployment; end if; exit when is_last_element (A_deployment.consumer_entities, consumer_Iterator); next_element (A_deployment.consumer_entities, consumer_Iterator); end loop; exit when is_last_element (My_deployments, My_Iterator); next_element (My_deployments, My_Iterator); end loop; end if; if not Found then Raise_Exception (deployment_Not_Found'Identity, To_String (Lb_deployment_Name (Current_Language) & "=" & Name)); end if; return Result; end Search_deployment_By_consumer_Task_Name; procedure Delete_Deployment (my_deployments : in out Deployments_Set; name : in Unbounded_String) is the_deployment : Generic_Deployment_Ptr; begin the_deployment := Search_Deployment(my_deployments,name); Delete(my_deployments,the_deployment); end Delete_Deployment; end deployment_Set;