1 /* 2 * hidl interface for wpa_supplicant daemon 3 * Copyright (c) 2004-2016, Jouni Malinen <j (at) w1.fi> 4 * Copyright (c) 2004-2016, Roshan Pius <rpius (at) google.com> 5 * 6 * This software may be distributed under the terms of the BSD license. 7 * See README for more details. 8 */ 9 10 #ifndef HIDL_RETURN_UTIL_H_ 11 #define HIDL_RETURN_UTIL_H_ 12 13 namespace android { 14 namespace hardware { 15 namespace wifi { 16 namespace offload { 17 namespace V1_0 { 18 namespace implementation { 19 namespace hidl_return_util { 20 21 /** 22 * These utility functions are used to invoke a method on the provided 23 * HIDL interface object. 24 * It then invokes the HIDL continuation callback with the status and 25 * any returned values. 26 */ 27 // Use for HIDL methods which return only an instance of OffloadStatus. 28 template<typename ObjT, typename WorkFuncT, typename... Args> 29 Return<void> validateAndCall(ObjT* obj, WorkFuncT&& work, 30 const std::function<void(const OffloadStatus&)>& hidl_cb, 31 Args&&... args) { 32 hidl_cb((obj->*work)(std::forward<Args>(args)...)); 33 return Void(); 34 } 35 36 // Use for HIDL methods which return instance of OffloadStatus and a single 37 // return value. 38 template<typename ObjT, typename WorkFuncT, typename ReturnT, typename... Args> 39 Return<void> validateAndCall(ObjT* obj, WorkFuncT&& work, 40 const std::function<void(const OffloadStatus&, ReturnT)>& hidl_cb, 41 Args&&... args) { 42 const auto& ret_pair = (obj->*work)(std::forward<Args>(args)...); 43 const OffloadStatus& status = std::get<0>(ret_pair); 44 const auto& ret_value = std::get<1>(ret_pair); 45 hidl_cb(status, ret_value); 46 return Void(); 47 } 48 49 // Use for HIDL methods which return instance of OffloadStatus and 2 return 50 // values. 51 template<typename ObjT, typename WorkFuncT, typename ReturnT1, typename ReturnT2, typename... Args> 52 Return<void> 53 validateAndCall(ObjT* obj, WorkFuncT&& work, 54 const std::function<void(const OffloadStatus&, ReturnT1, ReturnT2)>& hidl_cb, 55 Args&&... args) { 56 const auto& ret_tuple = (obj->*work)(std::forward<Args>(args)...); 57 const OffloadStatus& status = std::get<0>(ret_tuple); 58 const auto& ret_value1 = std::get<1>(ret_tuple); 59 const auto& ret_value2 = std::get<2>(ret_tuple); 60 hidl_cb(status, ret_value1, ret_value2); 61 return Void(); 62 } 63 64 } // namespace hidl_return_util 65 } // namespace implementation 66 } // namespace V1_0 67 } // namespace offload 68 } // namespace wifi 69 } // namespace hardware 70 } // namespace android 71 #endif // HIDL_RETURN_UTIL_H_ 72