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. | |
36 device::BluetoothUUID GetUUID() const override; | |
37 bool IsPrimary() const override; | |
38 | |
39 // device::BluetoothLocalGattService overrides. | |
40 static base::WeakPtr<device::BluetoothLocalGattService> Create( | 37 static base::WeakPtr<device::BluetoothLocalGattService> Create( |
41 device::BluetoothAdapter* adapter, | 38 device::BluetoothAdapter* adapter, |
42 const device::BluetoothUUID& uuid, | 39 const device::BluetoothUUID& uuid, |
43 bool is_primary, | 40 bool is_primary, |
44 BluetoothLocalGattService* included_service, | 41 BluetoothLocalGattService* included_service, |
45 BluetoothLocalGattService::Delegate* delegate); | 42 BluetoothLocalGattService::Delegate* delegate); |
46 void Register(const base::Closure& callback, | |
47 const ErrorCallback& error_callback) override; | |
48 void Unregister(const base::Closure& callback, | |
49 const ErrorCallback& error_callback) override; | |
50 | 43 |
51 BluetoothLocalGattServiceBlueZ( | 44 BluetoothLocalGattServiceBlueZ( |
52 BluetoothAdapterBlueZ* adapter, | 45 BluetoothAdapterBlueZ* adapter, |
53 const device::BluetoothUUID& uuid, | 46 const device::BluetoothUUID& uuid, |
54 bool is_primary, | 47 bool is_primary, |
55 device::BluetoothLocalGattService::Delegate* delegate); | 48 device::BluetoothLocalGattService::Delegate* delegate); |
| 49 |
56 ~BluetoothLocalGattServiceBlueZ() override; | 50 ~BluetoothLocalGattServiceBlueZ() override; |
57 | 51 |
| 52 // device::BluetoothGattService overrides. |
| 53 device::BluetoothUUID GetUUID() const override; |
| 54 bool IsPrimary() const override; |
| 55 |
| 56 // device::BluetoothLocalGattService overrides. |
| 57 void Register(const base::Closure& callback, |
| 58 const ErrorCallback& error_callback) override; |
| 59 void Unregister(const base::Closure& callback, |
| 60 const ErrorCallback& error_callback) override; |
| 61 |
| 62 const std::vector<std::unique_ptr<BluetoothLocalGattCharacteristicBlueZ>>& |
| 63 GetCharacteristics() const; |
| 64 |
| 65 Delegate* GetDelegate() { return delegate_; } |
| 66 |
| 67 static dbus::ObjectPath AddGuidToObjectPath(const std::string& path); |
| 68 |
58 private: | 69 private: |
| 70 friend class BluetoothLocalGattCharacteristicBlueZ; |
| 71 friend class device::BluetoothLocalGattService; |
| 72 |
59 // Called by dbus:: on unsuccessful completion of a request to register a | 73 // Called by dbus:: on unsuccessful completion of a request to register a |
60 // local service. | 74 // local service. |
61 void OnRegistrationError(const ErrorCallback& error_callback, | 75 void OnRegistrationError(const ErrorCallback& error_callback, |
62 const std::string& error_name, | 76 const std::string& error_name, |
63 const std::string& error_message); | 77 const std::string& error_message); |
64 | 78 |
65 BluetoothAdapterBlueZ* adapter_; | 79 void AddCharacteristic( |
66 const device::BluetoothUUID& uuid_; | 80 std::unique_ptr<BluetoothLocalGattCharacteristicBlueZ> characteristic); |
| 81 |
| 82 // UUID of this service. |
| 83 device::BluetoothUUID uuid_; |
| 84 |
| 85 // If this service is primary. |
67 bool is_primary_; | 86 bool is_primary_; |
| 87 |
| 88 // Delegate to receive read/write requests for attribute values contained |
| 89 // in this service. |
68 device::BluetoothLocalGattService::Delegate* delegate_; | 90 device::BluetoothLocalGattService::Delegate* delegate_; |
69 | 91 |
| 92 // Characteristics contained by this service. |
| 93 std::vector<std::unique_ptr<BluetoothLocalGattCharacteristicBlueZ>> |
| 94 characteristics_; |
| 95 |
70 // Note: This should remain the last member so it'll be destroyed and | 96 // Note: This should remain the last member so it'll be destroyed and |
71 // invalidate its weak pointers before any other members are destroyed. | 97 // invalidate its weak pointers before any other members are destroyed. |
72 base::WeakPtrFactory<BluetoothLocalGattServiceBlueZ> weak_ptr_factory_; | 98 base::WeakPtrFactory<BluetoothLocalGattServiceBlueZ> weak_ptr_factory_; |
73 | 99 |
74 DISALLOW_COPY_AND_ASSIGN(BluetoothLocalGattServiceBlueZ); | 100 DISALLOW_COPY_AND_ASSIGN(BluetoothLocalGattServiceBlueZ); |
75 }; | 101 }; |
76 | 102 |
77 } // namespace bluez | 103 } // namespace bluez |
78 | 104 |
79 #endif // DEVICE_BLUETOOTH_BLUEZ_BLUETOOTH_LOCAL_GATT_SERVICE_BLUEZ_H_ | 105 #endif // DEVICE_BLUETOOTH_BLUEZ_BLUETOOTH_LOCAL_GATT_SERVICE_BLUEZ_H_ |
OLD | NEW |