OLD | NEW |
---|---|
1 // Copyright (c) 2012 The Chromium Authors. All rights reserved. | 1 // Copyright (c) 2012 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 // TODO(satorux): | 5 // TODO(satorux): |
6 // - Handle "disconnected" signal. | 6 // - Handle "disconnected" signal. |
7 | 7 |
8 #include "dbus/bus.h" | 8 #include "dbus/bus.h" |
9 | 9 |
10 #include "base/bind.h" | 10 #include "base/bind.h" |
(...skipping 217 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
228 return iter->second; | 228 return iter->second; |
229 } | 229 } |
230 | 230 |
231 scoped_refptr<ObjectProxy> object_proxy = | 231 scoped_refptr<ObjectProxy> object_proxy = |
232 new ObjectProxy(this, service_name, object_path, options); | 232 new ObjectProxy(this, service_name, object_path, options); |
233 object_proxy_table_[key] = object_proxy; | 233 object_proxy_table_[key] = object_proxy; |
234 | 234 |
235 return object_proxy.get(); | 235 return object_proxy.get(); |
236 } | 236 } |
237 | 237 |
238 bool Bus::RemoveObjectProxy(const std::string& service_name, | |
239 const ObjectPath& object_path, | |
240 OnRemoveObjectProxyCallback callback) { | |
241 return RemoveObjectProxyWithOptions(service_name, object_path, | |
242 ObjectProxy::DEFAULT_OPTIONS, | |
243 callback); | |
244 } | |
245 | |
246 bool Bus::RemoveObjectProxyWithOptions(const std::string& service_name, | |
247 const dbus::ObjectPath& object_path, | |
248 int options, | |
249 OnRemoveObjectProxyCallback callback) { | |
250 AssertOnOriginThread(); | |
251 | |
252 // Check if we have the requested object proxy. | |
253 const ObjectProxyTable::key_type key(service_name + object_path.value(), | |
254 options); | |
255 ObjectProxyTable::iterator iter = object_proxy_table_.find(key); | |
256 if (iter != object_proxy_table_.end()) { | |
257 // Object is present. Remove it now and Detach in the DBus thread. | |
258 PostTaskToDBusThread(FROM_HERE, base::Bind( | |
259 &Bus::RemoveObjectProxyInternal, | |
260 this, iter->second, service_name, object_path, options, callback)); | |
261 | |
262 object_proxy_table_.erase(iter); | |
263 return true; | |
264 } | |
265 return false; | |
266 } | |
267 | |
268 void Bus::RemoveObjectProxyInternal( | |
269 scoped_refptr<dbus::ObjectProxy> object_proxy, | |
270 const std::string& service_name, | |
271 const dbus::ObjectPath& object_path, | |
272 int options, | |
273 OnRemoveObjectProxyCallback callback) { | |
274 AssertOnDBusThread(); | |
275 | |
276 object_proxy.get()->Detach(); | |
277 | |
278 PostTaskToOriginThread(FROM_HERE, | |
279 base::Bind(&Bus::OnRemoveObjectProxy, | |
280 this, | |
281 callback, | |
282 service_name, | |
283 object_path, | |
284 options)); | |
satorux1
2013/01/25 01:46:06
I think you don't need OnRemoveObjectProxy.
You s
deymo
2013/01/25 20:50:55
Done.
| |
285 } | |
286 | |
287 void Bus::OnRemoveObjectProxy(OnRemoveObjectProxyCallback callback, | |
288 const std::string& service_name, | |
289 const dbus::ObjectPath& object_path, | |
290 int options) { | |
291 AssertOnOriginThread(); | |
292 | |
293 callback.Run(service_name, object_path, options); | |
294 } | |
295 | |
238 ExportedObject* Bus::GetExportedObject(const ObjectPath& object_path) { | 296 ExportedObject* Bus::GetExportedObject(const ObjectPath& object_path) { |
239 AssertOnOriginThread(); | 297 AssertOnOriginThread(); |
240 | 298 |
241 // Check if we already have the requested exported object. | 299 // Check if we already have the requested exported object. |
242 ExportedObjectTable::iterator iter = exported_object_table_.find(object_path); | 300 ExportedObjectTable::iterator iter = exported_object_table_.find(object_path); |
243 if (iter != exported_object_table_.end()) { | 301 if (iter != exported_object_table_.end()) { |
244 return iter->second; | 302 return iter->second; |
245 } | 303 } |
246 | 304 |
247 scoped_refptr<ExportedObject> exported_object = | 305 scoped_refptr<ExportedObject> exported_object = |
(...skipping 159 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
407 | 465 |
408 bool success = Connect(); | 466 bool success = Connect(); |
409 if (success) | 467 if (success) |
410 success = RequestOwnershipAndBlock(service_name); | 468 success = RequestOwnershipAndBlock(service_name); |
411 | 469 |
412 PostTaskToOriginThread(FROM_HERE, | 470 PostTaskToOriginThread(FROM_HERE, |
413 base::Bind(&Bus::OnOwnership, | 471 base::Bind(&Bus::OnOwnership, |
414 this, | 472 this, |
415 on_ownership_callback, | 473 on_ownership_callback, |
416 service_name, | 474 service_name, |
417 success)); | 475 success)); |
satorux1
2013/01/25 01:46:06
While you are at it, could you remove OnOwnership?
deymo
2013/01/25 20:50:55
Done.
| |
418 } | 476 } |
419 | 477 |
420 void Bus::OnOwnership(OnOwnershipCallback on_ownership_callback, | 478 void Bus::OnOwnership(OnOwnershipCallback on_ownership_callback, |
421 const std::string& service_name, | 479 const std::string& service_name, |
422 bool success) { | 480 bool success) { |
423 AssertOnOriginThread(); | 481 AssertOnOriginThread(); |
424 | 482 |
425 on_ownership_callback.Run(service_name, success); | 483 on_ownership_callback.Run(service_name, success); |
426 } | 484 } |
427 | 485 |
(...skipping 415 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
843 } | 901 } |
844 | 902 |
845 void Bus::OnDispatchStatusChangedThunk(DBusConnection* connection, | 903 void Bus::OnDispatchStatusChangedThunk(DBusConnection* connection, |
846 DBusDispatchStatus status, | 904 DBusDispatchStatus status, |
847 void* data) { | 905 void* data) { |
848 Bus* self = static_cast<Bus*>(data); | 906 Bus* self = static_cast<Bus*>(data); |
849 self->OnDispatchStatusChanged(connection, status); | 907 self->OnDispatchStatusChanged(connection, status); |
850 } | 908 } |
851 | 909 |
852 } // namespace dbus | 910 } // namespace dbus |
OLD | NEW |