------------------------------------------------------------------------------ ------------------------------------------------------------------------------ -- 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 Ada.Exceptions; use Ada.Exceptions; with Caches; use Caches; with Objects; use Objects; with Objects.extended; use Objects.extended; with Text_IO; use Text_IO; with Translate; use Translate; with sets; with initialize_framework; use initialize_framework; with Caches; use Caches.Cache_Blocks_Table_Package; package body Cache_Block_Set is ------------------------------------------------------ -- CACHE BLOCK ------------------------------------------------------ procedure Check_Cache_Block (my_cache_blocks : in out Cache_Blocks_Set; a_cache_block : in out Cache_Block_Ptr; name : in Unbounded_String; cache_block_number : in Natural) is begin if (name = "") then Raise_Exception (Invalid_Parameter'Identity, To_String (Lb_Cache_Block_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_Cache_Block (Current_Language) & Name & " : " & Lb_Cache_Block_Name (Current_Language) & Lb_Colon & Lb_Invalid_Identifier (Current_Language))); end if; end Check_Cache_Block; procedure Add_Cache_Block (my_cache_blocks : in out Cache_Blocks_Set; a_cache_block : in out Cache_Block_Ptr; name : in Unbounded_String; cache_block_number : in Natural) is my_iterator : Cache_Blocks_Iterator; begin check_initialize; Check_Cache_Block(my_cache_blocks => my_cache_blocks, a_cache_block => a_cache_block, name => name, cache_block_number => cache_block_number); if (get_number_of_elements (my_cache_blocks) > 0) then reset_iterator(my_cache_blocks,my_iterator); loop current_element(my_cache_blocks,a_cache_block,my_iterator); if(name = a_cache_block.name) then Raise_Exception (Invalid_Parameter'Identity, To_String (Lb_Cache_Block (Current_Language) & " " & Name & " : " & Lb_Cache_Block_Name (Current_Language) & Lb_Already_Defined (Current_Language))); end if; exit when is_last_element (my_cache_blocks, my_iterator); next_element (my_cache_blocks, my_iterator); end loop; end if; a_cache_block := new Cache_Block; a_cache_block.name := name; a_cache_block.cache_block_number := cache_block_number; add (my_cache_blocks, a_cache_block); exception when Cache_Block_Set.full_set => Raise_Exception (Invalid_Parameter'Identity, To_String (Lb_Can_Not_Define_More_Cache_Blocks (Current_Language))); end Add_Cache_Block; procedure Add_Cache_Block (my_cache_blocks : in out Cache_Blocks_Set; name : in Unbounded_String; cache_block_number : in Natural) is a_cache_block : Cache_Block_Ptr; begin Add_Cache_Block(my_cache_blocks => my_cache_blocks, a_cache_block => a_cache_block, name => name, cache_block_number => cache_block_number); end Add_Cache_Block; function Search_Cache_Block (my_cache_blocks : in Cache_Blocks_Set; name : in Unbounded_String) return Cache_Block_Ptr is my_iterator : Cache_Blocks_Iterator; a_cache_block : Cache_Block_Ptr; result : Cache_Block_Ptr; found : Boolean := False; begin reset_iterator(my_cache_blocks,my_iterator); loop current_element (my_cache_blocks, a_cache_block, my_iterator); if (a_cache_block.name = name) then found := True; result := a_cache_block; end if; exit when is_last_element (my_cache_blocks,my_iterator); next_element (my_cache_blocks,my_iterator); end loop; if not Found then Raise_Exception (Cache_Block_Not_Found'Identity, To_String (Lb_Cache_Block (Current_Language) & "=" & Name)); end if; return Result; end Search_Cache_Block; function Search_Cache_Block_By_Id (my_cache_blocks : in Cache_Blocks_Set; id : in Unbounded_String) return Cache_Block_Ptr is my_iterator : Cache_Blocks_Iterator; a_cache_block : Cache_Block_Ptr; result : Cache_Block_Ptr; found : Boolean := False; begin reset_iterator(my_cache_blocks,my_iterator); loop current_element (my_cache_blocks, a_cache_block, my_iterator); if (a_cache_block.cheddar_private_id = id) then found := True; result := a_cache_block; end if; exit when is_last_element (my_cache_blocks,my_iterator); next_element (my_cache_blocks,my_iterator); end loop; if not Found then Raise_Exception (Cache_Block_Not_Found'Identity, To_String (Lb_Cache_Block (Current_Language) & "=" & id)); end if; return Result; end Search_Cache_Block_By_Id; procedure Delete_Cache_Block (my_cache_blocks : in out Cache_Blocks_Set; name : in Unbounded_String) is a_cache_block : Cache_Block_Ptr; begin a_cache_block := Search_Cache_Block(my_cache_blocks,name); Delete(my_cache_blocks,a_cache_block); end Delete_Cache_Block; procedure Update_Cache_Block (my_cache_blocks : in out Cache_Blocks_Set; name : in Unbounded_String; cache_block_number : in Natural) is a_cache_block : Cache_Block_Ptr; begin Check_Cache_Block(my_cache_blocks => my_cache_blocks, a_cache_block => a_cache_block, name => name, cache_block_number => cache_block_number); a_cache_block := Search_Cache_Block(my_cache_blocks,name); Delete(my_cache_blocks,a_cache_block); Add_Cache_Block(my_cache_blocks => my_cache_blocks, a_cache_block => a_cache_block, name => name, cache_block_number => cache_block_number); end Update_Cache_Block; end Cache_Block_Set;