Arman Uguray | 065d0f7 | 2015-07-16 18:12:13 -0700 | [diff] [blame] | 1 | // |
| 2 | // Copyright (C) 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 | #include "service/settings.h" |
| 18 | |
| 19 | #include <base/command_line.h> |
Arman Uguray | 065d0f7 | 2015-07-16 18:12:13 -0700 | [diff] [blame] | 20 | #include <base/logging.h> |
| 21 | |
| 22 | #include "service/switches.h" |
| 23 | |
| 24 | namespace bluetooth { |
| 25 | |
Arman Uguray | 065d0f7 | 2015-07-16 18:12:13 -0700 | [diff] [blame] | 26 | Settings::Settings() : initialized_(false) { |
| 27 | } |
| 28 | |
| 29 | Settings::~Settings() { |
| 30 | } |
| 31 | |
| 32 | bool Settings::Init() { |
| 33 | CHECK(!initialized_); |
| 34 | auto command_line = base::CommandLine::ForCurrentProcess(); |
Arman Uguray | fe65fb7 | 2015-07-24 19:14:42 -0700 | [diff] [blame^] | 35 | const auto& switches = command_line->GetSwitches(); |
Arman Uguray | 065d0f7 | 2015-07-16 18:12:13 -0700 | [diff] [blame] | 36 | |
Arman Uguray | fe65fb7 | 2015-07-24 19:14:42 -0700 | [diff] [blame^] | 37 | for (const auto& iter : switches) { |
| 38 | if (iter.first == switches::kIPCSocketPath) { |
| 39 | // kIPCSocketPath: An optional argument that initializes an IPC socket |
| 40 | // path for IPC. If this is not present, the daemon will default to Binder |
| 41 | // for the IPC mechanism. |
| 42 | base::FilePath path(iter.second); |
| 43 | if (path.empty() || path.EndsWithSeparator()) { |
| 44 | LOG(ERROR) << "Invalid IPC socket path"; |
| 45 | return false; |
| 46 | } |
Arman Uguray | 065d0f7 | 2015-07-16 18:12:13 -0700 | [diff] [blame] | 47 | |
Arman Uguray | fe65fb7 | 2015-07-24 19:14:42 -0700 | [diff] [blame^] | 48 | ipc_socket_path_ = path; |
| 49 | } else { |
| 50 | LOG(ERROR) << "Unexpected command-line switches found"; |
| 51 | return false; |
| 52 | } |
Arman Uguray | 065d0f7 | 2015-07-16 18:12:13 -0700 | [diff] [blame] | 53 | } |
| 54 | |
| 55 | // The daemon has no arguments |
| 56 | if (command_line->GetArgs().size()) { |
| 57 | LOG(ERROR) << "Unexpected command-line arguments found"; |
| 58 | return false; |
| 59 | } |
| 60 | |
Arman Uguray | 065d0f7 | 2015-07-16 18:12:13 -0700 | [diff] [blame] | 61 | initialized_ = true; |
| 62 | return true; |
| 63 | } |
| 64 | |
| 65 | } // namespace bluetooth |