| 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" |
| 11 #include "base/logging.h" | 11 #include "base/logging.h" |
| 12 #include "base/message_loop.h" | 12 #include "base/message_loop.h" |
| 13 #include "base/message_loop_proxy.h" | 13 #include "base/message_loop_proxy.h" |
| 14 #include "base/stl_util.h" | 14 #include "base/stl_util.h" |
| 15 #include "base/synchronization/waitable_event.h" |
| 15 #include "base/threading/thread.h" | 16 #include "base/threading/thread.h" |
| 16 #include "base/threading/thread_restrictions.h" | 17 #include "base/threading/thread_restrictions.h" |
| 17 #include "base/time.h" | 18 #include "base/time.h" |
| 18 #include "dbus/exported_object.h" | 19 #include "dbus/exported_object.h" |
| 19 #include "dbus/object_path.h" | 20 #include "dbus/object_path.h" |
| 20 #include "dbus/object_proxy.h" | 21 #include "dbus/object_proxy.h" |
| 21 #include "dbus/scoped_dbus_error.h" | 22 #include "dbus/scoped_dbus_error.h" |
| 22 | 23 |
| 23 namespace dbus { | 24 namespace dbus { |
| 24 | 25 |
| (...skipping 218 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 243 return iter->second; | 244 return iter->second; |
| 244 } | 245 } |
| 245 | 246 |
| 246 scoped_refptr<ExportedObject> exported_object = | 247 scoped_refptr<ExportedObject> exported_object = |
| 247 new ExportedObject(this, object_path); | 248 new ExportedObject(this, object_path); |
| 248 exported_object_table_[object_path] = exported_object; | 249 exported_object_table_[object_path] = exported_object; |
| 249 | 250 |
| 250 return exported_object.get(); | 251 return exported_object.get(); |
| 251 } | 252 } |
| 252 | 253 |
| 254 void Bus::UnregisterExportedObject(const ObjectPath& object_path) { |
| 255 AssertOnOriginThread(); |
| 256 |
| 257 base::WaitableEvent completion(false, false); |
| 258 |
| 259 PostTaskToDBusThread(FROM_HERE, base::Bind( |
| 260 &Bus::UnregisterExportedObjectInternal, |
| 261 this, object_path, &completion)); |
| 262 |
| 263 completion.Wait(); |
| 264 } |
| 265 |
| 266 void Bus::UnregisterExportedObjectInternal(const ObjectPath& object_path, |
| 267 base::WaitableEvent* completion) { |
| 268 DCHECK(completion); |
| 269 AssertOnDBusThread(); |
| 270 |
| 271 // Make sure the requested object exists. |
| 272 ExportedObjectTable::iterator iter = exported_object_table_.find(object_path); |
| 273 if (iter == exported_object_table_.end()) |
| 274 return; |
| 275 |
| 276 iter->second->Unregister(); |
| 277 exported_object_table_.erase(iter); |
| 278 |
| 279 completion->Signal(); |
| 280 } |
| 281 |
| 253 bool Bus::Connect() { | 282 bool Bus::Connect() { |
| 254 // dbus_bus_get_private() and dbus_bus_get() are blocking calls. | 283 // dbus_bus_get_private() and dbus_bus_get() are blocking calls. |
| 255 AssertOnDBusThread(); | 284 AssertOnDBusThread(); |
| 256 | 285 |
| 257 // Check if it's already initialized. | 286 // Check if it's already initialized. |
| 258 if (connection_) | 287 if (connection_) |
| 259 return true; | 288 return true; |
| 260 | 289 |
| 261 ScopedDBusError error; | 290 ScopedDBusError error; |
| 262 const DBusBusType dbus_bus_type = static_cast<DBusBusType>(bus_type_); | 291 const DBusBusType dbus_bus_type = static_cast<DBusBusType>(bus_type_); |
| (...skipping 526 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 789 } | 818 } |
| 790 | 819 |
| 791 void Bus::OnDispatchStatusChangedThunk(DBusConnection* connection, | 820 void Bus::OnDispatchStatusChangedThunk(DBusConnection* connection, |
| 792 DBusDispatchStatus status, | 821 DBusDispatchStatus status, |
| 793 void* data) { | 822 void* data) { |
| 794 Bus* self = static_cast<Bus*>(data); | 823 Bus* self = static_cast<Bus*>(data); |
| 795 return self->OnDispatchStatusChanged(connection, status); | 824 return self->OnDispatchStatusChanged(connection, status); |
| 796 } | 825 } |
| 797 | 826 |
| 798 } // namespace dbus | 827 } // namespace dbus |
| OLD | NEW |