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 21 namespace OHOS::Print { 22 #define PRINT_RET_NONE 23 24 #define PRINT_MAX_PRINT_COUNT 1000 25 26 #define NEW_PRINT_INTERFACE_SWITCH false 27 28 #define PRINT_ASSERT_BASE(env, assertion, message, retVal) \ 29 do { \ 30 if (!(assertion)) { \ 31 PRINT_HILOGE(message); \ 32 return retVal; \ 33 } \ 34 } while (0) 35 36 #define PRINT_ASSERT(env, assertion, message) PRINT_ASSERT_BASE(env, assertion, message, nullptr) 37 38 #define PRINT_ASSERT_RETURN_VOID(env, assertion, message) PRINT_ASSERT_BASE(env, assertion, message, PRINT_RET_NONE) 39 40 #define PRINT_CALL_BASE(env, theCall, retVal) \ 41 do { \ 42 if ((theCall) != napi_ok) { \ 43 return retVal; \ 44 } \ 45 } while (0) 46 47 #define PRINT_CALL(env, theCall) PRINT_CALL_BASE(env, theCall, nullptr) 48 49 #define PRINT_CALL_RETURN_VOID(env, theCall) PRINT_CALL_BASE(env, theCall, PRINT_RET_NONE) 50 51 #define CHECK_IS_EXCEED_PRINT_RANGE_BASE(count, retVal) \ 52 do { \ 53 if ((count) > PRINT_MAX_PRINT_COUNT) { \ 54 PRINT_HILOGW("input val is exceed print max range:%{public}d", PRINT_MAX_PRINT_COUNT); \ 55 return retVal; \ 56 } \ 57 } while (0) 58 59 #define CHECK_IS_EXCEED_PRINT_RANGE(count) CHECK_IS_EXCEED_PRINT_RANGE_BASE(count, nullptr) 60 #define CHECK_IS_EXCEED_PRINT_RANGE_BOOL(count) CHECK_IS_EXCEED_PRINT_RANGE_BASE(count, false) 61 #define CHECK_IS_EXCEED_PRINT_RANGE_VOID(count) CHECK_IS_EXCEED_PRINT_RANGE_BASE(count, PRINT_RET_NONE) 62 #define CHECK_IS_EXCEED_PRINT_RANGE_INT(count) CHECK_IS_EXCEED_PRINT_RANGE_BASE(count, E_PRINT_INVALID_PARAMETER) 63 64 65 enum PrintErrorCode { 66 E_PRINT_NONE = 0, 67 E_PRINT_NO_PERMISSION = 201, 68 E_PRINT_INVALID_PARAMETER = 401, 69 E_PRINT_GENERIC_FAILURE = 13100001, 70 E_PRINT_RPC_FAILURE = 13100002, 71 E_PRINT_SERVER_FAILURE = 13100003, 72 E_PRINT_INVALID_EXTENSION = 13100004, 73 E_PRINT_INVALID_PRINTER = 13100005, 74 E_PRINT_INVALID_PRINTJOB = 13100006, 75 E_PRINT_FILE_IO = 13100007, 76 E_PRINT_UNKNOWN = 13100255, 77 }; 78 79 const uint32_t PRINT_INVALID_ID = 0xFFFFFFFF; // -1 80 81 enum PrinterState { 82 PRINTER_ADDED = 0, // new printers arrival 83 PRINTER_REMOVED = 1, // printers lost 84 PRINTER_UPDATE_CAP = 2, // printers update 85 PRINTER_CONNECTED = 3, // printer has been connected 86 PRINTER_DISCONNECTED = 4, // printer has been disconnected 87 PRINTER_RUNNING = 5, // printer is working 88 PRINTER_UNKNOWN = 6, // unknown printer state 89 }; 90 91 enum PrintJobState { 92 PRINT_JOB_PREPARED = 0, // initial state of print job 93 PRINT_JOB_QUEUED = 1, // deliver print job to the printer 94 PRINT_JOB_RUNNING = 2, // executing print job 95 PRINT_JOB_BLOCKED = 3, // print job has been blocked 96 PRINT_JOB_COMPLETED = 4, // print job ocmpleted 97 PRINT_JOB_UNKNOWN = 5, // unknown state of print job 98 }; 99 100 enum PrintJobSubState { 101 PRINT_JOB_COMPLETED_SUCCESS = 0, // print job succeed 102 PRINT_JOB_COMPLETED_FAILED = 1, // print job fail 103 PRINT_JOB_COMPLETED_CANCELLED = 2, // print job has been cancelled 104 PRINT_JOB_COMPLETED_FILE_CORRUPT = 3, // print job has been corrupted 105 PRINT_JOB_BLOCKED_OFFLINE = 4, // printer is offline 106 PRINT_JOB_BLOCKED_BUSY = 5, // printer is occupied by other process 107 PRINT_JOB_BLOCKED_CANCELLED = 6, // print job has been canncelled 108 PRINT_JOB_BLOCKED_OUT_OF_PAPER = 7, // out of paper 109 PRINT_JOB_BLOCKED_OUT_OF_INK = 8, // out of ink 110 PRINT_JOB_BLOCKED_OUT_OF_TONER = 9, // out of toner 111 PRINT_JOB_BLOCKED_JAMMED = 10, // paper jam 112 PRINT_JOB_BLOCKED_DOOR_OPEN = 11, // cover open 113 PRINT_JOB_BLOCKED_SERVICE_REQUEST = 12, // service request 114 PRINT_JOB_BLOCKED_LOW_ON_INK = 13, // low on ink 115 PRINT_JOB_BLOCKED_LOW_ON_TONER = 14, // low on toner 116 PRINT_JOB_BLOCKED_REALLY_LOW_ON_INK = 15, // really low on ink 117 PRINT_JOB_BLOCKED_BAD_CERTIFICATE = 16, // bad certification 118 119 PRINT_JOB_BLOCKED_ACCOUNT_ERROR = 18, // An error occurred when printing the account. 120 PRINT_JOB_BLOCKED_PRINT_PERMISSION_ERROR = 19, // The printing permission is abnormal. 121 PRINT_JOB_BLOCKED_PRINT_COLOR_PERMISSION_ERROR = 20, // Color printing permission exception 122 PRINT_JOB_BLOCKED_NETWORK_ERROR = 21, // The device is not connected to the network. 123 PRINT_JOB_BLOCKED_CONNECT_SERVER_ERROR = 22, // Unable to connect to the server 124 PRINT_JOB_BLOCKED_LARGE_FILE_ERROR = 23, // Large file exception 125 PRINT_JOB_BLOCKED_PARSE_FILE_ERROR = 24, // File parsing exception. 126 PRINT_JOB_BLOCKED_FILE_CONVERT_SLOWLY = 25, // The file conversion is too slow. 127 PRINT_JOB_RUNNING_UPLOADING_FILES = 26, // Uploading file... 128 PRINT_JOB_RUNNING_CONVERTING_FILES = 27, // Converting files... 129 PRINT_JOB_BLOCKED_UNKNOWN = 99, // unknown issue 130 }; 131 132 enum PrintExtensionState { 133 PRINT_EXTENSION_UNLOAD, 134 PRINT_EXTENSION_LOADING, 135 PRINT_EXTENSION_LOADED, 136 }; 137 138 enum PrintParamStatus { 139 PRINT_PARAM_NOT_SET, 140 PRINT_PARAM_OPT, 141 PRINT_PARAM_SET, 142 }; 143 } // namespace OHOS::Print 144 #endif // PRINT_CONSTANT_H