• 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 
17 #ifndef NAPI_TIMER_H
18 #define NAPI_TIMER_H
19 
20 #include <memory>
21 #include "timer.h"
22 
23 namespace OHOS {
24 namespace Bluetooth {
25 class NapiTimer {
26 public:
27     using TimerCallback = std::function<void ()>;
28     static constexpr uint32_t DEFAULT_TIMEOUT = 10000; // 10s
29 
30     static NapiTimer *GetInstance(void);
31 
32     NapiTimer();
33     ~NapiTimer();
34 
35     int Register(const TimerCallback& callback, uint32_t &outTimerId, uint32_t interval = DEFAULT_TIMEOUT);
36     void Unregister(uint32_t timerId);
37 private:
38     std::unique_ptr<OHOS::Utils::Timer> timer_ {nullptr};
39 };
40 }  // namespace Bluetooth
41 }  // namespace OHOS
42 #endif // NAPI_TIMER_H