1-- 2-- Copyright (c) 2019, 3-- Reto Buerki, Adrian-Ken Rueegsegger 4-- 5-- This file is part of Alog. 6-- 7-- Alog is free software; you can redistribute it and/or modify 8-- it under the terms of the GNU Lesser General Public License as published 9-- by the Free Software Foundation; either version 2.1 of the License, or 10-- (at your option) any later version. 11-- 12-- Alog is distributed in the hope that it will be useful, 13-- but WITHOUT ANY WARRANTY; without even the implied warranty of 14-- MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 15-- GNU Lesser General Public License for more details. 16-- 17-- You should have received a copy of the GNU Lesser General Public License 18-- along with Alog; if not, write to the Free Software 19-- Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, 20-- MA 02110-1301 USA 21-- 22 23package body Alog.Policy_DB is 24 25 ------------------------------------------------------------------------- 26 27 protected body Protected_Policy_DB is 28 29 ---------------------------------------------------------------------- 30 31 function Accept_ID 32 (Identifier : String; 33 Level : Log_Level) 34 return Boolean 35 is 36 begin 37 return Level >= Lookup (Identifier => Identifier); 38 end Accept_ID; 39 40 ---------------------------------------------------------------------- 41 42 function Get_Default_Loglevel return Log_Level 43 is 44 begin 45 return Current_Default_Loglevel; 46 end Get_Default_Loglevel; 47 48 ---------------------------------------------------------------------- 49 50 function Get_Loglevel (Identifier : String) return Log_Level 51 is 52 begin 53 return Ident_Levels.Element (Key => Identifier); 54 55 exception 56 when Constraint_Error => 57 raise No_Ident_Loglevel with 58 "No loglevel for identifier '" & Identifier & "'"; 59 end Get_Loglevel; 60 61 ---------------------------------------------------------------------- 62 63 function Lookup (Identifier : String) return Log_Level 64 is 65 use type Alog.Maps.Cursor; 66 Position : Maps.Cursor; 67 begin 68 if Identifier'Length > 0 then 69 Position := Ident_Levels.Lookup (Key => Identifier); 70 71 if Position /= Maps.No_Element then 72 return Maps.Element (Position => Position); 73 end if; 74 end if; 75 76 return Current_Default_Loglevel; 77 end Lookup; 78 79 ---------------------------------------------------------------------- 80 81 procedure Reset 82 is 83 begin 84 Current_Default_Loglevel := Log_Level'First; 85 Ident_Levels.Clear; 86 end Reset; 87 88 ---------------------------------------------------------------------- 89 90 procedure Set_Default_Loglevel (Level : Log_Level) 91 is 92 begin 93 Current_Default_Loglevel := Level; 94 end Set_Default_Loglevel; 95 96 ---------------------------------------------------------------------- 97 98 procedure Set_Loglevel 99 (Identifier : String; 100 Level : Log_Level) 101 is 102 begin 103 Ident_Levels.Insert (Key => Identifier, 104 Item => Level); 105 end Set_Loglevel; 106 107 ---------------------------------------------------------------------- 108 109 procedure Set_Loglevel (Identifiers : Maps.Wildcard_Level_Map) 110 is 111 begin 112 Ident_Levels := Identifiers; 113 end Set_Loglevel; 114 115 end Protected_Policy_DB; 116 117end Alog.Policy_DB; 118