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