1 /*
2  * Copyright (c) 2024 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 ADVANCED_UI_COMPONENT_NAVPUSHPATHHELPER_INCLUDE_HSP_SILENT_INSTALL_NAPI_H
17 #define ADVANCED_UI_COMPONENT_NAVPUSHPATHHELPER_INCLUDE_HSP_SILENT_INSTALL_NAPI_H
18 
19 #include "native_engine/native_engine.h"
20 
21 #include "napi/native_api.h"
22 #include "napi/native_node_api.h"
23 
24 namespace OHOS::NavPushPathHelper {
25 class HspSilentInstallNapi {
26     public:
27         static napi_value SilentInstall(napi_env env, napi_callback_info info);
28         static napi_value IsHspExist(napi_env env, napi_callback_info info);
29         static napi_value InitRouteMap(napi_env env, napi_callback_info info);
30 
31     private:
32         struct CallbackData {
33             napi_env env = nullptr;
34             int32_t errCode = 0;
35             std::string errorMessage;
36             napi_ref successCallback = nullptr;
37             napi_ref failCallback = nullptr;
38 
~CallbackDataCallbackData39             ~CallbackData()
40             {
41                 if (this->successCallback != nullptr) {
42                     napi_delete_reference(this->env, this->successCallback);
43                     this->successCallback = nullptr;
44                 }
45                 if (this->failCallback != nullptr) {
46                     napi_delete_reference(this->env, this->failCallback);
47                     this->failCallback = nullptr;
48                 }
49             }
50         };
51 
52         static void SendSuccessBackWork(uv_work_t *work, int statusIn);
53         static void SendFailBackWork(uv_work_t *work, int statusIn);
54         static napi_value CreateResultMessage(CallbackData *callbackData);
55         static napi_value getModuleName(napi_env env, napi_value args, std::string& moduleName);
56 };
57 }
58 
59 #endif