1 /* 2 * Copyright (C) 2023 Huawei Device Co., Ltd. 3 * Licensed under the Apache License, Version 2.0 (the "License"); 4 * you may not use this file except in compliance with the License. 5 * You may obtain a copy of the License at 6 * 7 * http://www.apache.org/licenses/LICENSE-2.0 8 * 9 * Unless required by applicable law or agreed to in writing, software 10 * distributed under the License is distributed on an "AS IS" BASIS, 11 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 12 * See the License for the specific language governing permissions and 13 * limitations under the License. 14 */ 15 16 #ifndef WIFI_EVENT_HANDLER_H 17 #define WIFI_EVENT_HANDLER_H 18 19 #include <string> 20 #include <memory> 21 #include <chrono> 22 #include <future> 23 24 namespace OHOS { 25 namespace Wifi { 26 class WifiEventHandler { 27 public: 28 using Callback = std::function<void()>; 29 30 explicit WifiEventHandler(const std::string &threadName, const Callback &timeOutFunc = nullptr); 31 ~WifiEventHandler(); 32 33 /** 34 * @submit sync task to Handler 35 * 36 * @param Callback - Input task 37 * @return bool - true: submit success, false: submit failed 38 */ 39 bool PostSyncTask(const Callback &callback); 40 41 /** 42 * @submit Async task to Handler 43 * 44 * @param Callback - Input task 45 * @param delayTime - Wait delayTime ms excute task 46 * @return bool - true: submit success, false: submit failed 47 */ 48 bool PostAsyncTask(const Callback &callback, int64_t delayTime = 0); 49 50 /** 51 * @submit Async task to Handler 52 * 53 * @param Callback - Input task 54 * @param name - Describer of task 55 * @param delayTime - Wait delayTime ms excute task 56 * @return bool - true: submit success, false: submit failed 57 */ 58 bool PostAsyncTask(const Callback &callback, const std::string &name, int64_t delayTime = 0); 59 60 /** 61 * @Remove Async task 62 * 63 * @param name - Describer of task 64 */ 65 void RemoveAsyncTask(const std::string &name); 66 67 /** 68 * @submit sync timeout task to Handler 69 * 70 * @param callback - Input task 71 * @param waitTime - Wait time(ms) excute task 72 * @return bool - true: excute task success, false: excute task timeout 73 */ 74 static bool PostSyncTimeOutTask(const Callback &callback, uint64_t waitTime = 5000); 75 76 private: 77 class WifiEventHandlerImpl; 78 std::unique_ptr<WifiEventHandlerImpl> ptr; 79 }; 80 } // namespace Wifi 81 } // namespace OHOS 82 #endif