1 // 2 // Copyright 2015 Google, Inc. 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 <string> 20 21 #include <base/files/file_path.h> 22 23 namespace bluetooth { 24 25 // The Settings class stores global runtime configurations, such as IPC domain 26 // namespace, configuration file locations, and other system properties and 27 // flags. 28 class Settings { 29 public: 30 // Constant for the "--help" command-line switches. 31 static const char kHelp[]; 32 33 Settings(); 34 Settings(const Settings&) = delete; 35 Settings& operator=(const Settings&) = delete; 36 37 ~Settings(); 38 39 // TODO(armansito): Write an instance method for storing things into a file. 40 41 // Initializes the Settings object. This reads the command-line options for 42 // the current process (which must have been initialized using 43 // base::CommandLine) and sets up the initial global settings. Returns false 44 // if there is an error, e.g. if the parameters/switches are malformed. 45 bool Init(); 46 47 // If Android init created a server socket for the daemon, 48 // we can retrieve it through this suffix. android_ipc_socket_suffix()49 const std::string& android_ipc_socket_suffix() const { 50 return android_ipc_socket_suffix_; 51 } 52 53 // Path to create a Unix domain socket server for Bluetooth IPC. create_ipc_socket_path()54 const base::FilePath& create_ipc_socket_path() const { 55 return create_ipc_socket_path_; 56 } 57 58 // Returns true if domain-socket based IPC should be used. If false, then 59 // Binder IPC must be used. UseSocketIPC()60 inline bool UseSocketIPC() const { 61 return !android_ipc_socket_suffix().empty() || 62 !create_ipc_socket_path().empty(); 63 } 64 EnableOnStart()65 bool EnableOnStart() const { return enable_on_start_; } 66 67 private: 68 bool initialized_; 69 bool enable_on_start_; 70 std::string android_ipc_socket_suffix_; 71 base::FilePath create_ipc_socket_path_; 72 }; 73 74 } // namespace bluetooth 75