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_PRINT_EXT_H 17 #define NAPI_PRINT_EXT_H 18 19 #include "napi/native_api.h" 20 #include "noncopyable.h" 21 #include "print_async_call.h" 22 #include "print_margin.h" 23 #include "print_page_size.h" 24 #include "print_resolution.h" 25 #include "print_task.h" 26 #include "printer_capability.h" 27 #include "printer_info.h" 28 29 namespace OHOS::Print { 30 class NapiPrintExt { 31 public: 32 static napi_value AddPrinters(napi_env env, napi_callback_info info); 33 static napi_value RemovePrinters(napi_env env, napi_callback_info info); 34 static napi_value UpdatePrinters(napi_env env, napi_callback_info info); 35 static napi_value UpdatePrinterState(napi_env env, napi_callback_info info); 36 static napi_value UpdatePrintJobState(napi_env env, napi_callback_info info); 37 static napi_value UpdateExtensionInfo(napi_env env, napi_callback_info info); 38 static napi_value AddPrinterToCups(napi_env env, napi_callback_info info); 39 static napi_value QueryPrinterCapabilityByUri(napi_env env, napi_callback_info info); 40 41 private: 42 static bool IsValidPrinterState(uint32_t state); 43 static bool IsValidPrintJobState(uint32_t state); 44 static bool IsValidPrintJobSubState(uint32_t subState); 45 46 private: 47 struct NapiPrintExtContext : public PrintAsyncCall::Context { 48 bool result = true; 49 std::vector<PrinterInfo> printerInfos; 50 std::vector<std::string> printerIds; 51 52 std::string printerId = ""; 53 uint32_t printerState = 0; 54 55 std::string printJobId = ""; 56 uint32_t printJobState = 0; 57 uint32_t jobSubState = 0; 58 59 std::string extensionId = ""; 60 std::string extInfo = ""; 61 62 std::string printerUri = ""; 63 std::string printerName = ""; 64 PrinterCapability printerCaps; 65 NapiPrintExtContextNapiPrintExtContext66 NapiPrintExtContext() : Context(nullptr, nullptr) {}; NapiPrintExtContextNapiPrintExtContext67 NapiPrintExtContext(InputAction input, OutputAction output) : Context(std::move(input), std::move(output)) {}; ~NapiPrintExtContextNapiPrintExtContext68 virtual ~NapiPrintExtContext() {}; 69 }; 70 }; 71 } // namespace OHOS::Print 72 #endif // NAPI_PRINT_EXT_H 73