shill: cellular: update and test the scanning property
Update the scanning property while scanning for networks. Send out a
property change notification when this property changes. Update unit
tests to verify behavior of the scanning property.
BUG=none
TEST=run unit tests
Change-Id: I5264f180adf68206179393572337a506f68ef98e
Reviewed-on: https://gerrit.chromium.org/gerrit/21861
Commit-Ready: Jason Glasgow <jglasgow@chromium.org>
Reviewed-by: Jason Glasgow <jglasgow@chromium.org>
Tested-by: Jason Glasgow <jglasgow@chromium.org>
diff --git a/cellular_capability_gsm.cc b/cellular_capability_gsm.cc
index 1715fec..fbc1884 100644
--- a/cellular_capability_gsm.cc
+++ b/cellular_capability_gsm.cc
@@ -614,11 +614,19 @@
void CellularCapabilityGSM::Scan(Error *error, const ResultCallback &callback) {
SLOG(Cellular, 2) << __func__;
- // TODO(petkov): Defer scan requests if a scan is in progress already.
CHECK(error);
+ if (scanning_) {
+ Error::PopulateAndLog(error, Error::kInProgress, "Already scanning");
+ return;
+ }
ScanResultsCallback cb = Bind(&CellularCapabilityGSM::OnScanReply,
weak_ptr_factory_.GetWeakPtr(), callback);
network_proxy_->Scan(error, cb, kTimeoutScan);
+ if (!error->IsFailure()) {
+ scanning_ = true;
+ cellular()->adaptor()->EmitBoolChanged(flimflam::kScanningProperty,
+ scanning_);
+ }
}
void CellularCapabilityGSM::OnScanReply(const ResultCallback &callback,
@@ -631,6 +639,9 @@
// notification sent out.
//
// TODO(jglasgow): fix error handling
+ scanning_ = false;
+ cellular()->adaptor()->EmitBoolChanged(flimflam::kScanningProperty,
+ scanning_);
found_networks_.clear();
if (!error.IsFailure()) {
for (GSMScanResults::const_iterator it = results.begin();