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 // 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 421 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
432 } | 432 } |
433 | 433 |
434 void Bus::Send(DBusMessage* request, uint32* serial) { | 434 void Bus::Send(DBusMessage* request, uint32* serial) { |
435 DCHECK(connection_); | 435 DCHECK(connection_); |
436 AssertOnDBusThread(); | 436 AssertOnDBusThread(); |
437 | 437 |
438 const bool success = dbus_connection_send(connection_, request, serial); | 438 const bool success = dbus_connection_send(connection_, request, serial); |
439 CHECK(success) << "Unable to allocate memory"; | 439 CHECK(success) << "Unable to allocate memory"; |
440 } | 440 } |
441 | 441 |
442 void Bus::AddFilterFunction(DBusHandleMessageFunction filter_function, | 442 bool Bus::AddFilterFunction(DBusHandleMessageFunction filter_function, |
443 void* user_data) { | 443 void* user_data) { |
444 DCHECK(connection_); | 444 DCHECK(connection_); |
445 AssertOnDBusThread(); | 445 AssertOnDBusThread(); |
446 | 446 |
447 if (filter_functions_added_.find(filter_function) != | 447 std::pair<DBusHandleMessageFunction, void*> filter_data_pair = |
448 std::make_pair(filter_function, user_data); | |
449 if (filter_functions_added_.find(filter_data_pair) != | |
448 filter_functions_added_.end()) { | 450 filter_functions_added_.end()) { |
449 LOG(ERROR) << "Filter function already exists: " << filter_function; | 451 VLOG(1) << "Filter function already exists: " << filter_function |
450 return; | 452 << " with associated data: " << user_data; |
453 return false; | |
cwolfe
2011/10/05 22:39:16
Do not know our rules for logging pointer-like thi
satorux1
2011/10/05 23:04:40
I thought our logging library automatically conver
| |
451 } | 454 } |
452 | 455 |
453 const bool success = dbus_connection_add_filter( | 456 const bool success = dbus_connection_add_filter( |
454 connection_, filter_function, user_data, NULL); | 457 connection_, filter_function, user_data, NULL); |
455 CHECK(success) << "Unable to allocate memory"; | 458 CHECK(success) << "Unable to allocate memory"; |
456 filter_functions_added_.insert(filter_function); | 459 filter_functions_added_.insert(filter_data_pair); |
460 return true; | |
457 } | 461 } |
458 | 462 |
459 void Bus::RemoveFilterFunction(DBusHandleMessageFunction filter_function, | 463 bool Bus::RemoveFilterFunction(DBusHandleMessageFunction filter_function, |
460 void* user_data) { | 464 void* user_data) { |
461 DCHECK(connection_); | 465 DCHECK(connection_); |
462 AssertOnDBusThread(); | 466 AssertOnDBusThread(); |
463 | 467 |
464 if (filter_functions_added_.find(filter_function) == | 468 std::pair<DBusHandleMessageFunction, void*> filter_data_pair = |
469 std::make_pair(filter_function, user_data); | |
470 if (filter_functions_added_.find(filter_data_pair) == | |
465 filter_functions_added_.end()) { | 471 filter_functions_added_.end()) { |
466 LOG(ERROR) << "Requested to remove an unknown filter function: " | 472 VLOG(1) << "Requested to remove an unknown filter function: " |
467 << filter_function; | 473 << filter_function |
468 return; | 474 << " with associated data: " << user_data; |
475 return false; | |
469 } | 476 } |
470 | 477 |
471 dbus_connection_remove_filter(connection_, filter_function, user_data); | 478 dbus_connection_remove_filter(connection_, filter_function, user_data); |
472 filter_functions_added_.erase(filter_function); | 479 filter_functions_added_.erase(filter_data_pair); |
480 return true; | |
473 } | 481 } |
474 | 482 |
475 void Bus::AddMatch(const std::string& match_rule, DBusError* error) { | 483 void Bus::AddMatch(const std::string& match_rule, DBusError* error) { |
476 DCHECK(connection_); | 484 DCHECK(connection_); |
477 AssertOnDBusThread(); | 485 AssertOnDBusThread(); |
478 | 486 |
479 if (match_rules_added_.find(match_rule) != match_rules_added_.end()) { | 487 if (match_rules_added_.find(match_rule) != match_rules_added_.end()) { |
480 LOG(ERROR) << "Match rule already exists: " << match_rule; | 488 LOG(ERROR) << "Match rule already exists: " << match_rule; |
481 return; | 489 return; |
482 } | 490 } |
(...skipping 249 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
732 } | 740 } |
733 | 741 |
734 void Bus::OnDispatchStatusChangedThunk(DBusConnection* connection, | 742 void Bus::OnDispatchStatusChangedThunk(DBusConnection* connection, |
735 DBusDispatchStatus status, | 743 DBusDispatchStatus status, |
736 void* data) { | 744 void* data) { |
737 Bus* self = static_cast<Bus*>(data); | 745 Bus* self = static_cast<Bus*>(data); |
738 return self->OnDispatchStatusChanged(connection, status); | 746 return self->OnDispatchStatusChanged(connection, status); |
739 } | 747 } |
740 | 748 |
741 } // namespace dbus | 749 } // namespace dbus |
OLD | NEW |