1 /* 2 * Copyright (c) 2022 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 NAPI_INNER_PRINT_H 17 #define NAPI_INNER_PRINT_H 18 19 #include <string> 20 #include <vector> 21 22 #include "iprint_callback.h" 23 #include "napi/native_api.h" 24 #include "print_async_call.h" 25 #include "print_extension_info.h" 26 #include "print_job.h" 27 #include "print_task.h" 28 #include "printer_info.h" 29 30 namespace OHOS::Print { 31 class NapiInnerPrint { 32 public: 33 static napi_value QueryExtensionInfo(napi_env env, napi_callback_info info); 34 static napi_value StartDiscovery(napi_env env, napi_callback_info info); 35 static napi_value StopDiscovery(napi_env env, napi_callback_info info); 36 static napi_value ConnectPrinter(napi_env env, napi_callback_info info); 37 static napi_value DisconnectPrinter(napi_env env, napi_callback_info info); 38 static napi_value StartPrintJob(napi_env env, napi_callback_info info); 39 static napi_value CancelPrintJob(napi_env env, napi_callback_info info); 40 static napi_value RequestPreview(napi_env env, napi_callback_info info); 41 static napi_value QueryCapability(napi_env env, napi_callback_info info); 42 static napi_value QueryAllPrintJob(napi_env env, napi_callback_info info); 43 static napi_value QueryPrintJobById(napi_env env, napi_callback_info info); 44 static napi_value On(napi_env env, napi_callback_info info); 45 static napi_value Off(napi_env env, napi_callback_info info); 46 47 private: 48 static bool IsSupportType(const std::string& type); 49 50 private: 51 struct InnerPrintContext : public PrintAsyncCall::Context { 52 std::vector<PrintExtensionInfo> allExtensionInfos; 53 std::vector<PrintJob> allPrintJobs; 54 std::string previewResult = ""; 55 std::string type = ""; 56 sptr<IPrintCallback> callback = nullptr; 57 std::string fileUri = ""; 58 uint32_t fileOffset = 0; 59 uint32_t fileMaxRead = -1; 60 std::vector<uint8_t> fileRead; 61 PrinterCapability printerCapability; 62 bool result = false; 63 std::string stateType_ = ""; 64 PrintJob printJob; 65 std::string jobId = ""; 66 std::string printerId = ""; 67 std::vector<std::string> extensionList; 68 InnerPrintContextInnerPrintContext69 InnerPrintContext() : Context(nullptr, nullptr) {}; InnerPrintContextInnerPrintContext70 InnerPrintContext(InputAction input, OutputAction output) : Context(std::move(input), std::move(output)) {}; ~InnerPrintContextInnerPrintContext71 virtual ~InnerPrintContext() {}; 72 }; 73 }; 74 } // namespace OHOS::Print 75 #endif // NAPI_INNER_PRINT_H 76