| OLD | NEW |
| 1 // Copyright (c) 2011 The Chromium Authors. All rights reserved. | 1 // Copyright (c) 2011 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/metrics/histogram.h" | 10 #include "base/metrics/histogram.h" |
| (...skipping 106 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 117 this, | 117 this, |
| 118 interface_name, | 118 interface_name, |
| 119 signal_name, | 119 signal_name, |
| 120 signal_callback, | 120 signal_callback, |
| 121 on_connected_callback)); | 121 on_connected_callback)); |
| 122 } | 122 } |
| 123 | 123 |
| 124 void ObjectProxy::Detach() { | 124 void ObjectProxy::Detach() { |
| 125 bus_->AssertOnDBusThread(); | 125 bus_->AssertOnDBusThread(); |
| 126 | 126 |
| 127 if (filter_added_) | 127 if (filter_added_) { |
| 128 bus_->RemoveFilterFunction(&ObjectProxy::HandleMessageThunk, this); | 128 if (!bus_->RemoveFilterFunction(&ObjectProxy::HandleMessageThunk, this)) { |
| 129 LOG(ERROR) << "Failed to remove filter function"; |
| 130 } |
| 131 } |
| 129 | 132 |
| 130 for (size_t i = 0; i < match_rules_.size(); ++i) { | 133 for (size_t i = 0; i < match_rules_.size(); ++i) { |
| 131 ScopedDBusError error; | 134 ScopedDBusError error; |
| 132 bus_->RemoveMatch(match_rules_[i], error.get()); | 135 bus_->RemoveMatch(match_rules_[i], error.get()); |
| 133 if (error.is_set()) { | 136 if (error.is_set()) { |
| 134 // There is nothing we can do to recover, so just print the error. | 137 // There is nothing we can do to recover, so just print the error. |
| 135 LOG(ERROR) << "Failed to remove match rule: " << match_rules_[i]; | 138 LOG(ERROR) << "Failed to remove match rule: " << match_rules_[i]; |
| 136 } | 139 } |
| 137 } | 140 } |
| 138 } | 141 } |
| (...skipping 131 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 270 return; | 273 return; |
| 271 } | 274 } |
| 272 | 275 |
| 273 // Will become true, if everything is successful. | 276 // Will become true, if everything is successful. |
| 274 bool success = false; | 277 bool success = false; |
| 275 | 278 |
| 276 if (bus_->Connect() && bus_->SetUpAsyncOperations()) { | 279 if (bus_->Connect() && bus_->SetUpAsyncOperations()) { |
| 277 // We should add the filter only once. Otherwise, HandleMessage() will | 280 // We should add the filter only once. Otherwise, HandleMessage() will |
| 278 // be called more than once. | 281 // be called more than once. |
| 279 if (!filter_added_) { | 282 if (!filter_added_) { |
| 280 bus_->AddFilterFunction(&ObjectProxy::HandleMessageThunk, this); | 283 if (bus_->AddFilterFunction(&ObjectProxy::HandleMessageThunk, this)) { |
| 281 filter_added_ = true; | 284 filter_added_ = true; |
| 285 } else { |
| 286 LOG(ERROR) << "Failed to add filter function"; |
| 287 } |
| 282 } | 288 } |
| 283 // Add a match rule so the signal goes through HandleMessage(). | 289 // Add a match rule so the signal goes through HandleMessage(). |
| 284 // | 290 // |
| 285 // We don't restrict the sender object path to be |object_path_| here, | 291 // We don't restrict the sender object path to be |object_path_| here, |
| 286 // to make it easy to test D-Bus signal handling with dbus-send, that | 292 // to make it easy to test D-Bus signal handling with dbus-send, that |
| 287 // uses "/" as the sender object path. We can make the object path | 293 // uses "/" as the sender object path. We can make the object path |
| 288 // restriction customizable when it becomes necessary. | 294 // restriction customizable when it becomes necessary. |
| 289 const std::string match_rule = | 295 const std::string match_rule = |
| 290 base::StringPrintf("type='signal', interface='%s'", | 296 base::StringPrintf("type='signal', interface='%s'", |
| 291 interface_name.c_str()); | 297 interface_name.c_str()); |
| (...skipping 94 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 386 | 392 |
| 387 DBusHandlerResult ObjectProxy::HandleMessageThunk( | 393 DBusHandlerResult ObjectProxy::HandleMessageThunk( |
| 388 DBusConnection* connection, | 394 DBusConnection* connection, |
| 389 DBusMessage* raw_message, | 395 DBusMessage* raw_message, |
| 390 void* user_data) { | 396 void* user_data) { |
| 391 ObjectProxy* self = reinterpret_cast<ObjectProxy*>(user_data); | 397 ObjectProxy* self = reinterpret_cast<ObjectProxy*>(user_data); |
| 392 return self->HandleMessage(connection, raw_message); | 398 return self->HandleMessage(connection, raw_message); |
| 393 } | 399 } |
| 394 | 400 |
| 395 } // namespace dbus | 401 } // namespace dbus |
| OLD | NEW |