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_MANAGER_CLIENT_H_ | 5 #ifndef DEVICE_BLUETOOTH_DBUS_FAKE_BLUETOOTH_GATT_MANAGER_CLIENT_H_ |
6 #define DEVICE_BLUETOOTH_DBUS_FAKE_BLUETOOTH_GATT_MANAGER_CLIENT_H_ | 6 #define DEVICE_BLUETOOTH_DBUS_FAKE_BLUETOOTH_GATT_MANAGER_CLIENT_H_ |
7 | 7 |
8 #include <map> | 8 #include <map> |
9 #include <string> | 9 #include <set> |
10 #include <utility> | 10 #include <utility> |
11 | 11 |
12 #include "base/callback.h" | 12 #include "base/callback_forward.h" |
13 #include "base/macros.h" | 13 #include "base/macros.h" |
| 14 #include "dbus/bus.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/dbus/bluetooth_gatt_manager_client.h" | 17 #include "device/bluetooth/dbus/bluetooth_gatt_manager_client.h" |
| 18 #include "device/bluetooth/dbus/fake_bluetooth_gatt_application_service_provider
.h" |
| 19 #include "device/bluetooth/dbus/fake_bluetooth_gatt_characteristic_service_provi
der.h" |
| 20 #include "device/bluetooth/dbus/fake_bluetooth_gatt_descriptor_service_provider.
h" |
| 21 #include "device/bluetooth/dbus/fake_bluetooth_gatt_service_service_provider.h" |
17 | 22 |
18 namespace bluez { | 23 namespace bluez { |
19 | 24 |
| 25 class FakeBluetoothGattApplicationServiceProvider; |
20 class FakeBluetoothGattCharacteristicServiceProvider; | 26 class FakeBluetoothGattCharacteristicServiceProvider; |
21 class FakeBluetoothGattDescriptorServiceProvider; | 27 class FakeBluetoothGattDescriptorServiceProvider; |
22 class FakeBluetoothGattServiceServiceProvider; | 28 class FakeBluetoothGattServiceServiceProvider; |
23 | 29 |
24 // FakeBluetoothGattManagerClient simulates the behavior of the Bluetooth | 30 // FakeBluetoothGattManagerClient simulates the behavior of the Bluetooth |
25 // daemon's GATT manager object and is used both in test cases in place of a | 31 // daemon's GATT manager object and is used both in test cases in place of a |
26 // mock and on the Linux desktop. | 32 // mock and on the Linux desktop. |
27 class DEVICE_BLUETOOTH_EXPORT FakeBluetoothGattManagerClient | 33 class DEVICE_BLUETOOTH_EXPORT FakeBluetoothGattManagerClient |
28 : public BluetoothGattManagerClient { | 34 : public BluetoothGattManagerClient { |
29 public: | 35 public: |
30 FakeBluetoothGattManagerClient(); | 36 FakeBluetoothGattManagerClient(); |
31 ~FakeBluetoothGattManagerClient() override; | 37 ~FakeBluetoothGattManagerClient() override; |
32 | 38 |
33 // DBusClient override. | 39 // DBusClient override. |
34 void Init(dbus::Bus* bus) override; | 40 void Init(dbus::Bus* bus) override; |
35 | 41 |
36 // BluetoothGattManagerClient overrides. | 42 // BluetoothGattManagerClient overrides. |
37 void RegisterService(const dbus::ObjectPath& service_path, | 43 void RegisterApplication(const dbus::ObjectPath& application_path, |
38 const Options& options, | 44 const Options& options, |
39 const base::Closure& callback, | 45 const base::Closure& callback, |
40 const ErrorCallback& error_callback) override; | 46 const ErrorCallback& error_callback) override; |
41 void UnregisterService(const dbus::ObjectPath& service_path, | 47 void UnregisterApplication(const dbus::ObjectPath& application_path, |
42 const base::Closure& callback, | 48 const base::Closure& callback, |
43 const ErrorCallback& error_callback) override; | 49 const ErrorCallback& error_callback) override; |
44 | 50 |
45 // Register, unregister, and retrieve pointers to service, characteristic, and | 51 // Register, unregister, and retrieve pointers to application service |
46 // descriptor service providers. Automatically called from the service | 52 // providers. Automatically called from the application provider constructor |
47 // provider constructor and destructors. | 53 // and destructors. |
| 54 void RegisterApplicationServiceProvider( |
| 55 FakeBluetoothGattApplicationServiceProvider* provider); |
48 void RegisterServiceServiceProvider( | 56 void RegisterServiceServiceProvider( |
49 FakeBluetoothGattServiceServiceProvider* provider); | 57 FakeBluetoothGattServiceServiceProvider* provider); |
50 void RegisterCharacteristicServiceProvider( | 58 void RegisterCharacteristicServiceProvider( |
51 FakeBluetoothGattCharacteristicServiceProvider* provider); | 59 FakeBluetoothGattCharacteristicServiceProvider* provider); |
52 void RegisterDescriptorServiceProvider( | 60 void RegisterDescriptorServiceProvider( |
53 FakeBluetoothGattDescriptorServiceProvider* provider); | 61 FakeBluetoothGattDescriptorServiceProvider* provider); |
54 | 62 |
| 63 void UnregisterApplicationServiceProvider( |
| 64 FakeBluetoothGattApplicationServiceProvider* provider); |
55 void UnregisterServiceServiceProvider( | 65 void UnregisterServiceServiceProvider( |
56 FakeBluetoothGattServiceServiceProvider* provider); | 66 FakeBluetoothGattServiceServiceProvider* provider); |
57 void UnregisterCharacteristicServiceProvider( | 67 void UnregisterCharacteristicServiceProvider( |
58 FakeBluetoothGattCharacteristicServiceProvider* provider); | 68 FakeBluetoothGattCharacteristicServiceProvider* provider); |
59 void UnregisterDescriptorServiceProvider( | 69 void UnregisterDescriptorServiceProvider( |
60 FakeBluetoothGattDescriptorServiceProvider* provider); | 70 FakeBluetoothGattDescriptorServiceProvider* provider); |
61 | 71 |
62 // Return a pointer to the service provider that corresponds to the object | 72 // Return a pointer to the service provider that corresponds to the object |
63 // path |object_path| if it exists. | 73 // path |object_path| if it exists. |
64 FakeBluetoothGattServiceServiceProvider* GetServiceServiceProvider( | 74 FakeBluetoothGattServiceServiceProvider* GetServiceServiceProvider( |
65 const dbus::ObjectPath& object_path) const; | 75 const dbus::ObjectPath& object_path) const; |
66 FakeBluetoothGattCharacteristicServiceProvider* | 76 FakeBluetoothGattCharacteristicServiceProvider* |
67 GetCharacteristicServiceProvider(const dbus::ObjectPath& object_path) const; | 77 GetCharacteristicServiceProvider(const dbus::ObjectPath& object_path) const; |
68 FakeBluetoothGattDescriptorServiceProvider* GetDescriptorServiceProvider( | 78 FakeBluetoothGattDescriptorServiceProvider* GetDescriptorServiceProvider( |
69 const dbus::ObjectPath& object_path) const; | 79 const dbus::ObjectPath& object_path) const; |
70 | 80 |
71 // Returns true, if a GATT service with object path |object_path| was | |
72 // registered with the GATT manager using RegisterService. | |
73 bool IsServiceRegistered(const dbus::ObjectPath& object_path) const; | 81 bool IsServiceRegistered(const dbus::ObjectPath& object_path) const; |
74 | 82 |
75 private: | 83 private: |
76 // Mappings for GATT service, characteristic, and descriptor service | 84 // The boolean indicates whether this application service provider is |
77 // providers. The fake GATT manager stores references to all instances | 85 // registered or not. |
78 // created so that they can be obtained by tests. | 86 using ApplicationProvider = |
79 typedef std::map<dbus::ObjectPath, | 87 std::pair<FakeBluetoothGattApplicationServiceProvider*, bool>; |
80 FakeBluetoothGattCharacteristicServiceProvider*> | |
81 CharacteristicMap; | |
82 typedef std::map<dbus::ObjectPath, | |
83 FakeBluetoothGattDescriptorServiceProvider*> DescriptorMap; | |
84 | 88 |
85 // The mapping for services is from object paths to pairs of boolean and | 89 // Mappings for GATT application, service, characteristic, and descriptor |
86 // service provider pointer, where the boolean denotes whether or not the | 90 // service providers. The fake GATT manager stores references to all |
87 // service is already registered. | 91 // instances created so that they can be obtained by tests. |
88 typedef std::pair<bool, FakeBluetoothGattServiceServiceProvider*> | 92 using ApplicationMap = std::map<dbus::ObjectPath, ApplicationProvider>; |
89 ServiceProvider; | 93 using ServiceMap = |
90 typedef std::map<dbus::ObjectPath, ServiceProvider> ServiceMap; | 94 std::map<dbus::ObjectPath, FakeBluetoothGattServiceServiceProvider*>; |
| 95 using CharacteristicMap = |
| 96 std::map<dbus::ObjectPath, |
| 97 FakeBluetoothGattCharacteristicServiceProvider*>; |
| 98 using DescriptorMap = |
| 99 std::map<dbus::ObjectPath, FakeBluetoothGattDescriptorServiceProvider*>; |
91 | 100 |
| 101 // Return a pointer to the Application provider that corresponds to the object |
| 102 // path |object_path| if it exists. |
| 103 ApplicationProvider* GetApplicationServiceProvider( |
| 104 const dbus::ObjectPath& object_path); |
| 105 |
| 106 // Find attribute providers in this application. |
| 107 std::set<dbus::ObjectPath> FindServiceProviders( |
| 108 dbus::ObjectPath application_path); |
| 109 std::set<dbus::ObjectPath> FindCharacteristicProviders( |
| 110 dbus::ObjectPath application_path); |
| 111 std::set<dbus::ObjectPath> FindDescriptorProviders( |
| 112 dbus::ObjectPath application_path); |
| 113 |
| 114 // Verify that the attribute hierarchy exposed by this application provider |
| 115 // is correct. i.e., all descriptors have a characteristic, which all have a |
| 116 // service and all the attributes are under this application's object path. |
| 117 bool VerifyProviderHierarchy( |
| 118 FakeBluetoothGattApplicationServiceProvider* application_provider); |
| 119 |
| 120 ApplicationMap application_map_; |
92 ServiceMap service_map_; | 121 ServiceMap service_map_; |
93 CharacteristicMap characteristic_map_; | 122 CharacteristicMap characteristic_map_; |
94 DescriptorMap descriptor_map_; | 123 DescriptorMap descriptor_map_; |
95 | 124 |
96 DISALLOW_COPY_AND_ASSIGN(FakeBluetoothGattManagerClient); | 125 DISALLOW_COPY_AND_ASSIGN(FakeBluetoothGattManagerClient); |
97 }; | 126 }; |
98 | 127 |
99 } // namespace bluez | 128 } // namespace bluez |
100 | 129 |
101 #endif // DEVICE_BLUETOOTH_DBUS_FAKE_BLUETOOTH_GATT_MANAGER_CLIENT_H_ | 130 #endif // DEVICE_BLUETOOTH_DBUS_FAKE_BLUETOOTH_GATT_MANAGER_CLIENT_H_ |
OLD | NEW |