| 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: |
| 29 // Originally defined in bluetooth_test.h. Redefining here because we don't |
| 30 // want to use test includes in this code. This code is compiled into |
| 31 // non-test code also at the moment. |
| 32 using NotificationType = std::tuple<std::string, std::vector<uint8_t>, bool>; |
| 33 |
| 28 FakeBluetoothGattCharacteristicServiceProvider( | 34 FakeBluetoothGattCharacteristicServiceProvider( |
| 29 const dbus::ObjectPath& object_path, | 35 const dbus::ObjectPath& object_path, |
| 30 std::unique_ptr<BluetoothGattAttributeValueDelegate> delegate, | 36 std::unique_ptr<BluetoothGattAttributeValueDelegate> delegate, |
| 31 const std::string& uuid, | 37 const std::string& uuid, |
| 32 const std::vector<std::string>& flags, | 38 const std::vector<std::string>& flags, |
| 33 const dbus::ObjectPath& service_path); | 39 const dbus::ObjectPath& service_path); |
| 34 ~FakeBluetoothGattCharacteristicServiceProvider() override; | 40 ~FakeBluetoothGattCharacteristicServiceProvider() override; |
| 35 | 41 |
| 36 // BluetoothGattCharacteristicServiceProvider override. | 42 // BluetoothGattCharacteristicServiceProvider override. |
| 37 void SendValueChanged(const std::vector<uint8_t>& value) override; | 43 void SendValueChanged(const dbus::ObjectPath& device_path, |
| 44 const std::vector<uint8_t>& value, |
| 45 bool indicate) override; |
| 38 | 46 |
| 39 // Methods to simulate value get/set requests issued from a remote device. The | 47 // 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 | 48 // methods do nothing, if the associated service was not registered with the |
| 41 // GATT manager. | 49 // GATT manager. |
| 42 void GetValue( | 50 void GetValue( |
| 43 const dbus::ObjectPath& device_path, | 51 const dbus::ObjectPath& device_path, |
| 44 const device::BluetoothLocalGattService::Delegate::ValueCallback& | 52 const device::BluetoothLocalGattService::Delegate::ValueCallback& |
| 45 callback, | 53 callback, |
| 46 const device::BluetoothLocalGattService::Delegate::ErrorCallback& | 54 const device::BluetoothLocalGattService::Delegate::ErrorCallback& |
| 47 error_callback); | 55 error_callback); |
| 48 void SetValue( | 56 void SetValue( |
| 49 const dbus::ObjectPath& device_path, | 57 const dbus::ObjectPath& device_path, |
| 50 const std::vector<uint8_t>& value, | 58 const std::vector<uint8_t>& value, |
| 51 const base::Closure& callback, | 59 const base::Closure& callback, |
| 52 const device::BluetoothLocalGattService::Delegate::ErrorCallback& | 60 const device::BluetoothLocalGattService::Delegate::ErrorCallback& |
| 53 error_callback); | 61 error_callback); |
| 54 | 62 |
| 55 // Method to simulate starting and stopping notifications. | 63 // Method to simulate starting and stopping notifications. |
| 56 bool NotificationsChange(bool start); | 64 bool NotificationsChange(bool start); |
| 57 | 65 |
| 58 const dbus::ObjectPath& object_path() const override; | 66 const dbus::ObjectPath& object_path() const override; |
| 59 const std::string& uuid() const { return uuid_; } | 67 const std::string& uuid() const { return uuid_; } |
| 60 const dbus::ObjectPath& service_path() const { return service_path_; } | 68 const dbus::ObjectPath& service_path() const { return service_path_; } |
| 61 const std::vector<uint8_t>& sent_value() const { return sent_value_; } | 69 const NotificationType& sent_value() const { return sent_value_; } |
| 62 | 70 |
| 63 private: | 71 private: |
| 64 // D-Bus object path of the fake GATT characteristic. | 72 // D-Bus object path of the fake GATT characteristic. |
| 65 dbus::ObjectPath object_path_; | 73 dbus::ObjectPath object_path_; |
| 66 | 74 |
| 67 // 128-bit GATT characteristic UUID. | 75 // 128-bit GATT characteristic UUID. |
| 68 const std::string uuid_; | 76 const std::string uuid_; |
| 69 | 77 |
| 70 // Properties for this characteristic. | 78 // Properties for this characteristic. |
| 71 const std::vector<std::string> flags_; | 79 const std::vector<std::string> flags_; |
| 72 | 80 |
| 73 // Object path of the service that this characteristic belongs to. | 81 // Object path of the service that this characteristic belongs to. |
| 74 const dbus::ObjectPath service_path_; | 82 const dbus::ObjectPath service_path_; |
| 75 | 83 |
| 76 // Value that was sent to the fake remote device. | 84 // Value that was sent to the fake remote device. |
| 77 std::vector<uint8_t> sent_value_; | 85 NotificationType sent_value_; |
| 78 | 86 |
| 79 // The delegate that method calls are passed on to. | 87 // The delegate that method calls are passed on to. |
| 80 std::unique_ptr<BluetoothGattAttributeValueDelegate> delegate_; | 88 std::unique_ptr<BluetoothGattAttributeValueDelegate> delegate_; |
| 81 | 89 |
| 82 DISALLOW_COPY_AND_ASSIGN(FakeBluetoothGattCharacteristicServiceProvider); | 90 DISALLOW_COPY_AND_ASSIGN(FakeBluetoothGattCharacteristicServiceProvider); |
| 83 }; | 91 }; |
| 84 | 92 |
| 85 } // namespace bluez | 93 } // namespace bluez |
| 86 | 94 |
| 87 #endif // DEVICE_BLUETOOTH_DBUS_FAKE_BLUETOOTH_GATT_CHARACTERISTIC_SERVICE_PROV
IDER_H_ | 95 #endif // DEVICE_BLUETOOTH_DBUS_FAKE_BLUETOOTH_GATT_CHARACTERISTIC_SERVICE_PROV
IDER_H_ |
| OLD | NEW |