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

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>
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;
48 bool IsLocal() const override; 46 bool IsLocal() const override;
49 bool IsPrimary() const override;
50 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( 47 bool AddCharacteristic(
58 device::BluetoothGattCharacteristic* characteristic) override; 48 device::BluetoothGattCharacteristic* characteristic) override;
59 bool AddIncludedService(device::BluetoothGattService* service) override; 49 bool AddIncludedService(device::BluetoothGattService* service) override;
60 void Register(const base::Closure& callback, 50 void Register(const base::Closure& callback,
61 const ErrorCallback& error_callback) override; 51 const ErrorCallback& error_callback) override;
62 void Unregister(const base::Closure& callback, 52 void Unregister(const base::Closure& callback,
63 const ErrorCallback& error_callback) override; 53 const ErrorCallback& error_callback) override;
64 54
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. 55 // Parses a named D-Bus error into a service error code.
69 static device::BluetoothGattService::GattErrorCode DBusErrorToServiceError( 56 static device::BluetoothGattService::GattErrorCode DBusErrorToServiceError(
70 const std::string error_name); 57 const std::string error_name);
71 58
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 59 // Notifies its observers that the GATT service has changed. This is mainly
76 // used by BluetoothRemoteGattCharacteristicBlueZ instances to notify 60 // used by BluetoothRemoteGattCharacteristicBlueZ instances to notify
77 // service observers when characteristic descriptors get added and removed. 61 // service observers when characteristic descriptors get added and removed.
78 void NotifyServiceChanged(); 62 void NotifyServiceChanged();
79 63
80 // Notifies its observers that a descriptor |descriptor| belonging to 64 // Notifies its observers that a descriptor |descriptor| belonging to
81 // characteristic |characteristic| has been added or removed. This is used 65 // characteristic |characteristic| has been added or removed. This is used
82 // by BluetoothRemoteGattCharacteristicBlueZ instances to notify service 66 // by BluetoothRemoteGattCharacteristicBlueZ instances to notify service
83 // observers when characteristic descriptors get added and removed. If |added| 67 // observers when characteristic descriptors get added and removed. If |added|
84 // is true, an "Added" event will be sent. Otherwise, a "Removed" event will 68 // is true, an "Added" event will be sent. Otherwise, a "Removed" event will
85 // be sent. 69 // be sent.
86 void NotifyDescriptorAddedOrRemoved( 70 void NotifyDescriptorAddedOrRemoved(
87 BluetoothRemoteGattCharacteristicBlueZ* characteristic, 71 BluetoothRemoteGattCharacteristicBlueZ* characteristic,
88 BluetoothRemoteGattDescriptorBlueZ* descriptor, 72 BluetoothGattDescriptorBlueZ* descriptor,
89 bool added); 73 bool added);
90 74
91 // Notifies its observers that the value of a descriptor has changed. Called 75 // Notifies its observers that the value of a descriptor has changed. Called
92 // by BluetoothRemoteGattCharacteristicBlueZ instances to notify service 76 // by BluetoothRemoteGattCharacteristicBlueZ instances to notify service
93 // observers. 77 // observers.
94 void NotifyDescriptorValueChanged( 78 void NotifyDescriptorValueChanged(
95 BluetoothRemoteGattCharacteristicBlueZ* characteristic, 79 BluetoothRemoteGattCharacteristicBlueZ* characteristic,
96 BluetoothRemoteGattDescriptorBlueZ* descriptor, 80 BluetoothGattDescriptorBlueZ* descriptor,
97 const std::vector<uint8_t>& value); 81 const std::vector<uint8_t>& value);
98 82
99 private: 83 private:
100 friend class BluetoothDeviceBlueZ; 84 friend class BluetoothDeviceBlueZ;
101 85
102 typedef std::map<dbus::ObjectPath, BluetoothRemoteGattCharacteristicBlueZ*> 86 typedef std::map<dbus::ObjectPath, BluetoothRemoteGattCharacteristicBlueZ*>
103 CharacteristicMap; 87 CharacteristicMap;
104 88
105 BluetoothRemoteGattServiceBlueZ(BluetoothAdapterBlueZ* adapter, 89 BluetoothRemoteGattServiceBlueZ(BluetoothAdapterBlueZ* adapter,
106 BluetoothDeviceBlueZ* device, 90 BluetoothDeviceBlueZ* device,
107 const dbus::ObjectPath& object_path); 91 const dbus::ObjectPath& object_path);
108 ~BluetoothRemoteGattServiceBlueZ() override; 92 ~BluetoothRemoteGattServiceBlueZ() override;
109 93
110 // bluez::BluetoothGattServiceClient::Observer override. 94 // bluez::BluetoothGattServiceClient::Observer override.
111 void GattServicePropertyChanged(const dbus::ObjectPath& object_path, 95 void GattServicePropertyChanged(const dbus::ObjectPath& object_path,
112 const std::string& property_name) override; 96 const std::string& property_name) override;
113 97
114 // bluez::BluetoothGattCharacteristicClient::Observer override. 98 // bluez::BluetoothGattCharacteristicClient::Observer override.
115 void GattCharacteristicAdded(const dbus::ObjectPath& object_path) override; 99 void GattCharacteristicAdded(const dbus::ObjectPath& object_path) override;
116 void GattCharacteristicRemoved(const dbus::ObjectPath& object_path) override; 100 void GattCharacteristicRemoved(const dbus::ObjectPath& object_path) override;
117 void GattCharacteristicPropertyChanged( 101 void GattCharacteristicPropertyChanged(
118 const dbus::ObjectPath& object_path, 102 const dbus::ObjectPath& object_path,
119 const std::string& property_name) override; 103 const std::string& property_name) override;
120 104
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 105 // The device this GATT service belongs to. It's ok to store a raw pointer
129 // here since |device_| owns this instance. 106 // here since |device_| owns this instance.
130 BluetoothDeviceBlueZ* device_; 107 BluetoothDeviceBlueZ* device_;
131 108
132 // Mapping from GATT characteristic object paths to characteristic objects. 109 // Mapping from GATT characteristic object paths to characteristic objects.
133 // owned by this service. Since the BlueZ implementation uses object 110 // owned by this service. Since the BlueZ implementation uses object
134 // paths as unique identifiers, we also use this mapping to return 111 // paths as unique identifiers, we also use this mapping to return
135 // characteristics by identifier. 112 // characteristics by identifier.
136 CharacteristicMap characteristics_; 113 CharacteristicMap characteristics_;
137 114
138 // Indicates whether or not the characteristics of this service are known to 115 // Indicates whether or not the characteristics of this service are known to
139 // have been discovered. 116 // have been discovered.
140 bool discovery_complete_; 117 bool discovery_complete_;
141 118
142 // Note: This should remain the last member so it'll be destroyed and 119 // Note: This should remain the last member so it'll be destroyed and
143 // invalidate its weak pointers before any other members are destroyed. 120 // invalidate its weak pointers before any other members are destroyed.
144 base::WeakPtrFactory<BluetoothRemoteGattServiceBlueZ> weak_ptr_factory_; 121 base::WeakPtrFactory<BluetoothRemoteGattServiceBlueZ> weak_ptr_factory_;
145 122
146 DISALLOW_COPY_AND_ASSIGN(BluetoothRemoteGattServiceBlueZ); 123 DISALLOW_COPY_AND_ASSIGN(BluetoothRemoteGattServiceBlueZ);
147 }; 124 };
148 125
149 } // namespace bluez 126 } // namespace bluez
150 127
151 #endif // DEVICE_BLUETOOTH_BLUETOOTH_REMOTE_GATT_SERVICE_BLUEZ_H_ 128 #endif // DEVICE_BLUETOOTH_BLUETOOTH_REMOTE_GATT_SERVICE_BLUEZ_H_
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698