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 SCAN_CONSTANT_H 17 #define SCAN_CONSTANT_H 18 19 #include <string> 20 21 namespace OHOS::Scan { 22 23 #define SCAN_RET_NONE 24 #define SCAN_MAX_COUNT 1000 25 26 #define SCAN_ASSERT_BASE(env, assertion, message, retVal) \ 27 do { \ 28 if (!(assertion)) { \ 29 SCAN_HILOGE(message); \ 30 return retVal; \ 31 } \ 32 } while (0) 33 34 #define SCAN_ASSERT(env, assertion, message) SCAN_ASSERT_BASE(env, assertion, message, nullptr) 35 36 #define SCAN_ASSERT_RETURN_VOID(env, assertion, message) SCAN_ASSERT_BASE(env, assertion, message, SCAN_RET_NONE) 37 38 #define SCAN_CALL_BASE(env, theCall, retVal) \ 39 do { \ 40 if ((theCall) != napi_ok) { \ 41 return retVal; \ 42 } \ 43 } while (0) 44 45 #define SCAN_CALL(env, theCall) SCAN_CALL_BASE(env, theCall, nullptr) 46 47 #define SCAN_CALL_RETURN_VOID(env, theCall) SCAN_CALL_BASE(env, theCall, SCAN_RET_NONE) 48 49 #define DELETE_AND_NULLIFY(ptr) \ 50 if ((ptr) != nullptr) { \ 51 delete (ptr); \ 52 (ptr) = nullptr; \ 53 } 54 55 #define DELETE_ARRAY_AND_NULLIFY(ptr) \ 56 if ((ptr) != nullptr) { \ 57 delete[] (ptr); \ 58 (ptr) = nullptr; \ 59 } 60 61 #define FREE_AND_NULLPTR(ptr) \ 62 if ((ptr) != nullptr) { \ 63 free (ptr); \ 64 (ptr) = nullptr; \ 65 } 66 67 #define CHECK_AND_CREATE(pointer, error_message, flag) \ 68 if ((pointer) == nullptr) { \ 69 SCAN_HILOGE(error_message); \ 70 (flag) = false; \ 71 } 72 73 #define CREATE_PRC_MESSAGE \ 74 MessageParcel data; \ 75 MessageParcel reply; \ 76 MessageOption option; \ 77 data.WriteInterfaceToken(GetDescriptor()) \ 78 79 #define CHECK_IS_EXCEED_SCAN_RANGE_BASE(count, retVal) \ 80 do { \ 81 if ((count) > SCAN_MAX_COUNT) { \ 82 SCAN_HILOGW("input val is exceed scan max range:%{public}d", SCAN_MAX_COUNT); \ 83 return retVal; \ 84 } \ 85 } while (0) 86 87 #define CHECK_IS_EXCEED_SCAN_RANGE(count) CHECK_IS_EXCEED_SCAN_RANGE_BASE(count, nullptr) 88 #define CHECK_IS_EXCEED_SCAN_RANGE_BOOL(count) CHECK_IS_EXCEED_SCAN_RANGE_BASE(count, false) 89 #define CHECK_IS_EXCEED_SCAN_RANGE_VOID(count) CHECK_IS_EXCEED_SCAN_RANGE_BASE(count, E_SCAN_NONE) 90 #define CHECK_IS_EXCEED_SCAN_RANGE_INT(count) CHECK_IS_EXCEED_SCAN_RANGE_BASE(count, E_SCAN_INVALID_PARAMETER) 91 92 enum ScanErrorCode { 93 E_SCAN_NONE = 0, // no error 94 E_SCAN_NO_PERMISSION = 201, // no permission 95 E_SCAN_ERROR_NOT_SYSTEM_APPLICATION = 202, // not system application 96 E_SCAN_INVALID_PARAMETER = 401, // invalid parameter 97 E_SCAN_GENERIC_FAILURE = 13100001, // generic failure of scan 98 E_SCAN_RPC_FAILURE = 13100002, // RPC failure 99 E_SCAN_SERVER_FAILURE = 13100003, // failure of scan service 100 E_SCAN_UNSUPPORTED = 13100004, // operation is not supported 101 E_SCAN_CANCELLED = 13100005, // operation was cancelled 102 E_SCAN_DEVICE_BUSY = 13100006, // device is busy; try again later 103 E_SCAN_INVAL = 13100007, // data is invalid (includes no dev at open) 104 E_SCAN_JAMMED = 13100008, // document feeder jammed 105 E_SCAN_NO_DOCS = 13100009, // document feeder out of documents 106 E_SCAN_COVER_OPEN = 13100010, // scanner cover is open 107 E_SCAN_IO_ERROR = 13100011, // error during device I/O 108 E_SCAN_NO_MEM = 13200012, // out of memory 109 E_SCAN_EOF = 132000013, // no more data available (end-of-file) 110 E_SCAN_ACCESS_DENIED = 13200014, // access to resource has been denied 111 }; 112 113 const uint32_t SCAN_INVALID_ID = 0xFFFFFFFF; // -1 114 const uint16_t USB_VALUE_DESCRIPTOR_INDEX_SERIAL_NUMBER = 0X03; 115 const uint8_t USB_REQUESTTYPE_DEVICE_TO_HOST = 0X80; 116 const uint8_t USB_REQUEST_GET_DESCRIPTOR = 0X06; 117 const uint16_t USB_VALUE_DESCRIPTOR_TYPE_STRING = 0X03; 118 const int HTTP_COMMON_CONST_VALUE_8 = 8; 119 const uint16_t USB_INDEX_LANGUAGE_ID_ENGLISH = 0X409; 120 const int HTTP_COMMON_CONST_VALUE_500 = 500; 121 const int HTTP_COMMON_CONST_VALUE_100 = 100; 122 const int HTTP_COMMON_CONST_VALUE_2 = 2; 123 const int USB_DEVICEID_FIRSTID_LEN_3 = 3; 124 125 enum ScanFrame { 126 SCAN_FRAME_GRAY = 0, /* band covering human visual range */ 127 SCAN_FRAME_RGB = 1, /* pixel-interleaved red/green/blue bands */ 128 SCAN_FRAME_RED = 2, /* red band only */ 129 SCAN_FRAME_GREEN = 3, /* green band only */ 130 SCAN_FRAME_BLUE = 4, /* blue band only */ 131 }; 132 133 enum ScanExtensionState { 134 SCAN_EXTENSION_UNLOAD, 135 SCAN_EXTENSION_LOADING, 136 SCAN_EXTENSION_LOADED, 137 }; 138 139 enum ScanParamStatus { 140 SCAN_PARAM_NOT_SET, 141 SCAN_PARAM_OPT, 142 SCAN_PARAM_SET, 143 }; 144 145 enum ScanOptionOpType { 146 SCAN_ACTION_GET_VALUE = 0, 147 SCAN_ACTION_SET_VALUE, 148 SCAN_ACTION_SET_AUTO 149 }; 150 151 enum ScanOptionValueType { 152 SCAN_VALUE_BOOL = 0, 153 SCAN_VALUE_NUM, 154 SCAN_VALUE_FIXED, 155 SCAN_VALUE_STR, 156 SCAN_VALUE_BUTTON, 157 SCAN_VALUE_GROUP 158 }; 159 160 enum ScanConstraintType { 161 SCAN_CONSTRAINT_NONE = 0, 162 SCAN_CONSTRAINT_RANGE = 1, 163 SCAN_CONSTRAINT_WORD_LIST = 2, 164 SCAN_CONSTRAINT_STRING_LIST = 3, 165 }; 166 167 enum ScannerState { 168 SCANNER_READY = 0, 169 SCANNER_SCANING = 1, 170 SCANNER_SEARCHING = 2, 171 SCANNER_CANCELING = 3, 172 }; 173 174 enum PhysicalUnit { 175 SCANNER_UNIT_NONE = 0, // the value is unit-less (e.g., # of scans) 176 SCANNER_UNIT_PIXEL, // value is number of pixels 177 SCANNER_UNIT_BIT, // value is number of bits 178 SCANNER_UNIT_MM, // value is millimeters 179 SCANNER_UNIT_DPI, // value is resolution in dots/inch 180 SCANNER_UNIT_PERCENT, // value is a percentage 181 SCANNER_UNIT_MICROSECOND // value is micro seconds 182 }; 183 184 enum DiscoveryModeType { 185 TCP_STR = 0, 186 USB_STR, 187 }; 188 } // namespace OHOS::Scan 189 #endif // SCAN_CONSTANT_H 190