OLD | NEW |
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 CHROME_BROWSER_EXTENSIONS_API_BLUETOOTH_LOW_ENERGY_BLUETOOTH_LOW_ENERGY_
EVENT_ROUTER_H_ | 5 #ifndef EXTENSIONS_BROWSER_API_BLUETOOTH_LOW_ENERGY_BLUETOOTH_LOW_ENERGY_EVENT_R
OUTER_H_ |
6 #define CHROME_BROWSER_EXTENSIONS_API_BLUETOOTH_LOW_ENERGY_BLUETOOTH_LOW_ENERGY_
EVENT_ROUTER_H_ | 6 #define EXTENSIONS_BROWSER_API_BLUETOOTH_LOW_ENERGY_BLUETOOTH_LOW_ENERGY_EVENT_R
OUTER_H_ |
7 | 7 |
8 #include <map> | 8 #include <map> |
9 #include <set> | 9 #include <set> |
10 #include <string> | 10 #include <string> |
11 #include <vector> | 11 #include <vector> |
12 | 12 |
13 #include "base/callback.h" | 13 #include "base/callback.h" |
14 #include "base/memory/linked_ptr.h" | 14 #include "base/memory/linked_ptr.h" |
15 #include "base/memory/weak_ptr.h" | 15 #include "base/memory/weak_ptr.h" |
16 #include "chrome/common/extensions/api/bluetooth_low_energy.h" | |
17 #include "content/public/browser/notification_observer.h" | 16 #include "content/public/browser/notification_observer.h" |
18 #include "device/bluetooth/bluetooth_adapter.h" | 17 #include "device/bluetooth/bluetooth_adapter.h" |
19 #include "device/bluetooth/bluetooth_device.h" | 18 #include "device/bluetooth/bluetooth_device.h" |
20 #include "device/bluetooth/bluetooth_gatt_service.h" | 19 #include "device/bluetooth/bluetooth_gatt_service.h" |
| 20 #include "extensions/common/api/bluetooth_low_energy.h" |
21 | 21 |
22 namespace base { | 22 namespace base { |
23 | 23 |
24 class ListValue; | 24 class ListValue; |
25 | 25 |
26 } // namespace base | 26 } // namespace base |
27 | 27 |
28 namespace content { | 28 namespace content { |
29 | 29 |
30 class BrowserContext; | 30 class BrowserContext; |
(...skipping 65 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
96 // Disconnects the currently open GATT connection of extension |extension| to | 96 // Disconnects the currently open GATT connection of extension |extension| to |
97 // device with address |device_address|. |error_callback| is called with an | 97 // device with address |device_address|. |error_callback| is called with an |
98 // error status in case of failure, e.g. if the device is not found or the | 98 // error status in case of failure, e.g. if the device is not found or the |
99 // given | 99 // given |
100 // extension does not have an open connection to the device. | 100 // extension does not have an open connection to the device. |
101 void Disconnect(const Extension* extension, | 101 void Disconnect(const Extension* extension, |
102 const std::string& device_address, | 102 const std::string& device_address, |
103 const base::Closure& callback, | 103 const base::Closure& callback, |
104 const ErrorCallback& error_callback); | 104 const ErrorCallback& error_callback); |
105 | 105 |
106 // Returns the list of api::bluetooth_low_energy::Service objects associated | 106 // Returns the list of core_api::bluetooth_low_energy::Service objects |
107 // with the Bluetooth device with address |device_address| in |out_services|. | 107 // associated with the Bluetooth device with address |device_address| in |
| 108 // |out_services|. |
108 // Returns false, if no device with the given address is known. If the device | 109 // Returns false, if no device with the given address is known. If the device |
109 // is found but it has no GATT services, then returns true and leaves | 110 // is found but it has no GATT services, then returns true and leaves |
110 // |out_services| empty. Returns true, on success. |out_services| must not | 111 // |out_services| empty. Returns true, on success. |out_services| must not |
111 // be NULL. If it is non-empty, then its contents will be cleared. | 112 // be NULL. If it is non-empty, then its contents will be cleared. |
112 typedef std::vector<linked_ptr<api::bluetooth_low_energy::Service> > | 113 typedef std::vector<linked_ptr<core_api::bluetooth_low_energy::Service> > |
113 ServiceList; | 114 ServiceList; |
114 bool GetServices(const std::string& device_address, | 115 bool GetServices(const std::string& device_address, |
115 ServiceList* out_services) const; | 116 ServiceList* out_services) const; |
116 | 117 |
117 // Populates |out_service| based on GATT service with instance ID | 118 // Populates |out_service| based on GATT service with instance ID |
118 // |instance_id|. |out_service| must not be NULL. | 119 // |instance_id|. |out_service| must not be NULL. |
119 Status GetService(const std::string& instance_id, | 120 Status GetService(const std::string& instance_id, |
120 api::bluetooth_low_energy::Service* out_service) const; | 121 core_api::bluetooth_low_energy::Service* out_service) const; |
121 | 122 |
122 // Populates |out_services| with the list of GATT services that are included | 123 // Populates |out_services| with the list of GATT services that are included |
123 // by the GATT service with instance ID |instance_id|. Returns false, if not | 124 // by the GATT service with instance ID |instance_id|. Returns false, if not |
124 // GATT service with the given ID is known. If the given service has no | 125 // GATT service with the given ID is known. If the given service has no |
125 // included services, then |out_service| will be empty. |out_service| must not | 126 // included services, then |out_service| will be empty. |out_service| must not |
126 // be NULL. If it is non-empty, then its contents will be cleared. | 127 // be NULL. If it is non-empty, then its contents will be cleared. |
127 Status GetIncludedServices(const std::string& instance_id, | 128 Status GetIncludedServices(const std::string& instance_id, |
128 ServiceList* out_services) const; | 129 ServiceList* out_services) const; |
129 | 130 |
130 // Returns the list of api::bluetooth_low_energy::Characteristic objects | 131 // Returns the list of core_api::bluetooth_low_energy::Characteristic objects |
131 // associated with the GATT service with instance ID |instance_id| in | 132 // associated with the GATT service with instance ID |instance_id| in |
132 // |out_characteristics|. Returns false, if no service with the given instance | 133 // |out_characteristics|. Returns false, if no service with the given instance |
133 // ID is known. If the service is found but it has no characteristics, then | 134 // ID is known. If the service is found but it has no characteristics, then |
134 // returns true and leaves |out_characteristics| empty. | 135 // returns true and leaves |out_characteristics| empty. |
135 // |out_characteristics| must not be NULL and if it is non-empty, | 136 // |out_characteristics| must not be NULL and if it is non-empty, |
136 // then its contents will be cleared. |extension| is the extension that made | 137 // then its contents will be cleared. |extension| is the extension that made |
137 // the call. | 138 // the call. |
138 typedef std::vector<linked_ptr<api::bluetooth_low_energy::Characteristic> > | 139 typedef std::vector< |
| 140 linked_ptr<core_api::bluetooth_low_energy::Characteristic> > |
139 CharacteristicList; | 141 CharacteristicList; |
140 Status GetCharacteristics(const Extension* extension, | 142 Status GetCharacteristics(const Extension* extension, |
141 const std::string& instance_id, | 143 const std::string& instance_id, |
142 CharacteristicList* out_characteristics) const; | 144 CharacteristicList* out_characteristics) const; |
143 | 145 |
144 // Populates |out_characteristic| based on GATT characteristic with instance | 146 // Populates |out_characteristic| based on GATT characteristic with instance |
145 // ID |instance_id|. |out_characteristic| must not be NULL. |extension| is the | 147 // ID |instance_id|. |out_characteristic| must not be NULL. |extension| is the |
146 // extension that made the call. | 148 // extension that made the call. |
147 Status GetCharacteristic( | 149 Status GetCharacteristic( |
148 const Extension* extension, | 150 const Extension* extension, |
149 const std::string& instance_id, | 151 const std::string& instance_id, |
150 api::bluetooth_low_energy::Characteristic* out_characteristic) const; | 152 core_api::bluetooth_low_energy::Characteristic* out_characteristic) const; |
151 | 153 |
152 // Returns the list of api::bluetooth_low_energy::Descriptor objects | 154 // Returns the list of core_api::bluetooth_low_energy::Descriptor objects |
153 // associated with the GATT characteristic with instance ID |instance_id| in | 155 // associated with the GATT characteristic with instance ID |instance_id| in |
154 // |out_descriptors|. If the characteristic is found but it has no | 156 // |out_descriptors|. If the characteristic is found but it has no |
155 // descriptors, then returns true and leaves |out_descriptors| empty. | 157 // descriptors, then returns true and leaves |out_descriptors| empty. |
156 // |out_descriptors| must not be NULL and if it is non-empty, | 158 // |out_descriptors| must not be NULL and if it is non-empty, |
157 // then its contents will be cleared. |extension| is the extension that made | 159 // then its contents will be cleared. |extension| is the extension that made |
158 // the call. | 160 // the call. |
159 typedef std::vector<linked_ptr<api::bluetooth_low_energy::Descriptor> > | 161 typedef std::vector<linked_ptr<core_api::bluetooth_low_energy::Descriptor> > |
160 DescriptorList; | 162 DescriptorList; |
161 Status GetDescriptors(const Extension* extension, | 163 Status GetDescriptors(const Extension* extension, |
162 const std::string& instance_id, | 164 const std::string& instance_id, |
163 DescriptorList* out_descriptors) const; | 165 DescriptorList* out_descriptors) const; |
164 | 166 |
165 // Populates |out_descriptor| based on GATT characteristic descriptor with | 167 // Populates |out_descriptor| based on GATT characteristic descriptor with |
166 // instance ID |instance_id|. |out_descriptor| must not be NULL. | 168 // instance ID |instance_id|. |out_descriptor| must not be NULL. |
167 // |extension| is the extension that made the call. | 169 // |extension| is the extension that made the call. |
168 Status GetDescriptor( | 170 Status GetDescriptor( |
169 const Extension* extension, | 171 const Extension* extension, |
170 const std::string& instance_id, | 172 const std::string& instance_id, |
171 api::bluetooth_low_energy::Descriptor* out_descriptor) const; | 173 core_api::bluetooth_low_energy::Descriptor* out_descriptor) const; |
172 | 174 |
173 // Sends a request to read the value of the characteristic with intance ID | 175 // Sends a request to read the value of the characteristic with intance ID |
174 // |instance_id|. Invokes |callback| on success and |error_callback| on | 176 // |instance_id|. Invokes |callback| on success and |error_callback| on |
175 // failure. |extension| is the extension that made the call. | 177 // failure. |extension| is the extension that made the call. |
176 void ReadCharacteristicValue(const Extension* extension, | 178 void ReadCharacteristicValue(const Extension* extension, |
177 const std::string& instance_id, | 179 const std::string& instance_id, |
178 const base::Closure& callback, | 180 const base::Closure& callback, |
179 const ErrorCallback& error_callback); | 181 const ErrorCallback& error_callback); |
180 | 182 |
181 // Sends a request to write the value of the characteristic with instance ID | 183 // Sends a request to write the value of the characteristic with instance ID |
(...skipping 224 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
406 | 408 |
407 // Note: This should remain the last member so it'll be destroyed and | 409 // Note: This should remain the last member so it'll be destroyed and |
408 // invalidate its weak pointers before any other members are destroyed. | 410 // invalidate its weak pointers before any other members are destroyed. |
409 base::WeakPtrFactory<BluetoothLowEnergyEventRouter> weak_ptr_factory_; | 411 base::WeakPtrFactory<BluetoothLowEnergyEventRouter> weak_ptr_factory_; |
410 | 412 |
411 DISALLOW_COPY_AND_ASSIGN(BluetoothLowEnergyEventRouter); | 413 DISALLOW_COPY_AND_ASSIGN(BluetoothLowEnergyEventRouter); |
412 }; | 414 }; |
413 | 415 |
414 } // namespace extensions | 416 } // namespace extensions |
415 | 417 |
416 #endif // CHROME_BROWSER_EXTENSIONS_API_BLUETOOTH_LOW_ENERGY_BLUETOOTH_LOW_ENER
GY_EVENT_ROUTER_H_ | 418 #endif // EXTENSIONS_BROWSER_API_BLUETOOTH_LOW_ENERGY_BLUETOOTH_LOW_ENERGY_EVEN
T_ROUTER_H_ |
OLD | NEW |