| 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 273 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 284 bool success = false; | 284 bool success = false; |
| 285 | 285 |
| 286 if (bus_->Connect() && bus_->SetUpAsyncOperations()) { | 286 if (bus_->Connect() && bus_->SetUpAsyncOperations()) { |
| 287 // We should add the filter only once. Otherwise, HandleMessage() will | 287 // We should add the filter only once. Otherwise, HandleMessage() will |
| 288 // be called more than once. | 288 // be called more than once. |
| 289 if (!filter_added_) { | 289 if (!filter_added_) { |
| 290 bus_->AddFilterFunction(&ObjectProxy::HandleMessageThunk, this); | 290 bus_->AddFilterFunction(&ObjectProxy::HandleMessageThunk, this); |
| 291 filter_added_ = true; | 291 filter_added_ = true; |
| 292 } | 292 } |
| 293 // Add a match rule so the signal goes through HandleMessage(). | 293 // Add a match rule so the signal goes through HandleMessage(). |
| 294 // |
| 295 // We don't restrict the sender object path to be |object_path_| here, |
| 296 // to make it easy to test D-Bus signal handling with dbus-send, that |
| 297 // uses "/" as the sender object path. We can make the object path |
| 298 // restriction customizable when it becomes necessary. |
| 294 const std::string match_rule = | 299 const std::string match_rule = |
| 295 base::StringPrintf("type='signal', interface='%s', path='%s'", | 300 base::StringPrintf("type='signal', interface='%s'", |
| 296 interface_name.c_str(), | 301 interface_name.c_str()); |
| 297 object_path_.c_str()); | |
| 298 ScopedDBusError error; | 302 ScopedDBusError error; |
| 299 bus_->AddMatch(match_rule, error.get());; | 303 bus_->AddMatch(match_rule, error.get());; |
| 300 if (error.is_set()) { | 304 if (error.is_set()) { |
| 301 LOG(ERROR) << "Failed to add match rule: " << match_rule; | 305 LOG(ERROR) << "Failed to add match rule: " << match_rule; |
| 302 } else { | 306 } else { |
| 303 // Store the match rule, so that we can remove this in Detach(). | 307 // Store the match rule, so that we can remove this in Detach(). |
| 304 match_rules_.push_back(match_rule); | 308 match_rules_.push_back(match_rule); |
| 305 // Add the signal callback to the method table. | 309 // Add the signal callback to the method table. |
| 306 method_table_[absolute_signal_name] = signal_callback; | 310 method_table_[absolute_signal_name] = signal_callback; |
| 307 success = true; | 311 success = true; |
| (...skipping 26 matching lines...) Expand all Loading... |
| 334 bus_->AssertOnDBusThread(); | 338 bus_->AssertOnDBusThread(); |
| 335 if (dbus_message_get_type(raw_message) != DBUS_MESSAGE_TYPE_SIGNAL) | 339 if (dbus_message_get_type(raw_message) != DBUS_MESSAGE_TYPE_SIGNAL) |
| 336 return DBUS_HANDLER_RESULT_NOT_YET_HANDLED; | 340 return DBUS_HANDLER_RESULT_NOT_YET_HANDLED; |
| 337 | 341 |
| 338 // raw_message will be unrefed on exit of the function. Increment the | 342 // raw_message will be unrefed on exit of the function. Increment the |
| 339 // reference so we can use it in Signal. | 343 // reference so we can use it in Signal. |
| 340 dbus_message_ref(raw_message); | 344 dbus_message_ref(raw_message); |
| 341 scoped_ptr<Signal> signal( | 345 scoped_ptr<Signal> signal( |
| 342 Signal::FromRawMessage(raw_message)); | 346 Signal::FromRawMessage(raw_message)); |
| 343 | 347 |
| 344 // The signal is not coming from the remote object we are attaching to. | 348 VLOG(1) << "Signal received: " << signal->ToString(); |
| 345 if (signal->GetPath() != object_path_) | |
| 346 return DBUS_HANDLER_RESULT_NOT_YET_HANDLED; | |
| 347 | 349 |
| 348 const std::string interface = signal->GetInterface(); | 350 const std::string interface = signal->GetInterface(); |
| 349 const std::string member = signal->GetMember(); | 351 const std::string member = signal->GetMember(); |
| 350 | 352 |
| 351 // Check if we know about the signal. | 353 // Check if we know about the signal. |
| 352 const std::string absolute_signal_name = GetAbsoluteSignalName( | 354 const std::string absolute_signal_name = GetAbsoluteSignalName( |
| 353 interface, member); | 355 interface, member); |
| 354 MethodTable::const_iterator iter = method_table_.find(absolute_signal_name); | 356 MethodTable::const_iterator iter = method_table_.find(absolute_signal_name); |
| 355 if (iter == method_table_.end()) { | 357 if (iter == method_table_.end()) { |
| 356 // Don't know about the signal. | 358 // Don't know about the signal. |
| (...skipping 37 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 394 | 396 |
| 395 DBusHandlerResult ObjectProxy::HandleMessageThunk( | 397 DBusHandlerResult ObjectProxy::HandleMessageThunk( |
| 396 DBusConnection* connection, | 398 DBusConnection* connection, |
| 397 DBusMessage* raw_message, | 399 DBusMessage* raw_message, |
| 398 void* user_data) { | 400 void* user_data) { |
| 399 ObjectProxy* self = reinterpret_cast<ObjectProxy*>(user_data); | 401 ObjectProxy* self = reinterpret_cast<ObjectProxy*>(user_data); |
| 400 return self->HandleMessage(connection, raw_message); | 402 return self->HandleMessage(connection, raw_message); |
| 401 } | 403 } |
| 402 | 404 |
| 403 } // namespace dbus | 405 } // namespace dbus |
| OLD | NEW |