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 #include "chromeos/dbus/bluetooth_gatt_manager_client.h" | 5 #include "device/bluetooth/dbus/bluetooth_gatt_manager_client.h" |
6 | 6 |
7 #include "base/bind.h" | 7 #include "base/bind.h" |
8 #include "base/memory/weak_ptr.h" | 8 #include "base/memory/weak_ptr.h" |
9 #include "dbus/bus.h" | 9 #include "dbus/bus.h" |
10 #include "dbus/message.h" | 10 #include "dbus/message.h" |
11 #include "dbus/object_proxy.h" | 11 #include "dbus/object_proxy.h" |
12 #include "third_party/cros_system_api/dbus/service_constants.h" | 12 #include "third_party/cros_system_api/dbus/service_constants.h" |
13 | 13 |
14 namespace chromeos { | 14 namespace bluez { |
15 | 15 |
16 const char BluetoothGattManagerClient::kNoResponseError[] = | 16 const char BluetoothGattManagerClient::kNoResponseError[] = |
17 "org.chromium.Error.NoResponse"; | 17 "org.chromium.Error.NoResponse"; |
18 | 18 |
19 // The BluetoothGattManagerClient implementation used in production. | 19 // The BluetoothGattManagerClient implementation used in production. |
20 class BluetoothGattManagerClientImpl : public BluetoothGattManagerClient { | 20 class BluetoothGattManagerClientImpl : public BluetoothGattManagerClient { |
21 public: | 21 public: |
22 BluetoothGattManagerClientImpl() | 22 BluetoothGattManagerClientImpl() |
23 : object_proxy_(NULL), | 23 : object_proxy_(NULL), weak_ptr_factory_(this) {} |
24 weak_ptr_factory_(this) { | |
25 } | |
26 | 24 |
27 ~BluetoothGattManagerClientImpl() override {} | 25 ~BluetoothGattManagerClientImpl() override {} |
28 | 26 |
29 // BluetoothGattManagerClient override. | 27 // BluetoothGattManagerClient override. |
30 void RegisterService(const dbus::ObjectPath& service_path, | 28 void RegisterService(const dbus::ObjectPath& service_path, |
31 const Options& options, | 29 const Options& options, |
32 const base::Closure& callback, | 30 const base::Closure& callback, |
33 const ErrorCallback& error_callback) override { | 31 const ErrorCallback& error_callback) override { |
34 dbus::MethodCall method_call( | 32 dbus::MethodCall method_call( |
35 bluetooth_gatt_manager::kBluetoothGattManagerInterface, | 33 bluetooth_gatt_manager::kBluetoothGattManagerInterface, |
36 bluetooth_gatt_manager::kRegisterService); | 34 bluetooth_gatt_manager::kRegisterService); |
37 | 35 |
38 dbus::MessageWriter writer(&method_call); | 36 dbus::MessageWriter writer(&method_call); |
39 writer.AppendObjectPath(service_path); | 37 writer.AppendObjectPath(service_path); |
40 | 38 |
41 // TODO(armansito): The parameters of the Options dictionary are undefined | 39 // TODO(armansito): The parameters of the Options dictionary are undefined |
42 // but the method signature still requires a value dictionary. Pass an | 40 // but the method signature still requires a value dictionary. Pass an |
43 // empty dictionary and fill in the contents later once this is defined. | 41 // empty dictionary and fill in the contents later once this is defined. |
44 dbus::MessageWriter array_writer(NULL); | 42 dbus::MessageWriter array_writer(NULL); |
45 writer.OpenArray("{sv}", &array_writer); | 43 writer.OpenArray("{sv}", &array_writer); |
46 writer.CloseContainer(&array_writer); | 44 writer.CloseContainer(&array_writer); |
47 | 45 |
48 DCHECK(object_proxy_); | 46 DCHECK(object_proxy_); |
49 object_proxy_->CallMethodWithErrorCallback( | 47 object_proxy_->CallMethodWithErrorCallback( |
50 &method_call, | 48 &method_call, dbus::ObjectProxy::TIMEOUT_USE_DEFAULT, |
51 dbus::ObjectProxy::TIMEOUT_USE_DEFAULT, | |
52 base::Bind(&BluetoothGattManagerClientImpl::OnSuccess, | 49 base::Bind(&BluetoothGattManagerClientImpl::OnSuccess, |
53 weak_ptr_factory_.GetWeakPtr(), callback), | 50 weak_ptr_factory_.GetWeakPtr(), callback), |
54 base::Bind(&BluetoothGattManagerClientImpl::OnError, | 51 base::Bind(&BluetoothGattManagerClientImpl::OnError, |
55 weak_ptr_factory_.GetWeakPtr(), error_callback)); | 52 weak_ptr_factory_.GetWeakPtr(), error_callback)); |
56 } | 53 } |
57 | 54 |
58 // BluetoothGattManagerClient override. | 55 // BluetoothGattManagerClient override. |
59 void UnregisterService(const dbus::ObjectPath& service_path, | 56 void UnregisterService(const dbus::ObjectPath& service_path, |
60 const base::Closure& callback, | 57 const base::Closure& callback, |
61 const ErrorCallback& error_callback) override { | 58 const ErrorCallback& error_callback) override { |
62 dbus::MethodCall method_call( | 59 dbus::MethodCall method_call( |
63 bluetooth_gatt_manager::kBluetoothGattManagerInterface, | 60 bluetooth_gatt_manager::kBluetoothGattManagerInterface, |
64 bluetooth_gatt_manager::kUnregisterService); | 61 bluetooth_gatt_manager::kUnregisterService); |
65 | 62 |
66 dbus::MessageWriter writer(&method_call); | 63 dbus::MessageWriter writer(&method_call); |
67 writer.AppendObjectPath(service_path); | 64 writer.AppendObjectPath(service_path); |
68 | 65 |
69 DCHECK(object_proxy_); | 66 DCHECK(object_proxy_); |
70 object_proxy_->CallMethodWithErrorCallback( | 67 object_proxy_->CallMethodWithErrorCallback( |
71 &method_call, | 68 &method_call, dbus::ObjectProxy::TIMEOUT_USE_DEFAULT, |
72 dbus::ObjectProxy::TIMEOUT_USE_DEFAULT, | |
73 base::Bind(&BluetoothGattManagerClientImpl::OnSuccess, | 69 base::Bind(&BluetoothGattManagerClientImpl::OnSuccess, |
74 weak_ptr_factory_.GetWeakPtr(), callback), | 70 weak_ptr_factory_.GetWeakPtr(), callback), |
75 base::Bind(&BluetoothGattManagerClientImpl::OnError, | 71 base::Bind(&BluetoothGattManagerClientImpl::OnError, |
76 weak_ptr_factory_.GetWeakPtr(), error_callback)); | 72 weak_ptr_factory_.GetWeakPtr(), error_callback)); |
77 } | 73 } |
78 | 74 |
79 protected: | 75 protected: |
80 // chromeos::DBusClient override. | 76 // chromeos::DBusClient override. |
81 void Init(dbus::Bus* bus) override { | 77 void Init(dbus::Bus* bus) override { |
82 DCHECK(bus); | 78 DCHECK(bus); |
(...skipping 31 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
114 | 110 |
115 // Weak pointer factory for generating 'this' pointers that might live longer | 111 // Weak pointer factory for generating 'this' pointers that might live longer |
116 // than we do. | 112 // than we do. |
117 // Note: This should remain the last member so it'll be destroyed and | 113 // Note: This should remain the last member so it'll be destroyed and |
118 // invalidate its weak pointers before any other members are destroyed. | 114 // invalidate its weak pointers before any other members are destroyed. |
119 base::WeakPtrFactory<BluetoothGattManagerClientImpl> weak_ptr_factory_; | 115 base::WeakPtrFactory<BluetoothGattManagerClientImpl> weak_ptr_factory_; |
120 | 116 |
121 DISALLOW_COPY_AND_ASSIGN(BluetoothGattManagerClientImpl); | 117 DISALLOW_COPY_AND_ASSIGN(BluetoothGattManagerClientImpl); |
122 }; | 118 }; |
123 | 119 |
124 BluetoothGattManagerClient::BluetoothGattManagerClient() { | 120 BluetoothGattManagerClient::BluetoothGattManagerClient() {} |
125 } | |
126 | 121 |
127 BluetoothGattManagerClient::~BluetoothGattManagerClient() { | 122 BluetoothGattManagerClient::~BluetoothGattManagerClient() {} |
128 } | |
129 | 123 |
130 // static | 124 // static |
131 BluetoothGattManagerClient* BluetoothGattManagerClient::Create() { | 125 BluetoothGattManagerClient* BluetoothGattManagerClient::Create() { |
132 return new BluetoothGattManagerClientImpl(); | 126 return new BluetoothGattManagerClientImpl(); |
133 } | 127 } |
134 | 128 |
135 } // namespace chromeos | 129 } // namespace bluez |
OLD | NEW |