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

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

Issue 1054743003: Add CPP API for BLE advertisments. (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: Created 5 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 (c) 2012 The Chromium Authors. All rights reserved. 1 // Copyright (c) 2012 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_ADAPTER_H_ 5 #ifndef DEVICE_BLUETOOTH_BLUETOOTH_ADAPTER_H_
6 #define DEVICE_BLUETOOTH_BLUETOOTH_ADAPTER_H_ 6 #define DEVICE_BLUETOOTH_BLUETOOTH_ADAPTER_H_
7 7
8 #include <list> 8 #include <list>
9 #include <map> 9 #include <map>
10 #include <set> 10 #include <set>
11 #include <string> 11 #include <string>
12 #include <utility> 12 #include <utility>
13 13
14 #include "base/callback.h" 14 #include "base/callback.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 "device/bluetooth/bluetooth_advertisement.h"
17 #include "device/bluetooth/bluetooth_audio_sink.h" 18 #include "device/bluetooth/bluetooth_audio_sink.h"
18 #include "device/bluetooth/bluetooth_device.h" 19 #include "device/bluetooth/bluetooth_device.h"
19 #include "device/bluetooth/bluetooth_export.h" 20 #include "device/bluetooth/bluetooth_export.h"
20 21
21 namespace device { 22 namespace device {
22 23
24 class BluetoothAdvertisement;
23 class BluetoothDiscoveryFilter; 25 class BluetoothDiscoveryFilter;
24 class BluetoothDiscoverySession; 26 class BluetoothDiscoverySession;
25 class BluetoothGattCharacteristic; 27 class BluetoothGattCharacteristic;
26 class BluetoothGattDescriptor; 28 class BluetoothGattDescriptor;
27 class BluetoothGattService; 29 class BluetoothGattService;
28 class BluetoothSocket; 30 class BluetoothSocket;
29 class BluetoothUUID; 31 class BluetoothUUID;
30 struct BluetoothAdapterDeleter; 32 struct BluetoothAdapterDeleter;
31 33
32 // BluetoothAdapter represents a local Bluetooth adapter which may be used to 34 // BluetoothAdapter represents a local Bluetooth adapter which may be used to
(...skipping 134 matching lines...) Expand 10 before | Expand all | Expand 10 after
167 ServiceOptions(); 169 ServiceOptions();
168 ~ServiceOptions(); 170 ~ServiceOptions();
169 171
170 scoped_ptr<int> channel; 172 scoped_ptr<int> channel;
171 scoped_ptr<int> psm; 173 scoped_ptr<int> psm;
172 scoped_ptr<std::string> name; 174 scoped_ptr<std::string> name;
173 }; 175 };
174 176
175 // The ErrorCallback is used for methods that can fail in which case it is 177 // The ErrorCallback is used for methods that can fail in which case it is
176 // called, in the success case the callback is simply not called. 178 // called, in the success case the callback is simply not called.
177 typedef base::Closure ErrorCallback; 179 using ErrorCallback = base::Closure;
178 180
179 // The InitCallback is used to trigger a callback after asynchronous 181 // The InitCallback is used to trigger a callback after asynchronous
180 // initialization, if initialization is asynchronous on the platform. 182 // initialization, if initialization is asynchronous on the platform.
181 typedef base::Callback<void()> InitCallback; 183 using InitCallback = base::Callback<void()>;
182 184
183 typedef base::Callback<void(scoped_ptr<BluetoothDiscoverySession>)> 185 using DiscoverySessionCallback =
184 DiscoverySessionCallback; 186 base::Callback<void(scoped_ptr<BluetoothDiscoverySession>)>;
185 typedef std::vector<BluetoothDevice*> DeviceList; 187 using DeviceList = std::vector<BluetoothDevice*>;
186 typedef std::vector<const BluetoothDevice*> ConstDeviceList; 188 using ConstDeviceList = std::vector<const BluetoothDevice*>;
187 typedef base::Callback<void(scoped_refptr<BluetoothSocket>)> 189 using CreateServiceCallback =
188 CreateServiceCallback; 190 base::Callback<void(scoped_refptr<BluetoothSocket>)>;
189 typedef base::Callback<void(const std::string& message)> 191 using CreateServiceErrorCallback =
190 CreateServiceErrorCallback; 192 base::Callback<void(const std::string& message)>;
191 typedef base::Callback<void(scoped_refptr<BluetoothAudioSink>)> 193 using AcquiredCallback =
192 AcquiredCallback; 194 base::Callback<void(scoped_refptr<BluetoothAudioSink>)>;
195 using CreateAdvertisementCallback =
196 base::Callback<void(scoped_refptr<BluetoothAdvertisement>)>;
197 using CreateAdvertisementErrorCallback =
198 base::Callback<void(BluetoothAdvertisement::ErrorCode)>;
armansito 2015/04/24 22:11:00 Why did you do this here? I prefer that you perfor
rkc 2015/04/24 22:55:24 I agree in principle, but in this one case, I had
193 199
194 // Returns a weak pointer to a new adapter. For platforms with asynchronous 200 // Returns a weak pointer to a new adapter. For platforms with asynchronous
195 // initialization, the returned adapter will run the |init_callback| once 201 // initialization, the returned adapter will run the |init_callback| once
196 // asynchronous initialization is complete. 202 // asynchronous initialization is complete.
197 // Caution: The returned pointer also transfers ownership of the adapter. The 203 // Caution: The returned pointer also transfers ownership of the adapter. The
198 // caller is expected to call |AddRef()| on the returned pointer, typically by 204 // caller is expected to call |AddRef()| on the returned pointer, typically by
199 // storing it into a |scoped_refptr|. 205 // storing it into a |scoped_refptr|.
200 static base::WeakPtr<BluetoothAdapter> CreateAdapter( 206 static base::WeakPtr<BluetoothAdapter> CreateAdapter(
201 const InitCallback& init_callback); 207 const InitCallback& init_callback);
202 208
(...skipping 159 matching lines...) Expand 10 before | Expand all | Expand 10 after
362 // Creates and registers a BluetoothAudioSink with |options|. If the fields in 368 // Creates and registers a BluetoothAudioSink with |options|. If the fields in
363 // |options| are not specified, the default values will be used. |callback| 369 // |options| are not specified, the default values will be used. |callback|
364 // will be called on success with a BluetoothAudioSink which is to be owned by 370 // will be called on success with a BluetoothAudioSink which is to be owned by
365 // the caller of this method. |error_callback| will be called on failure with 371 // the caller of this method. |error_callback| will be called on failure with
366 // a message indicating the cause. 372 // a message indicating the cause.
367 virtual void RegisterAudioSink( 373 virtual void RegisterAudioSink(
368 const BluetoothAudioSink::Options& options, 374 const BluetoothAudioSink::Options& options,
369 const AcquiredCallback& callback, 375 const AcquiredCallback& callback,
370 const BluetoothAudioSink::ErrorCallback& error_callback) = 0; 376 const BluetoothAudioSink::ErrorCallback& error_callback) = 0;
371 377
378 // Creates and registers an advertisement for broadcast over the LE channel.
379 // The created advertisement will be returned via the success callback.
380 virtual void RegisterAdvertisement(
381 scoped_ptr<BluetoothAdvertisement::Data> advertisement_data,
382 const CreateAdvertisementCallback& callback,
383 const CreateAdvertisementErrorCallback& error_callback) = 0;
384
372 protected: 385 protected:
373 friend class base::RefCounted<BluetoothAdapter>; 386 friend class base::RefCounted<BluetoothAdapter>;
374 friend class BluetoothDiscoverySession; 387 friend class BluetoothDiscoverySession;
375 388
376 typedef std::map<const std::string, BluetoothDevice*> DevicesMap; 389 using DevicesMap = std::map<const std::string, BluetoothDevice*>;
377 typedef std::pair<BluetoothDevice::PairingDelegate*, PairingDelegatePriority> 390 using PairingDelegatePair =
378 PairingDelegatePair; 391 std::pair<BluetoothDevice::PairingDelegate*, PairingDelegatePriority>;
armansito 2015/04/24 22:11:00 Same as above. Do this typedef -> using conversion
rkc 2015/04/24 22:55:24 Since this really isn't directly next to my new co
379 392
380 BluetoothAdapter(); 393 BluetoothAdapter();
381 virtual ~BluetoothAdapter(); 394 virtual ~BluetoothAdapter();
382 395
383 // Internal methods for initiating and terminating device discovery sessions. 396 // Internal methods for initiating and terminating device discovery sessions.
384 // An implementation of BluetoothAdapter keeps an internal reference count to 397 // An implementation of BluetoothAdapter keeps an internal reference count to
385 // make sure that the underlying controller is constantly searching for nearby 398 // make sure that the underlying controller is constantly searching for nearby
386 // devices and retrieving information from them as long as there are clients 399 // devices and retrieving information from them as long as there are clients
387 // who have requested discovery. These methods behave in the following way: 400 // who have requested discovery. These methods behave in the following way:
388 // 401 //
(...skipping 86 matching lines...) Expand 10 before | Expand all | Expand 10 after
475 std::set<BluetoothDiscoverySession*> discovery_sessions_; 488 std::set<BluetoothDiscoverySession*> discovery_sessions_;
476 489
477 // Note: This should remain the last member so it'll be destroyed and 490 // Note: This should remain the last member so it'll be destroyed and
478 // invalidate its weak pointers before any other members are destroyed. 491 // invalidate its weak pointers before any other members are destroyed.
479 base::WeakPtrFactory<BluetoothAdapter> weak_ptr_factory_; 492 base::WeakPtrFactory<BluetoothAdapter> weak_ptr_factory_;
480 }; 493 };
481 494
482 } // namespace device 495 } // namespace device
483 496
484 #endif // DEVICE_BLUETOOTH_BLUETOOTH_ADAPTER_H_ 497 #endif // DEVICE_BLUETOOTH_BLUETOOTH_ADAPTER_H_
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698