OSDN Git Service

Revert "Add guest mode functionality (2/5)"
[android-x86/system-bt.git] / service / ipc / binder / bluetooth_binder_server.h
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 #pragma once
18
19 #include <string>
20 #include <vector>
21
22 #include <base/macros.h>
23 #include <utils/String16.h>
24 #include <utils/Vector.h>
25
26 #include "service/adapter.h"
27 #include "service/common/bluetooth/binder/IBluetooth.h"
28 #include "service/common/bluetooth/binder/IBluetoothCallback.h"
29 #include "service/common/bluetooth/binder/IBluetoothGattClient.h"
30 #include "service/common/bluetooth/binder/IBluetoothGattServer.h"
31 #include "service/common/bluetooth/binder/IBluetoothLowEnergy.h"
32 #include "service/common/bluetooth/uuid.h"
33 #include "service/ipc/binder/remote_callback_list.h"
34
35 namespace ipc {
36 namespace binder {
37
38 // Implements the server side of the IBluetooth Binder interface.
39 class BluetoothBinderServer : public BnBluetooth,
40                               public bluetooth::Adapter::Observer {
41  public:
42   explicit BluetoothBinderServer(bluetooth::Adapter* adapter);
43   ~BluetoothBinderServer() override;
44
45   // IBluetooth overrides:
46   bool IsEnabled() override;
47   int GetState() override;
48   bool Enable() override;
49   bool EnableNoAutoConnect() override;
50   bool Disable() override;
51
52   std::string GetAddress() override;
53   std::vector<bluetooth::UUID> GetUUIDs() override;
54   bool SetName(const std::string& name) override;
55   std::string GetName() override;
56
57   void RegisterCallback(
58       const android::sp<IBluetoothCallback>& callback) override;
59   void UnregisterCallback(
60       const android::sp<IBluetoothCallback>& callback) override;
61
62   bool IsMultiAdvertisementSupported() override;
63   android::sp<IBluetoothLowEnergy> GetLowEnergyInterface() override;
64   android::sp<IBluetoothGattClient> GetGattClientInterface() override;
65   android::sp<IBluetoothGattServer> GetGattServerInterface() override;
66
67   android::status_t dump(int fd, const android::Vector<android::String16>& args) override;
68
69   // bluetooth::Adapter::Observer overrides:
70   void OnAdapterStateChanged(bluetooth::Adapter* adapter,
71                              bluetooth::AdapterState prev_state,
72                              bluetooth::AdapterState new_state) override;
73
74  private:
75   bluetooth::Adapter* adapter_;  // weak
76   RemoteCallbackList<IBluetoothCallback> callbacks_;
77
78   // The IBluetoothLowEnergy interface handle. This is lazily initialized on the
79   // first call to GetLowEnergyInterface().
80   android::sp<IBluetoothLowEnergy> low_energy_interface_;
81
82   // The IBluetoothGattClient interface handle. This is lazily initialized on
83   // the first call to GetGattClientInterface().
84   android::sp<IBluetoothGattClient> gatt_client_interface_;
85
86   // The IBluetoothGattServer interface handle. This is lazily initialized on
87   // the first call to GetGattServerInterface().
88   android::sp<IBluetoothGattServer> gatt_server_interface_;
89
90   DISALLOW_COPY_AND_ASSIGN(BluetoothBinderServer);
91 };
92
93 }  // namespace binder
94 }  // namespace ipc