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