1 /* 2 * Copyright (C) 2021 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 17 #ifndef MOCK_NATIVE_INCLUDE_ERRORS_H 18 #define MOCK_NATIVE_INCLUDE_ERRORS_H 19 20 #include <cerrno> 21 22 namespace OHOS { 23 /** 24 * ErrCode layout 25 * 26 * +-----+--+--+--+--+--+--+--+--+--+--+--+--+--+--+--+--+--+--+--+--+--+--+--+--+--+--+--+--+--+--+--+--+ 27 * | Bit |31|30|29|28|27|26|25|24|23|22|21|20|19|18|17|16|15|14|13|12|11|10|09|08|07|06|05|04|03|02|01|00| 28 * +-----+--+--+--+--+--+--+--+--+--+--+--+--+--+--+--+--+--+--+--+--+--+--+--+--+--+--+--+--+--+--+--+--+ 29 * |Field|Reserved| Subsystem | Module | Code | 30 * +-----+--+--+--+--+--+--+--+--+--+--+--+--+--+--+--+--+--+--+--+--+--+--+--+--+--+--+--+--+--+--+--+--+ 31 */ 32 33 using ErrCode = int; 34 35 enum { 36 SUBSYS_COMMON = 0, 37 SUBSYS_AAFWK = 1, 38 SUBSYS_ACCOUNT = 2, 39 SUBSYS_AI = 3, 40 SUBSYS_APPEXECFWK = 4, 41 SUBSYS_APPLICATIONS = 5, 42 SUBSYS_ARVR = 6, 43 SUBSYS_ARVRHARDWARE = 7, 44 SUBSYS_BARRIERFREE = 8, 45 SUBSYS_BIOMETRICS = 9, 46 SUBSYS_CCRUNTIME = 10, 47 SUBSYS_COMMUNICATION = 11, 48 SUBSYS_DFX = 12, 49 SUBSYS_DISTRIBUTEDDATAMNG = 13, 50 SUBSYS_DISTRIBUTEDSCHEDULE = 14, 51 SUBSYS_DRIVERS = 15, 52 SUBSYS_GLOBAL = 16, 53 SUBSYS_GRAPHIC = 17, 54 SUBSYS_HBS = 18, 55 SUBSYS_IAWARE = 19, 56 SUBSYS_IDE = 20, 57 SUBSYS_INTELLIACCESSORIES = 21, 58 SUBSYS_INTELLISPEAKER = 22, 59 SUBSYS_INTELLITV = 23, 60 SUBSYS_IOT = 24, 61 SUBSYS_IOTHARDWARE = 25, 62 SUBSYS_IVIHARDWARE = 26, 63 SUBSYS_KERNEL = 27, 64 SUBSYS_LOCATION = 28, 65 SUBSYS_MSDP = 29, 66 SUBSYS_MULTIMEDIA = 30, 67 SUBSYS_MULTIMODAINPUT = 31, 68 SUBSYS_NOTIFICATION = 32, 69 SUBSYS_POWERMNG = 33, 70 SUBSYS_ROUTER = 34, 71 SUBSYS_SECURITY = 35, 72 SUBSYS_SENSORS = 36, 73 SUBSYS_SMALLSERVICES = 37, 74 SUBSYS_SOURCECODETRANSFORMER = 38, 75 SUBSYS_STARTUP = 39, 76 SUBSYS_TELEPONY = 40, 77 SUBSYS_UPDATE = 41, 78 SUBSYS_USB = 42, 79 SUBSYS_WEARABLE = 43, 80 SUBSYS_WEARABLEHARDWARE = 44, 81 SUBSYS_IVI = 45 82 // new type 83 }; 84 85 // be used to init the subsystem errorno. 86 constexpr ErrCode ErrCodeOffset(unsigned int subsystem, unsigned int module = 0) 87 { 88 constexpr int SUBSYSTEM_BIT_NUM = 21; 89 constexpr int MODULE_BIT_NUM = 16; 90 return (subsystem << SUBSYSTEM_BIT_NUM) | (module << MODULE_BIT_NUM); 91 } 92 93 // offset of common error, only be used in this file. 94 constexpr ErrCode BASE_ERR_OFFSET = ErrCodeOffset(SUBSYS_COMMON); 95 96 enum { 97 ERR_OK = 0, 98 ERR_NO_MEMORY = BASE_ERR_OFFSET + ENOMEM, 99 ERR_INVALID_OPERATION = BASE_ERR_OFFSET + ENOSYS, 100 ERR_INVALID_VALUE = BASE_ERR_OFFSET + EINVAL, 101 ERR_NAME_NOT_FOUND = BASE_ERR_OFFSET + ENOENT, 102 ERR_PERMISSION_DENIED = BASE_ERR_OFFSET + EPERM, 103 ERR_NO_INIT = BASE_ERR_OFFSET + ENODEV, 104 ERR_ALREADY_EXISTS = BASE_ERR_OFFSET + EEXIST, 105 ERR_DEAD_OBJECT = BASE_ERR_OFFSET + EPIPE, 106 ERR_OVERFLOW = BASE_ERR_OFFSET + EOVERFLOW, 107 ERR_ENOUGH_DATA = BASE_ERR_OFFSET + ENODATA, 108 ERR_WOULD_BLOCK = BASE_ERR_OFFSET + EWOULDBLOCK, 109 ERR_TIMED_OUT = BASE_ERR_OFFSET + ETIMEDOUT 110 }; 111 112 #define SUCCEEDED(errCode) ((errCode) == ERR_OK) 113 #define FAILED(errCode) ((errCode) != ERR_OK) 114 } // namespace OHOS 115 116 #endif // MOCK_NATIVE_INCLUDE_ERRORS_H 117