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_PRINTER_UNAVAILABLE = 98, // Printer is stopped. 146 PRINT_JOB_BLOCKED_UNKNOWN = 99, // unknown issue 147 PRINT_JOB_SPOOLER_CLOSED_FOR_CANCELED = 101, // For internal use only: Click Cancel 148 PRINT_JOB_SPOOLER_CLOSED_FOR_STARTED = 102, // For internal use only: Click Start 149 }; 150 151 enum PrintFileCreatedInfoCode { 152 PRINT_FILE_CREATED_SUCCESS = 0, 153 PRINT_FILE_CREATED_FAIL = 1, 154 PRINT_FILE_CREATED_SUCCESS_UNRENDERED = 2, 155 }; 156 157 enum PrintDocumentAdapterState { 158 PREVIEW_ABILITY_DESTROY = 0, 159 PRINT_TASK_SUCCEED = 1, 160 PRINT_TASK_FAIL = 2, 161 PRINT_TASK_CANCEL = 3, 162 PRINT_TASK_BLOCK = 4, 163 PREVIEW_ABILITY_DESTROY_FOR_CANCELED = 5, 164 PREVIEW_ABILITY_DESTROY_FOR_STARTED = 6, 165 }; 166 167 enum PrintExtensionState { 168 PRINT_EXTENSION_UNLOAD, 169 PRINT_EXTENSION_LOADING, 170 PRINT_EXTENSION_LOADED, 171 }; 172 173 enum PrintParamStatus { 174 PRINT_PARAM_NOT_SET, 175 PRINT_PARAM_OPT, 176 PRINT_PARAM_SET, 177 }; 178 179 enum PrintDirectionMode { 180 DIRECTION_MODE_AUTO = 0, 181 DIRECTION_MODE_PORTRAIT = 1, 182 DIRECTION_MODE_LANDSCAPE = 2, 183 }; 184 185 enum PrintColorMode { 186 PRINT_COLOR_MODE_MONOCHROME = 0, 187 PRINT_COLOR_MODE_COLOR = 1, 188 }; 189 190 enum PrintDuplexMode { 191 DUPLEX_MODE_NONE = 0, 192 DUPLEX_MODE_LONG_EDGE = 1, 193 DUPLEX_MODE_SHORT_EDGE = 2, 194 }; 195 196 enum PrintQualityCode { 197 PRINT_QUALITY_DRAFT = 3, 198 PRINT_QUALITY_NORMAL = 4, 199 PRINT_QUALITY_HIGH = 5 200 }; 201 202 enum PrintOrientationMode { 203 PRINT_ORIENTATION_MODE_PORTRAIT = 0, 204 PRINT_ORIENTATION_MODE_LANDSCAPE = 1, 205 PRINT_ORIENTATION_MODE_REVERSE_LANDSCAPE = 2, 206 PRINT_ORIENTATION_MODE_REVERSE_PORTRAIT = 3, 207 PRINT_ORIENTATION_MODE_NONE = 4 208 }; 209 210 enum PrintPageType { 211 PAGE_ISO_A3 = 0, 212 PAGE_ISO_A4 = 1, 213 PAGE_ISO_A5 = 2, 214 PAGE_JIS_B5 = 3, 215 PAGE_ISO_C5 = 4, 216 PAGE_ISO_DL = 5, 217 PAGE_LETTER = 6, 218 PAGE_LEGAL = 7, 219 PAGE_PHOTO_4X6 = 8, 220 PAGE_PHOTO_5X7 = 9, 221 PAGE_INT_DL_ENVELOPE = 10, 222 PAGE_B_TABLOID = 11, 223 }; 224 225 enum ApplicationEvent { 226 APPLICATION_CREATED = 0, 227 APPLICATION_CLOSED_FOR_STARTED = 1, 228 APPLICATION_CLOSED_FOR_CANCELED = 2, 229 }; 230 231 enum PrinterStatus { 232 PRINTER_STATUS_IDLE = 0, 233 PRINTER_STATUS_BUSY = 1, 234 PRINTER_STATUS_UNAVAILABLE = 2, 235 }; 236 237 enum PrinterEvent { 238 PRINTER_EVENT_ADDED = 0, 239 PRINTER_EVENT_DELETED = 1, 240 PRINTER_EVENT_STATE_CHANGED = 2, 241 PRINTER_EVENT_INFO_CHANGED = 3, 242 PRINTER_EVENT_PREFERENCE_CHANGED = 4, 243 PRINTER_EVENT_LAST_USED_PRINTER_CHANGED = 5, 244 }; 245 246 enum DefaultPrinterType { 247 DEFAULT_PRINTER_TYPE_SETTED_BY_USER = 0, 248 DEFAULT_PRINTER_TYPE_LAST_USED_PRINTER = 1, 249 }; 250 251 const std::string PRINTER_DISCOVER_EVENT_TYPE = "printerDiscover"; 252 const std::string PRINTER_CHANGE_EVENT_TYPE = "printerChange"; 253 static const std::string PERMISSION_NAME_PRINT = "ohos.permission.PRINT"; 254 static const std::string PERMISSION_NAME_PRINT_JOB = "ohos.permission.MANAGE_PRINT_JOB"; 255 const std::string PRINTER_SERVICE_FILE_PATH = "/data/service/el2/public/print_service"; 256 const std::string PRINTER_SERVICE_PRINTERS_PATH = "/data/service/el2/public/print_service/printers"; 257 const std::string PRINTER_LIST_FILE = "printer_list.json"; 258 const std::string PRINTER_LIST_VERSION = "v1"; 259 const std::string PRINT_USER_DATA_FILE = "print_user_data.json"; 260 const std::string PRINT_USER_DATA_VERSION = "v1"; 261 const std::string PRINTER_PREFERENCE_FILE = "printer_preference.json"; 262 const std::string DEFAULT_PAGESIZE_ID = "ISO_A4"; 263 const std::string DEFAULT_MEDIA_TYPE = "stationery"; 264 265 const std::string EPRINTER = "ePrint"; 266 267 const std::string E_PRINT_MSG_NONE = "none"; 268 const std::string E_PRINT_MSG_NO_PERMISSION = "the application does not hace permission"; 269 const std::string E_PRINT_MSG_INVALID_PARAMETER = "parameter error"; 270 static std::map<PrintErrorCode, const std::string> PRINT_ERROR_MSG_MAP { 271 {E_PRINT_NONE, E_PRINT_MSG_NONE }, 272 {E_PRINT_NO_PERMISSION, E_PRINT_MSG_NO_PERMISSION }, 273 {E_PRINT_INVALID_PARAMETER, E_PRINT_MSG_INVALID_PARAMETER }, 274 }; 275 276 const std::string VENDOR_WLAN_GROUP = "driver.wlan.group"; 277 const std::string VENDOR_BSUNI_DRIVER = "driver.bsuni"; 278 const std::string VENDOR_PPD_DRIVER = "driver.ppd"; 279 const std::string VENDOR_IPP_EVERYWHERE = "driver.ipp.everywhere"; 280 } // namespace OHOS::Print 281 #endif // PRINT_CONSTANT_H 282