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_CHARACTERISTIC_CLIENT_H_ | 5 #ifndef CHROMEOS_DBUS_FAKE_BLUETOOTH_GATT_CHARACTERISTIC_CLIENT_H_ |
6 #define CHROMEOS_DBUS_FAKE_BLUETOOTH_GATT_CHARACTERISTIC_CLIENT_H_ | 6 #define CHROMEOS_DBUS_FAKE_BLUETOOTH_GATT_CHARACTERISTIC_CLIENT_H_ |
7 | 7 |
8 #include <string> | 8 #include <string> |
9 #include <vector> | 9 #include <vector> |
10 | 10 |
(...skipping 55 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
66 // Makes the group of characteristics belonging to a particular GATT based | 66 // Makes the group of characteristics belonging to a particular GATT based |
67 // profile available under the GATT service with object path |service_path|. | 67 // profile available under the GATT service with object path |service_path|. |
68 // Characteristic paths are hierarchical to service paths. | 68 // Characteristic paths are hierarchical to service paths. |
69 void ExposeHeartRateCharacteristics(const dbus::ObjectPath& service_path); | 69 void ExposeHeartRateCharacteristics(const dbus::ObjectPath& service_path); |
70 void HideHeartRateCharacteristics(); | 70 void HideHeartRateCharacteristics(); |
71 | 71 |
72 // Returns whether or not the heart rate characteristics are visible and | 72 // Returns whether or not the heart rate characteristics are visible and |
73 // performs the appropriate assertions. | 73 // performs the appropriate assertions. |
74 bool IsHeartRateVisible() const; | 74 bool IsHeartRateVisible() const; |
75 | 75 |
76 // Makes this characteristic client really slow. | |
77 // So slow, that it is guaranteed that |requests| requests will | |
78 // come in while the client is doing the previous request. | |
79 // Setting |requests| to zero will cause all delayed actions to | |
80 // complete immediately. | |
81 void SetExtraProcessing(size_t requests); | |
82 | |
83 size_t GetExtraProcessing() const; | |
84 | |
85 // Sets whether the client is authorized or not. | |
86 // Defaults to authorized. | |
87 void SetAuthorized(bool authorized) { authorized_ = authorized; } | |
88 | |
89 // Get the current Authorization state. | |
90 bool IsAuthorized() const { return authorized_; } | |
91 | |
92 // Whether the client is Authenticated | |
93 // Defaults to authenticated. | |
94 void SetAuthenticated(bool authenticated) { authenticated_ = authenticated; } | |
95 | |
96 // Get the current Authenticated state. | |
97 bool IsAuthenticated() const { return authenticated_; } | |
98 | |
76 // Returns the current object paths of exposed characteristics. If the | 99 // Returns the current object paths of exposed characteristics. If the |
77 // characteristic is not visible, returns an invalid empty path. | 100 // characteristic is not visible, returns an invalid empty path. |
78 dbus::ObjectPath GetHeartRateMeasurementPath() const; | 101 dbus::ObjectPath GetHeartRateMeasurementPath() const; |
79 dbus::ObjectPath GetBodySensorLocationPath() const; | 102 dbus::ObjectPath GetBodySensorLocationPath() const; |
80 dbus::ObjectPath GetHeartRateControlPointPath() const; | 103 dbus::ObjectPath GetHeartRateControlPointPath() const; |
81 | 104 |
82 // Object path components and UUIDs of GATT characteristics. | 105 // Object path components and UUIDs of GATT characteristics. |
83 // Heart Rate Service: | 106 // Heart Rate Service: |
84 static const char kHeartRateMeasurementPathComponent[]; | 107 static const char kHeartRateMeasurementPathComponent[]; |
85 static const char kHeartRateMeasurementUUID[]; | 108 static const char kHeartRateMeasurementUUID[]; |
(...skipping 17 matching lines...) Expand all Loading... | |
103 | 126 |
104 // Returns a random Heart Rate Measurement value. All the fields of the value | 127 // Returns a random Heart Rate Measurement value. All the fields of the value |
105 // are populated according to the the fake behavior. The measurement value | 128 // are populated according to the the fake behavior. The measurement value |
106 // is a random value within a reasonable range. | 129 // is a random value within a reasonable range. |
107 std::vector<uint8> GetHeartRateMeasurementValue(); | 130 std::vector<uint8> GetHeartRateMeasurementValue(); |
108 | 131 |
109 // If true, characteristics of the Heart Rate Service are visible. Use | 132 // If true, characteristics of the Heart Rate Service are visible. Use |
110 // IsHeartRateVisible() to check the value. | 133 // IsHeartRateVisible() to check the value. |
111 bool heart_rate_visible_; | 134 bool heart_rate_visible_; |
112 | 135 |
136 // If true, the client is authorized to read and write. | |
137 bool authorized_; | |
138 | |
139 // If true, the client is authenticated. | |
140 bool authenticated_; | |
141 | |
113 // Total calories burned, used for the Heart Rate Measurement characteristic. | 142 // Total calories burned, used for the Heart Rate Measurement characteristic. |
114 uint16 calories_burned_; | 143 uint16 calories_burned_; |
115 | 144 |
116 // Static properties returned for simulated characteristics for the Heart | 145 // Static properties returned for simulated characteristics for the Heart |
117 // Rate Service. These pointers are not NULL only if the characteristics are | 146 // Rate Service. These pointers are not NULL only if the characteristics are |
118 // actually exposed. | 147 // actually exposed. |
119 scoped_ptr<Properties> heart_rate_measurement_properties_; | 148 scoped_ptr<Properties> heart_rate_measurement_properties_; |
120 scoped_ptr<Properties> body_sensor_location_properties_; | 149 scoped_ptr<Properties> body_sensor_location_properties_; |
121 scoped_ptr<Properties> heart_rate_control_point_properties_; | 150 scoped_ptr<Properties> heart_rate_control_point_properties_; |
122 | 151 |
123 // Object paths of the exposed characteristics. If a characteristic is not | 152 // Object paths of the exposed characteristics. If a characteristic is not |
124 // exposed, these will be empty. | 153 // exposed, these will be empty. |
125 std::string heart_rate_measurement_path_; | 154 std::string heart_rate_measurement_path_; |
126 std::string heart_rate_measurement_ccc_desc_path_; | 155 std::string heart_rate_measurement_ccc_desc_path_; |
127 std::string body_sensor_location_path_; | 156 std::string body_sensor_location_path_; |
128 std::string heart_rate_control_point_path_; | 157 std::string heart_rate_control_point_path_; |
129 | 158 |
159 // Number of extra requests that need to come in simulating slowness. | |
160 size_t extra_requests_; | |
161 | |
162 // Current countdowns for extra requests for various actions. | |
163 struct DelayedCallback { | |
164 public: | |
165 DelayedCallback(base::Closure callback, size_t delay); | |
166 ~DelayedCallback(); | |
167 | |
168 base::Closure callback_; | |
169 size_t delay_; | |
170 }; | |
171 | |
172 // Map of delayed callbacks. | |
173 std::map<std::string, DelayedCallback*> action_extra_requests_; | |
armansito
2014/10/01 22:25:54
Make sure to delete these in the destructor.
| |
174 | |
130 // List of observers interested in event notifications from us. | 175 // List of observers interested in event notifications from us. |
131 ObserverList<Observer> observers_; | 176 ObserverList<Observer> observers_; |
132 | 177 |
133 // Weak pointer factory for generating 'this' pointers that might live longer | 178 // Weak pointer factory for generating 'this' pointers that might live longer |
134 // than we do. | 179 // than we do. |
135 // Note: This should remain the last member so it'll be destroyed and | 180 // Note: This should remain the last member so it'll be destroyed and |
136 // invalidate its weak pointers before any other members are destroyed. | 181 // invalidate its weak pointers before any other members are destroyed. |
137 base::WeakPtrFactory<FakeBluetoothGattCharacteristicClient> | 182 base::WeakPtrFactory<FakeBluetoothGattCharacteristicClient> |
138 weak_ptr_factory_; | 183 weak_ptr_factory_; |
139 | 184 |
140 DISALLOW_COPY_AND_ASSIGN(FakeBluetoothGattCharacteristicClient); | 185 DISALLOW_COPY_AND_ASSIGN(FakeBluetoothGattCharacteristicClient); |
141 }; | 186 }; |
142 | 187 |
143 } // namespace chromeos | 188 } // namespace chromeos |
144 | 189 |
145 #endif // CHROMEOS_DBUS_FAKE_BLUETOOTH_GATT_CHARACTERISTIC_CLIENT_H_ | 190 #endif // CHROMEOS_DBUS_FAKE_BLUETOOTH_GATT_CHARACTERISTIC_CLIENT_H_ |
OLD | NEW |