• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
1 #ifndef ANDROID_HARDWARE_WIFI_OFFLOAD_V1_0_OFFLOAD_H
2 #define ANDROID_HARDWARE_WIFI_OFFLOAD_V1_0_OFFLOAD_H
3 
4 #include <android/hardware/wifi/offload/1.0/IOffload.h>
5 
6 #include <android-base/macros.h>
7 #include <hidl/MQDescriptor.h>
8 #include <hidl/Status.h>
9 
10 #include "offload_server.h"
11 
12 namespace {
13 // Type of callback invoked by the death handler.
14 using on_death_cb_function = std::function<void(uint64_t)>;
15 
16 // Private class used to keep track of death of callbacks
17 template<typename CallbackType>
18 class HidlDeathHandler : public android::hardware::hidl_death_recipient {
19   public:
HidlDeathHandler(const on_death_cb_function & user_cb_function)20     HidlDeathHandler(const on_death_cb_function &user_cb_function)
21         : cb_function_(user_cb_function) {
22     }
23     ~HidlDeathHandler() = default;
24 
25     // Death notification for callbacks.
serviceDied(uint64_t cookie,const android::wp<android::hidl::base::V1_0::IBase> &)26     void serviceDied(uint64_t cookie,
27                      const android::wp<android::hidl::base::V1_0::IBase>& /* who */) override {
28         cb_.clear();
29         cb_function_(cookie);
30     }
31 
setCallback(android::wp<CallbackType> cb)32     void setCallback(android::wp<CallbackType> cb) {
33         cb_ = cb;
34     }
35 
36   private:
37     android::wp<CallbackType> cb_;
38     on_death_cb_function cb_function_;
39 
40     DISALLOW_COPY_AND_ASSIGN(HidlDeathHandler);
41 };
42 }  // namespace
43 
44 namespace android {
45 namespace hardware {
46 namespace wifi {
47 namespace offload {
48 namespace V1_0 {
49 namespace implementation {
50 
51 /**
52  * Interface object to communicate with Offload HAL
53  */
54 class Offload : public IOffload {
55    public:
56     Offload();
57 
58     // Methods from ::android::hardware::wifi::offload::V1_0::IOffload follow.
59     Return<void> configureScans(const ScanParam &param, const ScanFilter &filter,
60                                 configureScans_cb _hidl_cb) override;
61     Return<void> getScanStats(getScanStats_cb _hidl_cb) override;
62     Return<void> subscribeScanResults(uint32_t delayMs, subscribeScanResults_cb _hidl_cb) override;
63     Return<void> unsubscribeScanResults() override;
64     Return<void> setEventCallback(const sp<IOffloadCallback>& cb) override;
65     // Methods from ::android::hidl::base::V1_0::IBase follow.
66 
67    private:
68      OffloadStatus configureScansInternal(const ScanParam &param, const ScanFilter &filter);
69      std::pair<OffloadStatus, ScanStats> getScanStatsInternal();
70      OffloadStatus subscribeScanResultsInternal(uint32_t delayMs);
71      void onObjectDeath(uint64_t cookie);
72 
73      std::unique_ptr<OffloadServer> mOffloadServer;
74      uint64_t cookie_;
75      sp<HidlDeathHandler<IOffloadCallback>> death_handler_;
76 
77      DISALLOW_COPY_AND_ASSIGN(Offload);
78 };
79 
80 }  // namespace implementation
81 }  // namespace V1_0
82 }  // namespace offload
83 }  // namespace wifi
84 }  // namespace hardware
85 }  // namespace android
86 
87 #endif  // ANDROID_HARDWARE_WIFI_OFFLOAD_V1_0_OFFLOAD_H
88