2 // Copyright (C) 2015 Google, Inc.
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:
8 // http://www.apache.org/licenses/LICENSE-2.0
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.
17 #include "service/ipc/ipc_manager.h"
19 #include "service/ipc/binder/ipc_handler_binder.h"
20 #include "service/ipc/ipc_handler_linux.h"
24 IPCManager::IPCManager(bluetooth::Adapter* adapter)
29 IPCManager::~IPCManager() {
30 // Don't rely on the handlers getting destroyed since another thread might be
31 // holding a reference to them. Instead, explicitly stop them here.
33 binder_handler_->Stop();
35 linux_handler_->Stop();
38 bool IPCManager::Start(Type type, Delegate* delegate) {
42 LOG(ERROR) << "IPCManagerLinux already started.";
46 linux_handler_ = new IPCHandlerLinux(adapter_, delegate);
47 if (!linux_handler_->Run()) {
48 linux_handler_ = nullptr;
54 if (BinderStarted()) {
55 LOG(ERROR) << "IPCManagerBinder already started.";
59 binder_handler_ = new IPCHandlerBinder(adapter_, delegate);
60 if (!binder_handler_->Run()) {
61 binder_handler_ = nullptr;
67 LOG(ERROR) << "Unsupported IPC type given: " << type;
73 bool IPCManager::BinderStarted() const {
74 return binder_handler_.get();
77 bool IPCManager::LinuxStarted() const {
78 return linux_handler_.get();