• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
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 #include "print_utils.h"
30 #include "print_constant.h"
31 #include "printer_preferences.h"
32 
33 namespace OHOS::Print {
34 class NapiInnerPrint {
35 public:
36     static napi_value QueryExtensionInfo(napi_env env, napi_callback_info info);
37     static napi_value StartDiscovery(napi_env env, napi_callback_info info);
38     static napi_value StopDiscovery(napi_env env, napi_callback_info info);
39     static napi_value ConnectPrinter(napi_env env, napi_callback_info info);
40     static napi_value DisconnectPrinter(napi_env env, napi_callback_info info);
41     static napi_value StartPrintJob(napi_env env, napi_callback_info info);
42     static napi_value CancelPrintJob(napi_env env, napi_callback_info info);
43     static napi_value RestartPrintJob(napi_env env, napi_callback_info info);
44     static napi_value RequestPreview(napi_env env, napi_callback_info info);
45     static napi_value QueryCapability(napi_env env, napi_callback_info info);
46     static napi_value QueryAllPrintJob(napi_env env, napi_callback_info info);
47     static napi_value QueryAllActivePrintJob(napi_env env, napi_callback_info info);
48     static napi_value QueryPrintJobById(napi_env env, napi_callback_info info);
49     static napi_value On(napi_env env, napi_callback_info info);
50     static napi_value Off(napi_env env, napi_callback_info info);
51     static napi_value StartGetPrintFile(napi_env env, napi_callback_info info);
52     static napi_value NotifyPrintService(napi_env env, napi_callback_info info);
53     static napi_value QueryAddedPrinter(napi_env env, napi_callback_info info);
54     static napi_value QueryPrinterInfoByPrinterId(napi_env env, napi_callback_info info);
55     static napi_value NotifyPrintServiceEvent(napi_env env, napi_callback_info info);
56     static napi_value SetPrinterPreference(napi_env env, napi_callback_info info);
57     static napi_value SetDefaultPrinter(napi_env env, napi_callback_info info);
58     static napi_value GetAddedPrinterInfoById(napi_env env, napi_callback_info info);
59 
60 private:
61     static bool IsSupportType(const std::string& type);
62     static bool IsValidApplicationEvent(uint32_t event);
63     static bool IsValidDefaultPrinterType(uint32_t type);
64     static void NapiThrowError(napi_env env, int32_t errCode);
65     static bool CheckCallerIsSystemApp();
66 
67 private:
68     struct InnerPrintContext : public PrintAsyncCall::Context {
69         std::vector<PrintExtensionInfo> allExtensionInfos;
70         std::vector<PrintJob> allPrintJobs;
71         std::vector<std::string> allPrinters;
72         std::string previewResult = "";
73         std::string type = "";
74         sptr<IPrintCallback> callback = nullptr;
75         std::string fileUri = "";
76         uint32_t fileOffset = 0;
77         uint32_t fileMaxRead = -1;
78         std::vector<uint8_t> fileRead;
79         PrinterCapability printerCapability;
80         bool result = false;
81         std::string stateType_ = "";
82         PrintJob printJob;
83         PrinterInfo printerInfo;
84         std::string jobId = "";
85         std::string printerId = "";
86         std::vector<std::string> extensionList;
87         uint32_t applicationEvent = -1;
88         PrinterPreferences printerPreference;
89         uint32_t defaultPrinterType = -1;
90 
InnerPrintContextInnerPrintContext91         InnerPrintContext() : Context(nullptr, nullptr) {};
InnerPrintContextInnerPrintContext92         InnerPrintContext(InputAction input, OutputAction output) : Context(std::move(input), std::move(output)) {};
~InnerPrintContextInnerPrintContext93         virtual ~InnerPrintContext() {};
94     };
95 };
96 }  // namespace OHOS::Print
97 #endif  // NAPI_INNER_PRINT_H
98