OLD | NEW |
1 // Copyright 2016 The Chromium Authors. All rights reserved. | 1 // Copyright 2016 The Chromium Authors. All rights reserved. |
2 // Use of this source code is governed by a BSD-style license that can be | 2 // Use of this source code is governed by a BSD-style license that can be |
3 // found in the LICENSE file. | 3 // found in the LICENSE file. |
4 | 4 |
5 #ifndef DEVICE_BLUETOOTH_BLUEZ_BLUETOOTH_LOCAL_GATT_SERVICE_BLUEZ_H_ | 5 #ifndef DEVICE_BLUETOOTH_BLUEZ_BLUETOOTH_LOCAL_GATT_SERVICE_BLUEZ_H_ |
6 #define DEVICE_BLUETOOTH_BLUEZ_BLUETOOTH_LOCAL_GATT_SERVICE_BLUEZ_H_ | 6 #define DEVICE_BLUETOOTH_BLUEZ_BLUETOOTH_LOCAL_GATT_SERVICE_BLUEZ_H_ |
7 | 7 |
8 #include <string> | 8 #include <string> |
| 9 #include <vector> |
9 | 10 |
10 #include "base/callback_forward.h" | 11 #include "base/callback_forward.h" |
11 #include "base/macros.h" | 12 #include "base/macros.h" |
12 #include "base/memory/weak_ptr.h" | 13 #include "base/memory/weak_ptr.h" |
13 #include "device/bluetooth/bluetooth_local_gatt_service.h" | 14 #include "device/bluetooth/bluetooth_local_gatt_service.h" |
14 #include "device/bluetooth/bluetooth_uuid.h" | 15 #include "device/bluetooth/bluetooth_uuid.h" |
15 #include "device/bluetooth/bluez/bluetooth_gatt_service_bluez.h" | 16 #include "device/bluetooth/bluez/bluetooth_gatt_service_bluez.h" |
| 17 #include "device/bluetooth/bluez/bluetooth_local_gatt_characteristic_bluez.h" |
16 | 18 |
17 namespace device { | 19 namespace device { |
18 | 20 |
19 class BluetoothAdapter; | 21 class BluetoothAdapter; |
20 class BluetoothDevice; | 22 class BluetoothDevice; |
21 | 23 |
22 } // namespace device | 24 } // namespace device |
23 | 25 |
24 namespace bluez { | 26 namespace bluez { |
25 | 27 |
26 class BluetoothAdapterBlueZ; | 28 class BluetoothAdapterBlueZ; |
27 class BluetoothDeviceBlueZ; | 29 class BluetoothLocalGattCharacteristicBlueZ; |
28 | 30 |
29 // The BluetoothLocalGattServiceBlueZ class implements BluetootGattService | 31 // The BluetoothLocalGattServiceBlueZ class implements BluetootGattService |
30 // for local GATT services for platforms that use BlueZ. | 32 // for local GATT services for platforms that use BlueZ. |
31 class BluetoothLocalGattServiceBlueZ | 33 class BluetoothLocalGattServiceBlueZ |
32 : public BluetoothGattServiceBlueZ, | 34 : public BluetoothGattServiceBlueZ, |
33 public device::BluetoothLocalGattService { | 35 public device::BluetoothLocalGattService { |
34 public: | 36 public: |
35 // device::BluetoothGattService overrides. | 37 // device::BluetoothGattService overrides. |
36 device::BluetoothUUID GetUUID() const override; | 38 device::BluetoothUUID GetUUID() const override; |
37 bool IsPrimary() const override; | 39 bool IsPrimary() const override; |
38 | 40 |
39 // device::BluetoothLocalGattService overrides. | 41 // device::BluetoothLocalGattService overrides. |
40 static base::WeakPtr<device::BluetoothLocalGattService> Create( | 42 static base::WeakPtr<device::BluetoothLocalGattService> Create( |
41 device::BluetoothAdapter* adapter, | 43 device::BluetoothAdapter* adapter, |
42 const device::BluetoothUUID& uuid, | 44 const device::BluetoothUUID& uuid, |
43 bool is_primary, | 45 bool is_primary, |
44 BluetoothLocalGattService* included_service, | 46 BluetoothLocalGattService* included_service, |
45 BluetoothLocalGattService::Delegate* delegate); | 47 BluetoothLocalGattService::Delegate* delegate); |
46 void Register(const base::Closure& callback, | 48 void Register(const base::Closure& callback, |
47 const ErrorCallback& error_callback) override; | 49 const ErrorCallback& error_callback) override; |
48 void Unregister(const base::Closure& callback, | 50 void Unregister(const base::Closure& callback, |
49 const ErrorCallback& error_callback) override; | 51 const ErrorCallback& error_callback) override; |
50 | 52 |
| 53 const std::vector<std::unique_ptr<BluetoothLocalGattCharacteristicBlueZ>>& |
| 54 GetCharacteristics() const; |
| 55 |
51 BluetoothLocalGattServiceBlueZ( | 56 BluetoothLocalGattServiceBlueZ( |
52 BluetoothAdapterBlueZ* adapter, | 57 BluetoothAdapterBlueZ* adapter, |
53 const device::BluetoothUUID& uuid, | 58 const device::BluetoothUUID& uuid, |
54 bool is_primary, | 59 bool is_primary, |
55 device::BluetoothLocalGattService::Delegate* delegate); | 60 device::BluetoothLocalGattService::Delegate* delegate); |
56 ~BluetoothLocalGattServiceBlueZ() override; | 61 ~BluetoothLocalGattServiceBlueZ() override; |
57 | 62 |
| 63 Delegate* GetDelegate() { return delegate_; } |
| 64 |
58 private: | 65 private: |
| 66 friend class BluetoothLocalGattCharacteristicBlueZ; |
| 67 |
59 // Called by dbus:: on unsuccessful completion of a request to register a | 68 // Called by dbus:: on unsuccessful completion of a request to register a |
60 // local service. | 69 // local service. |
61 void OnRegistrationError(const ErrorCallback& error_callback, | 70 void OnRegistrationError(const ErrorCallback& error_callback, |
62 const std::string& error_name, | 71 const std::string& error_name, |
63 const std::string& error_message); | 72 const std::string& error_message); |
64 | 73 |
65 BluetoothAdapterBlueZ* adapter_; | 74 void AddCharacteristic( |
66 const device::BluetoothUUID& uuid_; | 75 std::unique_ptr<BluetoothLocalGattCharacteristicBlueZ> characteristic); |
| 76 |
| 77 // UUID of this service. |
| 78 device::BluetoothUUID uuid_; |
| 79 |
| 80 // If this service is primary. |
67 bool is_primary_; | 81 bool is_primary_; |
| 82 |
| 83 // Delegate to receive read/write requests for attribute values contained |
| 84 // in this service. |
68 device::BluetoothLocalGattService::Delegate* delegate_; | 85 device::BluetoothLocalGattService::Delegate* delegate_; |
69 | 86 |
| 87 // Characteristics contained by this service. |
| 88 std::vector<std::unique_ptr<BluetoothLocalGattCharacteristicBlueZ>> |
| 89 characteristics_; |
| 90 |
70 // Note: This should remain the last member so it'll be destroyed and | 91 // Note: This should remain the last member so it'll be destroyed and |
71 // invalidate its weak pointers before any other members are destroyed. | 92 // invalidate its weak pointers before any other members are destroyed. |
72 base::WeakPtrFactory<BluetoothLocalGattServiceBlueZ> weak_ptr_factory_; | 93 base::WeakPtrFactory<BluetoothLocalGattServiceBlueZ> weak_ptr_factory_; |
73 | 94 |
74 DISALLOW_COPY_AND_ASSIGN(BluetoothLocalGattServiceBlueZ); | 95 DISALLOW_COPY_AND_ASSIGN(BluetoothLocalGattServiceBlueZ); |
75 }; | 96 }; |
76 | 97 |
77 } // namespace bluez | 98 } // namespace bluez |
78 | 99 |
79 #endif // DEVICE_BLUETOOTH_BLUEZ_BLUETOOTH_LOCAL_GATT_SERVICE_BLUEZ_H_ | 100 #endif // DEVICE_BLUETOOTH_BLUEZ_BLUETOOTH_LOCAL_GATT_SERVICE_BLUEZ_H_ |
OLD | NEW |