blob: fc5eec66cd550f7858c99b65d84d7dce4023c975 [file] [log] [blame]
Ian Coolidge611fcf92015-06-03 17:20:30 -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//
Arman Ugurayae43de62015-09-24 15:05:21 -070016
Pavlin Radoslavov1377f932016-02-11 19:44:47 -080017#ifdef BT_LIBCHROME_NDEBUG
18#define NDEBUG 1
19#endif
20
Arman Uguray065d0f72015-07-16 18:12:13 -070021#include <base/at_exit.h>
22#include <base/command_line.h>
23#include <base/files/scoped_file.h>
Pavlin Radoslavov1377f932016-02-11 19:44:47 -080024#include <base/logging.h>
Arman Uguray065d0f72015-07-16 18:12:13 -070025
Bluetooth Build Testb4a42e72016-04-07 14:10:40 +020026#include "osi/include/properties.h"
Arman Ugurayfe65fb72015-07-24 19:14:42 -070027#include "service/daemon.h"
Arman Uguray065d0f72015-07-16 18:12:13 -070028#include "service/switches.h"
Ian Coolidge611fcf92015-06-03 17:20:30 -070029
30namespace {
31
Arman Ugurayf2d64342015-07-08 15:47:39 -070032// TODO(armansito): None of these should be hardcoded here. Instead, pass these
33// via commandline.
Ian Coolidge611fcf92015-06-03 17:20:30 -070034const char kDisableProperty[] = "persist.bluetooth.disable";
Ian Coolidge611fcf92015-06-03 17:20:30 -070035
36} // namespace
37
Arman Uguray065d0f72015-07-16 18:12:13 -070038int main(int argc, char *argv[]) {
39 base::AtExitManager exit_manager;
40 base::CommandLine::Init(argc, argv);
41
Arman Uguray503baaa2015-08-20 11:49:00 -070042 logging::LoggingSettings log_settings;
43 if (!logging::InitLogging(log_settings)) {
44 LOG(ERROR) << "Failed to set up logging";
45 return EXIT_FAILURE;
46 }
47
Arman Uguray065d0f72015-07-16 18:12:13 -070048 // 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
Arman Ugurayf2d64342015-07-08 15:47:39 -070062#if !defined(OS_GENERIC)
Arman Uguray065d0f72015-07-16 18:12:13 -070063 // TODO(armansito): Remove Chromecast specific property out of here. This
64 // should just be obtained from global config.
Ian Coolidge611fcf92015-06-03 17:20:30 -070065 char disable_value[PROPERTY_VALUE_MAX];
Arman Ugurayfe65fb72015-07-24 19:14:42 -070066 int status = property_get(kDisableProperty, disable_value, nullptr);
Ian Coolidge611fcf92015-06-03 17:20:30 -070067 if (status && !strcmp(disable_value, "1")) {
Arman Uguray065d0f72015-07-16 18:12:13 -070068 LOG(INFO) << "service disabled";
Ian Coolidge611fcf92015-06-03 17:20:30 -070069 return EXIT_SUCCESS;
70 }
Arman Uguray065d0f72015-07-16 18:12:13 -070071#endif // !defined(OS_GENERIC)
Ian Coolidge611fcf92015-06-03 17:20:30 -070072
Arman Ugurayfe65fb72015-07-24 19:14:42 -070073 if (!bluetooth::Daemon::Initialize()) {
74 LOG(ERROR) << "Failed to initialize Daemon";
Arman Ugurayf2d64342015-07-08 15:47:39 -070075 return EXIT_FAILURE;
76 }
77
Arman Ugurayfe65fb72015-07-24 19:14:42 -070078 // Start the main event loop.
79 bluetooth::Daemon::Get()->StartMainLoop();
Arman Ugurayf2d64342015-07-08 15:47:39 -070080
Arman Ugurayfe65fb72015-07-24 19:14:42 -070081 // The main message loop has exited; clean up the Daemon.
82 bluetooth::Daemon::Get()->ShutDown();
Ian Coolidge611fcf92015-06-03 17:20:30 -070083
Ian Coolidge611fcf92015-06-03 17:20:30 -070084 return EXIT_SUCCESS;
85}