• 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 #include "timer_type.h"
17 
18 namespace OHOS {
19 namespace MiscServicesNapi {
SetNamedPropertyByInteger(napi_env env,napi_value dstObj,int32_t objName,const char * propName)20 void SetNamedPropertyByInteger(napi_env env, napi_value dstObj, int32_t objName, const char *propName)
21 {
22     napi_value prop = nullptr;
23     if (napi_create_int32(env, objName, &prop) == napi_ok) {
24         napi_set_named_property(env, dstObj, propName, prop);
25     }
26 }
27 
TimerTypeInit(napi_env env,napi_value exports)28 napi_value TimerTypeInit(napi_env env, napi_value exports)
29 {
30     napi_value obj = nullptr;
31     napi_create_object(env, &obj);
32 
33     SetNamedPropertyByInteger(env, obj, 1 << TIMER_TYPE_REALTIME, "TIMER_TYPE_REALTIME");
34     SetNamedPropertyByInteger(env, obj, 1 << TIMER_TYPE_WAKEUP, "TIMER_TYPE_WAKEUP");
35     SetNamedPropertyByInteger(env, obj, 1 << TIMER_TYPE_EXACT, "TIMER_TYPE_EXACT");
36     SetNamedPropertyByInteger(env, obj, 1 << TIMER_TYPE_IDLE, "TIMER_TYPE_IDLE");
37 
38     napi_property_descriptor exportFuncs[] = {DECLARE_NAPI_PROPERTY("systemTimer", obj)};
39     napi_define_properties(env, exports, sizeof(exportFuncs) / sizeof(*exportFuncs), exportFuncs);
40 
41     return exports;
42 }
43 }  // namespace MiscServicesNapi
44 }  // namespace OHOS