1 /* 2 * Copyright 2019 The Android Open Source Project 3 * 4 * Licensed under the Apache License, Version 2.0 (the "License"); 5 * you may not use this file except in compliance with the License. 6 * You may obtain a copy of the License at 7 * 8 * http://www.apache.org/licenses/LICENSE-2.0 9 * 10 * Unless required by applicable law or agreed to in writing, software 11 * distributed under the License is distributed on an "AS IS" BASIS, 12 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 13 * See the License for the specific language governing permissions and 14 * limitations under the License. 15 */ 16 17 #pragma once 18 19 #include <stdexcept> 20 #include <string> 21 #include <unordered_map> 22 23 #include "src/init_flags.rs.h" 24 25 namespace bluetooth { 26 namespace common { 27 28 class InitFlags final { 29 public: 30 static void Load(const char** flags); 31 IsDebugLoggingEnabledForTag(const std::string & tag)32 inline static bool IsDebugLoggingEnabledForTag(const std::string& tag) { 33 auto tag_setting = logging_debug_explicit_tag_settings.find(tag); 34 if (tag_setting != logging_debug_explicit_tag_settings.end()) { 35 return tag_setting->second; 36 } 37 return logging_debug_enabled_for_all; 38 } 39 IsDebugLoggingEnabledForAll()40 inline static bool IsDebugLoggingEnabledForAll() { 41 return logging_debug_enabled_for_all; 42 } 43 44 static void SetAllForTesting(); 45 46 private: 47 static void SetAll(bool value); 48 static bool logging_debug_enabled_for_all; 49 // save both log allow list and block list in the map to save hashing time 50 static std::unordered_map<std::string, bool> logging_debug_explicit_tag_settings; 51 }; 52 53 } // namespace common 54 } // namespace bluetooth 55