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 "chromeos/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" |
(...skipping 13 matching lines...) Expand all Loading... |
24 weak_ptr_factory_(this) { | 24 weak_ptr_factory_(this) { |
25 } | 25 } |
26 | 26 |
27 virtual ~BluetoothGattManagerClientImpl() { | 27 virtual ~BluetoothGattManagerClientImpl() { |
28 } | 28 } |
29 | 29 |
30 // BluetoothGattManagerClient override. | 30 // BluetoothGattManagerClient override. |
31 virtual void RegisterService(const dbus::ObjectPath& service_path, | 31 virtual void RegisterService(const dbus::ObjectPath& service_path, |
32 const Options& options, | 32 const Options& options, |
33 const base::Closure& callback, | 33 const base::Closure& callback, |
34 const ErrorCallback& error_callback) OVERRIDE { | 34 const ErrorCallback& error_callback) override { |
35 dbus::MethodCall method_call( | 35 dbus::MethodCall method_call( |
36 bluetooth_gatt_manager::kBluetoothGattManagerInterface, | 36 bluetooth_gatt_manager::kBluetoothGattManagerInterface, |
37 bluetooth_gatt_manager::kRegisterService); | 37 bluetooth_gatt_manager::kRegisterService); |
38 | 38 |
39 dbus::MessageWriter writer(&method_call); | 39 dbus::MessageWriter writer(&method_call); |
40 writer.AppendObjectPath(service_path); | 40 writer.AppendObjectPath(service_path); |
41 | 41 |
42 // TODO(armansito): The parameters of the Options dictionary are undefined | 42 // TODO(armansito): The parameters of the Options dictionary are undefined |
43 // but the method signature still requires a value dictionary. Pass an | 43 // but the method signature still requires a value dictionary. Pass an |
44 // empty dictionary and fill in the contents later once this is defined. | 44 // empty dictionary and fill in the contents later once this is defined. |
45 dbus::MessageWriter array_writer(NULL); | 45 dbus::MessageWriter array_writer(NULL); |
46 writer.OpenArray("{sv}", &array_writer); | 46 writer.OpenArray("{sv}", &array_writer); |
47 writer.CloseContainer(&array_writer); | 47 writer.CloseContainer(&array_writer); |
48 | 48 |
49 DCHECK(object_proxy_); | 49 DCHECK(object_proxy_); |
50 object_proxy_->CallMethodWithErrorCallback( | 50 object_proxy_->CallMethodWithErrorCallback( |
51 &method_call, | 51 &method_call, |
52 dbus::ObjectProxy::TIMEOUT_USE_DEFAULT, | 52 dbus::ObjectProxy::TIMEOUT_USE_DEFAULT, |
53 base::Bind(&BluetoothGattManagerClientImpl::OnSuccess, | 53 base::Bind(&BluetoothGattManagerClientImpl::OnSuccess, |
54 weak_ptr_factory_.GetWeakPtr(), callback), | 54 weak_ptr_factory_.GetWeakPtr(), callback), |
55 base::Bind(&BluetoothGattManagerClientImpl::OnError, | 55 base::Bind(&BluetoothGattManagerClientImpl::OnError, |
56 weak_ptr_factory_.GetWeakPtr(), error_callback)); | 56 weak_ptr_factory_.GetWeakPtr(), error_callback)); |
57 } | 57 } |
58 | 58 |
59 // BluetoothGattManagerClient override. | 59 // BluetoothGattManagerClient override. |
60 virtual void UnregisterService(const dbus::ObjectPath& service_path, | 60 virtual void UnregisterService(const dbus::ObjectPath& service_path, |
61 const base::Closure& callback, | 61 const base::Closure& callback, |
62 const ErrorCallback& error_callback) OVERRIDE { | 62 const ErrorCallback& error_callback) override { |
63 dbus::MethodCall method_call( | 63 dbus::MethodCall method_call( |
64 bluetooth_gatt_manager::kBluetoothGattManagerInterface, | 64 bluetooth_gatt_manager::kBluetoothGattManagerInterface, |
65 bluetooth_gatt_manager::kUnregisterService); | 65 bluetooth_gatt_manager::kUnregisterService); |
66 | 66 |
67 dbus::MessageWriter writer(&method_call); | 67 dbus::MessageWriter writer(&method_call); |
68 writer.AppendObjectPath(service_path); | 68 writer.AppendObjectPath(service_path); |
69 | 69 |
70 DCHECK(object_proxy_); | 70 DCHECK(object_proxy_); |
71 object_proxy_->CallMethodWithErrorCallback( | 71 object_proxy_->CallMethodWithErrorCallback( |
72 &method_call, | 72 &method_call, |
73 dbus::ObjectProxy::TIMEOUT_USE_DEFAULT, | 73 dbus::ObjectProxy::TIMEOUT_USE_DEFAULT, |
74 base::Bind(&BluetoothGattManagerClientImpl::OnSuccess, | 74 base::Bind(&BluetoothGattManagerClientImpl::OnSuccess, |
75 weak_ptr_factory_.GetWeakPtr(), callback), | 75 weak_ptr_factory_.GetWeakPtr(), callback), |
76 base::Bind(&BluetoothGattManagerClientImpl::OnError, | 76 base::Bind(&BluetoothGattManagerClientImpl::OnError, |
77 weak_ptr_factory_.GetWeakPtr(), error_callback)); | 77 weak_ptr_factory_.GetWeakPtr(), error_callback)); |
78 } | 78 } |
79 | 79 |
80 protected: | 80 protected: |
81 // chromeos::DBusClient override. | 81 // chromeos::DBusClient override. |
82 virtual void Init(dbus::Bus* bus) OVERRIDE { | 82 virtual void Init(dbus::Bus* bus) override { |
83 DCHECK(bus); | 83 DCHECK(bus); |
84 object_proxy_ = bus->GetObjectProxy( | 84 object_proxy_ = bus->GetObjectProxy( |
85 bluetooth_gatt_manager::kBluetoothGattManagerServiceName, | 85 bluetooth_gatt_manager::kBluetoothGattManagerServiceName, |
86 dbus::ObjectPath( | 86 dbus::ObjectPath( |
87 bluetooth_gatt_manager::kBluetoothGattManagerInterface)); | 87 bluetooth_gatt_manager::kBluetoothGattManagerInterface)); |
88 } | 88 } |
89 | 89 |
90 private: | 90 private: |
91 // Called when a response for a successful method call is received. | 91 // Called when a response for a successful method call is received. |
92 void OnSuccess(const base::Closure& callback, dbus::Response* response) { | 92 void OnSuccess(const base::Closure& callback, dbus::Response* response) { |
(...skipping 34 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
127 | 127 |
128 BluetoothGattManagerClient::~BluetoothGattManagerClient() { | 128 BluetoothGattManagerClient::~BluetoothGattManagerClient() { |
129 } | 129 } |
130 | 130 |
131 // static | 131 // static |
132 BluetoothGattManagerClient* BluetoothGattManagerClient::Create() { | 132 BluetoothGattManagerClient* BluetoothGattManagerClient::Create() { |
133 return new BluetoothGattManagerClientImpl(); | 133 return new BluetoothGattManagerClientImpl(); |
134 } | 134 } |
135 | 135 |
136 } // namespace chromeos | 136 } // namespace chromeos |
OLD | NEW |