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 CHROMEOS_DBUS_FAKE_BLUETOOTH_GATT_SERVICE_CLIENT_H_ | 5 #ifndef CHROMEOS_DBUS_FAKE_BLUETOOTH_GATT_SERVICE_CLIENT_H_ |
6 #define CHROMEOS_DBUS_FAKE_BLUETOOTH_GATT_SERVICE_CLIENT_H_ | 6 #define CHROMEOS_DBUS_FAKE_BLUETOOTH_GATT_SERVICE_CLIENT_H_ |
7 | 7 |
8 #include <string> | 8 #include <string> |
9 #include <vector> | 9 #include <vector> |
10 | 10 |
11 #include "base/memory/scoped_ptr.h" | 11 #include "base/memory/scoped_ptr.h" |
| 12 #include "base/memory/weak_ptr.h" |
12 #include "base/observer_list.h" | 13 #include "base/observer_list.h" |
13 #include "chromeos/chromeos_export.h" | 14 #include "chromeos/chromeos_export.h" |
14 #include "chromeos/dbus/bluetooth_gatt_service_client.h" | 15 #include "chromeos/dbus/bluetooth_gatt_service_client.h" |
15 #include "dbus/object_path.h" | 16 #include "dbus/object_path.h" |
16 #include "dbus/property.h" | 17 #include "dbus/property.h" |
17 | 18 |
18 namespace chromeos { | 19 namespace chromeos { |
19 | 20 |
20 // FakeBluetoothGattServiceClient simulates the behavior of the Bluetooth Daemon | 21 // FakeBluetoothGattServiceClient simulates the behavior of the Bluetooth Daemon |
21 // GATT service objects and is used in test cases in place of a mock and on the | 22 // GATT service objects and is used in test cases in place of a mock and on the |
(...skipping 25 matching lines...) Expand all Loading... |
47 virtual std::vector<dbus::ObjectPath> GetServices() OVERRIDE; | 48 virtual std::vector<dbus::ObjectPath> GetServices() OVERRIDE; |
48 virtual Properties* GetProperties(const dbus::ObjectPath& object_path) | 49 virtual Properties* GetProperties(const dbus::ObjectPath& object_path) |
49 OVERRIDE; | 50 OVERRIDE; |
50 | 51 |
51 // Makes a service visible for device with object path |device_path|. Note | 52 // Makes a service visible for device with object path |device_path|. Note |
52 // that only one instance of a specific service is simulated at a time. Hence, | 53 // that only one instance of a specific service is simulated at a time. Hence, |
53 // this method will fail, if the service is already visible. | 54 // this method will fail, if the service is already visible. |
54 void ExposeHeartRateService(const dbus::ObjectPath& device_path); | 55 void ExposeHeartRateService(const dbus::ObjectPath& device_path); |
55 void HideHeartRateService(); | 56 void HideHeartRateService(); |
56 | 57 |
| 58 // Returns whether or not the Heart Rate Service is visible. |
| 59 bool IsHeartRateVisible() const; |
| 60 |
| 61 // Returns the current object path of the visible Heart Rate service. If the |
| 62 // service is not visible, returns an invalid empty path. |
| 63 dbus::ObjectPath GetHeartRateServicePath() const; |
| 64 |
57 // Final object path components and the corresponding UUIDs of the GATT | 65 // Final object path components and the corresponding UUIDs of the GATT |
58 // services that we emulate. Service paths are hierarchical to Bluetooth | 66 // services that we emulate. Service paths are hierarchical to Bluetooth |
59 // device paths, so if the path component is "service0000", and the device | 67 // device paths, so if the path component is "service0000", and the device |
60 // path is "/org/foo/device0", the service path is | 68 // path is "/org/foo/device0", the service path is |
61 // "/org/foo/device0/service0000". | 69 // "/org/foo/device0/service0000". |
62 static const char kHeartRateServicePathComponent[]; | 70 static const char kHeartRateServicePathComponent[]; |
63 static const char kHeartRateServiceUUID[]; | 71 static const char kHeartRateServiceUUID[]; |
64 | 72 |
65 private: | 73 private: |
66 // Property callback passed when we create Properties structures. | 74 // Property callback passed when we create Properties structures. |
67 void OnPropertyChanged(const dbus::ObjectPath& object_path, | 75 void OnPropertyChanged(const dbus::ObjectPath& object_path, |
68 const std::string& property_name); | 76 const std::string& property_name); |
69 | 77 |
70 // Notifies observers. | 78 // Notifies observers. |
71 void NotifyServiceAdded(const dbus::ObjectPath& object_path); | 79 void NotifyServiceAdded(const dbus::ObjectPath& object_path); |
72 void NotifyServiceRemoved(const dbus::ObjectPath& object_path); | 80 void NotifyServiceRemoved(const dbus::ObjectPath& object_path); |
73 | 81 |
| 82 // Tells FakeBluetoothGattCharacteristicClient to expose GATT characteristics. |
| 83 // This is scheduled from ExposeHeartRateService to simulate asynchronous |
| 84 // retrieval of characteristics. If the Heart Rate Service is hidden at the |
| 85 // time this method is called, then it does nothing. |
| 86 void ExposeHeartRateCharacteristics(); |
| 87 |
74 // Static properties we return. As long as a service is exposed, this will be | 88 // Static properties we return. As long as a service is exposed, this will be |
75 // non-null. Otherwise it will be null. | 89 // non-null. Otherwise it will be null. |
76 scoped_ptr<Properties> heart_rate_service_properties_; | 90 scoped_ptr<Properties> heart_rate_service_properties_; |
77 std::string heart_rate_service_path_; | 91 std::string heart_rate_service_path_; |
78 | 92 |
79 // List of observers interested in event notifications from us. | 93 // List of observers interested in event notifications from us. |
80 ObserverList<Observer> observers_; | 94 ObserverList<Observer> observers_; |
81 | 95 |
| 96 // Weak pointer factory for generating 'this' pointers that might live longer |
| 97 // than we do. |
| 98 // Note: This should remain the last member so it'll be destroyed and |
| 99 // invalidate its weak pointers before any other members are destroyed. |
| 100 base::WeakPtrFactory<FakeBluetoothGattServiceClient> weak_ptr_factory_; |
| 101 |
82 DISALLOW_COPY_AND_ASSIGN(FakeBluetoothGattServiceClient); | 102 DISALLOW_COPY_AND_ASSIGN(FakeBluetoothGattServiceClient); |
83 }; | 103 }; |
84 | 104 |
85 } // namespace chromeos | 105 } // namespace chromeos |
86 | 106 |
87 #endif // CHROMEOS_DBUS_FAKE_BLUETOOTH_GATT_SERVICE_CLIENT_H_ | 107 #endif // CHROMEOS_DBUS_FAKE_BLUETOOTH_GATT_SERVICE_CLIENT_H_ |
OLD | NEW |