1 //
2 // Copyright 2016 The Android Open Source Project
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 "service/ipc/dbus/ipc_handler_dbus.h"
18
19 #include <base/bind.h>
20 #include <base/threading/thread_task_runner_handle.h>
21 #include <dbus/bus.h>
22 #include "service/daemon.h"
23 #include "service/ipc/dbus/bluetooth_adapter.h"
24
25 using dbus::Bus;
26
27 namespace ipc {
28
IPCHandlerDBus(bluetooth::Adapter * adapter,IPCManager::Delegate * delegate)29 IPCHandlerDBus::IPCHandlerDBus(bluetooth::Adapter* adapter,
30 IPCManager::Delegate* delegate)
31 : IPCHandler(adapter, delegate) {}
32
~IPCHandlerDBus()33 IPCHandlerDBus::~IPCHandlerDBus() {}
34
Run()35 bool IPCHandlerDBus::Run() {
36 LOG(INFO) << __func__;
37
38 dbus_thread_ = new base::Thread("D-Bus Thread");
39 base::Thread::Options thread_options;
40 thread_options.message_loop_type = base::MessageLoop::TYPE_IO;
41 dbus_thread_->StartWithOptions(thread_options);
42
43 dbus_thread_->task_runner()->PostTask(
44 FROM_HERE, base::Bind(&IPCHandlerDBus::InitDbus, base::Unretained(this)));
45
46 return true;
47 }
48
InitDbus()49 void IPCHandlerDBus::InitDbus() {
50 LOG(INFO) << __func__;
51
52 Bus::Options bus_options;
53 bus_options.bus_type = Bus::SYSTEM;
54 bus_options.connection_type = Bus::PRIVATE;
55 bus_options.dbus_task_runner = base::ThreadTaskRunnerHandle::Get();
56
57 scoped_refptr<Bus> bus_ = new Bus(bus_options);
58
59 ipc::dbus::BluetoothAdapter* bluetooth_adapter =
60 new ipc::dbus::BluetoothAdapter(bus_, adapter());
61
62 LOG(INFO) << __func__ << ": all services added";
63 }
64
Stop()65 void IPCHandlerDBus::Stop() { dbus_thread_->Stop(); }
66
67 } // namespace ipc
68