• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
1 /**
2  * Copyright (c) 2025 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 PANDA_PLUGINS_INTEROP_JS_TIMER_H
17 #define PANDA_PLUGINS_INTEROP_JS_TIMER_H
18 
19 #include <node_api.h>
20 #include <uv.h>
21 #include <vector>
22 
23 namespace ark::ets::interop::js::helper {
24 
25 struct TimerInfo {
26     explicit TimerInfo(napi_env env, napi_ref cb, std::vector<napi_ref> cbArgs, bool repeat);
27     TimerInfo(const TimerInfo &info) = delete;
28     TimerInfo(TimerInfo &&info) = delete;
29     TimerInfo &operator=(const TimerInfo &info) = delete;
30     TimerInfo &operator=(TimerInfo &&info) = delete;
31     ~TimerInfo();
32 
33     // NOLINTBEGIN(misc-non-private-member-variables-in-classes)
34     napi_env env;
35     napi_ref cb;
36     std::vector<napi_ref> cbArgs;
37     bool repeat;
38     uv_timer_t *timer;
39     uint32_t timerId;
40     static constexpr uv_close_cb TIMER_CLOSE_CALLBACK = [](uv_handle_t *handle) {
41         delete reinterpret_cast<uv_timer_t *>(handle);
42     };
43     // NOLINTEND(misc-non-private-member-variables-in-classes)
44 };
45 
46 napi_value SetTimeoutImpl(napi_env env, napi_callback_info info, bool repeat);
47 napi_value ClearTimerImpl(napi_env env, napi_callback_info info);
48 
49 }  // namespace ark::ets::interop::js::helper
50 
51 #endif  // PANDA_PLUGINS_INTEROP_JS_TIMER_H
52