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 NativeEngine *engine = nullptr; 68 AbilityRuntime::AsyncTask *asyncTask = nullptr; 69 }; 70 71 struct CallAbilityParamData { 72 PacMap paramArgs; 73 Want want; 74 }; 75 76 typedef enum { 77 NVT_NONE = 0, 78 NVT_UNDEFINED, 79 NVT_INT32, 80 NVT_BOOL, 81 NVT_STRING, 82 NVT_DOUBLE, 83 NVT_PACMAP, 84 } TNativeValueType; 85 86 typedef struct __ThreadReturnData { 87 TNativeValueType data_type; 88 int32_t int32_value; 89 bool bool_value; 90 std::string str_value; 91 double double_value; 92 PacMap pac_value; 93 } ThreadReturnData; 94 95 typedef struct __AsyncJSCallbackInfo { 96 CallbackInfo cbInfo; 97 napi_async_work asyncWork; 98 napi_deferred deferred; 99 Ability *ability; 100 AbilityType abilityType; 101 CallAbilityParamData param; 102 ThreadReturnData native_data; 103 napi_value result; 104 int error_code; 105 CallbackInfo *aceCallback; 106 } AsyncJSCallbackInfo; 107 108 typedef struct __AsyncParamEx { 109 std::string resource; 110 size_t argc; 111 napi_async_execute_callback execute; 112 napi_async_complete_callback complete; 113 } AsyncParamEx; 114 115 typedef struct __ComplexArrayData { 116 std::vector<int> intList; 117 std::vector<long> longList; 118 std::vector<bool> boolList; 119 std::vector<double> doubleList; 120 std::vector<std::string> stringList; 121 std::vector<napi_value> objectList; 122 } ComplexArrayData; 123 } // namespace AppExecFwk 124 } // namespace OHOS 125 #endif // OHOS_ABILITY_RUNTIME_NAPI_COMMON_DATA_H 126