• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
1 /*
2  * Copyright (c) 2022-2024 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 CM_NAPI_DIALOG_COMMON_H
17 #define CM_NAPI_DIALOG_COMMON_H
18 
19 #include <string>
20 
21 #include "napi/native_api.h"
22 #include "napi/native_node_api.h"
23 
24 #include "cm_mem.h"
25 #include "cm_type.h"
26 
27 namespace CMNapi {
28 
29 static const std::string BUSINESS_ERROR_PROPERTY_CODE = "code";
30 static const std::string BUSINESS_ERROR_PROPERTY_MESSAGE = "message";
31 static const int32_t RESULT_NUMBER = 2;
32 
33 napi_value ParseUint32(napi_env env, napi_value object, uint32_t &store);
34 napi_value ParseBoolean(napi_env env, napi_value object, bool &status);
35 napi_value ParseString(napi_env env, napi_value object, CmBlob *&blob);
36 
37 void ThrowError(napi_env env, int32_t errorCode, const std::string errMsg);
38 napi_value GenerateBusinessError(napi_env env, int32_t errorCode);
39 
40 void GeneratePromise(napi_env env, napi_deferred deferred, int32_t resultCode,
41     napi_value *result, int32_t length);
42 
GetNull(napi_env env)43 inline napi_value GetNull(napi_env env)
44 {
45     napi_value result = nullptr;
46     NAPI_CALL(env, napi_get_null(env, &result));
47     return result;
48 }
49 
GetInt32(napi_env env,int32_t value)50 inline napi_value GetInt32(napi_env env, int32_t value)
51 {
52     napi_value result = nullptr;
53     NAPI_CALL(env, napi_create_int32(env, value, &result));
54     return result;
55 }
56 
57 enum CmDialogPageType {
58     PAGE_MAIN = 1,
59     PAGE_CA_CERTIFICATE = 2,
60     PAGE_CREDENTIAL = 3,
61     PAGE_INSTALL_CERTIFICATE = 4
62 };
63 
64 enum ErrorCode {
65     SUCCESS = 0,
66     HAS_NO_PERMISSION = 201,
67     NOT_SYSTEM_APP = 202,
68     PARAM_ERROR = 401,
69     DIALOG_ERROR_GENERIC = 29700001,
70     DIALOG_ERROR_OPERATION_CANCELED = 29700002,
71 };
72 
73 }  // namespace CertManagerNapi
74 
75 #endif
76