1 /*
2  * Copyright (c) 2023 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 PRINT_MODAL_UI_CALLBACK_H
17 #define PRINT_MODAL_UI_CALLBACK_H
18 
19 #include "want.h"
20 #include <string>
21 #include <uv.h>
22 #include <js_native_api.h>
23 #include "napi/native_api.h"
24 #include "ability_context.h"
25 #include "ui_extension_context.h"
26 
27 #include "print_task.h"
28 #include "print_context.h"
29 
30 namespace OHOS {
31 namespace Print {
32 
33 class PrintModalUICallback {
34 public:
35     explicit PrintModalUICallback(std::shared_ptr<BaseContext> baseContext);
36     void OnRelease(int32_t releaseCode);
37     void OnResultForModal(int32_t resultCode, const OHOS::AAFwk::Want& result);
38     void OnReceive(const OHOS::AAFwk::WantParams& request);
39     void OnError(int32_t code, const std::string& name, const std::string& message);
40     void SetSessionId(int32_t sessionId);
41 
42 private:
43     static napi_status CreateResultMessage(BaseContext* context, napi_value* result, uint32_t length);
44     static napi_status CreatePrintResult(PrintContext* context, napi_value& result);
45     static napi_value CreateBusinessError(const napi_env& env, int32_t errCode, const std::string& errMsg);
46     void SendMessageBack();
47     static void SendMessageBackWork(uv_work_t* work, int statusIn);
48     int32_t sessionId_ = 0;
49     std::shared_ptr<BaseContext> baseContext = nullptr;
50     bool isResultForModal = false;
51 };
52 } // namespace Print
53 } // namespace OHOS
54 #endif // PRINT_MODAL_UI_CALLBACK_H