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 #include "dbus/bus.h" | 5 #include "dbus/bus.h" |
6 | 6 |
7 #include "base/bind.h" | 7 #include "base/bind.h" |
8 #include "base/logging.h" | 8 #include "base/logging.h" |
9 #include "base/message_loop.h" | 9 #include "base/message_loop.h" |
10 #include "base/message_loop_proxy.h" | 10 #include "base/message_loop_proxy.h" |
11 #include "base/stl_util.h" | 11 #include "base/stl_util.h" |
12 #include "base/threading/thread.h" | 12 #include "base/threading/thread.h" |
13 #include "base/threading/thread_restrictions.h" | 13 #include "base/threading/thread_restrictions.h" |
14 #include "base/time.h" | 14 #include "base/time.h" |
15 #include "dbus/exported_object.h" | 15 #include "dbus/exported_object.h" |
| 16 #include "dbus/object_manager.h" |
| 17 #include "dbus/object_path.h" |
16 #include "dbus/object_proxy.h" | 18 #include "dbus/object_proxy.h" |
17 #include "dbus/scoped_dbus_error.h" | 19 #include "dbus/scoped_dbus_error.h" |
18 | 20 |
19 namespace dbus { | 21 namespace dbus { |
20 | 22 |
21 namespace { | 23 namespace { |
22 | 24 |
23 const char kDisconnectedSignal[] = "Disconnected"; | 25 const char kDisconnectedSignal[] = "Disconnected"; |
24 const char kDisconnectedMatchRule[] = | 26 const char kDisconnectedMatchRule[] = |
25 "type='signal', path='/org/freedesktop/DBus/Local'," | 27 "type='signal', path='/org/freedesktop/DBus/Local'," |
(...skipping 289 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
315 this, exported_object)); | 317 this, exported_object)); |
316 } | 318 } |
317 | 319 |
318 void Bus::UnregisterExportedObjectInternal( | 320 void Bus::UnregisterExportedObjectInternal( |
319 scoped_refptr<dbus::ExportedObject> exported_object) { | 321 scoped_refptr<dbus::ExportedObject> exported_object) { |
320 AssertOnDBusThread(); | 322 AssertOnDBusThread(); |
321 | 323 |
322 exported_object->Unregister(); | 324 exported_object->Unregister(); |
323 } | 325 } |
324 | 326 |
| 327 ObjectManager* Bus::GetObjectManager(const std::string& service_name, |
| 328 const ObjectPath& object_path) { |
| 329 AssertOnOriginThread(); |
| 330 |
| 331 // Check if we already have the requested object manager. |
| 332 const ObjectManagerTable::key_type key(service_name + object_path.value()); |
| 333 ObjectManagerTable::iterator iter = object_manager_table_.find(key); |
| 334 if (iter != object_manager_table_.end()) { |
| 335 return iter->second; |
| 336 } |
| 337 |
| 338 scoped_refptr<ObjectManager> object_manager = |
| 339 new ObjectManager(this, service_name, object_path); |
| 340 object_manager_table_[key] = object_manager; |
| 341 |
| 342 return object_manager.get(); |
| 343 } |
| 344 |
| 345 void Bus::RemoveObjectManager(const std::string& service_name, |
| 346 const ObjectPath& object_path) { |
| 347 AssertOnOriginThread(); |
| 348 |
| 349 const ObjectManagerTable::key_type key(service_name + object_path.value()); |
| 350 ObjectManagerTable::iterator iter = object_manager_table_.find(key); |
| 351 if (iter == object_manager_table_.end()) |
| 352 return; |
| 353 |
| 354 scoped_refptr<ObjectManager> object_manager = iter->second; |
| 355 object_manager_table_.erase(iter); |
| 356 } |
| 357 |
| 358 void Bus::GetManagedObjects() { |
| 359 for (ObjectManagerTable::iterator iter = object_manager_table_.begin(); |
| 360 iter != object_manager_table_.end(); ++iter) { |
| 361 iter->second->GetManagedObjects(); |
| 362 } |
| 363 } |
| 364 |
325 bool Bus::Connect() { | 365 bool Bus::Connect() { |
326 // dbus_bus_get_private() and dbus_bus_get() are blocking calls. | 366 // dbus_bus_get_private() and dbus_bus_get() are blocking calls. |
327 AssertOnDBusThread(); | 367 AssertOnDBusThread(); |
328 | 368 |
329 // Check if it's already initialized. | 369 // Check if it's already initialized. |
330 if (connection_) | 370 if (connection_) |
331 return true; | 371 return true; |
332 | 372 |
333 ScopedDBusError error; | 373 ScopedDBusError error; |
334 if (bus_type_ == CUSTOM_ADDRESS) { | 374 if (bus_type_ == CUSTOM_ADDRESS) { |
(...skipping 599 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
934 kDisconnectedSignal)) { | 974 kDisconnectedSignal)) { |
935 Bus* self = static_cast<Bus*>(data); | 975 Bus* self = static_cast<Bus*>(data); |
936 self->AssertOnDBusThread(); | 976 self->AssertOnDBusThread(); |
937 self->OnConnectionDisconnected(connection); | 977 self->OnConnectionDisconnected(connection); |
938 return DBUS_HANDLER_RESULT_HANDLED; | 978 return DBUS_HANDLER_RESULT_HANDLED; |
939 } | 979 } |
940 return DBUS_HANDLER_RESULT_NOT_YET_HANDLED; | 980 return DBUS_HANDLER_RESULT_NOT_YET_HANDLED; |
941 } | 981 } |
942 | 982 |
943 } // namespace dbus | 983 } // namespace dbus |
OLD | NEW |