• 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 #include "napi_inner_print.h"
17 #include "napi_print_ext.h"
18 #include "napi_print_task.h"
19 #include "print_constant.h"
20 #include "print_log.h"
21 
22 using namespace OHOS::Print;
23 
24 static constexpr const char *FUNCTION_PRINT = "print";
25 static constexpr const char *FUNCTION_QUERY_EXT = "queryAllPrinterExtensionInfos";
26 static constexpr const char *FUNCTION_START_DISCOVERY = "startDiscoverPrinter";
27 static constexpr const char *FUNCTION_STOP_DISCOVERY = "stopDiscoverPrinter";
28 static constexpr const char *FUNCTION_CONNECT_PRINT = "connectPrinter";
29 static constexpr const char *FUNCTION_DISCONNECT_PRINT = "disconnectPrinter";
30 static constexpr const char *FUNCTION_START_PRINT = "startPrintJob";
31 static constexpr const char *FUNCTION_CANCEL_PRINT = "cancelPrintJob";
32 static constexpr const char *FUNCTION_REQUEST_PREVIEW = "requestPrintPreview";
33 static constexpr const char *FUNCTION_QUERY_CAPABILITY = "queryPrinterCapability";
34 static constexpr const char *FUNCTION_QUERY_ALL_PRINTJOB = "queryAllPrintJobs";
35 static constexpr const char *FUNCTION_QUERY_PRINTJOB_BYID = "queryPrintJobById";
36 static constexpr const char *FUNCTION_REGISTER_EVENT = "on";
37 static constexpr const char *FUNCTION_UNREGISTER_EVENT = "off";
38 static constexpr const char *FUNCTION_ADD_PRINTER = "addPrinters";
39 static constexpr const char *FUNCTION_REMOVE_PRINTER = "removePrinters";
40 static constexpr const char *FUNCTION_UPDATE_PRINTER = "updatePrinters";
41 static constexpr const char *FUNCTION_UPDATE_PRINTER_STATE = "updatePrinterState";
42 static constexpr const char *FUNCTION_UPDATE_JOB_STATE = "updatePrintJobState";
43 static constexpr const char *FUNCTION_UPDATE_EXTENSION_INFO = "updateExtensionInfo";
44 static constexpr const char *FUNCTION_NATIVE_ADD_PRINTER_TO_CUPS = "addPrinterToCups";
45 static constexpr const char *FUNCTION_QUERY_CAPABILITY_BY_URI = "queryPrinterCapabilityByUri";
46 
47 static constexpr const char *PROPERTY_PRINTER_ADD = "PRINTER_ADDED";
48 static constexpr const char *PROPERTY_PRINTER_REMOVE = "PRINTER_REMOVED";
49 static constexpr const char *PROPERTY_PRINTER_UPDATE_CAP = "PRINTER_UPDATE_CAP";
50 static constexpr const char *PROPERTY_PRINTER_CONNECTED = "PRINTER_CONNECTED";
51 static constexpr const char *PROPERTY_PRINTER_DISCONNECTED = "PRINTER_DISCONNECTED";
52 static constexpr const char *PROPERTY_PRINTER_RUNNING = "PRINTER_RUNNING";
53 
54 static constexpr const char *PROPERTY_PRINT_JOB_PREPARE = "PRINT_JOB_PREPARE";
55 static constexpr const char *PROPERTY_PRINT_JOB_QUEUED = "PRINT_JOB_QUEUED";
56 static constexpr const char *PROPERTY_PRINT_JOB_RUNNING = "PRINT_JOB_RUNNING";
57 static constexpr const char *PROPERTY_PRINT_JOB_BLOCKED = "PRINT_JOB_BLOCKED";
58 static constexpr const char *PROPERTY_PRINT_JOB_COMPLETED = "PRINT_JOB_COMPLETED";
59 
60 static constexpr const char *PROPERTY_COMPLETED_SUCCESS = "PRINT_JOB_COMPLETED_SUCCESS";
61 static constexpr const char *PROPERTY_COMPLETED_FAILED = "PRINT_JOB_COMPLETED_FAILED";
62 static constexpr const char *PROPERTY_COMPLETED_CANCELLED = "PRINT_JOB_COMPLETED_CANCELLED";
63 static constexpr const char *PROPERTY_COMPLETED_FILE_CORRUPT = "PRINT_JOB_COMPLETED_FILE_CORRUPT";
64 static constexpr const char *PROPERTY_BLOCK_OFFLINE = "PRINT_JOB_BLOCK_OFFLINE";
65 static constexpr const char *PROPERTY_BLOCK_BUSY = "PRINT_JOB_BLOCK_BUSY";
66 static constexpr const char *PROPERTY_BLOCK_CANCELLED = "PRINT_JOB_BLOCK_CANCELLED";
67 static constexpr const char *PROPERTY_BLOCK_OUT_OF_PAPER = "PRINT_JOB_BLOCK_OUT_OF_PAPER";
68 static constexpr const char *PROPERTY_BLOCK_OUT_OF_INK = "PRINT_JOB_BLOCK_OUT_OF_INK";
69 static constexpr const char *PROPERTY_BLOCK_OUT_OF_TONER = "PRINT_JOB_BLOCK_OUT_OF_TONER";
70 static constexpr const char *PROPERTY_BLOCK_JAMMED = "PRINT_JOB_BLOCK_JAMMED";
71 static constexpr const char *PROPERTY_BLOCK_DOOR_OPEN = "PRINT_JOB_BLOCK_DOOR_OPEN";
72 static constexpr const char *PROPERTY_BLOCK_SERVICE_REQUEST = "PRINT_JOB_BLOCK_SERVICE_REQUEST";
73 static constexpr const char *PROPERTY_BLOCK_LOW_ON_INK = "PRINT_JOB_BLOCK_LOW_ON_INK";
74 static constexpr const char *PROPERTY_BLOCK_LOW_ON_TONER = "PRINT_JOB_BLOCK_LOW_ON_TONER";
75 static constexpr const char *PROPERTY_BLOCK_REALLY_LOW_ON_INK = "PRINT_JOB_BLOCK_REALLY_LOW_ON_INK";
76 static constexpr const char *PROPERTY_BLOCK_BAD_CERTIFICATE = "PRINT_JOB_BLOCK_BAD_CERTIFICATE";
77 static constexpr const char *PROPERTY_BLOCK_ACCOUNT_ERROR = "PRINT_BLOCK_ACCOUNT_ERROR";
78 static constexpr const char *PROPERTY_BLOCK_PRINT_PERMISSION_ERROR = "PRINT_JOB_BLOCK_PRINT_PERMISSION_ERROR";
79 static constexpr const char *PROPERTY_BLOCK_PRINT_COLOR_PERMISSION_ERROR = "PRINT_JOB_BLOCK_PRINT_COLOR_PERMISSION_ERROR";
80 static constexpr const char *PROPERTY_BLOCK_NETWORK_ERROR = "PRINT_JOB_BLOCK_NETWORK_ERROR";
81 static constexpr const char *PROPERTY_BLOCK_CONNECT_SERVER_ERROR = "PRINT_JOB_BLOCK_CONNECT_SERVER_ERROR";
82 static constexpr const char *PROPERTY_BLOCK_LARGE_FILE_ERROR = "PRINT_JOB_BLOCK_LARGE_FILE_ERROR";
83 static constexpr const char *PROPERTY_BLOCK_PARSE_FILE_ERROR = "PRINT_JOB_BLOCK_PARSE_FILE_ERROR";
84 static constexpr const char *PROPERTY_BLOCK_FILE_CONVERT_SLOWLY = "PRINT_JOB_BLOCK_FILE_CONVERT_SLOWLY";
85 static constexpr const char *PROPERTY_RUNNING_UPLOADING_FILES = "PRINT_JOB_RUNNING_UPLOADING_FILES";
86 static constexpr const char *PROPERTY_RUNNING_CONVERTING_FILES = "PRINT_JOB_RUNNING_CONVERTING_FILES";
87 static constexpr const char *PROPERTY_BLOCK_UNKNOWN = "PRINT_JOB_BLOCK_UNKNOWN";
88 
89 static constexpr const char *PROPERTY_ERR_NONE = "E_PRINT_NONE";
90 static constexpr const char *PROPERTY_ERR_NO_PERMISSION = "E_PRINT_NO_PERMISSION";
91 static constexpr const char *PROPERTY_ERR_INVALID_PARAMETER = "E_PRINT_INVALID_PARAMETER";
92 static constexpr const char *PROPERTY_ERR_GENERIC_FAILURE = "E_PRINT_GENERIC_FAILURE";
93 static constexpr const char *PROPERTY_ERR_RPC_FAILURE = "E_PRINT_RPC_FAILURE";
94 static constexpr const char *PROPERTY_ERR_SERVER_FAILURE = "E_PRINT_SERVER_FAILURE";
95 static constexpr const char *PROPERTY_ERR_INVALID_EXTENSION = "E_PRINT_INVALID_EXTENSION";
96 static constexpr const char *PROPERTY_ERR_INVALID_PRINTER = "E_PRINT_INVALID_PRINTER";
97 static constexpr const char *PROPERTY_ERR_INVALID_PRINTJOB = "E_PRINT_INVALID_PRINTJOB";
98 static constexpr const char *PROPERTY_ERR_FILE_IO = "E_PRINT_FILE_IO";
99 
100 static napi_value printer_add = nullptr;
101 static napi_value printer_removed = nullptr;
102 static napi_value printer_updatecap = nullptr;
103 static napi_value printer_connected = nullptr;
104 static napi_value printer_disconnected = nullptr;
105 static napi_value printer_running = nullptr;
106 
107 static napi_value print_job_prepare = nullptr;
108 static napi_value print_job_queued = nullptr;
109 static napi_value print_job_running = nullptr;
110 static napi_value print_job_blocked = nullptr;
111 static napi_value print_job_completed = nullptr;
112 
113 static napi_value completed_success = nullptr;
114 static napi_value completed_failed = nullptr;
115 static napi_value completed_cancelled = nullptr;
116 static napi_value completed_file_corrupt = nullptr;
117 static napi_value block_offline = nullptr;
118 static napi_value block_busy = nullptr;
119 static napi_value block_cancelled = nullptr;
120 static napi_value block_out_of_paper = nullptr;
121 static napi_value block_out_of_ink = nullptr;
122 static napi_value block_out_of_toner = nullptr;
123 static napi_value block_jammed = nullptr;
124 static napi_value block_door_open = nullptr;
125 static napi_value block_service_request = nullptr;
126 static napi_value block_low_on_ink = nullptr;
127 static napi_value block_low_on_toner = nullptr;
128 static napi_value block_really_low_on_ink = nullptr;
129 static napi_value block_bad_certificate = nullptr;
130 static napi_value block_account_error = nullptr;
131 static napi_value block_print_permission_error = nullptr;
132 static napi_value block_print_color_permission_error = nullptr;
133 static napi_value block_network_error = nullptr;
134 static napi_value block_connect_server_error = nullptr;
135 static napi_value block_large_file_error = nullptr;
136 static napi_value block_parse_file_error = nullptr;
137 static napi_value block_file_convert_slowly = nullptr;
138 static napi_value running_uploading_files = nullptr;
139 static napi_value running_converting_files = nullptr;
140 static napi_value block_unknown = nullptr;
141 
142 static napi_value err_none = nullptr;
143 static napi_value err_no_permission = nullptr;
144 static napi_value err_invalid_parameter = nullptr;
145 static napi_value err_generic_failure = nullptr;
146 static napi_value err_rpc_failure = nullptr;
147 static napi_value err_server_failure = nullptr;
148 static napi_value err_invalid_extension = nullptr;
149 static napi_value err_invalid_printer = nullptr;
150 static napi_value err_invalid_printjob = nullptr;
151 static napi_value err_file_io = nullptr;
152 
153 #define PRINT_NAPI_METHOD(name, func)           \
154     {                                           \
155         name, 0, func, 0, 0, 0, napi_default, 0 \
156     }
157 
158 #define PRINT_NAPI_PROPERTY(name, val)                                          \
159     {                                                                           \
160         (name), nullptr, nullptr, nullptr, nullptr, val, napi_static, nullptr   \
161     }
162 
NapiCreateEnum(napi_env env)163 static void NapiCreateEnum(napi_env env)
164 {
165     // create printer state enum
166     napi_create_int32(env, static_cast<int32_t>(PRINTER_ADDED), &printer_add);
167     napi_create_int32(env, static_cast<int32_t>(PRINTER_REMOVED), &printer_removed);
168     napi_create_int32(env, static_cast<int32_t>(PRINTER_UPDATE_CAP), &printer_updatecap);
169     napi_create_int32(env, static_cast<int32_t>(PRINTER_CONNECTED), &printer_connected);
170     napi_create_int32(env, static_cast<int32_t>(PRINTER_DISCONNECTED), &printer_disconnected);
171     napi_create_int32(env, static_cast<int32_t>(PRINTER_RUNNING), &printer_running);
172 
173     // create print job state enum
174     napi_create_int32(env, static_cast<int32_t>(PRINT_JOB_PREPARED), &print_job_prepare);
175     napi_create_int32(env, static_cast<int32_t>(PRINT_JOB_QUEUED), &print_job_queued);
176     napi_create_int32(env, static_cast<int32_t>(PRINT_JOB_RUNNING), &print_job_running);
177     napi_create_int32(env, static_cast<int32_t>(PRINT_JOB_BLOCKED), &print_job_blocked);
178     napi_create_int32(env, static_cast<int32_t>(PRINT_JOB_COMPLETED), &print_job_completed);
179 
180     // create print job sub-state enum
181     napi_create_int32(env, static_cast<int32_t>(PRINT_JOB_COMPLETED_SUCCESS), &completed_success);
182     napi_create_int32(env, static_cast<int32_t>(PRINT_JOB_COMPLETED_FAILED), &completed_failed);
183     napi_create_int32(env, static_cast<int32_t>(PRINT_JOB_COMPLETED_CANCELLED), &completed_cancelled);
184     napi_create_int32(env, static_cast<int32_t>(PRINT_JOB_COMPLETED_FILE_CORRUPT), &completed_file_corrupt);
185     napi_create_int32(env, static_cast<int32_t>(PRINT_JOB_BLOCKED_OFFLINE), &block_offline);
186     napi_create_int32(env, static_cast<int32_t>(PRINT_JOB_BLOCKED_BUSY), &block_busy);
187     napi_create_int32(env, static_cast<int32_t>(PRINT_JOB_BLOCKED_CANCELLED), &block_cancelled);
188     napi_create_int32(env, static_cast<int32_t>(PRINT_JOB_BLOCKED_OUT_OF_PAPER), &block_out_of_paper);
189     napi_create_int32(env, static_cast<int32_t>(PRINT_JOB_BLOCKED_OUT_OF_INK), &block_out_of_ink);
190     napi_create_int32(env, static_cast<int32_t>(PRINT_JOB_BLOCKED_OUT_OF_TONER), &block_out_of_toner);
191     napi_create_int32(env, static_cast<int32_t>(PRINT_JOB_BLOCKED_JAMMED), &block_jammed);
192     napi_create_int32(env, static_cast<int32_t>(PRINT_JOB_BLOCKED_DOOR_OPEN), &block_door_open);
193     napi_create_int32(env, static_cast<int32_t>(PRINT_JOB_BLOCKED_SERVICE_REQUEST), &block_service_request);
194     napi_create_int32(env, static_cast<int32_t>(PRINT_JOB_BLOCKED_LOW_ON_INK), &block_low_on_ink);
195     napi_create_int32(env, static_cast<int32_t>(PRINT_JOB_BLOCKED_LOW_ON_TONER), &block_low_on_toner);
196     napi_create_int32(env, static_cast<int32_t>(PRINT_JOB_BLOCKED_REALLY_LOW_ON_INK), &block_really_low_on_ink);
197     napi_create_int32(env, static_cast<int32_t>(PRINT_JOB_BLOCKED_BAD_CERTIFICATE), &block_bad_certificate);
198     napi_create_int32(env, static_cast<int32_t>(PRINT_JOB_BLOCKED_ACCOUNT_ERROR), &block_account_error);
199     napi_create_int32(env, static_cast<int32_t>(PRINT_JOB_BLOCKED_PRINT_PERMISSION_ERROR), &block_print_permission_error);
200     napi_create_int32(env, static_cast<int32_t>(PRINT_JOB_BLOCKED_PRINT_COLOR_PERMISSION_ERROR), &block_print_color_permission_error);
201     napi_create_int32(env, static_cast<int32_t>(PRINT_JOB_BLOCKED_NETWORK_ERROR), &block_network_error);
202     napi_create_int32(env, static_cast<int32_t>(PRINT_JOB_BLOCKED_CONNECT_SERVER_ERROR), &block_connect_server_error);
203     napi_create_int32(env, static_cast<int32_t>(PRINT_JOB_BLOCKED_LARGE_FILE_ERROR), &block_large_file_error);
204     napi_create_int32(env, static_cast<int32_t>(PRINT_JOB_BLOCKED_PARSE_FILE_ERROR), &block_parse_file_error);
205     napi_create_int32(env, static_cast<int32_t>(PRINT_JOB_BLOCKED_FILE_CONVERT_SLOWLY), &block_file_convert_slowly);
206     napi_create_int32(env, static_cast<int32_t>(PRINT_JOB_RUNNING_UPLOADING_FILES), &running_uploading_files);
207     napi_create_int32(env, static_cast<int32_t>(PRINT_JOB_RUNNING_CONVERTING_FILES), &running_converting_files);
208     napi_create_int32(env, static_cast<int32_t>(PRINT_JOB_BLOCKED_UNKNOWN), &block_unknown);
209 
210     // create error code of js api
211     napi_create_int32(env, static_cast<int32_t>(E_PRINT_NONE), &err_none);
212     napi_create_int32(env, static_cast<int32_t>(E_PRINT_NO_PERMISSION), &err_no_permission);
213     napi_create_int32(env, static_cast<int32_t>(E_PRINT_INVALID_PARAMETER), &err_invalid_parameter);
214     napi_create_int32(env, static_cast<int32_t>(E_PRINT_GENERIC_FAILURE), &err_generic_failure);
215     napi_create_int32(env, static_cast<int32_t>(E_PRINT_RPC_FAILURE), &err_rpc_failure);
216     napi_create_int32(env, static_cast<int32_t>(E_PRINT_SERVER_FAILURE), &err_server_failure);
217     napi_create_int32(env, static_cast<int32_t>(E_PRINT_INVALID_EXTENSION), &err_invalid_extension);
218     napi_create_int32(env, static_cast<int32_t>(E_PRINT_INVALID_PRINTER), &err_invalid_printer);
219     napi_create_int32(env, static_cast<int32_t>(E_PRINT_INVALID_PRINTJOB), &err_invalid_printjob);
220     napi_create_int32(env, static_cast<int32_t>(E_PRINT_FILE_IO), &err_file_io);
221 }
222 
Init(napi_env env,napi_value exports)223 static napi_value Init(napi_env env, napi_value exports)
224 {
225     NapiCreateEnum(env);
226     napi_property_descriptor desc[] = {
227         PRINT_NAPI_PROPERTY(PROPERTY_PRINTER_ADD, printer_add),
228         PRINT_NAPI_PROPERTY(PROPERTY_PRINTER_REMOVE, printer_removed),
229         PRINT_NAPI_PROPERTY(PROPERTY_PRINTER_UPDATE_CAP, printer_updatecap),
230         PRINT_NAPI_PROPERTY(PROPERTY_PRINTER_CONNECTED, printer_connected),
231         PRINT_NAPI_PROPERTY(PROPERTY_PRINTER_DISCONNECTED, printer_disconnected),
232         PRINT_NAPI_PROPERTY(PROPERTY_PRINTER_RUNNING, printer_running),
233 
234         PRINT_NAPI_PROPERTY(PROPERTY_PRINT_JOB_PREPARE, print_job_prepare),
235         PRINT_NAPI_PROPERTY(PROPERTY_PRINT_JOB_QUEUED, print_job_queued),
236         PRINT_NAPI_PROPERTY(PROPERTY_PRINT_JOB_RUNNING, print_job_running),
237         PRINT_NAPI_PROPERTY(PROPERTY_PRINT_JOB_BLOCKED, print_job_blocked),
238         PRINT_NAPI_PROPERTY(PROPERTY_PRINT_JOB_COMPLETED, print_job_completed),
239 
240         PRINT_NAPI_PROPERTY(PROPERTY_COMPLETED_SUCCESS, completed_success),
241         PRINT_NAPI_PROPERTY(PROPERTY_COMPLETED_FAILED, completed_failed),
242         PRINT_NAPI_PROPERTY(PROPERTY_COMPLETED_CANCELLED, completed_cancelled),
243         PRINT_NAPI_PROPERTY(PROPERTY_COMPLETED_FILE_CORRUPT, completed_file_corrupt),
244         PRINT_NAPI_PROPERTY(PROPERTY_BLOCK_OFFLINE, block_offline),
245         PRINT_NAPI_PROPERTY(PROPERTY_BLOCK_BUSY, block_busy),
246         PRINT_NAPI_PROPERTY(PROPERTY_BLOCK_CANCELLED, block_cancelled),
247         PRINT_NAPI_PROPERTY(PROPERTY_BLOCK_OUT_OF_PAPER, block_out_of_paper),
248         PRINT_NAPI_PROPERTY(PROPERTY_BLOCK_OUT_OF_INK, block_out_of_ink),
249         PRINT_NAPI_PROPERTY(PROPERTY_BLOCK_OUT_OF_TONER, block_out_of_toner),
250         PRINT_NAPI_PROPERTY(PROPERTY_BLOCK_JAMMED, block_jammed),
251         PRINT_NAPI_PROPERTY(PROPERTY_BLOCK_DOOR_OPEN, block_door_open),
252         PRINT_NAPI_PROPERTY(PROPERTY_BLOCK_SERVICE_REQUEST, block_service_request),
253         PRINT_NAPI_PROPERTY(PROPERTY_BLOCK_LOW_ON_INK, block_low_on_ink),
254         PRINT_NAPI_PROPERTY(PROPERTY_BLOCK_LOW_ON_TONER, block_low_on_toner),
255         PRINT_NAPI_PROPERTY(PROPERTY_BLOCK_REALLY_LOW_ON_INK, block_really_low_on_ink),
256         PRINT_NAPI_PROPERTY(PROPERTY_BLOCK_BAD_CERTIFICATE, block_bad_certificate),
257         PRINT_NAPI_PROPERTY(PROPERTY_BLOCK_ACCOUNT_ERROR, block_account_error),
258         PRINT_NAPI_PROPERTY(PROPERTY_BLOCK_PRINT_PERMISSION_ERROR, block_print_permission_error),
259         PRINT_NAPI_PROPERTY(PROPERTY_BLOCK_PRINT_COLOR_PERMISSION_ERROR, block_print_color_permission_error),
260         PRINT_NAPI_PROPERTY(PROPERTY_BLOCK_NETWORK_ERROR, block_network_error),
261         PRINT_NAPI_PROPERTY(PROPERTY_BLOCK_CONNECT_SERVER_ERROR, block_connect_server_error),
262         PRINT_NAPI_PROPERTY(PROPERTY_BLOCK_LARGE_FILE_ERROR, block_large_file_error),
263         PRINT_NAPI_PROPERTY(PROPERTY_BLOCK_PARSE_FILE_ERROR, block_parse_file_error),
264         PRINT_NAPI_PROPERTY(PROPERTY_BLOCK_FILE_CONVERT_SLOWLY, block_file_convert_slowly),
265         PRINT_NAPI_PROPERTY(PROPERTY_RUNNING_UPLOADING_FILES, running_uploading_files),
266         PRINT_NAPI_PROPERTY(PROPERTY_RUNNING_CONVERTING_FILES, running_converting_files),
267         PRINT_NAPI_PROPERTY(PROPERTY_BLOCK_UNKNOWN, block_unknown),
268         PRINT_NAPI_PROPERTY(PROPERTY_ERR_NONE, err_none),
269         PRINT_NAPI_PROPERTY(PROPERTY_ERR_NO_PERMISSION, err_no_permission),
270         PRINT_NAPI_PROPERTY(PROPERTY_ERR_INVALID_PARAMETER, err_invalid_parameter),
271         PRINT_NAPI_PROPERTY(PROPERTY_ERR_GENERIC_FAILURE, err_generic_failure),
272         PRINT_NAPI_PROPERTY(PROPERTY_ERR_RPC_FAILURE, err_rpc_failure),
273         PRINT_NAPI_PROPERTY(PROPERTY_ERR_SERVER_FAILURE, err_server_failure),
274         PRINT_NAPI_PROPERTY(PROPERTY_ERR_INVALID_EXTENSION, err_invalid_extension),
275         PRINT_NAPI_PROPERTY(PROPERTY_ERR_INVALID_PRINTER, err_invalid_printer),
276         PRINT_NAPI_PROPERTY(PROPERTY_ERR_INVALID_PRINTJOB, err_invalid_printjob),
277         PRINT_NAPI_PROPERTY(PROPERTY_ERR_FILE_IO, err_file_io),
278         PRINT_NAPI_METHOD(FUNCTION_PRINT, NapiPrintTask::Print),
279         PRINT_NAPI_METHOD(FUNCTION_QUERY_EXT, NapiInnerPrint::QueryExtensionInfo),
280         PRINT_NAPI_METHOD(FUNCTION_START_DISCOVERY, NapiInnerPrint::StartDiscovery),
281         PRINT_NAPI_METHOD(FUNCTION_STOP_DISCOVERY, NapiInnerPrint::StopDiscovery),
282         PRINT_NAPI_METHOD(FUNCTION_CONNECT_PRINT, NapiInnerPrint::ConnectPrinter),
283         PRINT_NAPI_METHOD(FUNCTION_DISCONNECT_PRINT, NapiInnerPrint::DisconnectPrinter),
284         PRINT_NAPI_METHOD(FUNCTION_START_PRINT, NapiInnerPrint::StartPrintJob),
285         PRINT_NAPI_METHOD(FUNCTION_CANCEL_PRINT, NapiInnerPrint::CancelPrintJob),
286         PRINT_NAPI_METHOD(FUNCTION_REQUEST_PREVIEW, NapiInnerPrint::RequestPreview),
287         PRINT_NAPI_METHOD(FUNCTION_QUERY_CAPABILITY, NapiInnerPrint::QueryCapability),
288         PRINT_NAPI_METHOD(FUNCTION_QUERY_ALL_PRINTJOB, NapiInnerPrint::QueryAllPrintJob),
289         PRINT_NAPI_METHOD(FUNCTION_QUERY_PRINTJOB_BYID, NapiInnerPrint::QueryPrintJobById),
290         PRINT_NAPI_METHOD(FUNCTION_REGISTER_EVENT, NapiInnerPrint::On),
291         PRINT_NAPI_METHOD(FUNCTION_UNREGISTER_EVENT, NapiInnerPrint::Off),
292         PRINT_NAPI_METHOD(FUNCTION_ADD_PRINTER, NapiPrintExt::AddPrinters),
293         PRINT_NAPI_METHOD(FUNCTION_REMOVE_PRINTER, NapiPrintExt::RemovePrinters),
294         PRINT_NAPI_METHOD(FUNCTION_UPDATE_PRINTER, NapiPrintExt::UpdatePrinters),
295         PRINT_NAPI_METHOD(FUNCTION_UPDATE_PRINTER_STATE, NapiPrintExt::UpdatePrinterState),
296         PRINT_NAPI_METHOD(FUNCTION_UPDATE_JOB_STATE, NapiPrintExt::UpdatePrintJobState),
297         PRINT_NAPI_METHOD(FUNCTION_UPDATE_EXTENSION_INFO, NapiPrintExt::UpdateExtensionInfo),
298         PRINT_NAPI_METHOD(FUNCTION_NATIVE_ADD_PRINTER_TO_CUPS, NapiPrintExt::AddPrinterToCups),
299         PRINT_NAPI_METHOD(FUNCTION_QUERY_CAPABILITY_BY_URI, NapiPrintExt::QueryPrinterCapabilityByUri),
300     };
301 
302     napi_status status = napi_define_properties(env, exports, sizeof(desc) / sizeof(napi_property_descriptor), desc);
303     PRINT_HILOGD("init print module %{public}d", status);
304     return exports;
305 }
306 
RegisterModule()307 static __attribute__((constructor)) void RegisterModule()
308 {
309     static napi_module module = { .nm_version = 1,
310         .nm_flags = 0,
311         .nm_filename = nullptr,
312         .nm_register_func = Init,
313         .nm_modname = "print",
314         .nm_priv = ((void *)0),
315         .reserved = { 0 } };
316     napi_module_register(&module);
317     PRINT_HILOGD("module register print");
318 }
319