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 OHOS_ABILITY_RUNTIME_NAPI_COMMON_DATA_H
17 #define OHOS_ABILITY_RUNTIME_NAPI_COMMON_DATA_H
18 
19 #include <map>
20 #include <string>
21 #include <vector>
22 
23 #include "ability.h"
24 #include "js_runtime_utils.h"
25 #include "napi/native_api.h"
26 #include "napi/native_common.h"
27 #include "napi/native_node_api.h"
28 #include "native_engine/native_engine.h"
29 #include "pac_map.h"
30 
31 using Ability = OHOS::AppExecFwk::Ability;
32 namespace OHOS {
33 namespace AppExecFwk {
34 #define NATIVE_C_BUFFER_SIZE 1024 /* Converted to C-style string buffer size */
35 #define ARGS_MAX_COUNT 10
36 #define ARGS_ASYNC_COUNT 1
37 
38 #define ARGS_ZERO 0
39 #define ARGS_ONE 1
40 #define ARGS_TWO 2
41 #define ARGS_THREE 3
42 #define ARGS_FOUR 4
43 #define ARGS_FIVE 5
44 #define ARGS_SIX 6
45 #define ARGS_SEVEN 7
46 #define ARGS_EIGHT 8
47 #define ARGS_NINE 9
48 #define ARGS_TEN 10
49 
50 #define PARAM0 0
51 #define PARAM1 1
52 #define PARAM2 2
53 #define PARAM3 3
54 #define PARAM4 4
55 #define PARAM5 5
56 #define PARAM6 6
57 #define PARAM7 7
58 #define PARAM8 8
59 #define PARAM9 9
60 #define PARAM10 10
61 
62 struct CallbackInfo {
63     napi_env env = nullptr;
64     napi_ref callback = nullptr;
65     napi_deferred deferred;
66     int errCode = 0;
67     AbilityRuntime::NapiAsyncTask *napiAsyncTask = nullptr;
68 };
69 
70 struct CallAbilityParamData {
71     PacMap paramArgs;
72     Want want;
73 };
74 
75 typedef enum {
76     NVT_NONE = 0,
77     NVT_UNDEFINED,
78     NVT_INT32,
79     NVT_BOOL,
80     NVT_STRING,
81     NVT_DOUBLE,
82     NVT_PACMAP,
83 } TNativeValueType;
84 
85 typedef struct __ThreadReturnData {
86     TNativeValueType data_type;
87     int32_t int32_value;
88     bool bool_value;
89     std::string str_value;
90     double double_value;
91     PacMap pac_value;
92 } ThreadReturnData;
93 
94 typedef struct __AsyncJSCallbackInfo {
95     CallbackInfo cbInfo;
96     napi_async_work asyncWork;
97     napi_deferred deferred;
98     Ability *ability;
99     AbilityType abilityType;
100     CallAbilityParamData param;
101     ThreadReturnData native_data;
102     napi_value result;
103     int error_code;
104     CallbackInfo *aceCallback;
105 } AsyncJSCallbackInfo;
106 
107 typedef struct __AsyncParamEx {
108     std::string resource;
109     size_t argc;
110     napi_async_execute_callback execute;
111     napi_async_complete_callback complete;
112 } AsyncParamEx;
113 
114 typedef struct __ComplexArrayData {
115     std::vector<int> intList;
116     std::vector<long> longList;
117     std::vector<bool> boolList;
118     std::vector<double> doubleList;
119     std::vector<std::string> stringList;
120     std::vector<napi_value> objectList;
121 } ComplexArrayData;
122 }  // namespace AppExecFwk
123 }  // namespace OHOS
124 #endif  // OHOS_ABILITY_RUNTIME_NAPI_COMMON_DATA_H
125