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