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

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

Issue 1292263002: bluetooth: Create base class BluetoothDevice::CreateGattConnection impl. (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@bt-adapter-
Patch Set: fix ProximityAuthBluetoothLowEnergyConnectionTest Created 5 years, 3 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 | « device/bluetooth/bluetooth_classic_device_mac.mm ('k') | device/bluetooth/bluetooth_device.cc » ('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_DEVICE_H_ 5 #ifndef DEVICE_BLUETOOTH_BLUETOOTH_DEVICE_H_
6 #define DEVICE_BLUETOOTH_BLUETOOTH_DEVICE_H_ 6 #define DEVICE_BLUETOOTH_BLUETOOTH_DEVICE_H_
7 7
8 #include <map> 8 #include <map>
9 #include <set>
9 #include <string> 10 #include <string>
10 #include <vector> 11 #include <vector>
11 12
12 #include "base/callback.h" 13 #include "base/callback.h"
13 #include "base/memory/ref_counted.h" 14 #include "base/memory/ref_counted.h"
14 #include "base/strings/string16.h" 15 #include "base/strings/string16.h"
15 #include "device/bluetooth/bluetooth_export.h" 16 #include "device/bluetooth/bluetooth_export.h"
16 #include "device/bluetooth/bluetooth_uuid.h" 17 #include "device/bluetooth/bluetooth_uuid.h"
17 #include "net/log/net_log.h" 18 #include "net/log/net_log.h"
18 19
(...skipping 213 matching lines...) Expand 10 before | Expand all | Expand 10 after
232 virtual bool IsPaired() const = 0; 233 virtual bool IsPaired() const = 0;
233 234
234 // Indicates whether the device is currently connected to the adapter. 235 // Indicates whether the device is currently connected to the adapter.
235 // Note that if IsConnected() is true, does not imply that the device is 236 // Note that if IsConnected() is true, does not imply that the device is
236 // connected to any application or service. If the device is not paired, it 237 // connected to any application or service. If the device is not paired, it
237 // could be still connected to the adapter for other reason, for example, to 238 // could be still connected to the adapter for other reason, for example, to
238 // request the adapter's SDP records. The same holds for paired devices, since 239 // request the adapter's SDP records. The same holds for paired devices, since
239 // they could be connected to the adapter but not to an application. 240 // they could be connected to the adapter but not to an application.
240 virtual bool IsConnected() const = 0; 241 virtual bool IsConnected() const = 0;
241 242
243 // Indicates whether an active GATT connection exists to the device.
244 virtual bool IsGattConnected() const = 0;
245
242 // Indicates whether the paired device accepts connections initiated from the 246 // Indicates whether the paired device accepts connections initiated from the
243 // adapter. This value is undefined for unpaired devices. 247 // adapter. This value is undefined for unpaired devices.
244 virtual bool IsConnectable() const = 0; 248 virtual bool IsConnectable() const = 0;
245 249
246 // Indicates whether there is a call to Connect() ongoing. For this attribute, 250 // Indicates whether there is a call to Connect() ongoing. For this attribute,
247 // we consider a call is ongoing if none of the callbacks passed to Connect() 251 // we consider a call is ongoing if none of the callbacks passed to Connect()
248 // were called after the corresponding call to Connect(). 252 // were called after the corresponding call to Connect().
249 virtual bool IsConnecting() const = 0; 253 virtual bool IsConnecting() const = 0;
250 254
251 // Indicates whether the device can be trusted, based on device properties, 255 // Indicates whether the device can be trusted, based on device properties,
(...skipping 147 matching lines...) Expand 10 before | Expand all | Expand 10 after
399 // BluetoothGattConnection will be handed to the caller via |callback|. On 403 // BluetoothGattConnection will be handed to the caller via |callback|. On
400 // error, |error_callback| will be called. The connection will be kept alive, 404 // error, |error_callback| will be called. The connection will be kept alive,
401 // as long as there is at least one active GATT connection. In the case that 405 // as long as there is at least one active GATT connection. In the case that
402 // the underlying connection gets terminated, either due to a call to 406 // the underlying connection gets terminated, either due to a call to
403 // BluetoothDevice::Disconnect or other unexpected circumstances, the 407 // BluetoothDevice::Disconnect or other unexpected circumstances, the
404 // returned BluetoothGattConnection will be automatically marked as inactive. 408 // returned BluetoothGattConnection will be automatically marked as inactive.
405 // To monitor the state of the connection, observe the 409 // To monitor the state of the connection, observe the
406 // BluetoothAdapter::Observer::DeviceChanged method. 410 // BluetoothAdapter::Observer::DeviceChanged method.
407 typedef base::Callback<void(scoped_ptr<BluetoothGattConnection>)> 411 typedef base::Callback<void(scoped_ptr<BluetoothGattConnection>)>
408 GattConnectionCallback; 412 GattConnectionCallback;
409 virtual void CreateGattConnection( 413 virtual void CreateGattConnection(const GattConnectionCallback& callback,
410 const GattConnectionCallback& callback, 414 const ConnectErrorCallback& error_callback);
411 const ConnectErrorCallback& error_callback) = 0;
412 415
413 // Returns the list of discovered GATT services. 416 // Returns the list of discovered GATT services.
414 virtual std::vector<BluetoothGattService*> GetGattServices() const; 417 virtual std::vector<BluetoothGattService*> GetGattServices() const;
415 418
416 // Returns the GATT service with device-specific identifier |identifier|. 419 // Returns the GATT service with device-specific identifier |identifier|.
417 // Returns NULL, if no such service exists. 420 // Returns NULL, if no such service exists.
418 virtual BluetoothGattService* GetGattService( 421 virtual BluetoothGattService* GetGattService(
419 const std::string& identifier) const; 422 const std::string& identifier) const;
420 423
421 // Returns service data of a service given its UUID. 424 // Returns service data of a service given its UUID.
422 virtual base::BinaryValue* GetServiceData(BluetoothUUID serviceUUID) const; 425 virtual base::BinaryValue* GetServiceData(BluetoothUUID serviceUUID) const;
423 426
424 // Returns the list UUIDs of services that have service data. 427 // Returns the list UUIDs of services that have service data.
425 virtual UUIDList GetServiceDataUUIDs() const; 428 virtual UUIDList GetServiceDataUUIDs() const;
426 429
427 // Returns the |address| in the canonical format: XX:XX:XX:XX:XX:XX, where 430 // Returns the |address| in the canonical format: XX:XX:XX:XX:XX:XX, where
428 // each 'X' is a hex digit. If the input |address| is invalid, returns an 431 // each 'X' is a hex digit. If the input |address| is invalid, returns an
429 // empty string. 432 // empty string.
430 static std::string CanonicalizeAddress(const std::string& address); 433 static std::string CanonicalizeAddress(const std::string& address);
431 434
432 protected: 435 protected:
436 // BluetoothGattConnection is a friend to call Add/RemoveGattConnection.
437 friend BluetoothGattConnection;
438
433 BluetoothDevice(BluetoothAdapter* adapter); 439 BluetoothDevice(BluetoothAdapter* adapter);
434 440
435 // Returns the internal name of the Bluetooth device, used by GetName(). 441 // Returns the internal name of the Bluetooth device, used by GetName().
436 virtual std::string GetDeviceName() const = 0; 442 virtual std::string GetDeviceName() const = 0;
437 443
444 // Implements platform specific operations to initiate a GATT connection.
445 // Subclasses must also call DidConnectGatt, DidFailToConnectGatt, or
446 // DidDisconnectGatt immediately or asynchronously as the connection state
447 // changes.
448 virtual void CreateGattConnectionImpl() = 0;
449
450 // Disconnects GATT connection on platforms that maintain a specific GATT
451 // connection.
452 virtual void DisconnectGatt() = 0;
453
454 // Calls any pending callbacks for CreateGattConnection based on result of
455 // subclasses actions initiated in CreateGattConnectionImpl or related
456 // disconnection events. These may be called at any time, even multiple times,
457 // to ensure a change in platform state is correctly tracked.
458 //
459 // Under normal behavior it is expected that after CreateGattConnectionImpl
460 // an platform will call DidConnectGatt or DidFailToConnectGatt, but not
461 // DidDisconnectGatt.
462 void DidConnectGatt();
463 void DidFailToConnectGatt(ConnectErrorCode);
464 void DidDisconnectGatt();
465
466 // Tracks BluetoothGattConnection instances that act as a reference count
467 // keeping the GATT connection open. Instances call Add/RemoveGattConnection
468 // at creation & deletion.
469 void AddGattConnection(BluetoothGattConnection*);
470 void RemoveGattConnection(BluetoothGattConnection*);
471
438 // Clears the list of service data. 472 // Clears the list of service data.
439 void ClearServiceData(); 473 void ClearServiceData();
440 474
441 // Set the data of a given service designated by its UUID. 475 // Set the data of a given service designated by its UUID.
442 void SetServiceData(BluetoothUUID serviceUUID, const char* buffer, 476 void SetServiceData(BluetoothUUID serviceUUID, const char* buffer,
443 size_t size); 477 size_t size);
444 478
445 // Raw pointer to adapter owning this device object. Subclasses use platform 479 // Raw pointer to adapter owning this device object. Subclasses use platform
446 // specific pointers via adapter_. 480 // specific pointers via adapter_.
447 BluetoothAdapter* adapter_; 481 BluetoothAdapter* adapter_;
448 482
483 // Callbacks for pending success and error result of CreateGattConnection.
484 std::vector<GattConnectionCallback> create_gatt_connection_success_callbacks_;
485 std::vector<ConnectErrorCallback> create_gatt_connection_error_callbacks_;
486
487 // BluetoothGattConnection objects keeping the GATT connection alive.
488 std::set<BluetoothGattConnection*> gatt_connections_;
489
449 // Mapping from the platform-specific GATT service identifiers to 490 // Mapping from the platform-specific GATT service identifiers to
450 // BluetoothGattService objects. 491 // BluetoothGattService objects.
451 typedef std::map<std::string, BluetoothGattService*> GattServiceMap; 492 typedef std::map<std::string, BluetoothGattService*> GattServiceMap;
452 GattServiceMap gatt_services_; 493 GattServiceMap gatt_services_;
453 494
454 // Mapping from service UUID represented as a std::string of a bluetooth 495 // Mapping from service UUID represented as a std::string of a bluetooth
455 // service to 496 // service to
456 // the specific data. The data is stored as BinaryValue. 497 // the specific data. The data is stored as BinaryValue.
457 scoped_ptr<base::DictionaryValue> services_data_; 498 scoped_ptr<base::DictionaryValue> services_data_;
458 499
459 private: 500 private:
460 // Returns a localized string containing the device's bluetooth address and 501 // Returns a localized string containing the device's bluetooth address and
461 // a device type for display when |name_| is empty. 502 // a device type for display when |name_| is empty.
462 base::string16 GetAddressWithLocalizedDeviceTypeName() const; 503 base::string16 GetAddressWithLocalizedDeviceTypeName() const;
463 }; 504 };
464 505
465 } // namespace device 506 } // namespace device
466 507
467 #endif // DEVICE_BLUETOOTH_BLUETOOTH_DEVICE_H_ 508 #endif // DEVICE_BLUETOOTH_BLUETOOTH_DEVICE_H_
OLDNEW
« no previous file with comments | « device/bluetooth/bluetooth_classic_device_mac.mm ('k') | device/bluetooth/bluetooth_device.cc » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698