blob: 2558eaa007cd00d744b5e7cd87f343c447155d7e [file] [log] [blame]
Arman Uguray065d0f72015-07-16 18:12:13 -07001//
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 Uguray065d0f72015-07-16 18:12:13 -070020#include <base/logging.h>
21
22#include "service/switches.h"
23
24namespace bluetooth {
25
Arman Uguray065d0f72015-07-16 18:12:13 -070026Settings::Settings() : initialized_(false) {
27}
28
29Settings::~Settings() {
30}
31
32bool Settings::Init() {
33 CHECK(!initialized_);
34 auto command_line = base::CommandLine::ForCurrentProcess();
Arman Ugurayfe65fb72015-07-24 19:14:42 -070035 const auto& switches = command_line->GetSwitches();
Arman Uguray065d0f72015-07-16 18:12:13 -070036
Arman Ugurayfe65fb72015-07-24 19:14:42 -070037 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 Uguray065d0f72015-07-16 18:12:13 -070047
Arman Ugurayfe65fb72015-07-24 19:14:42 -070048 ipc_socket_path_ = path;
49 } else {
50 LOG(ERROR) << "Unexpected command-line switches found";
51 return false;
52 }
Arman Uguray065d0f72015-07-16 18:12:13 -070053 }
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 Uguray065d0f72015-07-16 18:12:13 -070061 initialized_ = true;
62 return true;
63}
64
65} // namespace bluetooth