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