diff options
author | dvh <dvh@chromium.org> | 2015-01-16 17:17:09 -0800 |
---|---|---|
committer | Commit bot <commit-bot@chromium.org> | 2015-01-17 01:18:10 +0000 |
commit | e13e69b825712c0f03a2b7cfa59c948454cf147e (patch) | |
tree | c84c7d74f3bc0673188311eae6247501ef53c0bf /device | |
parent | 6aea7e7289a79728eb9d2d42e60421ae7dc21622 (diff) | |
download | chromium_src-e13e69b825712c0f03a2b7cfa59c948454cf147e.zip chromium_src-e13e69b825712c0f03a2b7cfa59c948454cf147e.tar.gz chromium_src-e13e69b825712c0f03a2b7cfa59c948454cf147e.tar.bz2 |
Added API to BluetoothDevice to be able to access service data information
from the generic profile of a bluetooth low energy device.
BUG=449678
Review URL: https://codereview.chromium.org/851323004
Cr-Commit-Position: refs/heads/master@{#312000}
Diffstat (limited to 'device')
-rw-r--r-- | device/bluetooth/bluetooth_device.cc | 34 | ||||
-rw-r--r-- | device/bluetooth/bluetooth_device.h | 25 |
2 files changed, 57 insertions, 2 deletions
diff --git a/device/bluetooth/bluetooth_device.cc b/device/bluetooth/bluetooth_device.cc index 1f88d2e..6c72bcc 100644 --- a/device/bluetooth/bluetooth_device.cc +++ b/device/bluetooth/bluetooth_device.cc @@ -8,14 +8,15 @@ #include "base/strings/string_util.h" #include "base/strings/utf_string_conversions.h" +#include "base/values.h" #include "device/bluetooth/bluetooth_gatt_service.h" #include "grit/device_bluetooth_strings.h" #include "ui/base/l10n/l10n_util.h" namespace device { -BluetoothDevice::BluetoothDevice() { -} +BluetoothDevice::BluetoothDevice() + : services_data_(new base::DictionaryValue()) {} BluetoothDevice::~BluetoothDevice() { STLDeleteValues(&gatt_services_); @@ -250,4 +251,33 @@ std::string BluetoothDevice::CanonicalizeAddress(const std::string& address) { return canonicalized; } +std::string BluetoothDevice::GetIdentifier() const { return GetAddress(); } + +base::BinaryValue* BluetoothDevice::GetServiceData( + BluetoothUUID serviceUUID) const { + base::BinaryValue* value; + if (!services_data_->GetBinary(serviceUUID.value(), &value)) + return NULL; + return value; +} + +BluetoothDevice::UUIDList BluetoothDevice::GetServiceDataUUIDs() const { + std::vector<device::BluetoothUUID> uuids; + base::DictionaryValue::Iterator iter(*services_data_); + while (!iter.IsAtEnd()) { + BluetoothUUID uuid(iter.key()); + uuids.push_back(uuid); + iter.Advance(); + } + return uuids; +} + +void BluetoothDevice::ClearServiceData() { services_data_->Clear(); } + +void BluetoothDevice::SetServiceData(BluetoothUUID serviceUUID, + const char* buffer, size_t size) { + services_data_->Set(serviceUUID.value(), + base::BinaryValue::CreateWithCopiedBuffer(buffer, size)); +} + } // namespace device diff --git a/device/bluetooth/bluetooth_device.h b/device/bluetooth/bluetooth_device.h index 3c00e44..c9aa1ee 100644 --- a/device/bluetooth/bluetooth_device.h +++ b/device/bluetooth/bluetooth_device.h @@ -17,6 +17,10 @@ #include "device/bluetooth/bluetooth_uuid.h" #include "net/base/net_log.h" +namespace base { +class BinaryValue; +} + namespace device { class BluetoothGattConnection; @@ -185,6 +189,9 @@ class DEVICE_BLUETOOTH_EXPORT BluetoothDevice { // and metrics logging, virtual uint32 GetBluetoothClass() const = 0; + // Returns the identifier of the bluetooth device. + virtual std::string GetIdentifier() const; + // Returns the Bluetooth of address the device. This should be used as // a unique key to identify the device and copied where needed. virtual std::string GetAddress() const = 0; @@ -398,6 +405,12 @@ class DEVICE_BLUETOOTH_EXPORT BluetoothDevice { virtual BluetoothGattService* GetGattService( const std::string& identifier) const; + // Returns service data of a service given its UUID. + virtual base::BinaryValue* GetServiceData(BluetoothUUID serviceUUID) const; + + // Returns the list UUIDs of services that have service data. + virtual UUIDList GetServiceDataUUIDs() const; + // Returns the |address| in the canonical format: XX:XX:XX:XX:XX:XX, where // each 'X' is a hex digit. If the input |address| is invalid, returns an // empty string. @@ -409,11 +422,23 @@ class DEVICE_BLUETOOTH_EXPORT BluetoothDevice { // Returns the internal name of the Bluetooth device, used by GetName(). virtual std::string GetDeviceName() const = 0; + // Clears the list of service data. + void ClearServiceData(); + + // Set the data of a given service designated by its UUID. + void SetServiceData(BluetoothUUID serviceUUID, const char* buffer, + size_t size); + // Mapping from the platform-specific GATT service identifiers to // BluetoothGattService objects. typedef std::map<std::string, BluetoothGattService*> GattServiceMap; GattServiceMap gatt_services_; + // Mapping from service UUID represented as a std::string of a bluetooth + // service to + // the specific data. The data is stored as BinaryValue. + scoped_ptr<base::DictionaryValue> services_data_; + private: // Returns a localized string containing the device's bluetooth address and // a device type for display when |name_| is empty. |