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