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

Side by Side Diff: device/bluetooth/dbus/bluetooth_gatt_service_service_provider.cc

Issue 1920693002: Complete //device/bt implementation for hosting local GATT attributes. (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: Created 4 years, 7 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
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 "device/bluetooth/dbus/bluetooth_gatt_service_service_provider.h" 5 #include "device/bluetooth/dbus/bluetooth_gatt_service_service_provider.h"
6 6
7 #include <memory>
8 #include <utility>
9
10 #include "base/bind.h" 7 #include "base/bind.h"
8 #include "base/callback.h"
11 #include "base/logging.h" 9 #include "base/logging.h"
12 #include "base/macros.h"
13 #include "base/memory/ref_counted.h" 10 #include "base/memory/ref_counted.h"
14 #include "base/memory/weak_ptr.h" 11 #include "base/memory/weak_ptr.h"
15 #include "base/threading/platform_thread.h" 12 #include "base/threading/platform_thread.h"
16 #include "dbus/exported_object.h" 13 #include "dbus/exported_object.h"
17 #include "dbus/message.h"
18 #include "device/bluetooth/dbus/bluez_dbus_manager.h" 14 #include "device/bluetooth/dbus/bluez_dbus_manager.h"
19 #include "device/bluetooth/dbus/fake_bluetooth_gatt_service_service_provider.h" 15 #include "device/bluetooth/dbus/fake_bluetooth_gatt_service_service_provider.h"
20 #include "third_party/cros_system_api/dbus/service_constants.h" 16 #include "third_party/cros_system_api/dbus/service_constants.h"
21 17
22 namespace bluez { 18 namespace bluez {
23 namespace { 19 namespace {
24 const char kErrorInvalidArgs[] = "org.freedesktop.DBus.Error.InvalidArgs"; 20 const char kErrorInvalidArgs[] = "org.freedesktop.DBus.Error.InvalidArgs";
25 const char kErrorPropertyReadOnly[] = 21 const char kErrorPropertyReadOnly[] =
26 "org.freedesktop.DBus.Error.PropertyReadOnly"; 22 "org.freedesktop.DBus.Error.PropertyReadOnly";
27 } // namespace 23 } // namespace
(...skipping 157 matching lines...) Expand 10 before | Expand all | Expand 10 after
185 dbus::ErrorResponse::FromMethodCall( 181 dbus::ErrorResponse::FromMethodCall(
186 method_call, kErrorInvalidArgs, 182 method_call, kErrorInvalidArgs,
187 "No such interface: '" + interface_name + "'."); 183 "No such interface: '" + interface_name + "'.");
188 response_sender.Run(std::move(error_response)); 184 response_sender.Run(std::move(error_response));
189 return; 185 return;
190 } 186 }
191 187
192 std::unique_ptr<dbus::Response> response = 188 std::unique_ptr<dbus::Response> response =
193 dbus::Response::FromMethodCall(method_call); 189 dbus::Response::FromMethodCall(method_call);
194 dbus::MessageWriter writer(response.get()); 190 dbus::MessageWriter writer(response.get());
191 WriteProperties(&writer);
192 response_sender.Run(std::move(response));
193 }
194
195 void WriteProperties(dbus::MessageWriter* writer) override {
195 dbus::MessageWriter array_writer(NULL); 196 dbus::MessageWriter array_writer(NULL);
196 dbus::MessageWriter dict_entry_writer(NULL); 197 dbus::MessageWriter dict_entry_writer(NULL);
197 dbus::MessageWriter variant_writer(NULL); 198 dbus::MessageWriter variant_writer(NULL);
198 199
199 writer.OpenArray("{sv}", &array_writer); 200 writer->OpenArray("{sv}", &array_writer);
200 201
201 array_writer.OpenDictEntry(&dict_entry_writer); 202 array_writer.OpenDictEntry(&dict_entry_writer);
202 dict_entry_writer.AppendString(bluetooth_gatt_service::kUUIDProperty); 203 dict_entry_writer.AppendString(bluetooth_gatt_service::kUUIDProperty);
203 dict_entry_writer.AppendVariantOfString(uuid_); 204 dict_entry_writer.AppendVariantOfString(uuid_);
204 array_writer.CloseContainer(&dict_entry_writer); 205 array_writer.CloseContainer(&dict_entry_writer);
205 206
206 array_writer.OpenDictEntry(&dict_entry_writer); 207 array_writer.OpenDictEntry(&dict_entry_writer);
207 dict_entry_writer.AppendString(bluetooth_gatt_service::kIncludesProperty); 208 dict_entry_writer.AppendString(bluetooth_gatt_service::kIncludesProperty);
208 dict_entry_writer.OpenVariant("ao", &variant_writer); 209 dict_entry_writer.OpenVariant("ao", &variant_writer);
209 variant_writer.AppendArrayOfObjectPaths(includes_); 210 variant_writer.AppendArrayOfObjectPaths(includes_);
210 dict_entry_writer.CloseContainer(&variant_writer); 211 dict_entry_writer.CloseContainer(&variant_writer);
211 array_writer.CloseContainer(&dict_entry_writer); 212 array_writer.CloseContainer(&dict_entry_writer);
212 213
213 writer.CloseContainer(&array_writer); 214 writer->CloseContainer(&array_writer);
214
215 response_sender.Run(std::move(response));
216 } 215 }
217 216
218 // Called by dbus:: when a method is exported. 217 // Called by dbus:: when a method is exported.
219 void OnExported(const std::string& interface_name, 218 void OnExported(const std::string& interface_name,
220 const std::string& method_name, 219 const std::string& method_name,
221 bool success) { 220 bool success) {
222 LOG_IF(WARNING, !success) << "Failed to export " << interface_name << "." 221 LOG_IF(WARNING, !success) << "Failed to export " << interface_name << "."
223 << method_name; 222 << method_name;
224 } 223 }
225 224
225 const dbus::ObjectPath& object_path() const override { return object_path_; }
226
226 // Origin thread (i.e. the UI thread in production). 227 // Origin thread (i.e. the UI thread in production).
227 base::PlatformThreadId origin_thread_id_; 228 base::PlatformThreadId origin_thread_id_;
228 229
229 // 128-bit service UUID of this object. 230 // 128-bit service UUID of this object.
230 std::string uuid_; 231 std::string uuid_;
231 232
232 // List of object paths that represent other exported GATT services that are 233 // List of object paths that represent other exported GATT services that are
233 // included from this service. 234 // included from this service.
234 std::vector<dbus::ObjectPath> includes_; 235 std::vector<dbus::ObjectPath> includes_;
235 236
(...skipping 31 matching lines...) Expand 10 before | Expand all | Expand 10 after
267 const std::vector<dbus::ObjectPath>& includes) { 268 const std::vector<dbus::ObjectPath>& includes) {
268 if (!bluez::BluezDBusManager::Get()->IsUsingFakes()) { 269 if (!bluez::BluezDBusManager::Get()->IsUsingFakes()) {
269 return new BluetoothGattServiceServiceProviderImpl(bus, object_path, uuid, 270 return new BluetoothGattServiceServiceProviderImpl(bus, object_path, uuid,
270 includes); 271 includes);
271 } 272 }
272 return new FakeBluetoothGattServiceServiceProvider(object_path, uuid, 273 return new FakeBluetoothGattServiceServiceProvider(object_path, uuid,
273 includes); 274 includes);
274 } 275 }
275 276
276 } // namespace bluez 277 } // namespace bluez
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698