aboutsummaryrefslogtreecommitdiff
path: root/service/settings.h
blob: 1f298d6c0ebbc9950ac917c5c0ae8c6742bf840f (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
//
//  Copyright 2015 Google, Inc.
//
//  Licensed under the Apache License, Version 2.0 (the "License");
//  you may not use this file except in compliance with the License.
//  You may obtain a copy of the License at:
//
//  http://www.apache.org/licenses/LICENSE-2.0
//
//  Unless required by applicable law or agreed to in writing, software
//  distributed under the License is distributed on an "AS IS" BASIS,
//  WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
//  See the License for the specific language governing permissions and
//  limitations under the License.
//

#pragma once

#include <string>

#include <base/files/file_path.h>
#include <base/macros.h>

namespace bluetooth {

// The Settings class stores global runtime configurations, such as IPC domain
// namespace, configuration file locations, and other system properties and
// flags.
class Settings {
 public:
  // Constant for the "--help" command-line switches.
  static const char kHelp[];

  Settings();
  ~Settings();

  // TODO(armansito): Write an instance method for storing things into a file.

  // Initializes the Settings object. This reads the command-line options for
  // the current process (which must have been initialized using
  // base::CommandLine) and sets up the initial global settings. Returns false
  // if there is an error, e.g. if the parameters/switches are malformed.
  bool Init();

  // If Android init created a server socket for the daemon,
  // we can retrieve it through this suffix.
  const std::string& android_ipc_socket_suffix() const {
    return android_ipc_socket_suffix_;
  }

  // Path to create a Unix domain socket server for Bluetooth IPC.
  const base::FilePath& create_ipc_socket_path() const {
    return create_ipc_socket_path_;
  }

  // Returns true if domain-socket based IPC should be used. If false, then
  // Binder IPC must be used.
  inline bool UseSocketIPC() const {
    return !android_ipc_socket_suffix().empty() ||
           !create_ipc_socket_path().empty();
  }

  bool EnableOnStart() const { return enable_on_start_; }

 private:
  bool initialized_;
  bool enable_on_start_;
  std::string android_ipc_socket_suffix_;
  base::FilePath create_ipc_socket_path_;

  DISALLOW_COPY_AND_ASSIGN(Settings);
};

}  // namespace bluetooth