• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
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,
59         int64_t delayTime = 0, bool isHighPriority = false);
60 
61     /**
62      * @Remove Async task
63      *
64      * @param name - Describer of task
65      */
66     void RemoveAsyncTask(const std::string &name);
67 
68     /**
69     * @Check if Has Async Task
70     *
71     * @param name
72     * @param hasTask
73     * @return int - 0: supported, -1: unsupported
74     */
75     int HasAsyncTask(const std::string &name, bool &hasTask);
76 
77     /**
78     * @submit sync timeout task to Handler
79     *
80     * @param callback - Input task
81     * @param waitTime - Wait time(ms) excute task
82     * @return bool - true: excute task success, false: excute task timeout
83     */
84     static bool PostSyncTimeOutTask(const Callback &callback, uint64_t waitTime = 5000);
85 
86 private:
87     class WifiEventHandlerImpl;
88     std::unique_ptr<WifiEventHandlerImpl> ptr;
89 };
90 } // namespace Wifi
91 } // namespace OHOS
92 #endif