blob: 019098e9fc97142ce11b024f2440acc4cce6d799 [file] [log] [blame]
Ian Coolidge611fcf92015-06-03 17:20:30 -07001//
Jakub Pawlowski5b790fe2017-09-18 09:00:20 -07002// Copyright 2015 Google, Inc.
Ian Coolidge611fcf92015-06-03 17:20:30 -07003//
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
Arman Uguray065d0f72015-07-16 18:12:13 -070017#include <base/at_exit.h>
18#include <base/command_line.h>
19#include <base/files/scoped_file.h>
Pavlin Radoslavov1377f932016-02-11 19:44:47 -080020#include <base/logging.h>
Arman Uguray065d0f72015-07-16 18:12:13 -070021
Bluetooth Build Testb4a42e72016-04-07 14:10:40 +020022#include "osi/include/properties.h"
Arman Ugurayfe65fb72015-07-24 19:14:42 -070023#include "service/daemon.h"
Arman Uguray065d0f72015-07-16 18:12:13 -070024#include "service/switches.h"
Ian Coolidge611fcf92015-06-03 17:20:30 -070025
26namespace {
27
Arman Ugurayf2d64342015-07-08 15:47:39 -070028// TODO(armansito): None of these should be hardcoded here. Instead, pass these
29// via commandline.
Ian Coolidge611fcf92015-06-03 17:20:30 -070030const char kDisableProperty[] = "persist.bluetooth.disable";
Ian Coolidge611fcf92015-06-03 17:20:30 -070031
32} // namespace
33
Myles Watson911d1ae2016-11-28 16:44:40 -080034int main(int argc, char* argv[]) {
Arman Uguray065d0f72015-07-16 18:12:13 -070035 base::AtExitManager exit_manager;
36 base::CommandLine::Init(argc, argv);
37
Arman Uguray503baaa2015-08-20 11:49:00 -070038 logging::LoggingSettings log_settings;
39 if (!logging::InitLogging(log_settings)) {
40 LOG(ERROR) << "Failed to set up logging";
41 return EXIT_FAILURE;
42 }
43
Arman Uguray065d0f72015-07-16 18:12:13 -070044 // TODO(armansito): Initialize base/logging. By default it will dump to stdout
45 // but we might want to change that based on a command-line switch. Figure out
46 // how to route the logging to Android's syslog. Once that's done, we won't
47 // need to use osi/include/log.h anymore.
48
49 // TODO(armansito): Register exit-time clean-up handlers for the IPC sockets.
50 // Register signal handlers.
51 auto command_line = base::CommandLine::ForCurrentProcess();
52 if (command_line->HasSwitch(bluetooth::switches::kHelpLong) ||
53 command_line->HasSwitch(bluetooth::switches::kHelpShort)) {
54 LOG(INFO) << bluetooth::switches::kHelpMessage;
55 return EXIT_SUCCESS;
56 }
57
Arman Uguray065d0f72015-07-16 18:12:13 -070058 // TODO(armansito): Remove Chromecast specific property out of here. This
59 // should just be obtained from global config.
Ian Coolidge611fcf92015-06-03 17:20:30 -070060 char disable_value[PROPERTY_VALUE_MAX];
Myles Watson158fe8e2018-02-16 13:11:04 -080061 int status = osi_property_get(kDisableProperty, disable_value, nullptr);
Ian Coolidge611fcf92015-06-03 17:20:30 -070062 if (status && !strcmp(disable_value, "1")) {
Arman Uguray065d0f72015-07-16 18:12:13 -070063 LOG(INFO) << "service disabled";
Ian Coolidge611fcf92015-06-03 17:20:30 -070064 return EXIT_SUCCESS;
65 }
66
Arman Ugurayfe65fb72015-07-24 19:14:42 -070067 if (!bluetooth::Daemon::Initialize()) {
68 LOG(ERROR) << "Failed to initialize Daemon";
Arman Ugurayf2d64342015-07-08 15:47:39 -070069 return EXIT_FAILURE;
70 }
71
Arman Ugurayfe65fb72015-07-24 19:14:42 -070072 // Start the main event loop.
73 bluetooth::Daemon::Get()->StartMainLoop();
Arman Ugurayf2d64342015-07-08 15:47:39 -070074
Arman Ugurayfe65fb72015-07-24 19:14:42 -070075 // The main message loop has exited; clean up the Daemon.
76 bluetooth::Daemon::Get()->ShutDown();
Ian Coolidge611fcf92015-06-03 17:20:30 -070077
Ian Coolidge611fcf92015-06-03 17:20:30 -070078 return EXIT_SUCCESS;
79}