Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(41)

Side by Side Diff: device/bluetooth/bluetooth_remote_gatt_service_bluez.h

Issue 1872943002: Add support for local services/characteristics/descriptors. (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: Created 4 years, 8 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch
OLDNEW
1 // Copyright 2014 The Chromium Authors. All rights reserved. 1 // Copyright 2014 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_BLUETOOTH_REMOTE_GATT_SERVICE_BLUEZ_H_ 5 #ifndef DEVICE_BLUETOOTH_BLUETOOTH_REMOTE_GATT_SERVICE_BLUEZ_H_
6 #define DEVICE_BLUETOOTH_BLUETOOTH_REMOTE_GATT_SERVICE_BLUEZ_H_ 6 #define DEVICE_BLUETOOTH_BLUETOOTH_REMOTE_GATT_SERVICE_BLUEZ_H_
7 7
8 #include <stdint.h> 8 #include <stdint.h>
9 9
10 #include <map> 10 #include <map>
11 #include <string> 11 #include <string>
12 #include <vector> 12 #include <vector>
ortuno 2016/04/14 17:42:36 Clean up headers.
rkc 2016/04/14 19:27:28 Done.
13 13
14 #include "base/macros.h" 14 #include "base/macros.h"
15 #include "base/memory/ref_counted.h" 15 #include "base/memory/ref_counted.h"
16 #include "base/memory/weak_ptr.h" 16 #include "base/memory/weak_ptr.h"
17 #include "base/observer_list.h" 17 #include "base/observer_list.h"
18 #include "dbus/object_path.h" 18 #include "dbus/object_path.h"
19 #include "device/bluetooth/bluetooth_gatt_service.h" 19 #include "device/bluetooth/bluetooth_gatt_service_bluez.h"
20 #include "device/bluetooth/bluetooth_uuid.h" 20 #include "device/bluetooth/bluetooth_uuid.h"
21 #include "device/bluetooth/dbus/bluetooth_gatt_characteristic_client.h" 21 #include "device/bluetooth/dbus/bluetooth_gatt_characteristic_client.h"
22 #include "device/bluetooth/dbus/bluetooth_gatt_service_client.h" 22 #include "device/bluetooth/dbus/bluetooth_gatt_service_client.h"
23 23
24 namespace device { 24 namespace device {
25 25
26 class BluetoothAdapter; 26 class BluetoothAdapter;
27 class BluetoothGattCharacteristic; 27 class BluetoothGattCharacteristic;
28 28
29 } // namespace device 29 } // namespace device
30 30
31 namespace bluez { 31 namespace bluez {
32 32
33 class BluetoothAdapterBlueZ; 33 class BluetoothAdapterBlueZ;
34 class BluetoothDeviceBlueZ; 34 class BluetoothDeviceBlueZ;
35 class BluetoothRemoteGattCharacteristicBlueZ; 35 class BluetoothRemoteGattCharacteristicBlueZ;
36 class BluetoothRemoteGattDescriptorBlueZ; 36 class BluetoothGattDescriptorBlueZ;
37 37
38 // The BluetoothRemoteGattServiceBlueZ class implements BluetootGattService 38 // The BluetoothRemoteGattServiceBlueZ class implements BluetootGattService
39 // for remote GATT services for platforms that use BlueZ. 39 // for remote GATT services for platforms that use BlueZ.
40 class BluetoothRemoteGattServiceBlueZ 40 class BluetoothRemoteGattServiceBlueZ
41 : public device::BluetoothGattService, 41 : public BluetoothGattServiceBlueZ,
42 public bluez::BluetoothGattServiceClient::Observer, 42 public BluetoothGattServiceClient::Observer,
43 public bluez::BluetoothGattCharacteristicClient::Observer { 43 public BluetoothGattCharacteristicClient::Observer {
44 public: 44 public:
45 // device::BluetoothGattService overrides. 45 // device::BluetoothGattService overrides.
46 std::string GetIdentifier() const override;
47 device::BluetoothUUID GetUUID() const override; 46 device::BluetoothUUID GetUUID() const override;
48 bool IsLocal() const override; 47 bool IsLocal() const override;
49 bool IsPrimary() const override; 48 bool IsPrimary() const override;
50 device::BluetoothDevice* GetDevice() const override; 49 device::BluetoothDevice* GetDevice() const override;
51 std::vector<device::BluetoothGattCharacteristic*> GetCharacteristics()
52 const override;
53 std::vector<device::BluetoothGattService*> GetIncludedServices()
54 const override;
55 device::BluetoothGattCharacteristic* GetCharacteristic(
56 const std::string& identifier) const override;
57 bool AddCharacteristic( 50 bool AddCharacteristic(
58 device::BluetoothGattCharacteristic* characteristic) override; 51 device::BluetoothGattCharacteristic* characteristic) override;
59 bool AddIncludedService(device::BluetoothGattService* service) override; 52 bool AddIncludedService(device::BluetoothGattService* service) override;
60 void Register(const base::Closure& callback, 53 void Register(const base::Closure& callback,
61 const ErrorCallback& error_callback) override; 54 const ErrorCallback& error_callback) override;
62 void Unregister(const base::Closure& callback, 55 void Unregister(const base::Closure& callback,
63 const ErrorCallback& error_callback) override; 56 const ErrorCallback& error_callback) override;
64 57
65 // Object path of the underlying service.
66 const dbus::ObjectPath& object_path() const { return object_path_; }
67
68 // Parses a named D-Bus error into a service error code.
69 static device::BluetoothGattService::GattErrorCode DBusErrorToServiceError(
70 const std::string error_name);
71
72 // Returns the adapter associated with this service.
73 BluetoothAdapterBlueZ* GetAdapter() const;
74
75 // Notifies its observers that the GATT service has changed. This is mainly 58 // Notifies its observers that the GATT service has changed. This is mainly
76 // used by BluetoothRemoteGattCharacteristicBlueZ instances to notify 59 // used by BluetoothRemoteGattCharacteristicBlueZ instances to notify
77 // service observers when characteristic descriptors get added and removed. 60 // service observers when characteristic descriptors get added and removed.
78 void NotifyServiceChanged(); 61 void NotifyServiceChanged();
79 62
80 // Notifies its observers that a descriptor |descriptor| belonging to 63 // Notifies its observers that a descriptor |descriptor| belonging to
81 // characteristic |characteristic| has been added or removed. This is used 64 // characteristic |characteristic| has been added or removed. This is used
82 // by BluetoothRemoteGattCharacteristicBlueZ instances to notify service 65 // by BluetoothRemoteGattCharacteristicBlueZ instances to notify service
83 // observers when characteristic descriptors get added and removed. If |added| 66 // observers when characteristic descriptors get added and removed. If |added|
84 // is true, an "Added" event will be sent. Otherwise, a "Removed" event will 67 // is true, an "Added" event will be sent. Otherwise, a "Removed" event will
85 // be sent. 68 // be sent.
86 void NotifyDescriptorAddedOrRemoved( 69 void NotifyDescriptorAddedOrRemoved(
87 BluetoothRemoteGattCharacteristicBlueZ* characteristic, 70 BluetoothRemoteGattCharacteristicBlueZ* characteristic,
88 BluetoothRemoteGattDescriptorBlueZ* descriptor, 71 BluetoothGattDescriptorBlueZ* descriptor,
89 bool added); 72 bool added);
90 73
91 // Notifies its observers that the value of a descriptor has changed. Called 74 // Notifies its observers that the value of a descriptor has changed. Called
92 // by BluetoothRemoteGattCharacteristicBlueZ instances to notify service 75 // by BluetoothRemoteGattCharacteristicBlueZ instances to notify service
93 // observers. 76 // observers.
94 void NotifyDescriptorValueChanged( 77 void NotifyDescriptorValueChanged(
95 BluetoothRemoteGattCharacteristicBlueZ* characteristic, 78 BluetoothRemoteGattCharacteristicBlueZ* characteristic,
96 BluetoothRemoteGattDescriptorBlueZ* descriptor, 79 BluetoothGattDescriptorBlueZ* descriptor,
97 const std::vector<uint8_t>& value); 80 const std::vector<uint8_t>& value);
98 81
99 private: 82 private:
100 friend class BluetoothDeviceBlueZ; 83 friend class BluetoothDeviceBlueZ;
101 84
102 typedef std::map<dbus::ObjectPath, BluetoothRemoteGattCharacteristicBlueZ*>
103 CharacteristicMap;
104
105 BluetoothRemoteGattServiceBlueZ(BluetoothAdapterBlueZ* adapter, 85 BluetoothRemoteGattServiceBlueZ(BluetoothAdapterBlueZ* adapter,
106 BluetoothDeviceBlueZ* device, 86 BluetoothDeviceBlueZ* device,
107 const dbus::ObjectPath& object_path); 87 const dbus::ObjectPath& object_path);
108 ~BluetoothRemoteGattServiceBlueZ() override; 88 ~BluetoothRemoteGattServiceBlueZ() override;
109 89
110 // bluez::BluetoothGattServiceClient::Observer override. 90 // bluez::BluetoothGattServiceClient::Observer override.
111 void GattServicePropertyChanged(const dbus::ObjectPath& object_path, 91 void GattServicePropertyChanged(const dbus::ObjectPath& object_path,
112 const std::string& property_name) override; 92 const std::string& property_name) override;
113 93
114 // bluez::BluetoothGattCharacteristicClient::Observer override. 94 // bluez::BluetoothGattCharacteristicClient::Observer override.
115 void GattCharacteristicAdded(const dbus::ObjectPath& object_path) override; 95 void GattCharacteristicAdded(const dbus::ObjectPath& object_path) override;
116 void GattCharacteristicRemoved(const dbus::ObjectPath& object_path) override; 96 void GattCharacteristicRemoved(const dbus::ObjectPath& object_path) override;
117 void GattCharacteristicPropertyChanged( 97 void GattCharacteristicPropertyChanged(
118 const dbus::ObjectPath& object_path, 98 const dbus::ObjectPath& object_path,
119 const std::string& property_name) override; 99 const std::string& property_name) override;
120 100
121 // Object path of the GATT service.
122 dbus::ObjectPath object_path_;
123
124 // The adapter associated with this service. It's ok to store a raw pointer
125 // here since |adapter_| indirectly owns this instance.
126 BluetoothAdapterBlueZ* adapter_;
127
128 // The device this GATT service belongs to. It's ok to store a raw pointer 101 // The device this GATT service belongs to. It's ok to store a raw pointer
129 // here since |device_| owns this instance. 102 // here since |device_| owns this instance.
130 BluetoothDeviceBlueZ* device_; 103 BluetoothDeviceBlueZ* device_;
131 104
132 // Mapping from GATT characteristic object paths to characteristic objects.
133 // owned by this service. Since the BlueZ implementation uses object
134 // paths as unique identifiers, we also use this mapping to return
135 // characteristics by identifier.
136 CharacteristicMap characteristics_;
137
138 // Indicates whether or not the characteristics of this service are known to 105 // Indicates whether or not the characteristics of this service are known to
139 // have been discovered. 106 // have been discovered.
140 bool discovery_complete_; 107 bool discovery_complete_;
141 108
142 // Note: This should remain the last member so it'll be destroyed and 109 // Note: This should remain the last member so it'll be destroyed and
143 // invalidate its weak pointers before any other members are destroyed. 110 // invalidate its weak pointers before any other members are destroyed.
144 base::WeakPtrFactory<BluetoothRemoteGattServiceBlueZ> weak_ptr_factory_; 111 base::WeakPtrFactory<BluetoothRemoteGattServiceBlueZ> weak_ptr_factory_;
145 112
146 DISALLOW_COPY_AND_ASSIGN(BluetoothRemoteGattServiceBlueZ); 113 DISALLOW_COPY_AND_ASSIGN(BluetoothRemoteGattServiceBlueZ);
147 }; 114 };
148 115
149 } // namespace bluez 116 } // namespace bluez
150 117
151 #endif // DEVICE_BLUETOOTH_BLUETOOTH_REMOTE_GATT_SERVICE_BLUEZ_H_ 118 #endif // DEVICE_BLUETOOTH_BLUETOOTH_REMOTE_GATT_SERVICE_BLUEZ_H_
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698