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