OLD | NEW |
(Empty) | |
| 1 // Copyright 2014 The Chromium Authors. All rights reserved. |
| 2 // Use of this source code is governed by a BSD-style license that can be |
| 3 // found in the LICENSE file. |
| 4 |
| 5 #ifndef CHROMEOS_DBUS_FAKE_BLUETOOTH_GATT_CHARACTERISTIC_CLIENT_H_ |
| 6 #define CHROMEOS_DBUS_FAKE_BLUETOOTH_GATT_CHARACTERISTIC_CLIENT_H_ |
| 7 |
| 8 #include <string> |
| 9 #include <vector> |
| 10 |
| 11 #include "base/basictypes.h" |
| 12 #include "base/memory/scoped_ptr.h" |
| 13 #include "base/memory/weak_ptr.h" |
| 14 #include "base/observer_list.h" |
| 15 #include "chromeos/chromeos_export.h" |
| 16 #include "chromeos/dbus/bluetooth_gatt_characteristic_client.h" |
| 17 #include "dbus/object_path.h" |
| 18 #include "dbus/property.h" |
| 19 |
| 20 namespace chromeos { |
| 21 |
| 22 // FakeBluetoothGattCharacteristicClient simulates the behavior of the |
| 23 // Bluetooth Daemon GATT characteristic objects and is used in test cases in |
| 24 // place of a mock and on the Linux desktop. |
| 25 class CHROMEOS_EXPORT FakeBluetoothGattCharacteristicClient |
| 26 : public BluetoothGattCharacteristicClient { |
| 27 public: |
| 28 struct Properties : public BluetoothGattCharacteristicClient::Properties { |
| 29 explicit Properties(const PropertyChangedCallback& callback); |
| 30 virtual ~Properties(); |
| 31 |
| 32 // dbus::PropertySet override |
| 33 virtual void Get(dbus::PropertyBase* property, |
| 34 dbus::PropertySet::GetCallback callback) OVERRIDE; |
| 35 virtual void GetAll() OVERRIDE; |
| 36 virtual void Set(dbus::PropertyBase* property, |
| 37 dbus::PropertySet::SetCallback callback) OVERRIDE; |
| 38 }; |
| 39 |
| 40 FakeBluetoothGattCharacteristicClient(); |
| 41 virtual ~FakeBluetoothGattCharacteristicClient(); |
| 42 |
| 43 // DBusClient override. |
| 44 virtual void Init(dbus::Bus* bus) OVERRIDE; |
| 45 |
| 46 // BluetoothGattCharacteristicClient overrides. |
| 47 virtual void AddObserver(Observer* observer) OVERRIDE; |
| 48 virtual void RemoveObserver(Observer* observer) OVERRIDE; |
| 49 virtual std::vector<dbus::ObjectPath> GetCharacteristics() OVERRIDE; |
| 50 virtual Properties* GetProperties(const dbus::ObjectPath& object_path) |
| 51 OVERRIDE; |
| 52 |
| 53 // Makes the group of characteristics belonging to a particular GATT based |
| 54 // profile available under the GATT service with object path |service_path|. |
| 55 // Characteristic paths are hierarchical to service paths. |
| 56 void ExposeHeartRateCharacteristics(const dbus::ObjectPath& service_path); |
| 57 void HideHeartRateCharacteristics(); |
| 58 |
| 59 // Object path components and UUIDs of GATT characteristics. |
| 60 // Heart Rate Service: |
| 61 static const char kHeartRateMeasurementPathComponent[]; |
| 62 static const char kHeartRateMeasurementUUID[]; |
| 63 static const char kBodySensorLocationPathComponent[]; |
| 64 static const char kBodySensorLocationUUID[]; |
| 65 static const char kHeartRateControlPointPathComponent[]; |
| 66 static const char kHeartRateControlPointUUID[]; |
| 67 |
| 68 private: |
| 69 // Property callback passed when we create Properties structures. |
| 70 void OnPropertyChanged(const dbus::ObjectPath& object_path, |
| 71 const std::string& property_name); |
| 72 |
| 73 // Notifies observers. |
| 74 void NotifyCharacteristicAdded(const dbus::ObjectPath& object_path); |
| 75 void NotifyCharacteristicRemoved(const dbus::ObjectPath& object_path); |
| 76 |
| 77 // Schedules a heart rate measurement value change, if the heart rate |
| 78 // characteristics are visible. |
| 79 void ScheduleHeartRateMeasurementValueChange(); |
| 80 |
| 81 // Returns a random Heart Rate Measurement value. All the fields of the value |
| 82 // are populated according to the the fake behavior. The measurement value |
| 83 // is a random value within a reasonable range. |
| 84 std::vector<uint8> GetHeartRateMeasurementValue(); |
| 85 |
| 86 // Returns whether or not the heart rate characteristics are visible and |
| 87 // performs the appropriate assertions. |
| 88 bool IsHeartRateVisible() const; |
| 89 |
| 90 // If true, characteristics of the Heart Rate Service are visible. Use |
| 91 // IsHeartRateVisible() to check the value. |
| 92 bool heart_rate_visible_; |
| 93 |
| 94 // Total calories burned, used for the Heart Rate Measurement characteristic. |
| 95 uint16 calories_burned_; |
| 96 |
| 97 // Static properties returned for simulated characteristics for the Heart |
| 98 // Rate Service. These pointers are not NULL only if the characteristics are |
| 99 // actually exposed. |
| 100 scoped_ptr<Properties> heart_rate_measurement_properties_; |
| 101 scoped_ptr<Properties> body_sensor_location_properties_; |
| 102 scoped_ptr<Properties> heart_rate_control_point_properties_; |
| 103 |
| 104 // Object paths of the exposed characteristics. If a characteristic is not |
| 105 // exposed, these will be empty. |
| 106 std::string heart_rate_measurement_path_; |
| 107 std::string body_sensor_location_path_; |
| 108 std::string heart_rate_control_point_path_; |
| 109 |
| 110 // List of observers interested in event notifications from us. |
| 111 ObserverList<Observer> observers_; |
| 112 |
| 113 // Weak pointer factory for generating 'this' pointers that might live longer |
| 114 // than we do. |
| 115 // Note: This should remain the last member so it'll be destroyed and |
| 116 // invalidate its weak pointers before any other members are destroyed. |
| 117 base::WeakPtrFactory<FakeBluetoothGattCharacteristicClient> |
| 118 weak_ptr_factory_; |
| 119 |
| 120 DISALLOW_COPY_AND_ASSIGN(FakeBluetoothGattCharacteristicClient); |
| 121 }; |
| 122 |
| 123 } // namespace chromeos |
| 124 |
| 125 #endif // CHROMEOS_DBUS_FAKE_BLUETOOTH_GATT_CHARACTERISTIC_CLIENT_H_ |
OLD | NEW |