settings.h 2.2 KB

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