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

Side by Side Diff: src/device.cc

Issue 3528016: Cashew: implement backend usage API (Closed) Base URL: ssh://git@gitrw.chromium.org:9222/cashew.git
Patch Set: Fix code review nits and remove hardcoded usage URLs Created 10 years, 2 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 | Annotate | Revision Log
« no previous file with comments | « src/device.h ('k') | src/http_fetcher.h » ('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) 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/service.h" 9 #include "src/service.h"
10 10
(...skipping 11 matching lines...) Expand all
22 // Flimflam Device on-the-wire Type values 22 // Flimflam Device on-the-wire Type values
23 static const char* kFlimflamDeviceTypeEthernet = "ethernet"; 23 static const char* kFlimflamDeviceTypeEthernet = "ethernet";
24 static const char* kFlimflamDeviceTypeWifi = "wifi"; 24 static const char* kFlimflamDeviceTypeWifi = "wifi";
25 static const char* kFlimflamDeviceTypeWimax = "wimax"; 25 static const char* kFlimflamDeviceTypeWimax = "wimax";
26 static const char* kFlimflamDeviceTypeBluetooth = "bluetooth"; 26 static const char* kFlimflamDeviceTypeBluetooth = "bluetooth";
27 static const char* kFlimflamDeviceTypeGPS = "gps"; 27 static const char* kFlimflamDeviceTypeGPS = "gps";
28 static const char* kFlimflamDeviceTypeCellular = "cellular"; 28 static const char* kFlimflamDeviceTypeCellular = "cellular";
29 // TODO(vlaviano): what does vendor look like? 29 // TODO(vlaviano): what does vendor look like?
30 static const char* kFlimflamDeviceTypeVendor = ""; 30 static const char* kFlimflamDeviceTypeVendor = "";
31 31
32 Device::Device(DBus::Connection& connection, // NOLINT 32 Device::Device(Service * const parent, DBus::Connection& connection, // NOLINT
33 const DBus::Path& path) 33 const DBus::Path& path)
34 : DBus::ObjectProxy(connection, path, kFlimflamDeviceName), 34 : DBus::ObjectProxy(connection, path, kFlimflamDeviceName),
35 path_(path), type_(kTypeUnknown), carrier_(kCarrierUnknown) { 35 parent_(CHECK_NOTNULL(parent)), path_(path), type_(kTypeUnknown),
36 carrier_(kCarrierUnknown) {
36 // init our state with a GetProperties() call to our Flimflam service path 37 // init our state with a GetProperties() call to our Flimflam service path
37 // we'll update this state by monitoring PropertyChanged signals 38 // we'll update this state by monitoring PropertyChanged signals
38 GetDeviceProperties(); 39 GetDeviceProperties();
39 } 40 }
40 41
41 Device::~Device() { 42 Device::~Device() {
42 } 43 }
43 44
44 const DBus::Path& Device::GetPath() const { 45 const DBus::Path& Device::GetPath() const {
45 return path_; 46 return path_;
(...skipping 42 matching lines...) Expand 10 before | Expand all | Expand 10 after
88 return kTypeCellular; 89 return kTypeCellular;
89 } 90 }
90 if (type.compare(kFlimflamDeviceTypeVendor) == 0) { 91 if (type.compare(kFlimflamDeviceTypeVendor) == 0) {
91 return kTypeVendor; 92 return kTypeVendor;
92 } 93 }
93 return kTypeUnknown; 94 return kTypeUnknown;
94 } 95 }
95 96
96 void Device::OnCarrierUpdate(const std::string& carrier) { 97 void Device::OnCarrierUpdate(const std::string& carrier) {
97 DLOG(INFO) << path_ << ": OnCarrierUpdate: carrier = " << carrier; 98 DLOG(INFO) << path_ << ": OnCarrierUpdate: carrier = " << carrier;
98 if (carrier_.compare(kCarrierUnknown) && carrier_.compare(carrier)) { 99 // only propagate this to parent Service if there's been a change
99 LOG(WARNING) << path_ << ": OnCarrierUpdate: carrier change from " 100 // we expect to see only one such change (from "Unknown")
100 << carrier_ << " to " << carrier << "!"; 101 if (carrier_.compare(carrier)) {
102 if (carrier_.compare(kCarrierUnknown)) {
103 LOG(WARNING) << path_ << ": OnCarrierUpdate: carrier change from "
104 << carrier_ << " to " << carrier << "!";
105 }
106 carrier_ = carrier;
107 parent_->OnCarrierUpdate(carrier);
101 } 108 }
102 // TODO(vlaviano): load backend module for this carrier if needed
103 carrier_ = carrier;
104 } 109 }
105 110
106 void Device::OnTypeUpdate(const std::string& type) { 111 void Device::OnTypeUpdate(const std::string& type) {
107 DLOG(INFO) << path_ << ": OnTypeUpdate: type = " << type; 112 DLOG(INFO) << path_ << ": OnTypeUpdate: type = " << type;
108 type_ = TypeFromString(type); 113 type_ = TypeFromString(type);
109 if (type_ != kTypeCellular) { 114 if (type_ != kTypeCellular) {
110 LOG(WARNING) << path_ << ": OnTypeUpdate: type is not cellular!"; 115 LOG(WARNING) << path_ << ": OnTypeUpdate: type is not cellular!";
111 } 116 }
112 } 117 }
113 118
(...skipping 31 matching lines...) Expand 10 before | Expand all | Expand 10 after
145 } 150 }
146 // don't expect to find Cellular.* properties if we're not a cellular device 151 // don't expect to find Cellular.* properties if we're not a cellular device
147 if (type_ != kTypeCellular) { 152 if (type_ != kTypeCellular) {
148 return; 153 return;
149 } 154 }
150 it = properties.find(kFlimflamDeviceCarrierProperty); 155 it = properties.find(kFlimflamDeviceCarrierProperty);
151 if (it != properties.end()) { 156 if (it != properties.end()) {
152 const DBus::Variant& value = static_cast<DBus::Variant>(it->second); 157 const DBus::Variant& value = static_cast<DBus::Variant>(it->second);
153 OnCarrierUpdate(value.reader().get_string()); 158 OnCarrierUpdate(value.reader().get_string());
154 } else { 159 } else {
155 DLOG(WARNING) << path_ << ": GetDeviceProperties: no Carrier property"; 160 DLOG(WARNING) << path_
161 << ": GetDeviceProperties: no Cellular.Carrier property";
156 } 162 }
157 } 163 }
158 164
159 } // namespace cashew 165 } // namespace cashew
OLDNEW
« no previous file with comments | « src/device.h ('k') | src/http_fetcher.h » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698