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

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

Issue 1100483005: bluetooth: Refactor device/bluetooth for C++ Style: typedef ordering. (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: typedefs for all of src/device/bluetooth 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
« no previous file with comments | « no previous file | device/bluetooth/bluetooth_adapter_chromeos.h » ('j') | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
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>
(...skipping 163 matching lines...) Expand 10 before | Expand all | Expand 10 after
174 }; 174 };
175 175
176 // The ErrorCallback is used for methods that can fail in which case it is 176 // The ErrorCallback is used for methods that can fail in which case it is
177 // called, in the success case the callback is simply not called. 177 // called, in the success case the callback is simply not called.
178 typedef base::Closure ErrorCallback; 178 typedef base::Closure ErrorCallback;
179 179
180 // The InitCallback is used to trigger a callback after asynchronous 180 // The InitCallback is used to trigger a callback after asynchronous
181 // initialization, if initialization is asynchronous on the platform. 181 // initialization, if initialization is asynchronous on the platform.
182 typedef base::Callback<void()> InitCallback; 182 typedef base::Callback<void()> InitCallback;
183 183
184 typedef base::Callback<void(scoped_ptr<BluetoothDiscoverySession>)>
185 DiscoverySessionCallback;
186 typedef std::vector<BluetoothDevice*> DeviceList;
187 typedef std::vector<const BluetoothDevice*> ConstDeviceList;
188 typedef base::Callback<void(scoped_refptr<BluetoothSocket>)>
189 CreateServiceCallback;
190 typedef base::Callback<void(const std::string& message)>
191 CreateServiceErrorCallback;
192 typedef base::Callback<void(scoped_refptr<BluetoothAudioSink>)>
193 AcquiredCallback;
194
184 // Returns a weak pointer to a new adapter. For platforms with asynchronous 195 // Returns a weak pointer to a new adapter. For platforms with asynchronous
185 // initialization, the returned adapter will run the |init_callback| once 196 // initialization, the returned adapter will run the |init_callback| once
186 // asynchronous initialization is complete. 197 // asynchronous initialization is complete.
187 // Caution: The returned pointer also transfers ownership of the adapter. The 198 // Caution: The returned pointer also transfers ownership of the adapter. The
188 // caller is expected to call |AddRef()| on the returned pointer, typically by 199 // caller is expected to call |AddRef()| on the returned pointer, typically by
189 // storing it into a |scoped_refptr|. 200 // storing it into a |scoped_refptr|.
190 static base::WeakPtr<BluetoothAdapter> CreateAdapter( 201 static base::WeakPtr<BluetoothAdapter> CreateAdapter(
191 const InitCallback& init_callback); 202 const InitCallback& init_callback);
192 203
193 // Returns a weak pointer to an existing adapter for testing purposes only. 204 // Returns a weak pointer to an existing adapter for testing purposes only.
(...skipping 69 matching lines...) Expand 10 before | Expand all | Expand 10 after
263 // If clients desire device discovery to run, they should always call this 274 // If clients desire device discovery to run, they should always call this
264 // method and never make it conditional on the value of IsDiscovering(), as 275 // method and never make it conditional on the value of IsDiscovering(), as
265 // another client might cause discovery to stop unexpectedly. Hence, clients 276 // another client might cause discovery to stop unexpectedly. Hence, clients
266 // should always obtain a BluetoothDiscoverySession and call 277 // should always obtain a BluetoothDiscoverySession and call
267 // BluetoothDiscoverySession::Stop when done. When this method gets called, 278 // BluetoothDiscoverySession::Stop when done. When this method gets called,
268 // device discovery may actually be in progress. Clients can call GetDevices() 279 // device discovery may actually be in progress. Clients can call GetDevices()
269 // and check for those with IsPaired() as false to obtain the list of devices 280 // and check for those with IsPaired() as false to obtain the list of devices
270 // that have been discovered so far. Otherwise, clients can be notified of all 281 // that have been discovered so far. Otherwise, clients can be notified of all
271 // new and lost devices by implementing the Observer methods "DeviceAdded" and 282 // new and lost devices by implementing the Observer methods "DeviceAdded" and
272 // "DeviceRemoved". 283 // "DeviceRemoved".
273 typedef base::Callback<void(scoped_ptr<BluetoothDiscoverySession>)>
274 DiscoverySessionCallback;
275 virtual void StartDiscoverySession(const DiscoverySessionCallback& callback, 284 virtual void StartDiscoverySession(const DiscoverySessionCallback& callback,
276 const ErrorCallback& error_callback); 285 const ErrorCallback& error_callback);
277 virtual void StartDiscoverySessionWithFilter( 286 virtual void StartDiscoverySessionWithFilter(
278 scoped_ptr<BluetoothDiscoveryFilter> discovery_filter, 287 scoped_ptr<BluetoothDiscoveryFilter> discovery_filter,
279 const DiscoverySessionCallback& callback, 288 const DiscoverySessionCallback& callback,
280 const ErrorCallback& error_callback); 289 const ErrorCallback& error_callback);
281 290
282 // Return all discovery filters assigned to this adapter merged together. 291 // Return all discovery filters assigned to this adapter merged together.
283 scoped_ptr<BluetoothDiscoveryFilter> GetMergedDiscoveryFilter() const; 292 scoped_ptr<BluetoothDiscoveryFilter> GetMergedDiscoveryFilter() const;
284 293
285 // Works like GetMergedDiscoveryFilter, but doesn't take |masked_filter| into 294 // Works like GetMergedDiscoveryFilter, but doesn't take |masked_filter| into
286 // account. |masked_filter| is compared by pointer, and must be a member of 295 // account. |masked_filter| is compared by pointer, and must be a member of
287 // active session. 296 // active session.
288 scoped_ptr<BluetoothDiscoveryFilter> GetMergedDiscoveryFilterMasked( 297 scoped_ptr<BluetoothDiscoveryFilter> GetMergedDiscoveryFilterMasked(
289 BluetoothDiscoveryFilter* masked_filter) const; 298 BluetoothDiscoveryFilter* masked_filter) const;
290 299
291 // Requests the list of devices from the adapter. All devices are returned, 300 // Requests the list of devices from the adapter. All devices are returned,
292 // including those currently connected and those paired. Use the returned 301 // including those currently connected and those paired. Use the returned
293 // device pointers to determine which they are. 302 // device pointers to determine which they are.
294 typedef std::vector<BluetoothDevice*> DeviceList;
295 virtual DeviceList GetDevices(); 303 virtual DeviceList GetDevices();
296 typedef std::vector<const BluetoothDevice*> ConstDeviceList;
297 virtual ConstDeviceList GetDevices() const; 304 virtual ConstDeviceList GetDevices() const;
298 305
299 // Returns a pointer to the device with the given address |address| or NULL if 306 // Returns a pointer to the device with the given address |address| or NULL if
300 // no such device is known. 307 // no such device is known.
301 virtual BluetoothDevice* GetDevice(const std::string& address); 308 virtual BluetoothDevice* GetDevice(const std::string& address);
302 virtual const BluetoothDevice* GetDevice(const std::string& address) const; 309 virtual const BluetoothDevice* GetDevice(const std::string& address) const;
303 310
304 // Possible priorities for AddPairingDelegate(), low is intended for 311 // Possible priorities for AddPairingDelegate(), low is intended for
305 // permanent UI and high is intended for interactive UI or applications. 312 // permanent UI and high is intended for interactive UI or applications.
306 enum PairingDelegatePriority { 313 enum PairingDelegatePriority {
(...skipping 21 matching lines...) Expand all
328 // incoming pairing requests. 335 // incoming pairing requests.
329 virtual BluetoothDevice::PairingDelegate* DefaultPairingDelegate(); 336 virtual BluetoothDevice::PairingDelegate* DefaultPairingDelegate();
330 337
331 // Creates an RFCOMM service on this adapter advertised with UUID |uuid|, 338 // Creates an RFCOMM service on this adapter advertised with UUID |uuid|,
332 // listening on channel |options.channel|, which may be left null to 339 // listening on channel |options.channel|, which may be left null to
333 // automatically allocate one. The service will be advertised with 340 // automatically allocate one. The service will be advertised with
334 // |options.name| as the English name of the service. |callback| will be 341 // |options.name| as the English name of the service. |callback| will be
335 // called on success with a BluetoothSocket instance that is to be owned by 342 // called on success with a BluetoothSocket instance that is to be owned by
336 // the received. |error_callback| will be called on failure with a message 343 // the received. |error_callback| will be called on failure with a message
337 // indicating the cause. 344 // indicating the cause.
338 typedef base::Callback<void(scoped_refptr<BluetoothSocket>)>
339 CreateServiceCallback;
340 typedef base::Callback<void(const std::string& message)>
341 CreateServiceErrorCallback;
342 virtual void CreateRfcommService( 345 virtual void CreateRfcommService(
343 const BluetoothUUID& uuid, 346 const BluetoothUUID& uuid,
344 const ServiceOptions& options, 347 const ServiceOptions& options,
345 const CreateServiceCallback& callback, 348 const CreateServiceCallback& callback,
346 const CreateServiceErrorCallback& error_callback) = 0; 349 const CreateServiceErrorCallback& error_callback) = 0;
347 350
348 // Creates an L2CAP service on this adapter advertised with UUID |uuid|, 351 // Creates an L2CAP service on this adapter advertised with UUID |uuid|,
349 // listening on PSM |options.psm|, which may be left null to automatically 352 // listening on PSM |options.psm|, which may be left null to automatically
350 // allocate one. The service will be advertised with |options.name| as the 353 // allocate one. The service will be advertised with |options.name| as the
351 // English name of the service. |callback| will be called on success with a 354 // English name of the service. |callback| will be called on success with a
352 // BluetoothSocket instance that is to be owned by the received. 355 // BluetoothSocket instance that is to be owned by the received.
353 // |error_callback| will be called on failure with a message indicating the 356 // |error_callback| will be called on failure with a message indicating the
354 // cause. 357 // cause.
355 virtual void CreateL2capService( 358 virtual void CreateL2capService(
356 const BluetoothUUID& uuid, 359 const BluetoothUUID& uuid,
357 const ServiceOptions& options, 360 const ServiceOptions& options,
358 const CreateServiceCallback& callback, 361 const CreateServiceCallback& callback,
359 const CreateServiceErrorCallback& error_callback) = 0; 362 const CreateServiceErrorCallback& error_callback) = 0;
360 363
361 // Creates and registers a BluetoothAudioSink with |options|. If the fields in 364 // Creates and registers a BluetoothAudioSink with |options|. If the fields in
362 // |options| are not specified, the default values will be used. |callback| 365 // |options| are not specified, the default values will be used. |callback|
363 // will be called on success with a BluetoothAudioSink which is to be owned by 366 // will be called on success with a BluetoothAudioSink which is to be owned by
364 // the caller of this method. |error_callback| will be called on failure with 367 // the caller of this method. |error_callback| will be called on failure with
365 // a message indicating the cause. 368 // a message indicating the cause.
366 typedef base::Callback<void(scoped_refptr<BluetoothAudioSink>)>
367 AcquiredCallback;
368 virtual void RegisterAudioSink( 369 virtual void RegisterAudioSink(
369 const BluetoothAudioSink::Options& options, 370 const BluetoothAudioSink::Options& options,
370 const AcquiredCallback& callback, 371 const AcquiredCallback& callback,
371 const BluetoothAudioSink::ErrorCallback& error_callback) = 0; 372 const BluetoothAudioSink::ErrorCallback& error_callback) = 0;
372 373
373 protected: 374 protected:
374 friend class base::RefCountedThreadSafe<BluetoothAdapter, 375 friend class base::RefCountedThreadSafe<BluetoothAdapter,
375 BluetoothAdapterDeleter>; 376 BluetoothAdapterDeleter>;
376 friend struct BluetoothAdapterDeleter; 377 friend struct BluetoothAdapterDeleter;
377 friend class BluetoothDiscoverySession; 378 friend class BluetoothDiscoverySession;
379
380 typedef std::map<const std::string, BluetoothDevice*> DevicesMap;
381 typedef std::pair<BluetoothDevice::PairingDelegate*, PairingDelegatePriority>
382 PairingDelegatePair;
383
378 BluetoothAdapter(); 384 BluetoothAdapter();
379 virtual ~BluetoothAdapter(); 385 virtual ~BluetoothAdapter();
380 386
381 // Called by RefCountedThreadSafeDeleteOnCorrectThread to destroy this. 387 // Called by RefCountedThreadSafeDeleteOnCorrectThread to destroy this.
382 virtual void DeleteOnCorrectThread() const = 0; 388 virtual void DeleteOnCorrectThread() const = 0;
383 389
384 // Internal methods for initiating and terminating device discovery sessions. 390 // Internal methods for initiating and terminating device discovery sessions.
385 // An implementation of BluetoothAdapter keeps an internal reference count to 391 // An implementation of BluetoothAdapter keeps an internal reference count to
386 // make sure that the underlying controller is constantly searching for nearby 392 // make sure that the underlying controller is constantly searching for nearby
387 // devices and retrieving information from them as long as there are clients 393 // devices and retrieving information from them as long as there are clients
(...skipping 57 matching lines...) Expand 10 before | Expand all | Expand 10 after
445 // Removes |discovery_session| from |discovery_sessions_|, if its in there. 451 // Removes |discovery_session| from |discovery_sessions_|, if its in there.
446 // Called by DiscoverySession when an instance is destroyed or becomes 452 // Called by DiscoverySession when an instance is destroyed or becomes
447 // inactive. 453 // inactive.
448 void DiscoverySessionBecameInactive( 454 void DiscoverySessionBecameInactive(
449 BluetoothDiscoverySession* discovery_session); 455 BluetoothDiscoverySession* discovery_session);
450 456
451 // Devices paired with, connected to, discovered by, or visible to the 457 // Devices paired with, connected to, discovered by, or visible to the
452 // adapter. The key is the Bluetooth address of the device and the value is 458 // adapter. The key is the Bluetooth address of the device and the value is
453 // the BluetoothDevice object whose lifetime is managed by the adapter 459 // the BluetoothDevice object whose lifetime is managed by the adapter
454 // instance. 460 // instance.
455 typedef std::map<const std::string, BluetoothDevice*> DevicesMap;
456 DevicesMap devices_; 461 DevicesMap devices_;
457 462
458 // Default pairing delegates registered with the adapter. 463 // Default pairing delegates registered with the adapter.
459 typedef std::pair<BluetoothDevice::PairingDelegate*,
460 PairingDelegatePriority> PairingDelegatePair;
461 std::list<PairingDelegatePair> pairing_delegates_; 464 std::list<PairingDelegatePair> pairing_delegates_;
462 465
463 private: 466 private:
464 // Return all discovery filters assigned to this adapter merged together. 467 // Return all discovery filters assigned to this adapter merged together.
465 // If |omit| is true, |discovery_filter| will not be processed. 468 // If |omit| is true, |discovery_filter| will not be processed.
466 scoped_ptr<BluetoothDiscoveryFilter> GetMergedDiscoveryFilterHelper( 469 scoped_ptr<BluetoothDiscoveryFilter> GetMergedDiscoveryFilterHelper(
467 const BluetoothDiscoveryFilter* discovery_filter, 470 const BluetoothDiscoveryFilter* discovery_filter,
468 bool omit) const; 471 bool omit) const;
469 472
470 // List of active DiscoverySession objects. This is used to notify sessions to 473 // List of active DiscoverySession objects. This is used to notify sessions to
(...skipping 12 matching lines...) Expand all
483 // Trait for RefCountedThreadSafe that deletes BluetoothAdapter. 486 // Trait for RefCountedThreadSafe that deletes BluetoothAdapter.
484 struct BluetoothAdapterDeleter { 487 struct BluetoothAdapterDeleter {
485 static void Destruct(const BluetoothAdapter* adapter) { 488 static void Destruct(const BluetoothAdapter* adapter) {
486 adapter->DeleteOnCorrectThread(); 489 adapter->DeleteOnCorrectThread();
487 } 490 }
488 }; 491 };
489 492
490 } // namespace device 493 } // namespace device
491 494
492 #endif // DEVICE_BLUETOOTH_BLUETOOTH_ADAPTER_H_ 495 #endif // DEVICE_BLUETOOTH_BLUETOOTH_ADAPTER_H_
OLDNEW
« no previous file with comments | « no previous file | device/bluetooth/bluetooth_adapter_chromeos.h » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698