summaryrefslogtreecommitdiffstats
path: root/chromeos
diff options
context:
space:
mode:
authorarmansito@chromium.org <armansito@chromium.org@0039d316-1c4b-4281-b951-d872f2087c98>2014-04-10 13:32:55 +0000
committerarmansito@chromium.org <armansito@chromium.org@0039d316-1c4b-4281-b951-d872f2087c98>2014-04-10 13:32:55 +0000
commit9389175ac37ae00e7f020bf4b29ab8e7e074b963 (patch)
treec361980e90378ff91e42a2a3260f0f9489c06125 /chromeos
parent0e1886438d1e5aeb04b6c88014aeabf57452da64 (diff)
downloadchromium_src-9389175ac37ae00e7f020bf4b29ab8e7e074b963.zip
chromium_src-9389175ac37ae00e7f020bf4b29ab8e7e074b963.tar.gz
chromium_src-9389175ac37ae00e7f020bf4b29ab8e7e074b963.tar.bz2
device/bluetooth: Add chromeos::BluetoothRemoteGattCharacteristicChromeOS.
Added the chromeos::BluetoothRemoteGattCharacteristicChromeOS class which implements a remote instance of device::BluetoothGattCharacteristic for the Chrome OS platform. BUG=360266,340529 TEST=device_unittests Review URL: https://codereview.chromium.org/228643004 git-svn-id: svn://svn.chromium.org/chrome/trunk/src@262964 0039d316-1c4b-4281-b951-d872f2087c98
Diffstat (limited to 'chromeos')
-rw-r--r--chromeos/dbus/fake_bluetooth_gatt_characteristic_client.cc24
-rw-r--r--chromeos/dbus/fake_bluetooth_gatt_characteristic_client.h14
-rw-r--r--chromeos/dbus/fake_bluetooth_gatt_service_client.cc48
-rw-r--r--chromeos/dbus/fake_bluetooth_gatt_service_client.h20
4 files changed, 91 insertions, 15 deletions
diff --git a/chromeos/dbus/fake_bluetooth_gatt_characteristic_client.cc b/chromeos/dbus/fake_bluetooth_gatt_characteristic_client.cc
index c25e71c..55784a9 100644
--- a/chromeos/dbus/fake_bluetooth_gatt_characteristic_client.cc
+++ b/chromeos/dbus/fake_bluetooth_gatt_characteristic_client.cc
@@ -49,7 +49,10 @@ void FakeBluetoothGattCharacteristicClient::Properties::Get(
dbus::PropertyBase* property,
dbus::PropertySet::GetCallback callback) {
VLOG(1) << "Get " << property->name();
- callback.Run(false);
+
+ // TODO(armansito): Return success or failure here based on characteristic
+ // read permission.
+ callback.Run(true);
}
void FakeBluetoothGattCharacteristicClient::Properties::GetAll() {
@@ -116,8 +119,8 @@ FakeBluetoothGattCharacteristicClient::GetProperties(
return heart_rate_measurement_properties_.get();
}
if (object_path.value() == body_sensor_location_path_) {
- DCHECK(heart_rate_measurement_properties_.get());
- return heart_rate_measurement_properties_.get();
+ DCHECK(body_sensor_location_properties_.get());
+ return body_sensor_location_properties_.get();
}
if (object_path.value() == heart_rate_control_point_path_) {
DCHECK(heart_rate_control_point_properties_.get());
@@ -226,6 +229,21 @@ void FakeBluetoothGattCharacteristicClient::HideHeartRateCharacteristics() {
heart_rate_visible_ = false;
}
+dbus::ObjectPath
+FakeBluetoothGattCharacteristicClient::GetHeartRateMeasurementPath() const {
+ return dbus::ObjectPath(heart_rate_measurement_path_);
+}
+
+dbus::ObjectPath
+FakeBluetoothGattCharacteristicClient::GetBodySensorLocationPath() const {
+ return dbus::ObjectPath(body_sensor_location_path_);
+}
+
+dbus::ObjectPath
+FakeBluetoothGattCharacteristicClient::GetHeartRateControlPointPath() const {
+ return dbus::ObjectPath(heart_rate_control_point_path_);
+}
+
void FakeBluetoothGattCharacteristicClient::OnPropertyChanged(
const dbus::ObjectPath& object_path,
const std::string& property_name) {
diff --git a/chromeos/dbus/fake_bluetooth_gatt_characteristic_client.h b/chromeos/dbus/fake_bluetooth_gatt_characteristic_client.h
index 69eb23d..bd3d126 100644
--- a/chromeos/dbus/fake_bluetooth_gatt_characteristic_client.h
+++ b/chromeos/dbus/fake_bluetooth_gatt_characteristic_client.h
@@ -56,6 +56,16 @@ class CHROMEOS_EXPORT FakeBluetoothGattCharacteristicClient
void ExposeHeartRateCharacteristics(const dbus::ObjectPath& service_path);
void HideHeartRateCharacteristics();
+ // Returns whether or not the heart rate characteristics are visible and
+ // performs the appropriate assertions.
+ bool IsHeartRateVisible() const;
+
+ // Returns the current object paths of exposed characteristics. If the
+ // characteristic is not visible, returns an invalid empty path.
+ dbus::ObjectPath GetHeartRateMeasurementPath() const;
+ dbus::ObjectPath GetBodySensorLocationPath() const;
+ dbus::ObjectPath GetHeartRateControlPointPath() const;
+
// Object path components and UUIDs of GATT characteristics.
// Heart Rate Service:
static const char kHeartRateMeasurementPathComponent[];
@@ -83,10 +93,6 @@ class CHROMEOS_EXPORT FakeBluetoothGattCharacteristicClient
// is a random value within a reasonable range.
std::vector<uint8> GetHeartRateMeasurementValue();
- // Returns whether or not the heart rate characteristics are visible and
- // performs the appropriate assertions.
- bool IsHeartRateVisible() const;
-
// If true, characteristics of the Heart Rate Service are visible. Use
// IsHeartRateVisible() to check the value.
bool heart_rate_visible_;
diff --git a/chromeos/dbus/fake_bluetooth_gatt_service_client.cc b/chromeos/dbus/fake_bluetooth_gatt_service_client.cc
index 506ee05..ae2b0b4 100644
--- a/chromeos/dbus/fake_bluetooth_gatt_service_client.cc
+++ b/chromeos/dbus/fake_bluetooth_gatt_service_client.cc
@@ -5,12 +5,20 @@
#include "chromeos/dbus/fake_bluetooth_gatt_service_client.h"
#include "base/bind.h"
+#include "base/message_loop/message_loop.h"
+#include "base/time/time.h"
#include "chromeos/dbus/dbus_thread_manager.h"
#include "chromeos/dbus/fake_bluetooth_gatt_characteristic_client.h"
#include "third_party/cros_system_api/dbus/service_constants.h"
namespace chromeos {
+namespace {
+
+const int kExposeCharacteristicsDelayIntervalMs = 100;
+
+} // namespace
+
// static
const char FakeBluetoothGattServiceClient::kHeartRateServicePathComponent[] =
"service0000";
@@ -46,7 +54,8 @@ void FakeBluetoothGattServiceClient::Properties::Set(
callback.Run(false);
}
-FakeBluetoothGattServiceClient::FakeBluetoothGattServiceClient() {
+FakeBluetoothGattServiceClient::FakeBluetoothGattServiceClient()
+ : weak_ptr_factory_(this) {
}
FakeBluetoothGattServiceClient::~FakeBluetoothGattServiceClient() {
@@ -82,7 +91,7 @@ FakeBluetoothGattServiceClient::GetProperties(
void FakeBluetoothGattServiceClient::ExposeHeartRateService(
const dbus::ObjectPath& device_path) {
- if (heart_rate_service_properties_.get()) {
+ if (IsHeartRateVisible()) {
DCHECK(!heart_rate_service_path_.empty());
VLOG(1) << "Fake Heart Rate Service already exposed.";
return;
@@ -100,15 +109,17 @@ void FakeBluetoothGattServiceClient::ExposeHeartRateService(
NotifyServiceAdded(dbus::ObjectPath(heart_rate_service_path_));
- FakeBluetoothGattCharacteristicClient* char_client =
- static_cast<FakeBluetoothGattCharacteristicClient*>(
- DBusThreadManager::Get()->GetBluetoothGattCharacteristicClient());
- char_client->ExposeHeartRateCharacteristics(
- dbus::ObjectPath(heart_rate_service_path_));
+ base::MessageLoop::current()->PostDelayedTask(
+ FROM_HERE,
+ base::Bind(
+ &FakeBluetoothGattServiceClient::ExposeHeartRateCharacteristics,
+ weak_ptr_factory_.GetWeakPtr()),
+ base::TimeDelta::FromMilliseconds(
+ kExposeCharacteristicsDelayIntervalMs));
}
void FakeBluetoothGattServiceClient::HideHeartRateService() {
- if (!heart_rate_service_properties_.get()) {
+ if (!IsHeartRateVisible()) {
DCHECK(heart_rate_service_path_.empty());
VLOG(1) << "Fake Heart Rate Service already hidden.";
return;
@@ -127,6 +138,15 @@ void FakeBluetoothGattServiceClient::HideHeartRateService() {
heart_rate_service_path_.clear();
}
+bool FakeBluetoothGattServiceClient::IsHeartRateVisible() const {
+ return !!heart_rate_service_properties_.get();
+}
+
+dbus::ObjectPath
+FakeBluetoothGattServiceClient::GetHeartRateServicePath() const {
+ return dbus::ObjectPath(heart_rate_service_path_);
+}
+
void FakeBluetoothGattServiceClient::OnPropertyChanged(
const dbus::ObjectPath& object_path,
const std::string& property_name) {
@@ -152,4 +172,16 @@ void FakeBluetoothGattServiceClient::NotifyServiceRemoved(
GattServiceRemoved(object_path));
}
+void FakeBluetoothGattServiceClient::ExposeHeartRateCharacteristics() {
+ if (!IsHeartRateVisible()) {
+ VLOG(2) << "Heart Rate service not visible. Not exposing characteristics.";
+ return;
+ }
+ FakeBluetoothGattCharacteristicClient* char_client =
+ static_cast<FakeBluetoothGattCharacteristicClient*>(
+ DBusThreadManager::Get()->GetBluetoothGattCharacteristicClient());
+ char_client->ExposeHeartRateCharacteristics(
+ dbus::ObjectPath(heart_rate_service_path_));
+}
+
} // namespace chromeos
diff --git a/chromeos/dbus/fake_bluetooth_gatt_service_client.h b/chromeos/dbus/fake_bluetooth_gatt_service_client.h
index 35b05d4..59bcdb5 100644
--- a/chromeos/dbus/fake_bluetooth_gatt_service_client.h
+++ b/chromeos/dbus/fake_bluetooth_gatt_service_client.h
@@ -9,6 +9,7 @@
#include <vector>
#include "base/memory/scoped_ptr.h"
+#include "base/memory/weak_ptr.h"
#include "base/observer_list.h"
#include "chromeos/chromeos_export.h"
#include "chromeos/dbus/bluetooth_gatt_service_client.h"
@@ -54,6 +55,13 @@ class CHROMEOS_EXPORT FakeBluetoothGattServiceClient
void ExposeHeartRateService(const dbus::ObjectPath& device_path);
void HideHeartRateService();
+ // Returns whether or not the Heart Rate Service is visible.
+ bool IsHeartRateVisible() const;
+
+ // Returns the current object path of the visible Heart Rate service. If the
+ // service is not visible, returns an invalid empty path.
+ dbus::ObjectPath GetHeartRateServicePath() const;
+
// Final object path components and the corresponding UUIDs of the GATT
// services that we emulate. Service paths are hierarchical to Bluetooth
// device paths, so if the path component is "service0000", and the device
@@ -71,6 +79,12 @@ class CHROMEOS_EXPORT FakeBluetoothGattServiceClient
void NotifyServiceAdded(const dbus::ObjectPath& object_path);
void NotifyServiceRemoved(const dbus::ObjectPath& object_path);
+ // Tells FakeBluetoothGattCharacteristicClient to expose GATT characteristics.
+ // This is scheduled from ExposeHeartRateService to simulate asynchronous
+ // retrieval of characteristics. If the Heart Rate Service is hidden at the
+ // time this method is called, then it does nothing.
+ void ExposeHeartRateCharacteristics();
+
// Static properties we return. As long as a service is exposed, this will be
// non-null. Otherwise it will be null.
scoped_ptr<Properties> heart_rate_service_properties_;
@@ -79,6 +93,12 @@ class CHROMEOS_EXPORT FakeBluetoothGattServiceClient
// List of observers interested in event notifications from us.
ObserverList<Observer> observers_;
+ // Weak pointer factory for generating 'this' pointers that might live longer
+ // than we do.
+ // Note: This should remain the last member so it'll be destroyed and
+ // invalidate its weak pointers before any other members are destroyed.
+ base::WeakPtrFactory<FakeBluetoothGattServiceClient> weak_ptr_factory_;
+
DISALLOW_COPY_AND_ASSIGN(FakeBluetoothGattServiceClient);
};