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

Side by Side Diff: device/bluetooth/bluez/bluetooth_local_gatt_service_bluez.cc

Issue 1915803002: Bluetooth class changes for implementing 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 2016 The Chromium Authors. All rights reserved. 1 // Copyright 2016 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/bluez/bluetooth_local_gatt_service_bluez.h" 5 #include <device/bluetooth/bluez/bluetooth_local_gatt_service_bluez.h>
6 6
7 #include "base/callback.h"
8 #include "base/guid.h" 7 #include "base/guid.h"
9 #include "base/logging.h" 8 #include "base/logging.h"
10 #include "base/memory/ptr_util.h" 9 #include "base/memory/ptr_util.h"
11 #include "base/strings/string_util.h" 10 #include "base/strings/string_util.h"
12 #include "dbus/object_path.h" 11 #include "dbus/object_path.h"
13 #include "device/bluetooth/bluez/bluetooth_adapter_bluez.h" 12 #include "device/bluetooth/bluez/bluetooth_adapter_bluez.h"
14 13
14 namespace device {
15
16 // static
17 base::WeakPtr<BluetoothLocalGattService> BluetoothLocalGattService::Create(
18 BluetoothAdapter* adapter,
19 const BluetoothUUID& uuid,
20 bool is_primary,
21 BluetoothLocalGattService* included_service,
22 BluetoothLocalGattService::Delegate* delegate) {
23 return bluez::BluetoothLocalGattServiceBlueZ::Create(
24 adapter, uuid, is_primary, included_service, delegate);
25 }
26
27 } // device
28
15 namespace bluez { 29 namespace bluez {
16 30
31 // static
32 base::WeakPtr<device::BluetoothLocalGattService>
33 BluetoothLocalGattServiceBlueZ::Create(
34 device::BluetoothAdapter* adapter,
35 const device::BluetoothUUID& uuid,
36 bool is_primary,
37 BluetoothLocalGattService* /* included_service */,
38 BluetoothLocalGattService::Delegate* delegate) {
39 BluetoothAdapterBlueZ* adapter_bluez =
40 static_cast<BluetoothAdapterBlueZ*>(adapter);
41 BluetoothLocalGattServiceBlueZ* service = new BluetoothLocalGattServiceBlueZ(
42 adapter_bluez, uuid, is_primary, delegate);
43 adapter_bluez->AddLocalGattService(base::WrapUnique(service));
44 return service->weak_ptr_factory_.GetWeakPtr();
45 }
46
17 BluetoothLocalGattServiceBlueZ::BluetoothLocalGattServiceBlueZ( 47 BluetoothLocalGattServiceBlueZ::BluetoothLocalGattServiceBlueZ(
18 BluetoothAdapterBlueZ* adapter, 48 BluetoothAdapterBlueZ* adapter,
19 const device::BluetoothUUID& uuid, 49 const device::BluetoothUUID& uuid,
20 bool is_primary, 50 bool is_primary,
21 device::BluetoothLocalGattService::Delegate* delegate) 51 device::BluetoothLocalGattService::Delegate* delegate)
22 : BluetoothGattServiceBlueZ(adapter), 52 : BluetoothGattServiceBlueZ(adapter),
23 uuid_(uuid), 53 uuid_(uuid),
24 is_primary_(is_primary), 54 is_primary_(is_primary),
25 delegate_(delegate), 55 delegate_(delegate),
26 weak_ptr_factory_(this) { 56 weak_ptr_factory_(this) {
27 // TODO(rkc): Move this code in a common location. It is used by 57 // TODO(rkc): Get base application path from adapter and prefix it here.
scheib 2016/04/28 01:06:24 Use issue numbers for TODOs.
rkc 2016/04/28 02:06:58 This is just a remnant of the split to make the co
scheib 2016/04/28 04:34:07 OK, leave it for now but I'd suggest TODO(crrev.co
rkc 2016/04/28 05:07:23 Acknowledged.
28 // BluetoothAdvertisementBlueZ() also. 58 object_path_ = AddGuidToObjectPath("/service");
29 std::string GuidString = base::GenerateGUID();
30 base::RemoveChars(GuidString, "-", &GuidString);
31 object_path_ = dbus::ObjectPath(adapter_->object_path().value() +
32 "/service/" + GuidString);
33 VLOG(1) << "Creating local GATT service with identifier: " 59 VLOG(1) << "Creating local GATT service with identifier: "
34 << object_path_.value(); 60 << object_path_.value();
35 } 61 }
36 62
37 BluetoothLocalGattServiceBlueZ::~BluetoothLocalGattServiceBlueZ() {} 63 BluetoothLocalGattServiceBlueZ::~BluetoothLocalGattServiceBlueZ() {}
38 64
39 device::BluetoothUUID BluetoothLocalGattServiceBlueZ::GetUUID() const { 65 device::BluetoothUUID BluetoothLocalGattServiceBlueZ::GetUUID() const {
40 return uuid_; 66 return uuid_;
41 } 67 }
42 68
43 bool BluetoothLocalGattServiceBlueZ::IsPrimary() const { 69 bool BluetoothLocalGattServiceBlueZ::IsPrimary() const {
44 return is_primary_; 70 return is_primary_;
45 } 71 }
46 72
47 // static
48 base::WeakPtr<device::BluetoothLocalGattService>
49 BluetoothLocalGattServiceBlueZ::Create(
50 device::BluetoothAdapter* adapter,
51 const device::BluetoothUUID& uuid,
52 bool is_primary,
53 BluetoothLocalGattService* /* included_service */,
54 BluetoothLocalGattService::Delegate* delegate) {
55 BluetoothAdapterBlueZ* adapter_bluez =
56 static_cast<BluetoothAdapterBlueZ*>(adapter);
57 BluetoothLocalGattServiceBlueZ* service = new BluetoothLocalGattServiceBlueZ(
58 adapter_bluez, uuid, is_primary, delegate);
59 adapter_bluez->AddLocalGattService(base::WrapUnique(service));
60 return service->weak_ptr_factory_.GetWeakPtr();
61 }
62
63 void BluetoothLocalGattServiceBlueZ::Register( 73 void BluetoothLocalGattServiceBlueZ::Register(
64 const base::Closure& callback, 74 const base::Closure& callback,
65 const ErrorCallback& error_callback) { 75 const ErrorCallback& error_callback) {
66 // TODO(rkc): Call adapter_->RegisterGattService. 76 // GetAdapter()->RegisterGattService(this, callback, error_callback);
67 } 77 }
68 78
69 void BluetoothLocalGattServiceBlueZ::Unregister( 79 void BluetoothLocalGattServiceBlueZ::Unregister(
70 const base::Closure& callback, 80 const base::Closure& callback,
71 const ErrorCallback& error_callback) { 81 const ErrorCallback& error_callback) {
72 // TODO(rkc): Call adapter_->UnregisterGattService. 82 DCHECK(GetAdapter());
83 // GetAdapter()->UnregisterGattService(this, callback, error_callback);
73 } 84 }
74 85
75 void BluetoothLocalGattServiceBlueZ::OnRegistrationError( 86 const std::vector<std::unique_ptr<BluetoothLocalGattCharacteristicBlueZ>>&
76 const ErrorCallback& error_callback, 87 BluetoothLocalGattServiceBlueZ::GetCharacteristics() const {
77 const std::string& error_name, 88 return characteristics_;
78 const std::string& error_message) { 89 }
79 VLOG(1) << "[Un]Register Service failed: " << error_name 90
80 << ", message: " << error_message; 91 // static
81 error_callback.Run( 92 dbus::ObjectPath BluetoothLocalGattServiceBlueZ::AddGuidToObjectPath(
82 BluetoothGattServiceBlueZ::DBusErrorToServiceError(error_name)); 93 const std::string& path) {
94 std::string GuidString = base::GenerateGUID();
95 base::RemoveChars(GuidString, "-", &GuidString);
96
97 return dbus::ObjectPath(path + GuidString);
98 }
99
100 void BluetoothLocalGattServiceBlueZ::AddCharacteristic(
101 std::unique_ptr<BluetoothLocalGattCharacteristicBlueZ> characteristic) {
102 characteristics_.push_back(std::move(characteristic));
83 } 103 }
84 104
85 } // namespace bluez 105 } // namespace bluez
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698