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_UNKNOWN = 13100255,
86 };
87 
88 const uint32_t PRINT_INVALID_ID = 0xFFFFFFFF;   // -1
89 
90 enum PrinterState {
91     PRINTER_ADDED = 0,          // new printers arrival
92     PRINTER_REMOVED = 1,        // printers lost
93     PRINTER_UPDATE_CAP = 2,     // printers update
94     PRINTER_CONNECTED = 3,      // printer has been connected
95     PRINTER_DISCONNECTED = 4,   // printer has been disconnected
96     PRINTER_RUNNING = 5,        // printer is working
97     PRINTER_UNKNOWN = 6,        // unknown printer state
98 };
99 
100 enum PrintJobState {
101     PRINT_JOB_PREPARED = 0,     // initial state of print job
102     PRINT_JOB_QUEUED = 1,       // deliver print job to the printer
103     PRINT_JOB_RUNNING = 2,      // executing print job
104     PRINT_JOB_BLOCKED = 3,      // print job has been blocked
105     PRINT_JOB_COMPLETED = 4,    // print job ocmpleted
106     PRINT_JOB_UNKNOWN = 100,      // unknown state of print job
107     PRINT_JOB_CREATE_FILE_COMPLETED = 101,    // For internal use only: create print file completed
108     PRINT_JOB_SPOOLER_CLOSED = 102,    // For internal use only: spooler closed
109 };
110 
111 enum PrintJobSubState {
112     PRINT_JOB_COMPLETED_SUCCESS = 0,            // print job succeed
113     PRINT_JOB_COMPLETED_FAILED = 1,             // print job fail
114     PRINT_JOB_COMPLETED_CANCELLED = 2,          // print job has been cancelled
115     PRINT_JOB_COMPLETED_FILE_CORRUPT = 3,       // print job has been corrupted
116     PRINT_JOB_BLOCKED_OFFLINE = 4,              // printer is offline
117     PRINT_JOB_BLOCKED_BUSY = 5,                 // printer is occupied by other process
118     PRINT_JOB_BLOCKED_CANCELLED = 6,            // print job has been canncelled
119     PRINT_JOB_BLOCKED_OUT_OF_PAPER = 7,         // out of paper
120     PRINT_JOB_BLOCKED_OUT_OF_INK = 8,           // out of ink
121     PRINT_JOB_BLOCKED_OUT_OF_TONER = 9,         // out of toner
122     PRINT_JOB_BLOCKED_JAMMED = 10,              // paper jam
123     PRINT_JOB_BLOCKED_DOOR_OPEN = 11,           // cover open
124     PRINT_JOB_BLOCKED_SERVICE_REQUEST = 12,     // service request
125     PRINT_JOB_BLOCKED_LOW_ON_INK = 13,          // low on ink
126     PRINT_JOB_BLOCKED_LOW_ON_TONER = 14,        // low on toner
127     PRINT_JOB_BLOCKED_REALLY_LOW_ON_INK = 15,   // really low on ink
128     PRINT_JOB_BLOCKED_BAD_CERTIFICATE = 16,     // bad certification
129     PRINT_JOB_BLOCKED_DRIVER_EXCEPTION = 17,    // printer driver exception
130 
131     PRINT_JOB_BLOCKED_ACCOUNT_ERROR = 18, // An error occurred when printing the account.
132     PRINT_JOB_BLOCKED_PRINT_PERMISSION_ERROR = 19, // The printing permission is abnormal.
133     PRINT_JOB_BLOCKED_PRINT_COLOR_PERMISSION_ERROR = 20, // Color printing permission exception
134     PRINT_JOB_BLOCKED_NETWORK_ERROR = 21, // The device is not connected to the network.
135     PRINT_JOB_BLOCKED_SERVER_CONNECTION_ERROR = 22, // Unable to connect to the server
136     PRINT_JOB_BLOCKED_LARGE_FILE_ERROR = 23, // Large file exception
137     PRINT_JOB_BLOCKED_FILE_PARSING_ERROR = 24, // File parsing exception.
138     PRINT_JOB_BLOCKED_SLOW_FILE_CONVERSION = 25, // The file conversion is too slow.
139     PRINT_JOB_RUNNING_UPLOADING_FILES = 26, // Uploading file...
140     PRINT_JOB_RUNNING_CONVERTING_FILES = 27, // Converting files...
141     PRINT_JOB_CREATE_FILE_COMPLETED_SUCCESS = 28, // print job create file succeed
142     PRINT_JOB_CREATE_FILE_COMPLETED_FAILED = 29, // print job create file fail
143     PRINT_JOB_BLOCKED_UNKNOWN = 99,             // unknown issue
144     PRINT_JOB_SPOOLER_CLOSED_FOR_CANCELED = 101, // For internal use only: Click Cancel
145     PRINT_JOB_SPOOLER_CLOSED_FOR_STARTED = 102, // For internal use only: Click Start
146 };
147 
148 enum PrintFileCreatedInfoCode {
149     PRINT_FILE_CREATED_SUCCESS = 0,
150     PRINT_FILE_CREATED_FAIL = 1,
151     PRINT_FILE_CREATED_SUCCESS_UNRENDERED = 2,
152 };
153 
154 enum PrintDocumentAdapterState {
155     PREVIEW_ABILITY_DESTROY = 0,
156     PRINT_TASK_SUCCEED = 1,
157     PRINT_TASK_FAIL = 2,
158     PRINT_TASK_CANCEL = 3,
159     PRINT_TASK_BLOCK = 4,
160     PREVIEW_ABILITY_DESTROY_FOR_CANCELED = 5,
161     PREVIEW_ABILITY_DESTROY_FOR_STARTED = 6,
162 };
163 
164 enum PrintExtensionState {
165     PRINT_EXTENSION_UNLOAD,
166     PRINT_EXTENSION_LOADING,
167     PRINT_EXTENSION_LOADED,
168 };
169 
170 enum PrintParamStatus {
171     PRINT_PARAM_NOT_SET,
172     PRINT_PARAM_OPT,
173     PRINT_PARAM_SET,
174 };
175 
176 enum PrintDirectionMode {
177     DIRECTION_MODE_AUTO = 0,
178     DIRECTION_MODE_PORTRAIT = 1,
179     DIRECTION_MODE_LANDSCAPE = 2,
180 };
181 
182 enum PrintColorMode {
183     PRINT_COLOR_MODE_MONOCHROME = 0,
184     PRINT_COLOR_MODE_COLOR = 1,
185 };
186 
187 enum PrintDuplexMode {
188     DUPLEX_MODE_NONE = 0,
189     DUPLEX_MODE_LONG_EDGE = 1,
190     DUPLEX_MODE_SHORT_EDGE = 2,
191 };
192 
193 enum PrintQualityCode {
194     PRINT_QUALITY_DRAFT = 3,
195     PRINT_QUALITY_NORMAL = 4,
196     PRINT_QUALITY_HIGH = 5
197 };
198 
199 enum PrintOrientationMode {
200     PRINT_ORIENTATION_MODE_PORTRAIT = 0,
201     PRINT_ORIENTATION_MODE_LANDSCAPE= 1,
202     PRINT_ORIENTATION_MODE_REVERSE_LANDSCAPE = 2,
203     PRINT_ORIENTATION_MODE_REVERSE_PORTRAIT = 3,
204     PRINT_ORIENTATION_MODE_NONE = 4
205 };
206 
207 enum PrintPageType {
208     PAGE_ISO_A3 = 0,
209     PAGE_ISO_A4 = 1,
210     PAGE_ISO_A5 = 2,
211     PAGE_JIS_B5 = 3,
212     PAGE_ISO_C5 = 4,
213     PAGE_ISO_DL = 5,
214     PAGE_LETTER = 6,
215     PAGE_LEGAL = 7,
216     PAGE_PHOTO_4X6 = 8,
217     PAGE_PHOTO_5X7 = 9,
218     PAGE_INT_DL_ENVELOPE = 10,
219     PAGE_B_TABLOID = 11,
220 };
221 
222 enum ApplicationEvent {
223     APPLICATION_CREATED = 0,
224     APPLICATION_CLOSED_FOR_STARTED = 1,
225     APPLICATION_CLOSED_FOR_CANCELED = 2,
226 };
227 
228 enum PrinterStatus {
229     PRINTER_STATUS_IDLE = 0,
230     PRINTER_STATUS_BUSY = 1,
231     PRINTER_STATUS_UNAVAILABLE = 2,
232 };
233 
234 enum PrinterEvent {
235     PRINTER_EVENT_ADDED = 0,
236     PRINTER_EVENT_DELETED = 1,
237     PRINTER_EVENT_STATE_CHANGED = 2,
238     PRINTER_EVENT_INFO_CHANGED = 3,
239     PRINTER_EVENT_PREFERENCE_CHANGED = 4,
240     PRINTER_EVENT_LAST_USED_PRINTER_CHANGED = 5,
241 };
242 
243 enum DefaultPrinterType {
244     DEFAULT_PRINTER_TYPE_SETTED_BY_USER = 0,
245     DEFAULT_PRINTER_TYPE_LAST_USED_PRINTER = 1,
246 };
247 
248 const std::string PRINTER_DISCOVER_EVENT_TYPE = "printerDiscover";
249 const std::string PRINTER_CHANGE_EVENT_TYPE = "printerChange";
250 static const std::string PERMISSION_NAME_PRINT = "ohos.permission.PRINT";
251 static const std::string PERMISSION_NAME_PRINT_JOB = "ohos.permission.MANAGE_PRINT_JOB";
252 const std::string PRINTER_SERVICE_FILE_PATH = "/data/service/el2/public/print_service";
253 const std::string PRINTER_LIST_FILE = "printer_list.json";
254 const std::string PRINTER_LIST_VERSION = "v1";
255 const std::string PRINT_USER_DATA_FILE = "print_user_data.json";
256 const std::string PRINT_USER_DATA_VERSION = "v1";
257 
258 const std::string E_PRINT_MSG_NONE = "none";
259 const std::string E_PRINT_MSG_NO_PERMISSION = "the application does not hace permission";
260 const std::string E_PRINT_MSG_INVALID_PARAMETER = "parameter error";
261 static std::map<PrintErrorCode, const std::string> PRINT_ERROR_MSG_MAP {
262     {E_PRINT_NONE,                  E_PRINT_MSG_NONE                },
263     {E_PRINT_NO_PERMISSION,         E_PRINT_MSG_NO_PERMISSION       },
264     {E_PRINT_INVALID_PARAMETER,     E_PRINT_MSG_INVALID_PARAMETER   },
265 };
266 
267 const std::string VENDOR_WLAN_GROUP = "driver.wlan.group";
268 const std::string VENDOR_BSUNI_DRIVER = "driver.bsuni";
269 const std::string VENDOR_PPD_DRIVER = "driver.ppd";
270 const std::string VENDOR_IPP_EVERYWHERE = "driver.ipp.everywhere";
271 } // namespace OHOS::Print
272 #endif // PRINT_CONSTANT_H
273