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 "device/bluetooth/dbus/bluetooth_gatt_service_service_provider.h" | 5 #include "device/bluetooth/dbus/bluetooth_gatt_service_service_provider.h" |
6 | 6 |
| 7 #include <utility> |
| 8 |
7 #include "base/bind.h" | 9 #include "base/bind.h" |
8 #include "base/logging.h" | 10 #include "base/logging.h" |
9 #include "base/macros.h" | 11 #include "base/macros.h" |
10 #include "base/memory/ref_counted.h" | 12 #include "base/memory/ref_counted.h" |
11 #include "base/memory/weak_ptr.h" | 13 #include "base/memory/weak_ptr.h" |
12 #include "base/threading/platform_thread.h" | 14 #include "base/threading/platform_thread.h" |
13 #include "dbus/exported_object.h" | 15 #include "dbus/exported_object.h" |
14 #include "dbus/message.h" | 16 #include "dbus/message.h" |
15 #include "device/bluetooth/dbus/bluez_dbus_manager.h" | 17 #include "device/bluetooth/dbus/bluez_dbus_manager.h" |
16 #include "device/bluetooth/dbus/fake_bluetooth_gatt_service_service_provider.h" | 18 #include "device/bluetooth/dbus/fake_bluetooth_gatt_service_service_provider.h" |
(...skipping 72 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
89 | 91 |
90 dbus::MessageReader reader(method_call); | 92 dbus::MessageReader reader(method_call); |
91 | 93 |
92 std::string interface_name; | 94 std::string interface_name; |
93 std::string property_name; | 95 std::string property_name; |
94 if (!reader.PopString(&interface_name) || | 96 if (!reader.PopString(&interface_name) || |
95 !reader.PopString(&property_name) || reader.HasMoreData()) { | 97 !reader.PopString(&property_name) || reader.HasMoreData()) { |
96 scoped_ptr<dbus::ErrorResponse> error_response = | 98 scoped_ptr<dbus::ErrorResponse> error_response = |
97 dbus::ErrorResponse::FromMethodCall(method_call, kErrorInvalidArgs, | 99 dbus::ErrorResponse::FromMethodCall(method_call, kErrorInvalidArgs, |
98 "Expected 'ss'."); | 100 "Expected 'ss'."); |
99 response_sender.Run(error_response.Pass()); | 101 response_sender.Run(std::move(error_response)); |
100 return; | 102 return; |
101 } | 103 } |
102 | 104 |
103 // Only the GATT service interface is allowed. | 105 // Only the GATT service interface is allowed. |
104 if (interface_name != | 106 if (interface_name != |
105 bluetooth_gatt_service::kBluetoothGattServiceInterface) { | 107 bluetooth_gatt_service::kBluetoothGattServiceInterface) { |
106 scoped_ptr<dbus::ErrorResponse> error_response = | 108 scoped_ptr<dbus::ErrorResponse> error_response = |
107 dbus::ErrorResponse::FromMethodCall( | 109 dbus::ErrorResponse::FromMethodCall( |
108 method_call, kErrorInvalidArgs, | 110 method_call, kErrorInvalidArgs, |
109 "No such interface: '" + interface_name + "'."); | 111 "No such interface: '" + interface_name + "'."); |
110 response_sender.Run(error_response.Pass()); | 112 response_sender.Run(std::move(error_response)); |
111 return; | 113 return; |
112 } | 114 } |
113 | 115 |
114 // Return error if |property_name| is unknown. | 116 // Return error if |property_name| is unknown. |
115 if (property_name != bluetooth_gatt_service::kUUIDProperty && | 117 if (property_name != bluetooth_gatt_service::kUUIDProperty && |
116 property_name != bluetooth_gatt_service::kIncludesProperty) { | 118 property_name != bluetooth_gatt_service::kIncludesProperty) { |
117 scoped_ptr<dbus::ErrorResponse> error_response = | 119 scoped_ptr<dbus::ErrorResponse> error_response = |
118 dbus::ErrorResponse::FromMethodCall( | 120 dbus::ErrorResponse::FromMethodCall( |
119 method_call, kErrorInvalidArgs, | 121 method_call, kErrorInvalidArgs, |
120 "No such property: '" + property_name + "'."); | 122 "No such property: '" + property_name + "'."); |
121 response_sender.Run(error_response.Pass()); | 123 response_sender.Run(std::move(error_response)); |
122 return; | 124 return; |
123 } | 125 } |
124 | 126 |
125 scoped_ptr<dbus::Response> response = | 127 scoped_ptr<dbus::Response> response = |
126 dbus::Response::FromMethodCall(method_call); | 128 dbus::Response::FromMethodCall(method_call); |
127 dbus::MessageWriter writer(response.get()); | 129 dbus::MessageWriter writer(response.get()); |
128 dbus::MessageWriter variant_writer(NULL); | 130 dbus::MessageWriter variant_writer(NULL); |
129 | 131 |
130 if (property_name == bluetooth_gatt_service::kUUIDProperty) { | 132 if (property_name == bluetooth_gatt_service::kUUIDProperty) { |
131 writer.OpenVariant("s", &variant_writer); | 133 writer.OpenVariant("s", &variant_writer); |
132 variant_writer.AppendString(uuid_); | 134 variant_writer.AppendString(uuid_); |
133 writer.CloseContainer(&variant_writer); | 135 writer.CloseContainer(&variant_writer); |
134 } else { | 136 } else { |
135 writer.OpenVariant("ao", &variant_writer); | 137 writer.OpenVariant("ao", &variant_writer); |
136 variant_writer.AppendArrayOfObjectPaths(includes_); | 138 variant_writer.AppendArrayOfObjectPaths(includes_); |
137 writer.CloseContainer(&variant_writer); | 139 writer.CloseContainer(&variant_writer); |
138 } | 140 } |
139 | 141 |
140 response_sender.Run(response.Pass()); | 142 response_sender.Run(std::move(response)); |
141 } | 143 } |
142 | 144 |
143 // Called by dbus:: when the Bluetooth daemon sets a single property of the | 145 // Called by dbus:: when the Bluetooth daemon sets a single property of the |
144 // service. | 146 // service. |
145 void Set(dbus::MethodCall* method_call, | 147 void Set(dbus::MethodCall* method_call, |
146 dbus::ExportedObject::ResponseSender response_sender) { | 148 dbus::ExportedObject::ResponseSender response_sender) { |
147 VLOG(2) << "BluetoothGattServiceServiceProvider::Set: " | 149 VLOG(2) << "BluetoothGattServiceServiceProvider::Set: " |
148 << object_path_.value(); | 150 << object_path_.value(); |
149 DCHECK(OnOriginThread()); | 151 DCHECK(OnOriginThread()); |
150 | 152 |
151 // All of the properties on this interface are read-only, so just return | 153 // All of the properties on this interface are read-only, so just return |
152 // error. | 154 // error. |
153 scoped_ptr<dbus::ErrorResponse> error_response = | 155 scoped_ptr<dbus::ErrorResponse> error_response = |
154 dbus::ErrorResponse::FromMethodCall(method_call, kErrorPropertyReadOnly, | 156 dbus::ErrorResponse::FromMethodCall(method_call, kErrorPropertyReadOnly, |
155 "All properties are read-only."); | 157 "All properties are read-only."); |
156 response_sender.Run(error_response.Pass()); | 158 response_sender.Run(std::move(error_response)); |
157 } | 159 } |
158 | 160 |
159 // Called by dbus:: when the Bluetooth daemon fetches all properties of the | 161 // Called by dbus:: when the Bluetooth daemon fetches all properties of the |
160 // service. | 162 // service. |
161 void GetAll(dbus::MethodCall* method_call, | 163 void GetAll(dbus::MethodCall* method_call, |
162 dbus::ExportedObject::ResponseSender response_sender) { | 164 dbus::ExportedObject::ResponseSender response_sender) { |
163 VLOG(2) << "BluetoothGattServiceServiceProvider::GetAll: " | 165 VLOG(2) << "BluetoothGattServiceServiceProvider::GetAll: " |
164 << object_path_.value(); | 166 << object_path_.value(); |
165 DCHECK(OnOriginThread()); | 167 DCHECK(OnOriginThread()); |
166 | 168 |
167 dbus::MessageReader reader(method_call); | 169 dbus::MessageReader reader(method_call); |
168 | 170 |
169 std::string interface_name; | 171 std::string interface_name; |
170 if (!reader.PopString(&interface_name) || reader.HasMoreData()) { | 172 if (!reader.PopString(&interface_name) || reader.HasMoreData()) { |
171 scoped_ptr<dbus::ErrorResponse> error_response = | 173 scoped_ptr<dbus::ErrorResponse> error_response = |
172 dbus::ErrorResponse::FromMethodCall(method_call, kErrorInvalidArgs, | 174 dbus::ErrorResponse::FromMethodCall(method_call, kErrorInvalidArgs, |
173 "Expected 's'."); | 175 "Expected 's'."); |
174 response_sender.Run(error_response.Pass()); | 176 response_sender.Run(std::move(error_response)); |
175 return; | 177 return; |
176 } | 178 } |
177 | 179 |
178 // Only the GATT service interface is allowed. | 180 // Only the GATT service interface is allowed. |
179 if (interface_name != | 181 if (interface_name != |
180 bluetooth_gatt_service::kBluetoothGattServiceInterface) { | 182 bluetooth_gatt_service::kBluetoothGattServiceInterface) { |
181 scoped_ptr<dbus::ErrorResponse> error_response = | 183 scoped_ptr<dbus::ErrorResponse> error_response = |
182 dbus::ErrorResponse::FromMethodCall( | 184 dbus::ErrorResponse::FromMethodCall( |
183 method_call, kErrorInvalidArgs, | 185 method_call, kErrorInvalidArgs, |
184 "No such interface: '" + interface_name + "'."); | 186 "No such interface: '" + interface_name + "'."); |
185 response_sender.Run(error_response.Pass()); | 187 response_sender.Run(std::move(error_response)); |
186 return; | 188 return; |
187 } | 189 } |
188 | 190 |
189 scoped_ptr<dbus::Response> response = | 191 scoped_ptr<dbus::Response> response = |
190 dbus::Response::FromMethodCall(method_call); | 192 dbus::Response::FromMethodCall(method_call); |
191 dbus::MessageWriter writer(response.get()); | 193 dbus::MessageWriter writer(response.get()); |
192 dbus::MessageWriter array_writer(NULL); | 194 dbus::MessageWriter array_writer(NULL); |
193 dbus::MessageWriter dict_entry_writer(NULL); | 195 dbus::MessageWriter dict_entry_writer(NULL); |
194 dbus::MessageWriter variant_writer(NULL); | 196 dbus::MessageWriter variant_writer(NULL); |
195 | 197 |
196 writer.OpenArray("{sv}", &array_writer); | 198 writer.OpenArray("{sv}", &array_writer); |
197 | 199 |
198 array_writer.OpenDictEntry(&dict_entry_writer); | 200 array_writer.OpenDictEntry(&dict_entry_writer); |
199 dict_entry_writer.AppendString(bluetooth_gatt_service::kUUIDProperty); | 201 dict_entry_writer.AppendString(bluetooth_gatt_service::kUUIDProperty); |
200 dict_entry_writer.AppendVariantOfString(uuid_); | 202 dict_entry_writer.AppendVariantOfString(uuid_); |
201 array_writer.CloseContainer(&dict_entry_writer); | 203 array_writer.CloseContainer(&dict_entry_writer); |
202 | 204 |
203 array_writer.OpenDictEntry(&dict_entry_writer); | 205 array_writer.OpenDictEntry(&dict_entry_writer); |
204 dict_entry_writer.AppendString(bluetooth_gatt_service::kIncludesProperty); | 206 dict_entry_writer.AppendString(bluetooth_gatt_service::kIncludesProperty); |
205 dict_entry_writer.OpenVariant("ao", &variant_writer); | 207 dict_entry_writer.OpenVariant("ao", &variant_writer); |
206 variant_writer.AppendArrayOfObjectPaths(includes_); | 208 variant_writer.AppendArrayOfObjectPaths(includes_); |
207 dict_entry_writer.CloseContainer(&variant_writer); | 209 dict_entry_writer.CloseContainer(&variant_writer); |
208 array_writer.CloseContainer(&dict_entry_writer); | 210 array_writer.CloseContainer(&dict_entry_writer); |
209 | 211 |
210 writer.CloseContainer(&array_writer); | 212 writer.CloseContainer(&array_writer); |
211 | 213 |
212 response_sender.Run(response.Pass()); | 214 response_sender.Run(std::move(response)); |
213 } | 215 } |
214 | 216 |
215 // Called by dbus:: when a method is exported. | 217 // Called by dbus:: when a method is exported. |
216 void OnExported(const std::string& interface_name, | 218 void OnExported(const std::string& interface_name, |
217 const std::string& method_name, | 219 const std::string& method_name, |
218 bool success) { | 220 bool success) { |
219 LOG_IF(WARNING, !success) << "Failed to export " << interface_name << "." | 221 LOG_IF(WARNING, !success) << "Failed to export " << interface_name << "." |
220 << method_name; | 222 << method_name; |
221 } | 223 } |
222 | 224 |
(...skipping 41 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
264 const std::vector<dbus::ObjectPath>& includes) { | 266 const std::vector<dbus::ObjectPath>& includes) { |
265 if (!bluez::BluezDBusManager::Get()->IsUsingStub()) { | 267 if (!bluez::BluezDBusManager::Get()->IsUsingStub()) { |
266 return new BluetoothGattServiceServiceProviderImpl(bus, object_path, uuid, | 268 return new BluetoothGattServiceServiceProviderImpl(bus, object_path, uuid, |
267 includes); | 269 includes); |
268 } | 270 } |
269 return new FakeBluetoothGattServiceServiceProvider(object_path, uuid, | 271 return new FakeBluetoothGattServiceServiceProvider(object_path, uuid, |
270 includes); | 272 includes); |
271 } | 273 } |
272 | 274 |
273 } // namespace bluez | 275 } // namespace bluez |
OLD | NEW |