wifi: Make methods deliver status synchronously (1/3) am: 503582ed94 am: 40dac08a47

am: f3b2c4ab07

Change-Id: Ie196e61e3f49f18a7f0e0a3a91681dbfd21ec9a4
This commit is contained in:
Roshan Pius
2016-11-17 01:12:26 +00:00
committed by android-build-merger
2 changed files with 44 additions and 41 deletions

View File

@@ -18,8 +18,8 @@
#include <android-base/logging.h> #include <android-base/logging.h>
#include "failure_reason_util.h"
#include "wifi_chip.h" #include "wifi_chip.h"
#include "wifi_status_util.h"
namespace { namespace {
// Chip ID to use for the only supported chip. // Chip ID to use for the only supported chip.
@@ -36,9 +36,9 @@ Wifi::Wifi()
: legacy_hal_(new WifiLegacyHal()), run_state_(RunState::STOPPED) {} : legacy_hal_(new WifiLegacyHal()), run_state_(RunState::STOPPED) {}
Return<void> Wifi::registerEventCallback( Return<void> Wifi::registerEventCallback(
const sp<IWifiEventCallback>& callback) { const sp<IWifiEventCallback>& event_callback) {
// TODO(b/31632518): remove the callback when the client is destroyed // TODO(b/31632518): remove the callback when the client is destroyed
callbacks_.emplace_back(callback); event_callbacks_.emplace_back(event_callback);
return Void(); return Void();
} }
@@ -46,47 +46,44 @@ Return<bool> Wifi::isStarted() {
return run_state_ != RunState::STOPPED; return run_state_ != RunState::STOPPED;
} }
Return<void> Wifi::start() { Return<void> Wifi::start(start_cb hidl_status_cb) {
if (run_state_ == RunState::STARTED) { if (run_state_ == RunState::STARTED) {
for (const auto& callback : callbacks_) { hidl_status_cb(createWifiStatus(WifiStatusCode::SUCCESS));
callback->onStart();
}
return Void(); return Void();
} else if (run_state_ == RunState::STOPPING) { } else if (run_state_ == RunState::STOPPING) {
for (const auto& callback : callbacks_) { hidl_status_cb(createWifiStatus(WifiStatusCode::ERROR_NOT_AVAILABLE,
callback->onStartFailure(CreateFailureReason( "HAL is stopping"));
CommandFailureReason::NOT_AVAILABLE, "HAL is stopping"));
}
return Void(); return Void();
} }
LOG(INFO) << "Starting HAL"; LOG(INFO) << "Starting HAL";
wifi_error status = legacy_hal_->start(); wifi_error legacy_status = legacy_hal_->start();
if (status != WIFI_SUCCESS) { if (legacy_status != WIFI_SUCCESS) {
LOG(ERROR) << "Failed to start Wifi HAL"; LOG(ERROR) << "Failed to start Wifi HAL";
for (auto& callback : callbacks_) { hidl_status_cb(
callback->onStartFailure( createWifiStatusFromLegacyError(legacy_status, "Failed to start HAL"));
CreateFailureReasonLegacyError(status, "Failed to start HAL"));
}
return Void(); return Void();
} }
// Create the chip instance once the HAL is started. // Create the chip instance once the HAL is started.
chip_ = new WifiChip(kChipId, legacy_hal_); chip_ = new WifiChip(kChipId, legacy_hal_);
run_state_ = RunState::STARTED; run_state_ = RunState::STARTED;
for (const auto& callback : callbacks_) { for (const auto& callback : event_callbacks_) {
callback->onStart(); if (!callback->onStart().getStatus().isOk()) {
LOG(ERROR) << "Failed to invoke onStart callback";
};
} }
hidl_status_cb(createWifiStatus(WifiStatusCode::SUCCESS));
return Void(); return Void();
} }
Return<void> Wifi::stop() { Return<void> Wifi::stop(stop_cb hidl_status_cb) {
if (run_state_ == RunState::STOPPED) { if (run_state_ == RunState::STOPPED) {
for (const auto& callback : callbacks_) { hidl_status_cb(createWifiStatus(WifiStatusCode::SUCCESS));
callback->onStop();
}
return Void(); return Void();
} else if (run_state_ == RunState::STOPPING) { } else if (run_state_ == RunState::STOPPING) {
hidl_status_cb(createWifiStatus(WifiStatusCode::ERROR_NOT_AVAILABLE,
"HAL is stopping"));
return Void(); return Void();
} }
@@ -98,37 +95,43 @@ Return<void> Wifi::stop() {
} }
chip_.clear(); chip_.clear();
run_state_ = RunState::STOPPED; run_state_ = RunState::STOPPED;
for (const auto& callback : callbacks_) { for (const auto& callback : event_callbacks_) {
callback->onStop(); if (!callback->onStop().getStatus().isOk()) {
LOG(ERROR) << "Failed to invoke onStop callback";
};
} }
}; };
wifi_error status = legacy_hal_->stop(on_complete_callback_); wifi_error legacy_status = legacy_hal_->stop(on_complete_callback_);
if (status != WIFI_SUCCESS) { if (legacy_status != WIFI_SUCCESS) {
LOG(ERROR) << "Failed to stop Wifi HAL"; LOG(ERROR) << "Failed to stop Wifi HAL";
for (const auto& callback : callbacks_) { WifiStatus wifi_status =
callback->onFailure( createWifiStatusFromLegacyError(legacy_status, "Failed to stop HAL");
CreateFailureReasonLegacyError(status, "Failed to stop HAL")); for (const auto& callback : event_callbacks_) {
callback->onFailure(wifi_status);
} }
hidl_status_cb(wifi_status);
return Void();
} }
hidl_status_cb(createWifiStatus(WifiStatusCode::SUCCESS));
return Void(); return Void();
} }
Return<void> Wifi::getChipIds(getChipIds_cb cb) { Return<void> Wifi::getChipIds(getChipIds_cb hidl_status_cb) {
std::vector<ChipId> chip_ids; std::vector<ChipId> chip_ids;
if (chip_.get()) { if (chip_.get()) {
chip_ids.emplace_back(kChipId); chip_ids.emplace_back(kChipId);
} }
hidl_vec<ChipId> hidl_data; hidl_vec<ChipId> hidl_data;
hidl_data.setToExternal(chip_ids.data(), chip_ids.size()); hidl_data.setToExternal(chip_ids.data(), chip_ids.size());
cb(hidl_data); hidl_status_cb(hidl_data);
return Void(); return Void();
} }
Return<void> Wifi::getChip(ChipId chip_id, getChip_cb cb) { Return<void> Wifi::getChip(ChipId chip_id, getChip_cb hidl_status_cb) {
if (chip_.get() && chip_id == kChipId) { if (chip_.get() && chip_id == kChipId) {
cb(chip_); hidl_status_cb(chip_);
} else { } else {
cb(nullptr); hidl_status_cb(nullptr);
} }
return Void(); return Void();
} }

