1 /* 2 * Copyright (c) 2025 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_JS_INSIGHT_INTENT_UTILS_H 17 #define OHOS_ABILITY_RUNTIME_JS_INSIGHT_INTENT_UTILS_H 18 19 #include "insight_intent_execute_result.h" 20 #include "insight_intent_executor.h" 21 #include "napi/native_api.h" 22 23 namespace OHOS { 24 namespace AbilityRuntime { 25 class JsInsightIntentUtils final { 26 public: 27 enum class State : uint8_t { 28 INVALID, 29 CREATED, 30 INITIALIZED, 31 EXECUTING, 32 EXECUTATION_DONE, 33 DESTROYED 34 }; 35 36 static bool CallJsFunctionWithResult( 37 napi_env env, 38 napi_value obj, 39 const char* funcName, 40 size_t argc, 41 const napi_value* argv, 42 napi_value& result 43 ); 44 45 static std::shared_ptr<AppExecFwk::InsightIntentExecuteResult> GetResultFromJs(napi_env env, napi_value resultJs); 46 47 static napi_value ResolveCbCpp(napi_env env, napi_callback_info info); 48 49 static napi_value RejectCbCpp(napi_env env, napi_callback_info info); 50 51 static void ReplyFailed(InsightIntentExecutorAsyncCallback* callback, 52 InsightIntentInnerErr innerErr = InsightIntentInnerErr::INSIGHT_INTENT_EXECUTE_REPLY_FAILED); 53 54 static void ReplySucceeded(InsightIntentExecutorAsyncCallback* callback, 55 std::shared_ptr<AppExecFwk::InsightIntentExecuteResult> resultCpp); 56 57 static std::string StringifyObject(napi_env env, napi_value result); 58 }; 59 } // namespace AbilityRuntime 60 } // namespace OHOS 61 #endif // OHOS_ABILITY_RUNTIME_JS_INSIGHT_INTENT_UTILS_H