OSDN Git Service

78d7213c22a266c6a850ef1bf2fabdcce27cedc3
[android-x86/system-bt.git] / service / common / bluetooth / binder / IBluetoothLowEnergy.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 <base/macros.h>
20 #include <binder/IBinder.h>
21 #include <binder/IInterface.h>
22
23 #include <bluetooth/advertise_data.h>
24 #include <bluetooth/advertise_settings.h>
25 #include <bluetooth/scan_filter.h>
26 #include <bluetooth/scan_settings.h>
27 #include <bluetooth/binder/IBluetoothLowEnergyCallback.h>
28
29 namespace ipc {
30 namespace binder {
31
32 // This class defines the Binder IPC interface for interacting with Bluetooth
33 // Low-Energy features.
34 // TODO(armansito): This class was written based on a new design doc proposal.
35 // We need to add an AIDL for this to the framework code.
36 //
37 // NOTE: KEEP THIS FILE UP-TO-DATE with the corresponding AIDL, otherwise this
38 // won't be compatible with the Android framework.
39 class IBluetoothLowEnergy : public android::IInterface {
40  public:
41   DECLARE_META_INTERFACE(BluetoothLowEnergy);
42
43   static const char kServiceName[];
44
45   // Transaction codes for interface methods.
46   enum {
47     GET_DEVICES_MATCHING_CONNECTION_STATE_TRANSACTION =
48         android::IBinder::FIRST_CALL_TRANSACTION,
49
50     REGISTER_CLIENT_TRANSACTION,
51     UNREGISTER_CLIENT_TRANSACTION,
52     UNREGISTER_ALL_TRANSACTION,
53
54     START_SCAN_TRANSACTION,
55     STOP_SCAN_TRANSACTION,
56     FLUSH_PENDING_BATCH_RESULTS_TRANSACTION,
57     START_MULTI_ADVERTISING_TRANSACTION,
58     STOP_MULTI_ADVERTISING_TRANSACTION,
59
60     CONNECT_TRANSACTION,
61     DISCONNECT_TRANSACTION,
62     READ_REMOTE_RSSI_TRANSACTION,
63     CONFIGURE_ATT_MTU_TRANSACTION,
64     CONNECTION_PARAMETER_UPDATE_TRANSACTION,
65     DISCONNECT_ALL_TRANSACTION,
66
67     NUM_HW_TRACK_FILTERS_AVAILABLE,
68   };
69
70   virtual bool RegisterClient(
71       const android::sp<IBluetoothLowEnergyCallback>& callback) = 0;
72   virtual void UnregisterClient(int client_if) = 0;
73   virtual void UnregisterAll() = 0;
74
75   virtual bool Connect(int client_id, const char* address, bool is_direct) = 0;
76   virtual bool Disconnect(int client_id, const char* address) = 0;
77
78   virtual bool StartScan(
79       int client_id,
80       const bluetooth::ScanSettings& settings,
81       const std::vector<bluetooth::ScanFilter>& filters) = 0;
82   virtual bool StopScan(int client_id) = 0;
83
84   virtual bool StartMultiAdvertising(
85       int client_if,
86       const bluetooth::AdvertiseData& advertise_data,
87       const bluetooth::AdvertiseData& scan_response,
88       const bluetooth::AdvertiseSettings& settings) = 0;
89   virtual bool StopMultiAdvertising(int client_if) = 0;
90
91   // TODO(armansito): Complete the API definition.
92
93  private:
94   DISALLOW_COPY_AND_ASSIGN(IBluetoothLowEnergy);
95 };
96
97 // The Binder server interface to IBluetoothLowEnergy. A class that implements
98 // IBluetoothLowEnergy must inherit from this class.
99 class BnBluetoothLowEnergy : public android::BnInterface<IBluetoothLowEnergy> {
100  public:
101   BnBluetoothLowEnergy() = default;
102   virtual ~BnBluetoothLowEnergy() = default;
103
104  private:
105   virtual android::status_t onTransact(
106       uint32_t code,
107       const android::Parcel& data,
108       android::Parcel* reply,
109       uint32_t flags = 0);
110
111   DISALLOW_COPY_AND_ASSIGN(BnBluetoothLowEnergy);
112 };
113
114 // The Binder client interface to IBluetoothLowEnergy.
115 class BpBluetoothLowEnergy : public android::BpInterface<IBluetoothLowEnergy> {
116  public:
117   explicit BpBluetoothLowEnergy(const android::sp<android::IBinder>& impl);
118   virtual ~BpBluetoothLowEnergy() = default;
119
120   // IBluetoothLowEnergy overrides:
121   bool RegisterClient(
122       const android::sp<IBluetoothLowEnergyCallback>& callback) override;
123   void UnregisterClient(int client_if) override;
124   void UnregisterAll() override;
125
126   bool Connect(int client_id, const char* address, bool is_direct) override;
127   bool Disconnect(int client_id, const char* address) override;
128
129   bool StartScan(
130       int client_id,
131       const bluetooth::ScanSettings& settings,
132       const std::vector<bluetooth::ScanFilter>& filters) override;
133   bool StopScan(int client_id) override;
134   bool StartMultiAdvertising(
135       int client_if,
136       const bluetooth::AdvertiseData& advertise_data,
137       const bluetooth::AdvertiseData& scan_response,
138       const bluetooth::AdvertiseSettings& settings) override;
139   bool StopMultiAdvertising(int client_if) override;
140
141  private:
142   DISALLOW_COPY_AND_ASSIGN(BpBluetoothLowEnergy);
143 };
144
145 }  // namespace binder
146 }  // namespace ipc