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

Side by Side Diff: src/service_manager.cc

Issue 5380002: cashew: defer all D-Bus signal processing to main loop (Closed) Base URL: ssh://git@gitrw.chromium.org:9222/cashew.git@master
Patch Set: Created 10 years 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 | Annotate | Revision Log
« src/property_changed_handler.cc ('K') | « src/service_manager.h ('k') | no next file » | 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) 2010 The Chromium OS Authors. All rights reserved. 1 // Copyright (c) 2010 The Chromium OS 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 "src/service_manager.h" 5 #include "src/service_manager.h"
6 6
7 #include <glog/logging.h> 7 #include <glog/logging.h>
8 8
9 #include "src/cashew_server.h" 9 #include "src/cashew_server.h"
10 #include "src/service.h" 10 #include "src/service.h"
(...skipping 15 matching lines...) Expand all
26 static const char *kFlimflamStateOnline = "online"; 26 static const char *kFlimflamStateOnline = "online";
27 27
28 // Flimflam service types 28 // Flimflam service types
29 static const char *kTypeCellular = "cellular"; 29 static const char *kTypeCellular = "cellular";
30 30
31 // GetFlimflamProperties retry interval 31 // GetFlimflamProperties retry interval
32 static const guint kSecondsPerMinute = 60; 32 static const guint kSecondsPerMinute = 60;
33 static const guint kGetFlimflamPropertiesIntervalSeconds = 33 static const guint kGetFlimflamPropertiesIntervalSeconds =
34 1 * kSecondsPerMinute; 34 1 * kSecondsPerMinute;
35 35
36 ServiceManager::ServiceManager(DBus::Connection& connection) // NOLINT 36 ServiceManager::ServiceManager(DBus::Connection& connection, // NOLINT
37 GMainLoop * const main_loop)
37 : DBus::ObjectProxy(connection, kFlimflamManagerPath, 38 : DBus::ObjectProxy(connection, kFlimflamManagerPath,
38 kFlimflamManagerName), 39 kFlimflamManagerName),
39 connection_(connection), cashew_server_(NULL), 40 connection_(connection), main_loop_(CHECK_NOTNULL(main_loop)),
40 default_technology_(Service::kTypeUnknown), 41 cashew_server_(NULL), default_technology_(Service::kTypeUnknown),
41 default_cellular_service_(NULL), 42 default_cellular_service_(NULL),
42 connectivity_state_(kConnectivityStateUnknown), 43 connectivity_state_(kConnectivityStateUnknown),
43 get_properties_source_id_(0), retrying_get_properties_(false) { 44 get_properties_source_id_(0), retrying_get_properties_(false) {
44 // schedule a GetProperties() call to Flimflam to init our state 45 // schedule a GetProperties() call to Flimflam to init our state
45 // we'll keep trying periodically until we succeed 46 // we'll keep trying periodically until we succeed
46 // we'll subsequently update this state by monitoring PropertyChanged signals 47 // we'll subsequently update this state by monitoring PropertyChanged signals
47 get_properties_source_id_ = 48 get_properties_source_id_ =
48 g_idle_add(StaticGetFlimflamPropertiesCallback, this); 49 g_idle_add(StaticGetFlimflamPropertiesCallback, this);
49 if (get_properties_source_id_ == 0) { 50 if (get_properties_source_id_ == 0) {
50 LOG(ERROR) << "ctor: g_idle_add failed"; 51 LOG(ERROR) << "ctor: g_idle_add failed";
51 } 52 }
53 property_changed_handler_.delegate(this);
52 } 54 }
53 55
54 ServiceManager::~ServiceManager() { 56 ServiceManager::~ServiceManager() {
57 DCHECK(!g_main_loop_is_running(main_loop_));
55 ClearDefaultCellularService(); 58 ClearDefaultCellularService();
56 DeleteServices(&services_); 59 DeleteServices(&services_);
57 if (get_properties_source_id_ != 0 && 60 if (get_properties_source_id_ != 0 &&
58 !g_source_remove(get_properties_source_id_)) { 61 !g_source_remove(get_properties_source_id_)) {
59 DLOG(WARNING) << "dtor: g_source_remove failed"; 62 DLOG(WARNING) << "dtor: g_source_remove failed";
60 } 63 }
61 } 64 }
62 65
63 const Service* ServiceManager::GetService(const std::string& service_path) 66 const Service* ServiceManager::GetService(const std::string& service_path)
64 const { 67 const {
(...skipping 37 matching lines...) Expand 10 before | Expand all | Expand 10 after
102 return true; 105 return true;
103 } 106 }
104 return false; 107 return false;
105 } 108 }
106 109
107 // Flimflam Manager D-Bus Proxy methods 110 // Flimflam Manager D-Bus Proxy methods
108 111
109 void ServiceManager::PropertyChanged(const std::string& property_name, 112 void ServiceManager::PropertyChanged(const std::string& property_name,
110 const DBus::Variant& new_value) { 113 const DBus::Variant& new_value) {
111 DLOG(INFO) << "PropertyChanged: property_name = " << property_name; 114 DLOG(INFO) << "PropertyChanged: property_name = " << property_name;
115 // Queue a tuple representing this signal for later processing from the glib
116 // main loop. We do this to avoid libdbus-c++ deadlocks that can occur when
117 // sending a dbus message from within a dbus callback like this one.
118 PropertyChangedSignal signal(property_name, new_value);
119 property_changed_handler_.EnqueueSignal(signal);
120 }
121
122 void ServiceManager::StateChanged(const std::string& new_state_string) {
123 DLOG(INFO) << "StateChanged: new_state_string = " << new_state_string;
124 // Queue a tuple representing this signal for later processing from the glib
125 // main loop. See comments in PropertyChanged above.
126 DBus::Variant new_value;
127 new_value.writer().append_string(new_state_string.c_str());
128 // StateChanged is a special case of PropertyChanged, so we just construct a
129 // PropertyChanged signal containing the new state info
130 PropertyChangedSignal signal(kStateProperty, new_value);
131 property_changed_handler_.EnqueueSignal(signal);
132 }
133
134 // PropertyChangedDelegate methods
135
136 void ServiceManager::OnPropertyChanged(const PropertyChangedHandler *handler,
137 const std::string& property_name,
138 const DBus::Variant& new_value) {
139 DCHECK(handler == &property_changed_handler_);
140 DLOG(INFO) << "OnPropertyChanged: property_name = " << property_name;
112 if (property_name == kDefaultTechnologyProperty) { 141 if (property_name == kDefaultTechnologyProperty) {
113 OnDefaultTechnologyUpdate(new_value.reader().get_string()); 142 OnDefaultTechnologyUpdate(new_value.reader().get_string());
114 } else if (property_name == kServicesProperty) { 143 } else if (property_name == kServicesProperty) {
115 // interpret new_value as a vector of service paths 144 // interpret new_value as a vector of service paths
116 ServicePathList paths; 145 ServicePathList paths;
117 DBus::MessageIter reader = new_value.reader(); 146 DBus::MessageIter reader = new_value.reader();
118 reader >> paths; 147 reader >> paths;
119 OnServicesUpdate(paths); 148 OnServicesUpdate(paths);
120 } else if (property_name == kStateProperty) { 149 } else if (property_name == kStateProperty) {
121 // this has its own signal, StateChanged, but just in case... 150 OnStateUpdate(new_value.reader().get_string());
122 StateChanged(new_value.reader().get_string());
123 } else { 151 } else {
124 // we don't care about this property 152 // we don't care about this property
125 } 153 }
126 } 154 }
127 155
128 void ServiceManager::StateChanged(const std::string& new_state_string) {
129 DLOG(INFO) << "StateChanged: new_state = " << new_state_string;
130 ConnectivityState old_state = connectivity_state_;
131 connectivity_state_ = ConnectivityStateFromString(new_state_string);
132 // see if we're coming online or going offline
133 // NOTE: we consider "unknown" to be offline
134 if (IsOfflineConnectivityState(old_state) &&
135 IsOnlineConnectivityState(connectivity_state_)) {
136 OnFlimflamOnline();
137 } else if (IsOnlineConnectivityState(old_state) &&
138 IsOfflineConnectivityState(connectivity_state_)) {
139 OnFlimflamOffline();
140 }
141 }
142
143 // Service methods 156 // Service methods
144 157
145 void ServiceManager::EmitDataPlansUpdate(const Service& service) { 158 void ServiceManager::EmitDataPlansUpdate(const Service& service) {
146 DLOG(INFO) << "EmitDataPlansUpdate: service = " << service.GetPath(); 159 DLOG(INFO) << "EmitDataPlansUpdate: service = " << service.GetPath();
147 if (cashew_server_ == NULL) { 160 if (cashew_server_ == NULL) {
148 DLOG(WARNING) << "EmitDataPlansUpdate: no Cashew server"; 161 DLOG(WARNING) << "EmitDataPlansUpdate: no Cashew server";
149 return; 162 return;
150 } 163 }
151 cashew_server_->EmitDataPlansUpdate(service); 164 cashew_server_->EmitDataPlansUpdate(service);
152 } 165 }
(...skipping 110 matching lines...) Expand 10 before | Expand all | Expand 10 after
263 it = properties.find(kStateProperty); 276 it = properties.find(kStateProperty);
264 if (it != properties.end()) { 277 if (it != properties.end()) {
265 const DBus::Variant& value = static_cast<DBus::Variant>(it->second); 278 const DBus::Variant& value = static_cast<DBus::Variant>(it->second);
266 StateChanged(value.reader().get_string()); 279 StateChanged(value.reader().get_string());
267 } else { 280 } else {
268 DLOG(WARNING) << "GetFlimflamProperties: no State property"; 281 DLOG(WARNING) << "GetFlimflamProperties: no State property";
269 } 282 }
270 return true; 283 return true;
271 } 284 }
272 285
286 void ServiceManager::OnStateUpdate(const std::string& new_state_string) {
287 DLOG(INFO) << "OnStateUpdate: new_state = " << new_state_string;
288 ConnectivityState old_state = connectivity_state_;
289 connectivity_state_ = ConnectivityStateFromString(new_state_string);
290 // see if we're coming online or going offline
291 // NOTE: we consider "unknown" to be offline
292 if (IsOfflineConnectivityState(old_state) &&
293 IsOnlineConnectivityState(connectivity_state_)) {
294 OnFlimflamOnline();
295 } else if (IsOnlineConnectivityState(old_state) &&
296 IsOfflineConnectivityState(connectivity_state_)) {
297 OnFlimflamOffline();
298 }
299 }
300
273 void ServiceManager::OnDefaultTechnologyUpdate( 301 void ServiceManager::OnDefaultTechnologyUpdate(
274 const std::string& default_technology) { 302 const std::string& default_technology) {
275 DLOG(INFO) << "OnDefaultTechnologyUpdate: default technology = " 303 DLOG(INFO) << "OnDefaultTechnologyUpdate: default technology = "
276 << default_technology; 304 << default_technology;
277 default_technology_ = Service::TypeFromString(default_technology); 305 default_technology_ = Service::TypeFromString(default_technology);
278 if (default_technology_ == Service::kTypeUnknown) { 306 if (default_technology_ == Service::kTypeUnknown) {
279 LOG(WARNING) << "OnDefaultTechnologyUpdate: unknown default technology: " 307 LOG(WARNING) << "OnDefaultTechnologyUpdate: unknown default technology: "
280 << default_technology; 308 << default_technology;
281 } 309 }
282 if (default_technology_ != Service::kTypeCellular && 310 if (default_technology_ != Service::kTypeCellular &&
(...skipping 148 matching lines...) Expand 10 before | Expand all | Expand 10 after
431 // notify our child services 459 // notify our child services
432 ServiceMap::iterator it; 460 ServiceMap::iterator it;
433 for (it = services_.begin(); it != services_.end(); ++it) { 461 for (it = services_.begin(); it != services_.end(); ++it) {
434 Service *service = static_cast<Service*>(it->second); 462 Service *service = static_cast<Service*>(it->second);
435 DCHECK(service != NULL); 463 DCHECK(service != NULL);
436 service->OnFlimflamOffline(); 464 service->OnFlimflamOffline();
437 } 465 }
438 } 466 }
439 467
440 } // namespace cashew 468 } // namespace cashew
OLDNEW
« src/property_changed_handler.cc ('K') | « src/service_manager.h ('k') | no next file » | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698