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