| OLD | NEW |
| 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/device.h" | 5 #include "src/device.h" |
| 6 | 6 |
| 7 #include <glog/logging.h> | 7 #include <glog/logging.h> |
| 8 | 8 |
| 9 #include "src/byte_counter.h" | 9 #include "src/byte_counter.h" |
| 10 #include "src/service.h" | 10 #include "src/service.h" |
| (...skipping 29 matching lines...) Expand all Loading... |
| 40 get_properties_source_id_(0), retrying_get_properties_(false), | 40 get_properties_source_id_(0), retrying_get_properties_(false), |
| 41 byte_counter_(NULL), byte_counter_running_(false) { | 41 byte_counter_(NULL), byte_counter_running_(false) { |
| 42 // schedule a GetProperties() call to our Flimflam service path to init state | 42 // schedule a GetProperties() call to our Flimflam service path to init state |
| 43 // we'll keep trying periodically until we succeed | 43 // we'll keep trying periodically until we succeed |
| 44 // we'll subsequently update this state by monitoring PropertyChanged signals | 44 // we'll subsequently update this state by monitoring PropertyChanged signals |
| 45 get_properties_source_id_ = | 45 get_properties_source_id_ = |
| 46 g_idle_add(StaticGetDevicePropertiesCallback, this); | 46 g_idle_add(StaticGetDevicePropertiesCallback, this); |
| 47 if (get_properties_source_id_ == 0) { | 47 if (get_properties_source_id_ == 0) { |
| 48 LOG(ERROR) << path_ << ": ctor: g_idle_add failed"; | 48 LOG(ERROR) << path_ << ": ctor: g_idle_add failed"; |
| 49 } | 49 } |
| 50 property_changed_handler_.delegate(this); |
| 50 } | 51 } |
| 51 | 52 |
| 52 Device::~Device() { | 53 Device::~Device() { |
| 53 StopByteCounter(); | 54 StopByteCounter(); |
| 54 if (get_properties_source_id_ != 0 && | 55 if (get_properties_source_id_ != 0 && |
| 55 !g_source_remove(get_properties_source_id_)) { | 56 !g_source_remove(get_properties_source_id_)) { |
| 56 DLOG(WARNING) << path_ << ": dtor: g_source_remove failed"; | 57 DLOG(WARNING) << path_ << ": dtor: g_source_remove failed"; |
| 57 } | 58 } |
| 58 } | 59 } |
| 59 | 60 |
| (...skipping 11 matching lines...) Expand all Loading... |
| 71 | 72 |
| 72 const std::string& Device::GetInterface() const { | 73 const std::string& Device::GetInterface() const { |
| 73 return interface_; | 74 return interface_; |
| 74 } | 75 } |
| 75 | 76 |
| 76 // Flimflam Device D-Bus Proxy methods | 77 // Flimflam Device D-Bus Proxy methods |
| 77 | 78 |
| 78 void Device::PropertyChanged(const std::string& property_name, | 79 void Device::PropertyChanged(const std::string& property_name, |
| 79 const DBus::Variant& new_value) { | 80 const DBus::Variant& new_value) { |
| 80 DLOG(INFO) << path_ << ": PropertyChanged: property_name = " << property_name; | 81 DLOG(INFO) << path_ << ": PropertyChanged: property_name = " << property_name; |
| 82 // Queue a tuple representing this signal for later processing from the glib |
| 83 // main loop. We do this to avoid libdbus-c++ deadlocks that can occur when |
| 84 // sending a dbus message from within a dbus callback like this one. |
| 85 PropertyChangedSignal signal(property_name, new_value); |
| 86 property_changed_handler_.EnqueueSignal(signal); |
| 87 } |
| 88 |
| 89 // PropertyChangedDelegate methods |
| 90 |
| 91 void Device::OnPropertyChanged(const PropertyChangedHandler *handler, |
| 92 const std::string& property_name, |
| 93 const DBus::Variant& new_value) { |
| 94 DCHECK(handler == &property_changed_handler_); |
| 95 DLOG(INFO) << path_ << ": OnPropertyChanged: property_name = " |
| 96 << property_name; |
| 81 if (property_name == kFlimflamDeviceCarrierProperty) { | 97 if (property_name == kFlimflamDeviceCarrierProperty) { |
| 82 OnCarrierUpdate(new_value.reader().get_string()); | 98 OnCarrierUpdate(new_value.reader().get_string()); |
| 83 } else if (property_name == kFlimflamDeviceInterfaceProperty) { | 99 } else if (property_name == kFlimflamDeviceInterfaceProperty) { |
| 84 OnInterfaceUpdate(new_value.reader().get_string()); | 100 OnInterfaceUpdate(new_value.reader().get_string()); |
| 85 } else if (property_name == kFlimflamDeviceTypeProperty) { | 101 } else if (property_name == kFlimflamDeviceTypeProperty) { |
| 86 OnTypeUpdate(new_value.reader().get_string()); | 102 OnTypeUpdate(new_value.reader().get_string()); |
| 87 } else { | 103 } else { |
| 88 // we don't care about this property | 104 // we don't care about this property |
| 89 } | 105 } |
| 90 } | 106 } |
| (...skipping 257 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 348 | 364 |
| 349 void Device::DeleteByteCounter() { | 365 void Device::DeleteByteCounter() { |
| 350 DLOG(INFO) << path_ << ": DeleteByteCounter"; | 366 DLOG(INFO) << path_ << ": DeleteByteCounter"; |
| 351 if (byte_counter_ != NULL) { | 367 if (byte_counter_ != NULL) { |
| 352 delete byte_counter_; | 368 delete byte_counter_; |
| 353 byte_counter_ = NULL; | 369 byte_counter_ = NULL; |
| 354 } | 370 } |
| 355 } | 371 } |
| 356 | 372 |
| 357 } // namespace cashew | 373 } // namespace cashew |
| OLD | NEW |