• 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 PRINT_CONSTANT_H
17 #define PRINT_CONSTANT_H
18 
19 #include <string>
20 #include <map>
21 
22 namespace OHOS::Print {
23 #define PRINT_RET_NONE
24 
25 #define PRINT_MAX_PRINT_COUNT 1000
26 #define PRINT_CALLBACK_ADAPTER "printCallback_adapter"
27 #define PRINT_GET_FILE_CALLBACK_ADAPTER "getPrintFileCallback_adapter"
28 
29 #define PRINT_ASSERT_BASE(env, assertion, message, retVal)  \
30     do {                                                    \
31         if (!(assertion)) {                                 \
32             PRINT_HILOGE(message);                          \
33             return retVal;                                  \
34         }                                                   \
35     } while (0)
36 
37 #define PRINT_ASSERT(env, assertion, message) PRINT_ASSERT_BASE(env, assertion, message, nullptr)
38 
39 #define PRINT_ASSERT_RETURN_VOID(env, assertion, message) PRINT_ASSERT_BASE(env, assertion, message, PRINT_RET_NONE)
40 
41 #define PRINT_CALL_BASE(env, theCall, retVal)   \
42     do {                                        \
43         if ((theCall) != napi_ok) {             \
44             return retVal;                      \
45         }                                       \
46     } while (0)
47 
48 #define PRINT_CALL(env, theCall) PRINT_CALL_BASE(env, theCall, nullptr)
49 
50 #define PRINT_CALL_RETURN_VOID(env, theCall) PRINT_CALL_BASE(env, theCall, PRINT_RET_NONE)
51 
52 #define CHECK_IS_EXCEED_PRINT_RANGE_BASE(count, retVal)                                             \
53     do {                                                                                            \
54         if ((count) > PRINT_MAX_PRINT_COUNT) {                                                      \
55             PRINT_HILOGW("input val is exceed print max range:%{public}d", PRINT_MAX_PRINT_COUNT);  \
56             return retVal;                                                                          \
57         }                                                                                           \
58     } while (0)
59 
60 #define CHECK_IS_EXCEED_PRINT_RANGE(count)          CHECK_IS_EXCEED_PRINT_RANGE_BASE(count, nullptr)
61 #define CHECK_IS_EXCEED_PRINT_RANGE_BOOL(count)     CHECK_IS_EXCEED_PRINT_RANGE_BASE(count, false)
62 #define CHECK_IS_EXCEED_PRINT_RANGE_VOID(count)     CHECK_IS_EXCEED_PRINT_RANGE_BASE(count, PRINT_RET_NONE)
63 #define CHECK_IS_EXCEED_PRINT_RANGE_INT(count)      CHECK_IS_EXCEED_PRINT_RANGE_BASE(count, E_PRINT_INVALID_PARAMETER)
64 
65 #define PRINT_SAFE_DELETE(ptr) \
66     if ((ptr) != nullptr) { \
67         delete (ptr); \
68         (ptr) = nullptr; \
69     }
70 
71 enum PrintErrorCode {
72     E_PRINT_NONE = 0,
73     E_PRINT_NO_PERMISSION = 201,
74     E_PRINT_ILLEGAL_USE_OF_SYSTEM_API = 202,
75     E_PRINT_INVALID_PARAMETER = 401,
76     E_PRINT_GENERIC_FAILURE = 13100001,
77     E_PRINT_RPC_FAILURE = 13100002,
78     E_PRINT_SERVER_FAILURE = 13100003,
79     E_PRINT_INVALID_EXTENSION = 13100004,
80     E_PRINT_INVALID_PRINTER = 13100005,
81     E_PRINT_INVALID_PRINTJOB = 13100006,
82     E_PRINT_FILE_IO = 13100007,
83     E_PRINT_INVALID_TOKEN = 13100008,
84     E_PRINT_INVALID_USERID = 13100009,
85     E_PRINT_TOO_MANY_FILES = 13100010,
86     E_PRINT_UNKNOWN = 13100255,
87 };
88 
89 const uint32_t PRINT_INVALID_ID = 0xFFFFFFFF;   // -1
90 
91 enum PrinterState {
92     PRINTER_ADDED = 0,          // new printers arrival
93     PRINTER_REMOVED = 1,        // printers lost
94     PRINTER_UPDATE_CAP = 2,     // printers update
95     PRINTER_CONNECTED = 3,      // printer has been connected
96     PRINTER_DISCONNECTED = 4,   // printer has been disconnected
97     PRINTER_RUNNING = 5,        // printer is working
98     PRINTER_UNKNOWN = 6,        // unknown printer state
99 };
100 
101 enum PrintJobState {
102     PRINT_JOB_PREPARED = 0,     // initial state of print job
103     PRINT_JOB_QUEUED = 1,       // deliver print job to the printer
104     PRINT_JOB_RUNNING = 2,      // executing print job
105     PRINT_JOB_BLOCKED = 3,      // print job has been blocked
106     PRINT_JOB_COMPLETED = 4,    // print job completed
107     PRINT_JOB_UNKNOWN = 100,      // unknown state of print job
108     PRINT_JOB_CREATE_FILE_COMPLETED = 101,    // For internal use only: create print file completed
109     PRINT_JOB_SPOOLER_CLOSED = 102,    // For internal use only: spooler closed
110 };
111 
112 enum PrintJobSubState {
113     PRINT_JOB_COMPLETED_SUCCESS = 0,            // print job succeed
114     PRINT_JOB_COMPLETED_FAILED = 1,             // print job fail
115     PRINT_JOB_COMPLETED_CANCELLED = 2,          // print job has been cancelled
116     PRINT_JOB_COMPLETED_FILE_CORRUPT = 3,       // print job has been corrupted
117     PRINT_JOB_BLOCKED_OFFLINE = 4,              // printer is offline
118     PRINT_JOB_BLOCKED_BUSY = 5,                 // printer is occupied by other process
119     PRINT_JOB_BLOCKED_CANCELLED = 6,            // print job has been canncelled
120     PRINT_JOB_BLOCKED_OUT_OF_PAPER = 7,         // out of paper
121     PRINT_JOB_BLOCKED_OUT_OF_INK = 8,           // out of ink
122     PRINT_JOB_BLOCKED_OUT_OF_TONER = 9,         // out of toner
123     PRINT_JOB_BLOCKED_JAMMED = 10,              // paper jam
124     PRINT_JOB_BLOCKED_DOOR_OPEN = 11,           // cover open
125     PRINT_JOB_BLOCKED_SERVICE_REQUEST = 12,     // service request
126     PRINT_JOB_BLOCKED_LOW_ON_INK = 13,          // low on ink
127     PRINT_JOB_BLOCKED_LOW_ON_TONER = 14,        // low on toner
128     PRINT_JOB_BLOCKED_REALLY_LOW_ON_INK = 15,   // really low on ink
129     PRINT_JOB_BLOCKED_BAD_CERTIFICATE = 16,     // bad certification
130     PRINT_JOB_BLOCKED_DRIVER_EXCEPTION = 17,    // printer driver exception
131 
132     PRINT_JOB_BLOCKED_ACCOUNT_ERROR = 18, // An error occurred when printing the account.
133     PRINT_JOB_BLOCKED_PRINT_PERMISSION_ERROR = 19, // The printing permission is abnormal.
134     PRINT_JOB_BLOCKED_PRINT_COLOR_PERMISSION_ERROR = 20, // Color printing permission exception
135     PRINT_JOB_BLOCKED_NETWORK_ERROR = 21, // The device is not connected to the network.
136     PRINT_JOB_BLOCKED_SERVER_CONNECTION_ERROR = 22, // Unable to connect to the server
137     PRINT_JOB_BLOCKED_LARGE_FILE_ERROR = 23, // Large file exception
138     PRINT_JOB_BLOCKED_FILE_PARSING_ERROR = 24, // File parsing exception.
139     PRINT_JOB_BLOCKED_SLOW_FILE_CONVERSION = 25, // The file conversion is too slow.
140     PRINT_JOB_RUNNING_UPLOADING_FILES = 26, // Uploading file...
141     PRINT_JOB_RUNNING_CONVERTING_FILES = 27, // Converting files...
142     PRINT_JOB_CREATE_FILE_COMPLETED_SUCCESS = 28, // print job create file succeed
143     PRINT_JOB_CREATE_FILE_COMPLETED_FAILED = 29, // print job create file fail
144     PRINT_JOB_BLOCK_FILE_UPLOADING_ERROR = 30, // File uploading exception.
145     PRINT_JOB_BLOCKED_DRIVER_MISSING = 34, // driver file missing
146     PRINT_JOB_BLOCKED_INTERRUPT = 35, // print job interrupt
147     PRINT_JOB_BLOCKED_PRINTER_UNAVAILABLE = 98, // Printer is stopped.
148     PRINT_JOB_BLOCKED_UNKNOWN = 99,             // unknown issue
149     PRINT_JOB_SPOOLER_CLOSED_FOR_CANCELED = 101, // For internal use only: Click Cancel
150     PRINT_JOB_SPOOLER_CLOSED_FOR_STARTED = 102, // For internal use only: Click Start
151 };
152 
153 enum PrintFileCreatedInfoCode {
154     PRINT_FILE_CREATED_SUCCESS = 0,
155     PRINT_FILE_CREATED_FAIL = 1,
156     PRINT_FILE_CREATED_SUCCESS_UNRENDERED = 2,
157 };
158 
159 enum PrintDocumentAdapterState {
160     PREVIEW_ABILITY_DESTROY = 0,
161     PRINT_TASK_SUCCEED = 1,
162     PRINT_TASK_FAIL = 2,
163     PRINT_TASK_CANCEL = 3,
164     PRINT_TASK_BLOCK = 4,
165     PREVIEW_ABILITY_DESTROY_FOR_CANCELED = 5,
166     PREVIEW_ABILITY_DESTROY_FOR_STARTED = 6,
167 };
168 
169 enum PrintExtensionState {
170     PRINT_EXTENSION_UNLOAD,
171     PRINT_EXTENSION_LOADING,
172     PRINT_EXTENSION_LOADED,
173 };
174 
175 enum PrintParamStatus {
176     PRINT_PARAM_NOT_SET,
177     PRINT_PARAM_OPT,
178     PRINT_PARAM_SET,
179 };
180 
181 enum PrintDirectionMode {
182     DIRECTION_MODE_AUTO = 0,
183     DIRECTION_MODE_PORTRAIT = 1,
184     DIRECTION_MODE_LANDSCAPE = 2,
185 };
186 
187 enum PrintColorMode {
188     PRINT_COLOR_MODE_MONOCHROME = 0,
189     PRINT_COLOR_MODE_COLOR = 1,
190 };
191 
192 enum PrintDuplexMode {
193     DUPLEX_MODE_NONE = 0,
194     DUPLEX_MODE_LONG_EDGE = 1,
195     DUPLEX_MODE_SHORT_EDGE = 2,
196 };
197 
198 enum PrintQualityCode {
199     PRINT_QUALITY_DRAFT = 3,
200     PRINT_QUALITY_NORMAL = 4,
201     PRINT_QUALITY_HIGH = 5
202 };
203 
204 enum PrintOrientationMode {
205     PRINT_ORIENTATION_MODE_PORTRAIT = 0,
206     PRINT_ORIENTATION_MODE_LANDSCAPE = 1,
207     PRINT_ORIENTATION_MODE_REVERSE_LANDSCAPE = 2,
208     PRINT_ORIENTATION_MODE_REVERSE_PORTRAIT = 3,
209     PRINT_ORIENTATION_MODE_NONE = 4
210 };
211 
212 enum PrintPageType {
213     PAGE_ISO_A3 = 0,
214     PAGE_ISO_A4 = 1,
215     PAGE_ISO_A5 = 2,
216     PAGE_JIS_B5 = 3,
217     PAGE_ISO_C5 = 4,
218     PAGE_ISO_DL = 5,
219     PAGE_LETTER = 6,
220     PAGE_LEGAL = 7,
221     PAGE_PHOTO_4X6 = 8,
222     PAGE_PHOTO_5X7 = 9,
223     PAGE_INT_DL_ENVELOPE = 10,
224     PAGE_B_TABLOID = 11,
225 };
226 
227 enum ApplicationEvent {
228     APPLICATION_CREATED = 0,
229     APPLICATION_CLOSED_FOR_STARTED = 1,
230     APPLICATION_CLOSED_FOR_CANCELED = 2,
231 };
232 
233 enum PrinterStatus {
234     PRINTER_STATUS_IDLE = 0,
235     PRINTER_STATUS_BUSY = 1,
236     PRINTER_STATUS_UNAVAILABLE = 2,
237 };
238 
239 enum PrinterEvent {
240     PRINTER_EVENT_ADDED = 0,
241     PRINTER_EVENT_DELETED = 1,
242     PRINTER_EVENT_STATE_CHANGED = 2,
243     PRINTER_EVENT_INFO_CHANGED = 3,
244     PRINTER_EVENT_PREFERENCE_CHANGED = 4,
245     PRINTER_EVENT_LAST_USED_PRINTER_CHANGED = 5,
246 };
247 
248 enum DefaultPrinterType {
249     DEFAULT_PRINTER_TYPE_SETTED_BY_USER = 0,
250     DEFAULT_PRINTER_TYPE_LAST_USED_PRINTER = 1,
251 };
252 
253 const std::string PRINTER_DISCOVER_EVENT_TYPE = "printerDiscover";
254 const std::string PRINTER_CHANGE_EVENT_TYPE = "printerChange";
255 static const std::string PERMISSION_NAME_PRINT = "ohos.permission.PRINT";
256 static const std::string PERMISSION_NAME_PRINT_JOB = "ohos.permission.MANAGE_PRINT_JOB";
257 const std::string PRINTER_SERVICE_FILE_PATH = "/data/service/el2/public/print_service";
258 const std::string PRINTER_SERVICE_PRINTERS_PATH = "/data/service/el2/public/print_service/printers";
259 const std::string PRINTER_SERVICE_PRINTERS_ENTERPRISE_PATH =
260     "/data/service/el2/public/print_service/printers_enterprise";
261 const std::string PRINTER_LIST_FILE = "printer_list.json";
262 const std::string PRINTER_LIST_VERSION_FILE = "version.json";
263 const std::string PRINTER_LIST_VERSION_V1 = "v1";
264 const std::string PRINTER_LIST_VERSION_V3 = "v3";
265 const std::string PRINT_USER_DATA_FILE = "print_user_data.json";
266 const std::string PRINT_USER_DATA_VERSION = "v1";
267 const std::string PRINTER_PREFERENCE_FILE = "printer_preference.json";
268 const std::string DEFAULT_PAGESIZE_ID = "ISO_A4";
269 const std::string DEFAULT_MEDIA_TYPE = "stationery";
270 const std::string DEFAULT_USER_NAME = "print";
271 static const std::string P2P_PRINTER = "p2p";
272 
273 const std::string E_PRINT_MSG_NONE = "none";
274 const std::string E_PRINT_MSG_NO_PERMISSION = "the application does not hace permission";
275 const std::string E_PRINT_MSG_INVALID_PARAMETER = "parameter error";
276 static std::map<PrintErrorCode, const std::string> PRINT_ERROR_MSG_MAP {
277     {E_PRINT_NONE,                  E_PRINT_MSG_NONE                },
278     {E_PRINT_NO_PERMISSION,         E_PRINT_MSG_NO_PERMISSION       },
279     {E_PRINT_INVALID_PARAMETER,     E_PRINT_MSG_INVALID_PARAMETER   },
280 };
281 
282 const std::string VENDOR_WLAN_GROUP = "driver.wlan.group";
283 const std::string VENDOR_BSUNI_DRIVER = "driver.bsuni";
284 const std::string VENDOR_PPD_DRIVER = "driver.ppd";
285 const std::string VENDOR_IPP_EVERYWHERE = "driver.ipp.everywhere";
286 const std::string BSUNI_PPD_NAME = "Brocadesoft Universal Driver";
287 static const std::string DEFAULT_PPD_NAME = "everywhere";
288 
289 const int32_t INVALID_USER_ID = -1;
290 } // namespace OHOS::Print
291 #endif // PRINT_CONSTANT_H
292