OSDN Git Service

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