146debc2cSopenharmony_ci/*
246debc2cSopenharmony_ci * Copyright (c) 2022 Huawei Device Co., Ltd.
346debc2cSopenharmony_ci * Licensed under the Apache License, Version 2.0 (the "License");
446debc2cSopenharmony_ci * you may not use this file except in compliance with the License.
546debc2cSopenharmony_ci * You may obtain a copy of the License at
646debc2cSopenharmony_ci *
746debc2cSopenharmony_ci *     http://www.apache.org/licenses/LICENSE-2.0
846debc2cSopenharmony_ci *
946debc2cSopenharmony_ci * Unless required by applicable law or agreed to in writing, software
1046debc2cSopenharmony_ci * distributed under the License is distributed on an "AS IS" BASIS,
1146debc2cSopenharmony_ci * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
1246debc2cSopenharmony_ci * See the License for the specific language governing permissions and
1346debc2cSopenharmony_ci * limitations under the License.
1446debc2cSopenharmony_ci */
1546debc2cSopenharmony_ci
1646debc2cSopenharmony_ci#ifndef PRINT_CONSTANT_H
1746debc2cSopenharmony_ci#define PRINT_CONSTANT_H
1846debc2cSopenharmony_ci
1946debc2cSopenharmony_ci#include <string>
2046debc2cSopenharmony_ci
2146debc2cSopenharmony_cinamespace OHOS::Print {
2246debc2cSopenharmony_ci#define PRINT_RET_NONE
2346debc2cSopenharmony_ci
2446debc2cSopenharmony_ci#define PRINT_MAX_PRINT_COUNT 1000
2546debc2cSopenharmony_ci#define PRINT_CALLBACK_ADAPTER "printCallback_adapter"
2646debc2cSopenharmony_ci#define PRINT_GET_FILE_CALLBACK_ADAPTER "getPrintFileCallback_adapter"
2746debc2cSopenharmony_ci
2846debc2cSopenharmony_ci#define PRINT_ASSERT_BASE(env, assertion, message, retVal)  \
2946debc2cSopenharmony_ci    do {                                                    \
3046debc2cSopenharmony_ci        if (!(assertion)) {                                 \
3146debc2cSopenharmony_ci            PRINT_HILOGE(message);                          \
3246debc2cSopenharmony_ci            return retVal;                                  \
3346debc2cSopenharmony_ci        }                                                   \
3446debc2cSopenharmony_ci    } while (0)
3546debc2cSopenharmony_ci
3646debc2cSopenharmony_ci#define PRINT_ASSERT(env, assertion, message) PRINT_ASSERT_BASE(env, assertion, message, nullptr)
3746debc2cSopenharmony_ci
3846debc2cSopenharmony_ci#define PRINT_ASSERT_RETURN_VOID(env, assertion, message) PRINT_ASSERT_BASE(env, assertion, message, PRINT_RET_NONE)
3946debc2cSopenharmony_ci
4046debc2cSopenharmony_ci#define PRINT_CALL_BASE(env, theCall, retVal)   \
4146debc2cSopenharmony_ci    do {                                        \
4246debc2cSopenharmony_ci        if ((theCall) != napi_ok) {             \
4346debc2cSopenharmony_ci            return retVal;                      \
4446debc2cSopenharmony_ci        }                                       \
4546debc2cSopenharmony_ci    } while (0)
4646debc2cSopenharmony_ci
4746debc2cSopenharmony_ci#define PRINT_CALL(env, theCall) PRINT_CALL_BASE(env, theCall, nullptr)
4846debc2cSopenharmony_ci
4946debc2cSopenharmony_ci#define PRINT_CALL_RETURN_VOID(env, theCall) PRINT_CALL_BASE(env, theCall, PRINT_RET_NONE)
5046debc2cSopenharmony_ci
5146debc2cSopenharmony_ci#define CHECK_IS_EXCEED_PRINT_RANGE_BASE(count, retVal)                                             \
5246debc2cSopenharmony_ci    do {                                                                                            \
5346debc2cSopenharmony_ci        if ((count) > PRINT_MAX_PRINT_COUNT) {                                                      \
5446debc2cSopenharmony_ci            PRINT_HILOGW("input val is exceed print max range:%{public}d", PRINT_MAX_PRINT_COUNT);  \
5546debc2cSopenharmony_ci            return retVal;                                                                          \
5646debc2cSopenharmony_ci        }                                                                                           \
5746debc2cSopenharmony_ci    } while (0)
5846debc2cSopenharmony_ci
5946debc2cSopenharmony_ci#define CHECK_IS_EXCEED_PRINT_RANGE(count)          CHECK_IS_EXCEED_PRINT_RANGE_BASE(count, nullptr)
6046debc2cSopenharmony_ci#define CHECK_IS_EXCEED_PRINT_RANGE_BOOL(count)     CHECK_IS_EXCEED_PRINT_RANGE_BASE(count, false)
6146debc2cSopenharmony_ci#define CHECK_IS_EXCEED_PRINT_RANGE_VOID(count)     CHECK_IS_EXCEED_PRINT_RANGE_BASE(count, PRINT_RET_NONE)
6246debc2cSopenharmony_ci#define CHECK_IS_EXCEED_PRINT_RANGE_INT(count)      CHECK_IS_EXCEED_PRINT_RANGE_BASE(count, E_PRINT_INVALID_PARAMETER)
6346debc2cSopenharmony_ci
6446debc2cSopenharmony_ci
6546debc2cSopenharmony_cienum PrintErrorCode {
6646debc2cSopenharmony_ci    E_PRINT_NONE = 0,
6746debc2cSopenharmony_ci    E_PRINT_NO_PERMISSION = 201,
6846debc2cSopenharmony_ci    E_PRINT_INVALID_PARAMETER = 401,
6946debc2cSopenharmony_ci    E_PRINT_GENERIC_FAILURE = 13100001,
7046debc2cSopenharmony_ci    E_PRINT_RPC_FAILURE = 13100002,
7146debc2cSopenharmony_ci    E_PRINT_SERVER_FAILURE = 13100003,
7246debc2cSopenharmony_ci    E_PRINT_INVALID_EXTENSION = 13100004,
7346debc2cSopenharmony_ci    E_PRINT_INVALID_PRINTER = 13100005,
7446debc2cSopenharmony_ci    E_PRINT_INVALID_PRINTJOB = 13100006,
7546debc2cSopenharmony_ci    E_PRINT_FILE_IO = 13100007,
7646debc2cSopenharmony_ci    E_PRINT_INVALID_TOKEN = 13100008,
7746debc2cSopenharmony_ci    E_PRINT_INVALID_USERID = 13100009,
7846debc2cSopenharmony_ci    E_PRINT_UNKNOWN = 13100255,
7946debc2cSopenharmony_ci};
8046debc2cSopenharmony_ci
8146debc2cSopenharmony_ciconst uint32_t PRINT_INVALID_ID = 0xFFFFFFFF;   // -1
8246debc2cSopenharmony_ci
8346debc2cSopenharmony_cienum PrinterState {
8446debc2cSopenharmony_ci    PRINTER_ADDED = 0,          // new printers arrival
8546debc2cSopenharmony_ci    PRINTER_REMOVED = 1,        // printers lost
8646debc2cSopenharmony_ci    PRINTER_UPDATE_CAP = 2,     // printers update
8746debc2cSopenharmony_ci    PRINTER_CONNECTED = 3,      // printer has been connected
8846debc2cSopenharmony_ci    PRINTER_DISCONNECTED = 4,   // printer has been disconnected
8946debc2cSopenharmony_ci    PRINTER_RUNNING = 5,        // printer is working
9046debc2cSopenharmony_ci    PRINTER_UNKNOWN = 6,        // unknown printer state
9146debc2cSopenharmony_ci};
9246debc2cSopenharmony_ci
9346debc2cSopenharmony_cienum PrintJobState {
9446debc2cSopenharmony_ci    PRINT_JOB_PREPARED = 0,     // initial state of print job
9546debc2cSopenharmony_ci    PRINT_JOB_QUEUED = 1,       // deliver print job to the printer
9646debc2cSopenharmony_ci    PRINT_JOB_RUNNING = 2,      // executing print job
9746debc2cSopenharmony_ci    PRINT_JOB_BLOCKED = 3,      // print job has been blocked
9846debc2cSopenharmony_ci    PRINT_JOB_COMPLETED = 4,    // print job ocmpleted
9946debc2cSopenharmony_ci    PRINT_JOB_UNKNOWN = 100,      // unknown state of print job
10046debc2cSopenharmony_ci    PRINT_JOB_CREATE_FILE_COMPLETED = 101,    // For internal use only: create print file completed
10146debc2cSopenharmony_ci    PRINT_JOB_SPOOLER_CLOSED = 102,    // For internal use only: spooler closed
10246debc2cSopenharmony_ci};
10346debc2cSopenharmony_ci
10446debc2cSopenharmony_cienum PrintJobSubState {
10546debc2cSopenharmony_ci    PRINT_JOB_COMPLETED_SUCCESS = 0,            // print job succeed
10646debc2cSopenharmony_ci    PRINT_JOB_COMPLETED_FAILED = 1,             // print job fail
10746debc2cSopenharmony_ci    PRINT_JOB_COMPLETED_CANCELLED = 2,          // print job has been cancelled
10846debc2cSopenharmony_ci    PRINT_JOB_COMPLETED_FILE_CORRUPT = 3,       // print job has been corrupted
10946debc2cSopenharmony_ci    PRINT_JOB_BLOCKED_OFFLINE = 4,              // printer is offline
11046debc2cSopenharmony_ci    PRINT_JOB_BLOCKED_BUSY = 5,                 // printer is occupied by other process
11146debc2cSopenharmony_ci    PRINT_JOB_BLOCKED_CANCELLED = 6,            // print job has been canncelled
11246debc2cSopenharmony_ci    PRINT_JOB_BLOCKED_OUT_OF_PAPER = 7,         // out of paper
11346debc2cSopenharmony_ci    PRINT_JOB_BLOCKED_OUT_OF_INK = 8,           // out of ink
11446debc2cSopenharmony_ci    PRINT_JOB_BLOCKED_OUT_OF_TONER = 9,         // out of toner
11546debc2cSopenharmony_ci    PRINT_JOB_BLOCKED_JAMMED = 10,              // paper jam
11646debc2cSopenharmony_ci    PRINT_JOB_BLOCKED_DOOR_OPEN = 11,           // cover open
11746debc2cSopenharmony_ci    PRINT_JOB_BLOCKED_SERVICE_REQUEST = 12,     // service request
11846debc2cSopenharmony_ci    PRINT_JOB_BLOCKED_LOW_ON_INK = 13,          // low on ink
11946debc2cSopenharmony_ci    PRINT_JOB_BLOCKED_LOW_ON_TONER = 14,        // low on toner
12046debc2cSopenharmony_ci    PRINT_JOB_BLOCKED_REALLY_LOW_ON_INK = 15,   // really low on ink
12146debc2cSopenharmony_ci    PRINT_JOB_BLOCKED_BAD_CERTIFICATE = 16,     // bad certification
12246debc2cSopenharmony_ci    PRINT_JOB_BLOCKED_DRIVER_EXCEPTION = 17,    // printer driver exception
12346debc2cSopenharmony_ci
12446debc2cSopenharmony_ci    PRINT_JOB_BLOCKED_ACCOUNT_ERROR = 18, // An error occurred when printing the account.
12546debc2cSopenharmony_ci    PRINT_JOB_BLOCKED_PRINT_PERMISSION_ERROR = 19, // The printing permission is abnormal.
12646debc2cSopenharmony_ci    PRINT_JOB_BLOCKED_PRINT_COLOR_PERMISSION_ERROR = 20, // Color printing permission exception
12746debc2cSopenharmony_ci    PRINT_JOB_BLOCKED_NETWORK_ERROR = 21, // The device is not connected to the network.
12846debc2cSopenharmony_ci    PRINT_JOB_BLOCKED_SERVER_CONNECTION_ERROR = 22, // Unable to connect to the server
12946debc2cSopenharmony_ci    PRINT_JOB_BLOCKED_LARGE_FILE_ERROR = 23, // Large file exception
13046debc2cSopenharmony_ci    PRINT_JOB_BLOCKED_FILE_PARSING_ERROR = 24, // File parsing exception.
13146debc2cSopenharmony_ci    PRINT_JOB_BLOCKED_SLOW_FILE_CONVERSION = 25, // The file conversion is too slow.
13246debc2cSopenharmony_ci    PRINT_JOB_RUNNING_UPLOADING_FILES = 26, // Uploading file...
13346debc2cSopenharmony_ci    PRINT_JOB_RUNNING_CONVERTING_FILES = 27, // Converting files...
13446debc2cSopenharmony_ci    PRINT_JOB_CREATE_FILE_COMPLETED_SUCCESS = 28, // print job create file succeed
13546debc2cSopenharmony_ci    PRINT_JOB_CREATE_FILE_COMPLETED_FAILED = 29, // print job create file fail
13646debc2cSopenharmony_ci    PRINT_JOB_BLOCKED_UNKNOWN = 99,             // unknown issue
13746debc2cSopenharmony_ci    PRINT_JOB_SPOOLER_CLOSED_FOR_CANCELED = 101, // For internal use only: Click Cancel
13846debc2cSopenharmony_ci    PRINT_JOB_SPOOLER_CLOSED_FOR_STARTED = 102, // For internal use only: Click Start
13946debc2cSopenharmony_ci};
14046debc2cSopenharmony_ci
14146debc2cSopenharmony_cienum PrintFileCreatedInfoCode {
14246debc2cSopenharmony_ci    PRINT_FILE_CREATED_SUCCESS = 0,
14346debc2cSopenharmony_ci    PRINT_FILE_CREATED_FAIL = 1,
14446debc2cSopenharmony_ci    PRINT_FILE_CREATED_SUCCESS_UNRENDERED = 2,
14546debc2cSopenharmony_ci};
14646debc2cSopenharmony_ci
14746debc2cSopenharmony_cienum PrintDocumentAdapterState {
14846debc2cSopenharmony_ci    PREVIEW_ABILITY_DESTROY = 0,
14946debc2cSopenharmony_ci    PRINT_TASK_SUCCEED = 1,
15046debc2cSopenharmony_ci    PRINT_TASK_FAIL = 2,
15146debc2cSopenharmony_ci    PRINT_TASK_CANCEL = 3,
15246debc2cSopenharmony_ci    PRINT_TASK_BLOCK = 4,
15346debc2cSopenharmony_ci    PREVIEW_ABILITY_DESTROY_FOR_CANCELED = 5,
15446debc2cSopenharmony_ci    PREVIEW_ABILITY_DESTROY_FOR_STARTED = 6,
15546debc2cSopenharmony_ci};
15646debc2cSopenharmony_ci
15746debc2cSopenharmony_cienum PrintExtensionState {
15846debc2cSopenharmony_ci    PRINT_EXTENSION_UNLOAD,
15946debc2cSopenharmony_ci    PRINT_EXTENSION_LOADING,
16046debc2cSopenharmony_ci    PRINT_EXTENSION_LOADED,
16146debc2cSopenharmony_ci};
16246debc2cSopenharmony_ci
16346debc2cSopenharmony_cienum PrintParamStatus {
16446debc2cSopenharmony_ci    PRINT_PARAM_NOT_SET,
16546debc2cSopenharmony_ci    PRINT_PARAM_OPT,
16646debc2cSopenharmony_ci    PRINT_PARAM_SET,
16746debc2cSopenharmony_ci};
16846debc2cSopenharmony_ci
16946debc2cSopenharmony_cienum PrintDirectionMode {
17046debc2cSopenharmony_ci    DIRECTION_MODE_AUTO = 0,
17146debc2cSopenharmony_ci    DIRECTION_MODE_PORTRAIT = 1,
17246debc2cSopenharmony_ci    DIRECTION_MODE_LANDSCAPE = 2,
17346debc2cSopenharmony_ci};
17446debc2cSopenharmony_ci
17546debc2cSopenharmony_cienum PrintColorMode {
17646debc2cSopenharmony_ci    PRINT_COLOR_MODE_MONOCHROME = 0,
17746debc2cSopenharmony_ci    PRINT_COLOR_MODE_COLOR = 1,
17846debc2cSopenharmony_ci};
17946debc2cSopenharmony_ci
18046debc2cSopenharmony_cienum PrintDuplexMode {
18146debc2cSopenharmony_ci    DUPLEX_MODE_NONE = 0,
18246debc2cSopenharmony_ci    DUPLEX_MODE_LONG_EDGE = 1,
18346debc2cSopenharmony_ci    DUPLEX_MODE_SHORT_EDGE = 2,
18446debc2cSopenharmony_ci};
18546debc2cSopenharmony_ci
18646debc2cSopenharmony_cienum PrintQualityCode {
18746debc2cSopenharmony_ci    PRINT_QUALITY_DRAFT = 3,
18846debc2cSopenharmony_ci    PRINT_QUALITY_NORMAL = 4,
18946debc2cSopenharmony_ci    PRINT_QUALITY_HIGH = 5
19046debc2cSopenharmony_ci};
19146debc2cSopenharmony_ci
19246debc2cSopenharmony_cienum PrintPageType {
19346debc2cSopenharmony_ci    PAGE_ISO_A3 = 0,
19446debc2cSopenharmony_ci    PAGE_ISO_A4 = 1,
19546debc2cSopenharmony_ci    PAGE_ISO_A5 = 2,
19646debc2cSopenharmony_ci    PAGE_JIS_B5 = 3,
19746debc2cSopenharmony_ci    PAGE_ISO_C5 = 4,
19846debc2cSopenharmony_ci    PAGE_ISO_DL = 5,
19946debc2cSopenharmony_ci    PAGE_LETTER = 6,
20046debc2cSopenharmony_ci    PAGE_LEGAL = 7,
20146debc2cSopenharmony_ci    PAGE_PHOTO_4X6 = 8,
20246debc2cSopenharmony_ci    PAGE_PHOTO_5X7 = 9,
20346debc2cSopenharmony_ci    PAGE_INT_DL_ENVELOPE = 10,
20446debc2cSopenharmony_ci    PAGE_B_TABLOID = 11,
20546debc2cSopenharmony_ci};
20646debc2cSopenharmony_ci
20746debc2cSopenharmony_cienum ApplicationEvent {
20846debc2cSopenharmony_ci    APPLICATION_CREATED = 0,
20946debc2cSopenharmony_ci    APPLICATION_CLOSED_FOR_STARTED = 1,
21046debc2cSopenharmony_ci    APPLICATION_CLOSED_FOR_CANCELED = 2,
21146debc2cSopenharmony_ci};
21246debc2cSopenharmony_ci
21346debc2cSopenharmony_cienum PrinterStatus {
21446debc2cSopenharmony_ci    PRINTER_STATUS_IDLE = 0,
21546debc2cSopenharmony_ci    PRINTER_STATUS_BUSY = 1,
21646debc2cSopenharmony_ci    PRINTER_STATUS_UNAVAILABLE = 2,
21746debc2cSopenharmony_ci};
21846debc2cSopenharmony_ci
21946debc2cSopenharmony_cienum PrinterEvent {
22046debc2cSopenharmony_ci    PRINTER_EVENT_ADDED = 0,
22146debc2cSopenharmony_ci    PRINTER_EVENT_DELETED = 1,
22246debc2cSopenharmony_ci    PRINTER_EVENT_STATE_CHANGED = 2,
22346debc2cSopenharmony_ci    PRINTER_EVENT_INFO_CHANGED = 3,
22446debc2cSopenharmony_ci    PRINTER_EVENT_PREFERENCE_CHANGED = 4,
22546debc2cSopenharmony_ci    PRINTER_EVENT_LAST_USED_PRINTER_CHANGED = 5,
22646debc2cSopenharmony_ci};
22746debc2cSopenharmony_ci
22846debc2cSopenharmony_cienum DefaultPrinterType {
22946debc2cSopenharmony_ci    DEFAULT_PRINTER_TYPE_SETTED_BY_USER = 0,
23046debc2cSopenharmony_ci    DEFAULT_PRINTER_TYPE_LAST_USED_PRINTER = 1,
23146debc2cSopenharmony_ci};
23246debc2cSopenharmony_ci
23346debc2cSopenharmony_ciconst std::string PRINTER_DISCOVER_EVENT_TYPE = "printerDiscover";
23446debc2cSopenharmony_ciconst std::string PRINTER_CHANGE_EVENT_TYPE = "printerChange";
23546debc2cSopenharmony_cistatic const std::string PERMISSION_NAME_PRINT = "ohos.permission.PRINT";
23646debc2cSopenharmony_cistatic const std::string PERMISSION_NAME_PRINT_JOB = "ohos.permission.MANAGE_PRINT_JOB";
23746debc2cSopenharmony_ciconst std::string PRINTER_SERVICE_FILE_PATH = "/data/service/el2/public/print_service";
23846debc2cSopenharmony_ciconst std::string PRINTER_LIST_FILE = "printer_list.json";
23946debc2cSopenharmony_ciconst std::string PRINTER_LIST_VERSION = "v1";
24046debc2cSopenharmony_ciconst std::string PRINT_USER_DATA_FILE = "print_user_data.json";
24146debc2cSopenharmony_ciconst std::string PRINT_USER_DATA_VERSION = "v1";
24246debc2cSopenharmony_ci} // namespace OHOS::Print
24346debc2cSopenharmony_ci#endif // PRINT_CONSTANT_H
244