Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(90)

Side by Side Diff: chromeos/dbus/fake_bluetooth_gatt_characteristic_client.cc

Issue 307453007: device/bluetooth: Implement GATT characteristic properties on Chrome OS. (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src
Patch Set: Created 6 years, 6 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch | Annotate | Revision Log
OLDNEW
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 #include "chromeos/dbus/fake_bluetooth_gatt_characteristic_client.h" 5 #include "chromeos/dbus/fake_bluetooth_gatt_characteristic_client.h"
6 6
7 #include "base/bind.h" 7 #include "base/bind.h"
8 #include "base/message_loop/message_loop.h" 8 #include "base/message_loop/message_loop.h"
9 #include "base/rand_util.h" 9 #include "base/rand_util.h"
10 #include "base/time/time.h" 10 #include "base/time/time.h"
(...skipping 51 matching lines...) Expand 10 before | Expand all | Expand 10 after
62 } 62 }
63 63
64 void FakeBluetoothGattCharacteristicClient::Properties::Set( 64 void FakeBluetoothGattCharacteristicClient::Properties::Set(
65 dbus::PropertyBase* property, 65 dbus::PropertyBase* property,
66 dbus::PropertySet::SetCallback callback) { 66 dbus::PropertySet::SetCallback callback) {
67 VLOG(1) << "Set " << property->name(); 67 VLOG(1) << "Set " << property->name();
68 if (property->name() != value.name()) { 68 if (property->name() != value.name()) {
69 callback.Run(false); 69 callback.Run(false);
70 return; 70 return;
71 } 71 }
72
72 // Allow writing to only certain characteristics that are defined with the 73 // Allow writing to only certain characteristics that are defined with the
73 // write permission. 74 // write permission.
74 // TODO(armansito): Actually check against the permissions property instead of 75 bool write = false;
75 // UUID, once that property is fully defined in the API. 76 for (std::vector<std::string>::const_iterator iter = flags.value().begin();
76 if (uuid.value() != kHeartRateControlPointUUID) { 77 iter != flags.value().end();
78 ++iter) {
79 if (*iter == kFlagWrite || *iter == kFlagWriteWithoutResponse ||
80 *iter == kFlagAuthenticatedSignedWrites ||
81 *iter == kFlagReliableWrite) {
82 write = true;
83 break;
84 }
85 }
86
87 if (!write) {
77 callback.Run(false); 88 callback.Run(false);
78 return; 89 return;
79 } 90 }
91
80 callback.Run(true); 92 callback.Run(true);
81 property->ReplaceValueWithSetValue(); 93 property->ReplaceValueWithSetValue();
82 } 94 }
83 95
84 FakeBluetoothGattCharacteristicClient::FakeBluetoothGattCharacteristicClient() 96 FakeBluetoothGattCharacteristicClient::FakeBluetoothGattCharacteristicClient()
85 : heart_rate_visible_(false), 97 : heart_rate_visible_(false),
86 calories_burned_(0), 98 calories_burned_(0),
87 weak_ptr_factory_(this) { 99 weak_ptr_factory_(this) {
88 } 100 }
89 101
(...skipping 43 matching lines...) Expand 10 before | Expand all | Expand 10 after
133 145
134 void FakeBluetoothGattCharacteristicClient::ExposeHeartRateCharacteristics( 146 void FakeBluetoothGattCharacteristicClient::ExposeHeartRateCharacteristics(
135 const dbus::ObjectPath& service_path) { 147 const dbus::ObjectPath& service_path) {
136 if (IsHeartRateVisible()) { 148 if (IsHeartRateVisible()) {
137 VLOG(2) << "Fake Heart Rate characteristics are already visible."; 149 VLOG(2) << "Fake Heart Rate characteristics are already visible.";
138 return; 150 return;
139 } 151 }
140 152
141 VLOG(2) << "Exposing fake Heart Rate characteristics."; 153 VLOG(2) << "Exposing fake Heart Rate characteristics.";
142 154
155 std::vector<std::string> flags;
156
143 // ==== Heart Rate Measurement Characteristic ==== 157 // ==== Heart Rate Measurement Characteristic ====
144 heart_rate_measurement_path_ = 158 heart_rate_measurement_path_ =
145 service_path.value() + "/" + kHeartRateMeasurementPathComponent; 159 service_path.value() + "/" + kHeartRateMeasurementPathComponent;
146 heart_rate_measurement_properties_.reset(new Properties(base::Bind( 160 heart_rate_measurement_properties_.reset(new Properties(base::Bind(
147 &FakeBluetoothGattCharacteristicClient::OnPropertyChanged, 161 &FakeBluetoothGattCharacteristicClient::OnPropertyChanged,
148 weak_ptr_factory_.GetWeakPtr(), 162 weak_ptr_factory_.GetWeakPtr(),
149 dbus::ObjectPath(heart_rate_measurement_path_)))); 163 dbus::ObjectPath(heart_rate_measurement_path_))));
150 heart_rate_measurement_properties_->uuid.ReplaceValue( 164 heart_rate_measurement_properties_->uuid.ReplaceValue(
151 kHeartRateMeasurementUUID); 165 kHeartRateMeasurementUUID);
152 heart_rate_measurement_properties_->service.ReplaceValue(service_path); 166 heart_rate_measurement_properties_->service.ReplaceValue(service_path);
153 167 flags.push_back(kFlagNotify);
154 // TODO(armansito): Fill out the flags field once bindings for the values have 168 heart_rate_measurement_properties_->flags.ReplaceValue(flags);
155 // been added. For now, leave it empty.
156 169
157 std::vector<uint8> measurement_value = GetHeartRateMeasurementValue(); 170 std::vector<uint8> measurement_value = GetHeartRateMeasurementValue();
158 heart_rate_measurement_properties_->value.ReplaceValue(measurement_value); 171 heart_rate_measurement_properties_->value.ReplaceValue(measurement_value);
159 172
160 // ==== Body Sensor Location Characteristic ==== 173 // ==== Body Sensor Location Characteristic ====
161 body_sensor_location_path_ = 174 body_sensor_location_path_ =
162 service_path.value() + "/" + kBodySensorLocationPathComponent; 175 service_path.value() + "/" + kBodySensorLocationPathComponent;
163 body_sensor_location_properties_.reset(new Properties(base::Bind( 176 body_sensor_location_properties_.reset(new Properties(base::Bind(
164 &FakeBluetoothGattCharacteristicClient::OnPropertyChanged, 177 &FakeBluetoothGattCharacteristicClient::OnPropertyChanged,
165 weak_ptr_factory_.GetWeakPtr(), 178 weak_ptr_factory_.GetWeakPtr(),
166 dbus::ObjectPath(body_sensor_location_path_)))); 179 dbus::ObjectPath(body_sensor_location_path_))));
167 body_sensor_location_properties_->uuid.ReplaceValue(kBodySensorLocationUUID); 180 body_sensor_location_properties_->uuid.ReplaceValue(kBodySensorLocationUUID);
168 body_sensor_location_properties_->service.ReplaceValue(service_path); 181 body_sensor_location_properties_->service.ReplaceValue(service_path);
169 182 flags.clear();
170 // TODO(armansito): Fill out the flags field once bindings for the values have 183 flags.push_back(kFlagRead);
171 // been added. For now, leave it empty. 184 body_sensor_location_properties_->flags.ReplaceValue(flags);
172 185
173 // The sensor is in the "Other" location. 186 // The sensor is in the "Other" location.
174 std::vector<uint8> body_sensor_location_value; 187 std::vector<uint8> body_sensor_location_value;
175 body_sensor_location_value.push_back(0); 188 body_sensor_location_value.push_back(0);
176 body_sensor_location_properties_->value.ReplaceValue( 189 body_sensor_location_properties_->value.ReplaceValue(
177 body_sensor_location_value); 190 body_sensor_location_value);
178 191
179 // ==== Heart Rate Control Point Characteristic ==== 192 // ==== Heart Rate Control Point Characteristic ====
180 heart_rate_control_point_path_ = 193 heart_rate_control_point_path_ =
181 service_path.value() + "/" + kHeartRateControlPointPathComponent; 194 service_path.value() + "/" + kHeartRateControlPointPathComponent;
182 heart_rate_control_point_properties_.reset(new Properties(base::Bind( 195 heart_rate_control_point_properties_.reset(new Properties(base::Bind(
183 &FakeBluetoothGattCharacteristicClient::OnPropertyChanged, 196 &FakeBluetoothGattCharacteristicClient::OnPropertyChanged,
184 weak_ptr_factory_.GetWeakPtr(), 197 weak_ptr_factory_.GetWeakPtr(),
185 dbus::ObjectPath(heart_rate_control_point_path_)))); 198 dbus::ObjectPath(heart_rate_control_point_path_))));
186 heart_rate_control_point_properties_->uuid.ReplaceValue( 199 heart_rate_control_point_properties_->uuid.ReplaceValue(
187 kHeartRateControlPointUUID); 200 kHeartRateControlPointUUID);
188 heart_rate_control_point_properties_->service.ReplaceValue(service_path); 201 heart_rate_control_point_properties_->service.ReplaceValue(service_path);
189 202 flags.clear();
190 // TODO(armansito): Fill out the flags field once bindings for the values have 203 flags.push_back(kFlagWrite);
191 // been added. For now, leave it empty. 204 heart_rate_control_point_properties_->flags.ReplaceValue(flags);
192 205
193 // Set the initial value to 0. Whenever this gets set to 1, we will reset the 206 // Set the initial value to 0. Whenever this gets set to 1, we will reset the
194 // total calories burned and change the value back to 0. 207 // total calories burned and change the value back to 0.
195 std::vector<uint8> heart_rate_control_point_value; 208 std::vector<uint8> heart_rate_control_point_value;
196 heart_rate_control_point_value.push_back(0); 209 heart_rate_control_point_value.push_back(0);
197 heart_rate_control_point_properties_->value.ReplaceValue( 210 heart_rate_control_point_properties_->value.ReplaceValue(
198 heart_rate_control_point_value); 211 heart_rate_control_point_value);
199 212
200 heart_rate_visible_ = true; 213 heart_rate_visible_ = true;
201 214
(...skipping 167 matching lines...) Expand 10 before | Expand all | Expand 10 after
369 DCHECK(heart_rate_visible_ != heart_rate_measurement_path_.empty()); 382 DCHECK(heart_rate_visible_ != heart_rate_measurement_path_.empty());
370 DCHECK(heart_rate_visible_ != body_sensor_location_path_.empty()); 383 DCHECK(heart_rate_visible_ != body_sensor_location_path_.empty());
371 DCHECK(heart_rate_visible_ != heart_rate_control_point_path_.empty()); 384 DCHECK(heart_rate_visible_ != heart_rate_control_point_path_.empty());
372 DCHECK(heart_rate_visible_ == !!heart_rate_measurement_properties_.get()); 385 DCHECK(heart_rate_visible_ == !!heart_rate_measurement_properties_.get());
373 DCHECK(heart_rate_visible_ == !!body_sensor_location_properties_.get()); 386 DCHECK(heart_rate_visible_ == !!body_sensor_location_properties_.get());
374 DCHECK(heart_rate_visible_ == !!heart_rate_control_point_properties_.get()); 387 DCHECK(heart_rate_visible_ == !!heart_rate_control_point_properties_.get());
375 return heart_rate_visible_; 388 return heart_rate_visible_;
376 } 389 }
377 390
378 } // namespace chromeos 391 } // namespace chromeos
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698