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_CONTEXT_H 17 #define PRINT_CONTEXT_H 18 19 #include "ability_context.h" 20 #include "ui_extension_context.h" 21 #include "napi/native_api.h" 22 #include <string> 23 #include <vector> 24 25 #include "print_log.h" 26 27 namespace OHOS { 28 namespace Print { 29 30 enum PrintRequestType { 31 REQUEST_TYPE_START, 32 REQUEST_TYPE_INVALID, 33 }; 34 35 struct PrintInfo { 36 std::string jobId; 37 std::string fileList; 38 }; 39 40 struct ErrorMessage { 41 int32_t code; 42 std::string message; 43 }; 44 45 struct BaseContext { 46 napi_env env = nullptr; 47 napi_deferred deferred = nullptr; 48 napi_ref callback = nullptr; 49 50 std::shared_ptr<OHOS::AbilityRuntime::AbilityContext> context = nullptr; 51 std::shared_ptr<OHOS::AbilityRuntime::UIExtensionContext> uiExtensionContext = nullptr; 52 PrintRequestType requestType = PrintRequestType::REQUEST_TYPE_INVALID; 53 ErrorMessage errorMessage; 54 ~BaseContextBaseContext55 ~BaseContext() 56 { 57 PRINT_HILOGI("release enter"); 58 if (this->callback != nullptr) { 59 napi_delete_reference(this->env, this->callback); 60 this->callback = nullptr; 61 PRINT_HILOGI("release callback"); 62 } 63 64 if (this->deferred != nullptr) { 65 this->deferred = nullptr; 66 PRINT_HILOGI("release deferred"); 67 } 68 PRINT_HILOGI("release exit"); 69 } 70 }; 71 72 struct PrintContext : BaseContext { 73 PrintInfo printInfo; 74 }; 75 } // namespace OHOS 76 } // namespace Print 77 #endif 78