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

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 bluez::BluetoothAdapterBlueZ* adapter_bluez =
24 static_cast<bluez::BluetoothAdapterBlueZ*>(adapter);
25 bluez::BluetoothLocalGattServiceBlueZ* service =
26 new bluez::BluetoothLocalGattServiceBlueZ(adapter_bluez, uuid, is_primary,
27 delegate);
28 return service->weak_ptr_factory_.GetWeakPtr();
29 }
30
31 } // device
32
15 namespace bluez { 33 namespace bluez {
16 34
17 BluetoothLocalGattServiceBlueZ::BluetoothLocalGattServiceBlueZ( 35 BluetoothLocalGattServiceBlueZ::BluetoothLocalGattServiceBlueZ(
18 BluetoothAdapterBlueZ* adapter, 36 BluetoothAdapterBlueZ* adapter,
19 const device::BluetoothUUID& uuid, 37 const device::BluetoothUUID& uuid,
20 bool is_primary, 38 bool is_primary,
21 device::BluetoothLocalGattService::Delegate* delegate) 39 device::BluetoothLocalGattService::Delegate* delegate)
22 : BluetoothGattServiceBlueZ(adapter), 40 : BluetoothGattServiceBlueZ(adapter, AddGuidToObjectPath("/service")),
23 uuid_(uuid), 41 uuid_(uuid),
24 is_primary_(is_primary), 42 is_primary_(is_primary),
25 delegate_(delegate), 43 delegate_(delegate),
26 weak_ptr_factory_(this) { 44 weak_ptr_factory_(this) {
27 // TODO(rkc): Move this code in a common location. It is used by 45 // TODO(rkc): Get base application path from adapter and prefix it here.
28 // BluetoothAdvertisementBlueZ() also. 46 VLOG(1) << "Creating local GATT service with identifier: " << GetIdentifier();
29 std::string GuidString = base::GenerateGUID(); 47 adapter->AddLocalGattService(base::WrapUnique(this));
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: "
34 << object_path_.value();
35 } 48 }
36 49
37 BluetoothLocalGattServiceBlueZ::~BluetoothLocalGattServiceBlueZ() {} 50 BluetoothLocalGattServiceBlueZ::~BluetoothLocalGattServiceBlueZ() {}
38 51
39 device::BluetoothUUID BluetoothLocalGattServiceBlueZ::GetUUID() const { 52 device::BluetoothUUID BluetoothLocalGattServiceBlueZ::GetUUID() const {
40 return uuid_; 53 return uuid_;
41 } 54 }
42 55
43 bool BluetoothLocalGattServiceBlueZ::IsPrimary() const { 56 bool BluetoothLocalGattServiceBlueZ::IsPrimary() const {
44 return is_primary_; 57 return is_primary_;
45 } 58 }
46 59
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( 60 void BluetoothLocalGattServiceBlueZ::Register(
64 const base::Closure& callback, 61 const base::Closure& callback,
65 const ErrorCallback& error_callback) { 62 const ErrorCallback& error_callback) {
66 // TODO(rkc): Call adapter_->RegisterGattService. 63 // GetAdapter()->RegisterGattService(this, callback, error_callback);
67 } 64 }
68 65
69 void BluetoothLocalGattServiceBlueZ::Unregister( 66 void BluetoothLocalGattServiceBlueZ::Unregister(
70 const base::Closure& callback, 67 const base::Closure& callback,
71 const ErrorCallback& error_callback) { 68 const ErrorCallback& error_callback) {
72 // TODO(rkc): Call adapter_->UnregisterGattService. 69 DCHECK(GetAdapter());
70 // GetAdapter()->UnregisterGattService(this, callback, error_callback);
73 } 71 }
74 72
75 void BluetoothLocalGattServiceBlueZ::OnRegistrationError( 73 const std::vector<std::unique_ptr<BluetoothLocalGattCharacteristicBlueZ>>&
76 const ErrorCallback& error_callback, 74 BluetoothLocalGattServiceBlueZ::GetCharacteristics() const {
77 const std::string& error_name, 75 return characteristics_;
78 const std::string& error_message) { 76 }
79 VLOG(1) << "[Un]Register Service failed: " << error_name 77
80 << ", message: " << error_message; 78 // static
81 error_callback.Run( 79 dbus::ObjectPath BluetoothLocalGattServiceBlueZ::AddGuidToObjectPath(
82 BluetoothGattServiceBlueZ::DBusErrorToServiceError(error_name)); 80 const std::string& path) {
81 std::string GuidString = base::GenerateGUID();
82 base::RemoveChars(GuidString, "-", &GuidString);
83
84 return dbus::ObjectPath(path + GuidString);
85 }
86
87 void BluetoothLocalGattServiceBlueZ::AddCharacteristic(
88 std::unique_ptr<BluetoothLocalGattCharacteristicBlueZ> characteristic) {
89 characteristics_.push_back(std::move(characteristic));
83 } 90 }
84 91
85 } // namespace bluez 92 } // namespace bluez
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698