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

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: Updated patchset dependency Created 5 years, 4 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_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 <string> 9 #include <string>
10 #include <vector> 10 #include <vector>
(...skipping 222 matching lines...) Expand 10 before | Expand all | Expand 10 after
233 virtual bool IsPaired() const = 0; 233 virtual bool IsPaired() const = 0;
234 234
235 // Indicates whether the device is currently connected to the adapter. 235 // Indicates whether the device is currently connected to the adapter.
236 // 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
237 // 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
238 // 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
239 // 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
240 // 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.
241 virtual bool IsConnected() const = 0; 241 virtual bool IsConnected() const = 0;
242 242
243 // Indicates whether an active GATT connection exists to the device.
244 virtual bool IsGattConnected() const = 0;
245
243 // Indicates whether the paired device accepts connections initiated from the 246 // Indicates whether the paired device accepts connections initiated from the
244 // adapter. This value is undefined for unpaired devices. 247 // adapter. This value is undefined for unpaired devices.
245 virtual bool IsConnectable() const = 0; 248 virtual bool IsConnectable() const = 0;
246 249
247 // 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,
248 // 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()
249 // were called after the corresponding call to Connect(). 252 // were called after the corresponding call to Connect().
250 virtual bool IsConnecting() const = 0; 253 virtual bool IsConnecting() const = 0;
251 254
252 // 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
400 // BluetoothGattConnection will be handed to the caller via |callback|. On 403 // BluetoothGattConnection will be handed to the caller via |callback|. On
401 // 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,
402 // 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
403 // the underlying connection gets terminated, either due to a call to 406 // the underlying connection gets terminated, either due to a call to
404 // BluetoothDevice::Disconnect or other unexpected circumstances, the 407 // BluetoothDevice::Disconnect or other unexpected circumstances, the
405 // returned BluetoothGattConnection will be automatically marked as inactive. 408 // returned BluetoothGattConnection will be automatically marked as inactive.
406 // To monitor the state of the connection, observe the 409 // To monitor the state of the connection, observe the
407 // BluetoothAdapter::Observer::DeviceChanged method. 410 // BluetoothAdapter::Observer::DeviceChanged method.
408 typedef base::Callback<void(scoped_ptr<BluetoothGattConnection>)> 411 typedef base::Callback<void(scoped_ptr<BluetoothGattConnection>)>
409 GattConnectionCallback; 412 GattConnectionCallback;
410 virtual void CreateGattConnection( 413 virtual void CreateGattConnection(const GattConnectionCallback& callback,
411 const GattConnectionCallback& callback, 414 const ConnectErrorCallback& error_callback);
412 const ConnectErrorCallback& error_callback) = 0;
413 415
414 // Returns the list of discovered GATT services. 416 // Returns the list of discovered GATT services.
415 virtual std::vector<BluetoothGattService*> GetGattServices() const; 417 virtual std::vector<BluetoothGattService*> GetGattServices() const;
416 418
417 // Returns the GATT service with device-specific identifier |identifier|. 419 // Returns the GATT service with device-specific identifier |identifier|.
418 // Returns NULL, if no such service exists. 420 // Returns NULL, if no such service exists.
419 virtual BluetoothGattService* GetGattService( 421 virtual BluetoothGattService* GetGattService(
420 const std::string& identifier) const; 422 const std::string& identifier) const;
421 423
422 // Returns service data of a service given its UUID. 424 // Returns service data of a service given its UUID.
423 virtual base::BinaryValue* GetServiceData(BluetoothUUID serviceUUID) const; 425 virtual base::BinaryValue* GetServiceData(BluetoothUUID serviceUUID) const;
424 426
425 // Returns the list UUIDs of services that have service data. 427 // Returns the list UUIDs of services that have service data.
426 virtual UUIDList GetServiceDataUUIDs() const; 428 virtual UUIDList GetServiceDataUUIDs() const;
427 429
428 // 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
429 // 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
430 // empty string. 432 // empty string.
431 static std::string CanonicalizeAddress(const std::string& address); 433 static std::string CanonicalizeAddress(const std::string& address);
432 434
433 protected: 435 protected:
436 // BluetoothGattConnection is a friend to call
437 // In/DecrementGattConnectionReferenceCount.
Jeffrey Yasskin 2015/08/19 22:49:45 "Inc/Decrement", I think.
scheib 2015/09/13 02:40:27 Done.
438 friend BluetoothGattConnection;
439
434 BluetoothDevice(BluetoothAdapter* adapter); 440 BluetoothDevice(BluetoothAdapter* adapter);
435 441
436 // Returns the internal name of the Bluetooth device, used by GetName(). 442 // Returns the internal name of the Bluetooth device, used by GetName().
437 virtual std::string GetDeviceName() const = 0; 443 virtual std::string GetDeviceName() const = 0;
438 444
445 // Implements platform specific operations to initiate a GATT connection.
446 // Subclasses must also call DidConnectGatt, DidFailToConnectGatt, or
447 // DidDisconnectGatt immediately or asynchronously as the connection state
Jeffrey Yasskin 2015/08/19 22:49:45 "immediately or asynchronously" covers all the opt
scheib 2015/09/13 02:40:27 Done. I was trying to communicate that these may b
Jeffrey Yasskin 2015/09/16 00:45:39 Ah, yeah, I like the explicit statement you've add
448 // changes.
449 virtual void CreateGattConnectionImpl() = 0;
Jeffrey Yasskin 2015/08/19 22:49:45 If you intend to only call this from BluetoothDevi
scheib 2015/09/13 02:40:28 Doesn't overriding for implementation then defeat
Jeffrey Yasskin 2015/09/16 00:45:39 Yeah, good point: subclasses will be able to call
450
451 // Disconnects GATT connection on platforms that maintain a specific GATT
452 // connection.
453 virtual void DisconnectGatt() = 0;
454
455 // Calls pending callbacks for CreateGattConnection based on result of
Jeffrey Yasskin 2015/08/19 22:49:45 Say something about how Did*Gatt() calls need to m
scheib 2015/09/13 02:40:27 Done. Regarding out of range, there isn't anything
456 // subclasses actions initiated in CreateGattConnectionImpl or related
457 // disconnection event.
458 void DidConnectGatt();
459 void DidFailToConnectGatt(ConnectErrorCode);
460 void DidDisconnectGatt();
461
462 // Maintains GattConnection reference count. Called by friend class
463 // BluetoothGattConnection.
464 void IncrementGattConnectionReferenceCount();
465 void DecrementGattConnectionReferenceCount();
466
439 // Clears the list of service data. 467 // Clears the list of service data.
440 void ClearServiceData(); 468 void ClearServiceData();
441 469
442 // Set the data of a given service designated by its UUID. 470 // Set the data of a given service designated by its UUID.
443 void SetServiceData(BluetoothUUID serviceUUID, const char* buffer, 471 void SetServiceData(BluetoothUUID serviceUUID, const char* buffer,
444 size_t size); 472 size_t size);
445 473
446 // Raw pointer to adapter owning this device object. Subclasses use platform 474 // Raw pointer to adapter owning this device object. Subclasses use platform
447 // specific pointers via adapter_. 475 // specific pointers via adapter_.
448 BluetoothAdapter* adapter_; 476 BluetoothAdapter* adapter_;
449 477
478 // Callbacks for pending success and error result of CreateGattConnection.
479 std::vector<GattConnectionCallback> create_gatt_connection_success_callbacks_;
480 std::vector<ConnectErrorCallback> create_gatt_connection_error_callbacks_;
481
482 // Represents the number of BluetoothGattConnection objects keeping the
483 // Gatt connection alive to the device.
484 uint32_t gatt_connection_reference_count_ = 0;
485
450 // Mapping from the platform-specific GATT service identifiers to 486 // Mapping from the platform-specific GATT service identifiers to
451 // BluetoothGattService objects. 487 // BluetoothGattService objects.
452 typedef std::map<std::string, BluetoothGattService*> GattServiceMap; 488 typedef std::map<std::string, BluetoothGattService*> GattServiceMap;
453 GattServiceMap gatt_services_; 489 GattServiceMap gatt_services_;
454 490
455 // Mapping from service UUID represented as a std::string of a bluetooth 491 // Mapping from service UUID represented as a std::string of a bluetooth
456 // service to 492 // service to
457 // the specific data. The data is stored as BinaryValue. 493 // the specific data. The data is stored as BinaryValue.
458 scoped_ptr<base::DictionaryValue> services_data_; 494 scoped_ptr<base::DictionaryValue> services_data_;
459 495
460 private: 496 private:
461 // Returns a localized string containing the device's bluetooth address and 497 // Returns a localized string containing the device's bluetooth address and
462 // a device type for display when |name_| is empty. 498 // a device type for display when |name_| is empty.
463 base::string16 GetAddressWithLocalizedDeviceTypeName() const; 499 base::string16 GetAddressWithLocalizedDeviceTypeName() const;
464 }; 500 };
465 501
466 } // namespace device 502 } // namespace device
467 503
468 #endif // DEVICE_BLUETOOTH_BLUETOOTH_DEVICE_H_ 504 #endif // DEVICE_BLUETOOTH_BLUETOOTH_DEVICE_H_
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698