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 #include "os/parameter_provider.h" 18 19 #include <unistd.h> 20 21 #include <cerrno> 22 #include <mutex> 23 #include <string> 24 25 #include "os/log.h" 26 27 namespace bluetooth { 28 namespace os { 29 30 namespace { 31 std::mutex parameter_mutex; 32 std::string config_file_path; 33 std::string snoop_log_file_path; 34 std::string snooz_log_file_path; 35 } // namespace 36 37 // Write to $PWD/bt_stack.conf if $PWD can be found, otherwise, write to $HOME/bt_stack.conf ConfigFilePath()38std::string ParameterProvider::ConfigFilePath() { 39 { 40 std::lock_guard<std::mutex> lock(parameter_mutex); 41 if (!config_file_path.empty()) { 42 return config_file_path; 43 } 44 } 45 return "/etc/bluetooth/bt_config.conf"; 46 } 47 OverrideConfigFilePath(const std::string & path)48void ParameterProvider::OverrideConfigFilePath(const std::string& path) { 49 std::lock_guard<std::mutex> lock(parameter_mutex); 50 config_file_path = path; 51 } 52 SnoopLogFilePath()53std::string ParameterProvider::SnoopLogFilePath() { 54 { 55 std::lock_guard<std::mutex> lock(parameter_mutex); 56 if (!snoop_log_file_path.empty()) { 57 return snoop_log_file_path; 58 } 59 } 60 61 return "/etc/bluetooth/btsnoop_hci.log"; 62 } 63 OverrideSnoopLogFilePath(const std::string & path)64void ParameterProvider::OverrideSnoopLogFilePath(const std::string& path) { 65 std::lock_guard<std::mutex> lock(parameter_mutex); 66 snoop_log_file_path = path; 67 } 68 SnoozLogFilePath()69std::string ParameterProvider::SnoozLogFilePath() { 70 { 71 std::lock_guard<std::mutex> lock(parameter_mutex); 72 if (!snooz_log_file_path.empty()) { 73 return snooz_log_file_path; 74 } 75 } 76 return "/etc/bluetooth/btsnooz_hci.log"; 77 } 78 79 } // namespace os 80 } // namespace bluetooth 81