• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
1 /*
2  * Copyright (C) 2022 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 NAPI_SYSTEM_TIMER_H
17 #define NAPI_SYSTEM_TIMER_H
18 
19 #include "napi_work.h"
20 #include "time_service_client.h"
21 
22 namespace OHOS {
23 namespace MiscServices {
24 namespace Time {
25 using namespace OHOS::AppExecFwk;
26 class ITimerInfoInstance : public OHOS::MiscServices::ITimerInfo {
27 public:
28     ITimerInfoInstance();
29     virtual ~ITimerInfoInstance();
30     virtual void OnTrigger() override;
31     virtual void SetType(const int &type) override;
32     virtual void SetRepeat(bool repeat) override;
33     virtual void SetInterval(const uint64_t &interval) override;
34     virtual void SetWantAgent(std::shared_ptr<OHOS::AbilityRuntime::WantAgent::WantAgent> wantAgent) override;
35     void SetCallbackInfo(const napi_env &env, const napi_ref &ref);
36 
37 private:
38     struct CallbackInfo {
CallbackInfoCallbackInfo39         CallbackInfo(){};
CallbackInfoCallbackInfo40         CallbackInfo(napi_env napiEnv, napi_ref napiRef) : env(napiEnv), ref(napiRef){};
41         napi_env env = nullptr;
42         napi_ref ref = nullptr;
43     };
44 
45     void Call(napi_env env, void *data);
46     CallbackInfo callbackInfo_;
47 };
48 
49 class NapiSystemTimer {
50 public:
51     static napi_value SystemTimerInit(napi_env env, napi_value exports);
52     static void GetTimerOptions(const napi_env &env, ContextBase *context, const napi_value &value,
53                                 std::shared_ptr<ITimerInfoInstance> &iTimerInfoInstance);
54     static napi_value CreateTimer(napi_env env, napi_callback_info info);
55     static napi_value StartTimer(napi_env env, napi_callback_info info);
56     static napi_value StopTimer(napi_env env, napi_callback_info info);
57     static napi_value DestroyTimer(napi_env env, napi_callback_info info);
58 };
59 
60 }
61 }
62 }
63 #endif // NAPI_SYSTEM_TIMER_H