| OLD | NEW |
| 1 // Copyright 2014 The Chromium Authors. All rights reserved. | 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 | 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_DBUS_FAKE_BLUETOOTH_GATT_CHARACTERISTIC_SERVICE_PROVIDE
R_H_ | 5 #ifndef DEVICE_BLUETOOTH_DBUS_FAKE_BLUETOOTH_GATT_CHARACTERISTIC_SERVICE_PROVIDE
R_H_ |
| 6 #define DEVICE_BLUETOOTH_DBUS_FAKE_BLUETOOTH_GATT_CHARACTERISTIC_SERVICE_PROVIDE
R_H_ | 6 #define DEVICE_BLUETOOTH_DBUS_FAKE_BLUETOOTH_GATT_CHARACTERISTIC_SERVICE_PROVIDE
R_H_ |
| 7 | 7 |
| 8 #include <stdint.h> | 8 #include <stdint.h> |
| 9 #include <memory> |
| 9 #include <string> | 10 #include <string> |
| 10 #include <vector> | 11 #include <vector> |
| 11 | 12 |
| 12 #include "base/callback_forward.h" | 13 #include "base/callback_forward.h" |
| 13 #include "base/macros.h" | 14 #include "base/macros.h" |
| 14 #include "dbus/object_path.h" | 15 #include "dbus/object_path.h" |
| 15 #include "device/bluetooth/bluetooth_export.h" | 16 #include "device/bluetooth/bluetooth_export.h" |
| 16 #include "device/bluetooth/bluetooth_local_gatt_service.h" | 17 #include "device/bluetooth/bluetooth_local_gatt_service.h" |
| 17 #include "device/bluetooth/bluez/bluetooth_local_gatt_service_bluez.h" | 18 #include "device/bluetooth/dbus/bluetooth_gatt_attribute_value_delegate.h" |
| 18 #include "device/bluetooth/dbus/bluetooth_gatt_characteristic_service_provider.h
" | 19 #include "device/bluetooth/dbus/bluetooth_gatt_characteristic_service_provider.h
" |
| 19 | 20 |
| 20 namespace bluez { | 21 namespace bluez { |
| 21 | 22 |
| 22 // FakeBluetoothGattCharacteristicServiceProvider simulates behavior of a local | 23 // FakeBluetoothGattCharacteristicServiceProvider simulates behavior of a local |
| 23 // GATT characteristic object and is used both in test cases in place of a mock | 24 // GATT characteristic object and is used both in test cases in place of a mock |
| 24 // and on the Linux desktop. | 25 // and on the Linux desktop. |
| 25 class DEVICE_BLUETOOTH_EXPORT FakeBluetoothGattCharacteristicServiceProvider | 26 class DEVICE_BLUETOOTH_EXPORT FakeBluetoothGattCharacteristicServiceProvider |
| 26 : public BluetoothGattCharacteristicServiceProvider { | 27 : public BluetoothGattCharacteristicServiceProvider { |
| 27 public: | 28 public: |
| 28 FakeBluetoothGattCharacteristicServiceProvider( | 29 FakeBluetoothGattCharacteristicServiceProvider( |
| 29 const dbus::ObjectPath& object_path, | 30 const dbus::ObjectPath& object_path, |
| 30 std::unique_ptr<BluetoothGattAttributeValueDelegate> delegate, | 31 std::unique_ptr<BluetoothGattAttributeValueDelegate> delegate, |
| 31 const std::string& uuid, | 32 const std::string& uuid, |
| 32 const std::vector<std::string>& flags, | 33 const std::vector<std::string>& flags, |
| 33 const dbus::ObjectPath& service_path); | 34 const dbus::ObjectPath& service_path); |
| 34 ~FakeBluetoothGattCharacteristicServiceProvider() override; | 35 ~FakeBluetoothGattCharacteristicServiceProvider() override; |
| 35 | 36 |
| 36 // BluetoothGattCharacteristicServiceProvider override. | 37 // BluetoothGattCharacteristicServiceProvider override. |
| 37 void SendValueChanged(const std::vector<uint8_t>& value) override; | 38 void SendValueChanged(const dbus::ObjectPath& device_path, |
| 39 const std::vector<uint8_t>& value, |
| 40 bool indicate) override; |
| 38 | 41 |
| 39 // Methods to simulate value get/set requests issued from a remote device. The | 42 // Methods to simulate value get/set requests issued from a remote device. The |
| 40 // methods do nothing, if the associated service was not registered with the | 43 // methods do nothing, if the associated service was not registered with the |
| 41 // GATT manager. | 44 // GATT manager. |
| 42 void GetValue( | 45 void GetValue( |
| 43 const dbus::ObjectPath& device_path, | 46 const dbus::ObjectPath& device_path, |
| 44 const device::BluetoothLocalGattService::Delegate::ValueCallback& | 47 const device::BluetoothLocalGattService::Delegate::ValueCallback& |
| 45 callback, | 48 callback, |
| 46 const device::BluetoothLocalGattService::Delegate::ErrorCallback& | 49 const device::BluetoothLocalGattService::Delegate::ErrorCallback& |
| 47 error_callback); | 50 error_callback); |
| 48 void SetValue( | 51 void SetValue( |
| 49 const dbus::ObjectPath& device_path, | 52 const dbus::ObjectPath& device_path, |
| 50 const std::vector<uint8_t>& value, | 53 const std::vector<uint8_t>& value, |
| 51 const base::Closure& callback, | 54 const base::Closure& callback, |
| 52 const device::BluetoothLocalGattService::Delegate::ErrorCallback& | 55 const device::BluetoothLocalGattService::Delegate::ErrorCallback& |
| 53 error_callback); | 56 error_callback); |
| 54 | 57 |
| 55 // Method to simulate starting and stopping notifications. | 58 // Method to simulate starting and stopping notifications. |
| 56 bool NotificationsChange(bool start); | 59 bool NotificationsChange(bool start); |
| 57 | 60 |
| 58 const dbus::ObjectPath& object_path() const override; | 61 const dbus::ObjectPath& object_path() const override; |
| 59 const std::string& uuid() const { return uuid_; } | 62 const std::string& uuid() const { return uuid_; } |
| 60 const dbus::ObjectPath& service_path() const { return service_path_; } | 63 const dbus::ObjectPath& service_path() const { return service_path_; } |
| 61 const std::vector<uint8_t>& sent_value() const { return sent_value_; } | 64 const dbus::ObjectPath& last_device_path() const { return last_device_path_; } |
| 65 const std::vector<uint8_t>& last_value() const { return last_value_; } |
| 66 const bool& last_indicate_flag() const { return last_indicate_flag_; } |
| 62 | 67 |
| 63 private: | 68 private: |
| 64 // D-Bus object path of the fake GATT characteristic. | 69 // D-Bus object path of the fake GATT characteristic. |
| 65 dbus::ObjectPath object_path_; | 70 dbus::ObjectPath object_path_; |
| 66 | 71 |
| 67 // 128-bit GATT characteristic UUID. | 72 // 128-bit GATT characteristic UUID. |
| 68 const std::string uuid_; | 73 const std::string uuid_; |
| 69 | 74 |
| 70 // Properties for this characteristic. | 75 // Properties for this characteristic. |
| 71 const std::vector<std::string> flags_; | 76 const std::vector<std::string> flags_; |
| 72 | 77 |
| 73 // Object path of the service that this characteristic belongs to. | 78 // Object path of the service that this characteristic belongs to. |
| 74 const dbus::ObjectPath service_path_; | 79 const dbus::ObjectPath service_path_; |
| 75 | 80 |
| 76 // Value that was sent to the fake remote device. | 81 // Last device that sent a value. |
| 77 std::vector<uint8_t> sent_value_; | 82 dbus::ObjectPath last_device_path_; |
| 83 // Last value that was sent to the fake remote device. |
| 84 std::vector<uint8_t> last_value_; |
| 85 // Last value of the indicate flag used when sending a notification. |
| 86 bool last_indicate_flag_; |
| 78 | 87 |
| 79 // The delegate that method calls are passed on to. | 88 // The delegate that method calls are passed on to. |
| 80 std::unique_ptr<BluetoothGattAttributeValueDelegate> delegate_; | 89 std::unique_ptr<BluetoothGattAttributeValueDelegate> delegate_; |
| 81 | 90 |
| 82 DISALLOW_COPY_AND_ASSIGN(FakeBluetoothGattCharacteristicServiceProvider); | 91 DISALLOW_COPY_AND_ASSIGN(FakeBluetoothGattCharacteristicServiceProvider); |
| 83 }; | 92 }; |
| 84 | 93 |
| 85 } // namespace bluez | 94 } // namespace bluez |
| 86 | 95 |
| 87 #endif // DEVICE_BLUETOOTH_DBUS_FAKE_BLUETOOTH_GATT_CHARACTERISTIC_SERVICE_PROV
IDER_H_ | 96 #endif // DEVICE_BLUETOOTH_DBUS_FAKE_BLUETOOTH_GATT_CHARACTERISTIC_SERVICE_PROV
IDER_H_ |
| OLD | NEW |