• 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/native_api.h"
20 #include "napi/native_node_api.h"
21 #include "napi_async_work.h"
22 #include "time_service_client.h"
23 
24 namespace OHOS {
25 namespace MiscServices {
26 namespace Time {
27 class ITimerInfoInstance : public OHOS::MiscServices::ITimerInfo {
28 public:
29     ITimerInfoInstance();
30     virtual ~ITimerInfoInstance();
31     virtual void OnTrigger() override;
32     virtual void SetType(const int &type) override;
33     virtual void SetRepeat(bool repeat) override;
34     virtual void SetInterval(const uint64_t &interval) override;
35     virtual void SetWantAgent(std::shared_ptr<OHOS::AbilityRuntime::WantAgent::WantAgent> wantAgent) override;
36     void SetCallbackInfo(const napi_env &env, const napi_ref &ref);
37 
38 private:
39     struct CallbackInfo {
40         napi_env env;
41         napi_ref ref;
42     };
43 
44     CallbackInfo callbackInfo_;
45 };
46 
47 class NapiSystemTimer {
48 public:
49     static napi_value SystemTimerInit(napi_env env, napi_value exports);
50     static void GetTimerOptions(const napi_env &env, ContextBase *context, const napi_value &value,
51                                 std::shared_ptr<ITimerInfoInstance> &iTimerInfoInstance);
52     static napi_value CreateTimer(napi_env env, napi_callback_info info);
53     static napi_value StartTimer(napi_env env, napi_callback_info info);
54     static napi_value StopTimer(napi_env env, napi_callback_info info);
55     static napi_value DestroyTimer(napi_env env, napi_callback_info info);
56 };
57 
58 }
59 }
60 }
61 #endif // NAPI_SYSTEM_TIMER_H