View File

@@ -41,12 +41,12 @@ class Wifi : public IWifi {
// HIDL methods exposed. // HIDL methods exposed.
Return<void> registerEventCallback( Return<void> registerEventCallback(
const sp<IWifiEventCallback>& callback) override; const sp<IWifiEventCallback>& event_callback) override;
Return<bool> isStarted() override; Return<bool> isStarted() override;
Return<void> start() override; Return<void> start(start_cb hidl_status_cb) override;
Return<void> stop() override; Return<void> stop(stop_cb hidl_status_cb) override;
Return<void> getChipIds(getChipIds_cb cb) override; Return<void> getChipIds(getChipIds_cb hidl_status_cb) override;
Return<void> getChip(ChipId chip_id, getChip_cb cb) override; Return<void> getChip(ChipId chip_id, getChip_cb hidl_status_cb) override;
private: private:
enum class RunState { STOPPED, STARTED, STOPPING }; enum class RunState { STOPPED, STARTED, STOPPING };
@@ -55,7 +55,7 @@ class Wifi : public IWifi {
// and shared with all the child HIDL interface objects. // and shared with all the child HIDL interface objects.
std::shared_ptr<WifiLegacyHal> legacy_hal_; std::shared_ptr<WifiLegacyHal> legacy_hal_;
RunState run_state_; RunState run_state_;
std::vector<sp<IWifiEventCallback>> callbacks_; std::vector<sp<IWifiEventCallback>> event_callbacks_;
sp<WifiChip> chip_; sp<WifiChip> chip_;
DISALLOW_COPY_AND_ASSIGN(Wifi); DISALLOW_COPY_AND_ASSIGN(Wifi);