• 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 #ifndef N_JS_SYSTEMTIME_H
16 #define N_JS_SYSTEMTIME_H
17 
18 #include <string>
19 #include "napi/native_api.h"
20 #include "napi/native_node_api.h"
21 #include "js_native_api.h"
22 
23 namespace OHOS {
24 namespace MiscServicesNapi {
25 namespace {
26 const int NONE_PARAMETER = 0;
27 const int ONE_PARAMETER = 1;
28 const int TWO_PARAMETERS = 2;
29 const int THREE_PARAMETERS = 3;
30 const int SET_TIME_MAX_PARA = 2;
31 const int SET_TIMEZONE_MAX_PARA = 2;
32 const int MAX_TIME_ZONE_ID = 1024;
33 const int INVALID_TIME = -1;
34 const int NO_ERROR = 0;
35 const int ERROR = -1;
36 const int PARAM0 = 0;
37 const int PARAM1 = 1;
38 const int ARGS_TWO = 2;
39 }
40 
41 typedef struct AsyncContext {
~AsyncContextAsyncContext42     ~AsyncContext()
43     {
44         if (callbackRef != nullptr) {
45             napi_delete_reference(env, callbackRef);
46         }
47     }
48     napi_env env = nullptr;
49     napi_async_work work = nullptr;
50     int64_t time = INVALID_TIME;
51     std::string timeZone = "";
52     napi_deferred deferred = nullptr;
53     napi_ref callbackRef = nullptr;
54     bool isCallback = false;
55     bool isOK = false;
56     bool isNano = false;
57     int errorCode = NO_ERROR;
58 } AsyncContext;
59 
60 struct TimeCallbackPromiseInfo {
61     napi_ref callback = nullptr;
62     napi_deferred deferred = nullptr;
63     bool isCallback = false;
64     int errorCode = NO_ERROR;
65 };
66 } // MiscServicesNapi
67 } // OHOS
68 #endif