Home | History | Annotate | Download | only in wifi_offload
      1 #include "Offload.h"
      2 
      3 #include <android-base/logging.h>
      4 
      5 #include "chre_interface_factory.h"
      6 #include "hidl_return_util.h"
      7 
      8 namespace android {
      9 namespace hardware {
     10 namespace wifi {
     11 namespace offload {
     12 namespace V1_0 {
     13 namespace implementation {
     14 
     15 using hidl_return_util::validateAndCall;
     16 
     17 Offload::Offload()
     18     : mOffloadServer(new OffloadServer(new ChreInterfaceFactory())), cookie_(0),
     19       death_handler_(new HidlDeathHandler<IOffloadCallback>(
     20           std::bind(&Offload::onObjectDeath, this, std::placeholders::_1))) {
     21     LOG(android::base::INFO) << "Wifi Offload HAL impl";
     22 }
     23 
     24 // Methods from ::android::hardware::wifi::offload::V1_0::IOffload follow.
     25 Return<void> Offload::configureScans(const ScanParam &param, const ScanFilter &filter,
     26                                      configureScans_cb _hidl_cb) {
     27     return validateAndCall(this, &Offload::configureScansInternal, _hidl_cb, param, filter);
     28 }
     29 
     30 Return<void> Offload::getScanStats(getScanStats_cb _hidl_cb) {
     31     return validateAndCall(this, &Offload::getScanStatsInternal, _hidl_cb);
     32 }
     33 
     34 Return<void> Offload::subscribeScanResults(uint32_t delayMs, subscribeScanResults_cb _hidl_cb) {
     35     return validateAndCall(this, &Offload::subscribeScanResultsInternal, _hidl_cb, delayMs);
     36 }
     37 
     38 Return<void> Offload::unsubscribeScanResults() {
     39     if (!mOffloadServer->unsubscribeScanResults()) {
     40         LOG(ERROR) << "Unable to unsubscribe";
     41     }
     42     return Void();
     43 }
     44 
     45 Return<void> Offload::setEventCallback(const sp<IOffloadCallback>& cb) {
     46     if (!mOffloadServer->setEventCallback(cb)) {
     47         LOG(ERROR) << "No callback set";
     48         return Void();
     49     }
     50     cookie_ = reinterpret_cast<uint64_t>(cb.get());
     51     death_handler_->setCallback(cb);
     52     cb->linkToDeath(death_handler_, cookie_);
     53     return Void();
     54 }
     55 
     56 OffloadStatus Offload::configureScansInternal(const ScanParam &param, const ScanFilter &filter) {
     57     return mOffloadServer->configureScans(param, filter);
     58 }
     59 
     60 std::pair<OffloadStatus, ScanStats> Offload::getScanStatsInternal() {
     61     return mOffloadServer->getScanStats();
     62 }
     63 
     64 OffloadStatus Offload::subscribeScanResultsInternal(uint32_t delayMs) {
     65     return mOffloadServer->subscribeScanResults(delayMs);
     66 }
     67 
     68 void Offload::onObjectDeath(uint64_t cookie) {
     69     if (cookie == cookie_) {
     70         LOG(DEBUG) << "OffloadCallback death notification received";
     71         mOffloadServer->clearEventCallback();
     72         cookie_ = 0;
     73     }
     74 }
     75 // Methods from ::android::hidl::base::V1_0::IBase follow.
     76 
     77 }  // namespace implementation
     78 }  // namespace V1_0
     79 }  // namespace offload
     80 }  // namespace wifi
     81 }  // namespace hardware
     82 }  // namespace android
     83