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 |
| 65 static dbus::ObjectPath AddGuidToObjectPath(const std::string& path); |
| 66 |
58 private: | 67 private: |
| 68 friend class BluetoothLocalGattCharacteristicBlueZ; |
| 69 |
59 // Called by dbus:: on unsuccessful completion of a request to register a | 70 // Called by dbus:: on unsuccessful completion of a request to register a |
60 // local service. | 71 // local service. |
61 void OnRegistrationError(const ErrorCallback& error_callback, | 72 void OnRegistrationError(const ErrorCallback& error_callback, |
62 const std::string& error_name, | 73 const std::string& error_name, |
63 const std::string& error_message); | 74 const std::string& error_message); |
64 | 75 |
65 BluetoothAdapterBlueZ* adapter_; | 76 void AddCharacteristic( |
66 const device::BluetoothUUID& uuid_; | 77 std::unique_ptr<BluetoothLocalGattCharacteristicBlueZ> characteristic); |
| 78 |
| 79 // UUID of this service. |
| 80 device::BluetoothUUID uuid_; |
| 81 |
| 82 // If this service is primary. |
67 bool is_primary_; | 83 bool is_primary_; |
| 84 |
| 85 // Delegate to receive read/write requests for attribute values contained |
| 86 // in this service. |
68 device::BluetoothLocalGattService::Delegate* delegate_; | 87 device::BluetoothLocalGattService::Delegate* delegate_; |
69 | 88 |
| 89 // Characteristics contained by this service. |
| 90 std::vector<std::unique_ptr<BluetoothLocalGattCharacteristicBlueZ>> |
| 91 characteristics_; |
| 92 |
70 // Note: This should remain the last member so it'll be destroyed and | 93 // Note: This should remain the last member so it'll be destroyed and |
71 // invalidate its weak pointers before any other members are destroyed. | 94 // invalidate its weak pointers before any other members are destroyed. |
72 base::WeakPtrFactory<BluetoothLocalGattServiceBlueZ> weak_ptr_factory_; | 95 base::WeakPtrFactory<BluetoothLocalGattServiceBlueZ> weak_ptr_factory_; |
73 | 96 |
74 DISALLOW_COPY_AND_ASSIGN(BluetoothLocalGattServiceBlueZ); | 97 DISALLOW_COPY_AND_ASSIGN(BluetoothLocalGattServiceBlueZ); |
75 }; | 98 }; |
76 | 99 |
77 } // namespace bluez | 100 } // namespace bluez |
78 | 101 |
79 #endif // DEVICE_BLUETOOTH_BLUEZ_BLUETOOTH_LOCAL_GATT_SERVICE_BLUEZ_H_ | 102 #endif // DEVICE_BLUETOOTH_BLUEZ_BLUETOOTH_LOCAL_GATT_SERVICE_BLUEZ_H_ |
OLD | NEW |