main.cc 2.6 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879
  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. #include <base/at_exit.h>
  17. #include <base/command_line.h>
  18. #include <base/files/scoped_file.h>
  19. #include <base/logging.h>
  20. #include "osi/include/properties.h"
  21. #include "service/daemon.h"
  22. #include "service/switches.h"
  23. namespace {
  24. // TODO(armansito): None of these should be hardcoded here. Instead, pass these
  25. // via commandline.
  26. const char kDisableProperty[] = "persist.bluetooth.disable";
  27. } // namespace
  28. int main(int argc, char* argv[]) {
  29. base::AtExitManager exit_manager;
  30. base::CommandLine::Init(argc, argv);
  31. logging::LoggingSettings log_settings;
  32. if (!logging::InitLogging(log_settings)) {
  33. LOG(ERROR) << "Failed to set up logging";
  34. return EXIT_FAILURE;
  35. }
  36. // TODO(armansito): Initialize base/logging. By default it will dump to stdout
  37. // but we might want to change that based on a command-line switch. Figure out
  38. // how to route the logging to Android's syslog. Once that's done, we won't
  39. // need to use osi/include/log.h anymore.
  40. // TODO(armansito): Register exit-time clean-up handlers for the IPC sockets.
  41. // Register signal handlers.
  42. auto command_line = base::CommandLine::ForCurrentProcess();
  43. if (command_line->HasSwitch(bluetooth::switches::kHelpLong) ||
  44. command_line->HasSwitch(bluetooth::switches::kHelpShort)) {
  45. LOG(INFO) << bluetooth::switches::kHelpMessage;
  46. return EXIT_SUCCESS;
  47. }
  48. // TODO(armansito): Remove Chromecast specific property out of here. This
  49. // should just be obtained from global config.
  50. char disable_value[PROPERTY_VALUE_MAX];
  51. int status = osi_property_get(kDisableProperty, disable_value, nullptr);
  52. if (status && !strcmp(disable_value, "1")) {
  53. LOG(INFO) << "service disabled";
  54. return EXIT_SUCCESS;
  55. }
  56. if (!bluetooth::Daemon::Initialize()) {
  57. LOG(ERROR) << "Failed to initialize Daemon";
  58. return EXIT_FAILURE;
  59. }
  60. // Start the main event loop.
  61. bluetooth::Daemon::Get()->StartMainLoop();
  62. // The main message loop has exited; clean up the Daemon.
  63. bluetooth::Daemon::Get()->ShutDown();
  64. return EXIT_SUCCESS;
  65. }