• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
1 /*
2  * Copyright (C) 2024 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 OHOS_WIFI_TIMER_H
17 #define OHOS_WIFI_TIMER_H
18 
19 #ifndef OHOS_ARCH_LITE
20 #ifndef WIFI_FFRT_ENABLE
21 #include "timer.h"
22 #else
23 #include "wifi_event_handler.h"
24 #endif
25 #include "wifi_errcode.h"
26 namespace OHOS {
27 namespace Wifi {
28 #ifdef WIFI_FFRT_ENABLE
29 class WifiTimer {
30 public:
31     using TimerCallback = std::function<void()>;
32     static constexpr uint32_t DEFAULT_TIMEROUT = 10000;
33     static WifiTimer *GetInstance(void);
34 
35     WifiTimer();
36     ~WifiTimer();
37 
38     ErrCode Register(
39         const TimerCallback &callback, uint32_t &outTimerId, uint32_t interval = DEFAULT_TIMEROUT, bool once = true);
40     void UnRegister(uint32_t timerId);
41 
42 private:
43     std::unique_ptr<WifiEventHandler> timer_{nullptr};
44     uint32_t timerIdInit = 0;
45 };
46 #else
47 class WifiTimer {
48 public:
49     using TimerCallback = std::function<void()>;
50     static constexpr uint32_t DEFAULT_TIMEROUT = 10000;
51     static WifiTimer *GetInstance(void);
52 
53     WifiTimer();
54     ~WifiTimer();
55 
56     ErrCode Register(
57         const TimerCallback &callback, uint32_t &outTimerId, uint32_t interval = DEFAULT_TIMEROUT, bool once = true);
58     void UnRegister(uint32_t timerId);
59 
60 private:
61     std::unique_ptr<Utils::Timer> timer_{nullptr};
62 };
63 #endif
64 }
65 }
66 #endif
67 #endif
68