Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(264)

Side by Side Diff: dbus/bus.cc

Issue 12088068: DBus: Bus::AddMatch and RemoveMatch support repeated rules. (Closed) Base URL: http://git.chromium.org/chromium/src.git@master
Patch Set: RemoveMatch returns a bool. Created 7 years, 10 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch
« no previous file with comments | « dbus/bus.h ('k') | dbus/bus_unittest.cc » ('j') | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
OLDNEW
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"
(...skipping 569 matching lines...) Expand 10 before | Expand all | Expand 10 after
580 580
581 dbus_connection_remove_filter(connection_, filter_function, user_data); 581 dbus_connection_remove_filter(connection_, filter_function, user_data);
582 filter_functions_added_.erase(filter_data_pair); 582 filter_functions_added_.erase(filter_data_pair);
583 return true; 583 return true;
584 } 584 }
585 585
586 void Bus::AddMatch(const std::string& match_rule, DBusError* error) { 586 void Bus::AddMatch(const std::string& match_rule, DBusError* error) {
587 DCHECK(connection_); 587 DCHECK(connection_);
588 AssertOnDBusThread(); 588 AssertOnDBusThread();
589 589
590 if (match_rules_added_.find(match_rule) != match_rules_added_.end()) { 590 std::map<std::string, int>::iterator iter =
591 match_rules_added_.find(match_rule);
592 if (iter != match_rules_added_.end()) {
593 // The already existing rule's counter is incremented.
594 iter->second++;
595
591 VLOG(1) << "Match rule already exists: " << match_rule; 596 VLOG(1) << "Match rule already exists: " << match_rule;
592 return; 597 return;
593 } 598 }
594 599
595 dbus_bus_add_match(connection_, match_rule.c_str(), error); 600 dbus_bus_add_match(connection_, match_rule.c_str(), error);
596 match_rules_added_.insert(match_rule); 601 match_rules_added_[match_rule] = 1;
597 } 602 }
598 603
599 void Bus::RemoveMatch(const std::string& match_rule, DBusError* error) { 604 bool Bus::RemoveMatch(const std::string& match_rule, DBusError* error) {
600 DCHECK(connection_); 605 DCHECK(connection_);
601 AssertOnDBusThread(); 606 AssertOnDBusThread();
602 607
603 if (match_rules_added_.find(match_rule) == match_rules_added_.end()) { 608 std::map<std::string, int>::iterator iter =
609 match_rules_added_.find(match_rule);
610 if (iter == match_rules_added_.end()) {
604 LOG(ERROR) << "Requested to remove an unknown match rule: " << match_rule; 611 LOG(ERROR) << "Requested to remove an unknown match rule: " << match_rule;
605 return; 612 return false;
606 } 613 }
607 614
608 dbus_bus_remove_match(connection_, match_rule.c_str(), error); 615 // The rule's counter is decremented and the rule is deleted when reachs 0.
609 match_rules_added_.erase(match_rule); 616 iter->second--;
617 if (iter->second == 0) {
618 dbus_bus_remove_match(connection_, match_rule.c_str(), error);
619 match_rules_added_.erase(match_rule);
620 }
621 return true;
610 } 622 }
611 623
612 bool Bus::TryRegisterObjectPath(const ObjectPath& object_path, 624 bool Bus::TryRegisterObjectPath(const ObjectPath& object_path,
613 const DBusObjectPathVTable* vtable, 625 const DBusObjectPathVTable* vtable,
614 void* user_data, 626 void* user_data,
615 DBusError* error) { 627 DBusError* error) {
616 DCHECK(connection_); 628 DCHECK(connection_);
617 AssertOnDBusThread(); 629 AssertOnDBusThread();
618 630
619 if (registered_object_paths_.find(object_path) != 631 if (registered_object_paths_.find(object_path) !=
(...skipping 223 matching lines...) Expand 10 before | Expand all | Expand 10 after
843 } 855 }
844 856
845 void Bus::OnDispatchStatusChangedThunk(DBusConnection* connection, 857 void Bus::OnDispatchStatusChangedThunk(DBusConnection* connection,
846 DBusDispatchStatus status, 858 DBusDispatchStatus status,
847 void* data) { 859 void* data) {
848 Bus* self = static_cast<Bus*>(data); 860 Bus* self = static_cast<Bus*>(data);
849 self->OnDispatchStatusChanged(connection, status); 861 self->OnDispatchStatusChanged(connection, status);
850 } 862 }
851 863
852 } // namespace dbus 864 } // namespace dbus
OLDNEW
« no previous file with comments | « dbus/bus.h ('k') | dbus/bus_unittest.cc » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698