• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
1 /*
2  * Copyright (c); 2021 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 SYSTEM_TIMER_H
17 #define SYSTEM_TIMER_H
18 
19 #include "napi/native_api.h"
20 #include "napi/native_node_api.h"
21 #include "time_service_client.h"
22 
23 namespace OHOS {
24 namespace MiscServicesNapi {
25 using namespace OHOS::MiscServices;
26 
27 constexpr int NONE_PARAMETER = 0;
28 constexpr int ONE_PARAMETER = 1;
29 constexpr int TWO_PARAMETERS = 2;
30 constexpr int THREE_PARAMETERS = 3;
31 
32 class ITimerInfoInstance : public ITimerInfo {
33 public:
34     ITimerInfoInstance();
35     virtual ~ITimerInfoInstance();
36     virtual void OnTrigger() override;
37     virtual void SetType(const int &type) override;
38     virtual void SetRepeat(bool repeat) override;
39     virtual void SetInterval(const uint64_t &interval) override;
40     virtual void SetWantAgent(std::shared_ptr<OHOS::AbilityRuntime::WantAgent::WantAgent> wantAgent) override;
41     void SetCallbackInfo(const napi_env &env, const napi_ref &ref);
42 
43 private:
44     struct CallbackInfo {
45         napi_env env;
46         napi_ref ref;
47     };
48 
49     CallbackInfo callbackInfo_;
50 };
51 
52 napi_value SystemtimerInit(napi_env env, napi_value exports);
53 napi_value CreateTimer(napi_env env, napi_callback_info info);
54 napi_value StartTimer(napi_env env, napi_callback_info info);
55 napi_value StopTimer(napi_env env, napi_callback_info info);
56 napi_value DestroyTimer(napi_env env, napi_callback_info info);
57 }  // namespace MiscServicesNapi
58 }  // namespace OHOS
59 #endif  // SYSTEM_TIMER_H