13f4cbf05Sopenharmony_ci/* 23f4cbf05Sopenharmony_ci * Copyright (c) 2021 Huawei Device Co., Ltd. 33f4cbf05Sopenharmony_ci * Licensed under the Apache License, Version 2.0 (the "License"); 43f4cbf05Sopenharmony_ci * you may not use this file except in compliance with the License. 53f4cbf05Sopenharmony_ci * You may obtain a copy of the License at 63f4cbf05Sopenharmony_ci * 73f4cbf05Sopenharmony_ci * http://www.apache.org/licenses/LICENSE-2.0 83f4cbf05Sopenharmony_ci * 93f4cbf05Sopenharmony_ci * Unless required by applicable law or agreed to in writing, software 103f4cbf05Sopenharmony_ci * distributed under the License is distributed on an "AS IS" BASIS, 113f4cbf05Sopenharmony_ci * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 123f4cbf05Sopenharmony_ci * See the License for the specific language governing permissions and 133f4cbf05Sopenharmony_ci * limitations under the License. 143f4cbf05Sopenharmony_ci */ 153f4cbf05Sopenharmony_ci 163f4cbf05Sopenharmony_ci /** 173f4cbf05Sopenharmony_ci * @file errors.h 183f4cbf05Sopenharmony_ci * 193f4cbf05Sopenharmony_ci * @brief Provides format of error code in OpenHarmony. 203f4cbf05Sopenharmony_ci */ 213f4cbf05Sopenharmony_ci 223f4cbf05Sopenharmony_ci#ifndef UTILS_BASE_ERRORS_H 233f4cbf05Sopenharmony_ci#define UTILS_BASE_ERRORS_H 243f4cbf05Sopenharmony_ci 253f4cbf05Sopenharmony_ci#include <cerrno> 263f4cbf05Sopenharmony_ci 273f4cbf05Sopenharmony_cinamespace OHOS { 283f4cbf05Sopenharmony_ci 293f4cbf05Sopenharmony_ci/** 303f4cbf05Sopenharmony_ci * ErrCode layout 313f4cbf05Sopenharmony_ci * 323f4cbf05Sopenharmony_ci * +-----+--+--+--+--+--+--+--+--+--+--+--+--+--+--+--+--+--+--+--+--+--+--+--+--+--+--+--+--+--+--+--+--+ 333f4cbf05Sopenharmony_ci * | 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| 343f4cbf05Sopenharmony_ci * +-----+--+--+--+--+--+--+--+--+--+--+--+--+--+--+--+--+--+--+--+--+--+--+--+--+--+--+--+--+--+--+--+--+ 353f4cbf05Sopenharmony_ci * |Field|Reserved| Subsystem | Module | Code | 363f4cbf05Sopenharmony_ci * +-----+--+--+--+--+--+--+--+--+--+--+--+--+--+--+--+--+--+--+--+--+--+--+--+--+--+--+--+--+--+--+--+--+ 373f4cbf05Sopenharmony_ci */ 383f4cbf05Sopenharmony_ci 393f4cbf05Sopenharmony_ciusing ErrCode = int; 403f4cbf05Sopenharmony_ci 413f4cbf05Sopenharmony_ci/** 423f4cbf05Sopenharmony_ci * @brief Enumerates the values of the <b>Subsystem</b> segment 433f4cbf05Sopenharmony_ci * of ErrCode for every subsystem. 443f4cbf05Sopenharmony_ci */ 453f4cbf05Sopenharmony_cienum { 463f4cbf05Sopenharmony_ci SUBSYS_COMMON = 0, 473f4cbf05Sopenharmony_ci SUBSYS_AAFWK = 1, 483f4cbf05Sopenharmony_ci SUBSYS_ACCOUNT = 2, 493f4cbf05Sopenharmony_ci SUBSYS_AI = 3, 503f4cbf05Sopenharmony_ci SUBSYS_APPEXECFWK = 4, 513f4cbf05Sopenharmony_ci SUBSYS_APPLICATIONS = 5, 523f4cbf05Sopenharmony_ci SUBSYS_ARVR = 6, 533f4cbf05Sopenharmony_ci SUBSYS_ARVRHARDWARE = 7, 543f4cbf05Sopenharmony_ci SUBSYS_BARRIERFREE = 8, 553f4cbf05Sopenharmony_ci SUBSYS_BIOMETRICS = 9, 563f4cbf05Sopenharmony_ci SUBSYS_CCRUNTIME = 10, 573f4cbf05Sopenharmony_ci SUBSYS_COMMUNICATION = 11, 583f4cbf05Sopenharmony_ci SUBSYS_DFX = 12, 593f4cbf05Sopenharmony_ci SUBSYS_DISTRIBUTEDDATAMNG = 13, 603f4cbf05Sopenharmony_ci SUBSYS_DISTRIBUTEDSCHEDULE = 14, 613f4cbf05Sopenharmony_ci SUBSYS_DRIVERS = 15, 623f4cbf05Sopenharmony_ci SUBSYS_GLOBAL = 16, 633f4cbf05Sopenharmony_ci SUBSYS_GRAPHIC = 17, 643f4cbf05Sopenharmony_ci SUBSYS_HBS = 18, 653f4cbf05Sopenharmony_ci SUBSYS_IAWARE = 19, 663f4cbf05Sopenharmony_ci SUBSYS_IDE = 20, 673f4cbf05Sopenharmony_ci SUBSYS_INTELLIACCESSORIES = 21, 683f4cbf05Sopenharmony_ci SUBSYS_INTELLISPEAKER = 22, 693f4cbf05Sopenharmony_ci SUBSYS_INTELLITV = 23, 703f4cbf05Sopenharmony_ci SUBSYS_IOT = 24, 713f4cbf05Sopenharmony_ci SUBSYS_IOTHARDWARE = 25, 723f4cbf05Sopenharmony_ci SUBSYS_IVIHARDWARE = 26, 733f4cbf05Sopenharmony_ci SUBSYS_KERNEL = 27, 743f4cbf05Sopenharmony_ci SUBSYS_LOCATION = 28, 753f4cbf05Sopenharmony_ci SUBSYS_MSDP = 29, 763f4cbf05Sopenharmony_ci SUBSYS_MULTIMEDIA = 30, 773f4cbf05Sopenharmony_ci SUBSYS_MULTIMODAINPUT = 31, 783f4cbf05Sopenharmony_ci SUBSYS_NOTIFICATION = 32, 793f4cbf05Sopenharmony_ci SUBSYS_POWERMNG = 33, 803f4cbf05Sopenharmony_ci SUBSYS_ROUTER = 34, 813f4cbf05Sopenharmony_ci SUBSYS_SECURITY = 35, 823f4cbf05Sopenharmony_ci SUBSYS_SENSORS = 36, 833f4cbf05Sopenharmony_ci SUBSYS_SMALLSERVICES = 37, 843f4cbf05Sopenharmony_ci SUBSYS_SOURCECODETRANSFORMER = 38, 853f4cbf05Sopenharmony_ci SUBSYS_STARTUP = 39, 863f4cbf05Sopenharmony_ci SUBSYS_TELEPONY = 40, 873f4cbf05Sopenharmony_ci SUBSYS_UPDATE = 41, 883f4cbf05Sopenharmony_ci SUBSYS_USB = 42, 893f4cbf05Sopenharmony_ci SUBSYS_WEARABLE = 43, 903f4cbf05Sopenharmony_ci SUBSYS_WEARABLEHARDWARE = 44, 913f4cbf05Sopenharmony_ci SUBSYS_IVI = 45, 923f4cbf05Sopenharmony_ci SUBSYS_DISTRIBUTEDHARDWARE = 46, 933f4cbf05Sopenharmony_ci SUBSYS_DEVICEPROFILE = 47, 943f4cbf05Sopenharmony_ci SUBSYS_CUSTOMIZATION = 48, 953f4cbf05Sopenharmony_ci SUBSYS_FILEMANAGEMENT = 49, 963f4cbf05Sopenharmony_ci // new type 973f4cbf05Sopenharmony_ci}; 983f4cbf05Sopenharmony_ci 993f4cbf05Sopenharmony_ci// be used to init the subsystem errorno. 1003f4cbf05Sopenharmony_ci/** 1013f4cbf05Sopenharmony_ci * @brief Generates the base error codes for a specified module 1023f4cbf05Sopenharmony_ci * in specified subsystem. 1033f4cbf05Sopenharmony_ci * 1043f4cbf05Sopenharmony_ci * @param subsystem Indicates the subsystem. 1053f4cbf05Sopenharmony_ci * @param module Indicates the module. 1063f4cbf05Sopenharmony_ci * The default value is 0. 1073f4cbf05Sopenharmony_ci * @return Returns the base error codes of the specified module. 1083f4cbf05Sopenharmony_ci */ 1093f4cbf05Sopenharmony_ciconstexpr ErrCode ErrCodeOffset(unsigned int subsystem, unsigned int module = 0) 1103f4cbf05Sopenharmony_ci{ 1113f4cbf05Sopenharmony_ci constexpr int SUBSYSTEM_BIT_NUM = 21; 1123f4cbf05Sopenharmony_ci constexpr int MODULE_BIT_NUM = 16; 1133f4cbf05Sopenharmony_ci return (subsystem << SUBSYSTEM_BIT_NUM) | (module << MODULE_BIT_NUM); 1143f4cbf05Sopenharmony_ci} 1153f4cbf05Sopenharmony_ci 1163f4cbf05Sopenharmony_ci// offset of common error, only be used in this file. 1173f4cbf05Sopenharmony_ci/** 1183f4cbf05Sopenharmony_ci * @brief Provides the common base error codes, which apply to all modules, 1193f4cbf05Sopenharmony_ci * in the commonlibrary subsystem. 1203f4cbf05Sopenharmony_ci */ 1213f4cbf05Sopenharmony_ciconstexpr ErrCode BASE_ERR_OFFSET = ErrCodeOffset(SUBSYS_COMMON); 1223f4cbf05Sopenharmony_ci 1233f4cbf05Sopenharmony_ci/** 1243f4cbf05Sopenharmony_ci * @brief Enumerates the common base error codes 1253f4cbf05Sopenharmony_ci * in the commonlibrary subsystem. 1263f4cbf05Sopenharmony_ci * 1273f4cbf05Sopenharmony_ci * @see Related error codes defined in errno.h 1283f4cbf05Sopenharmony_ci */ 1293f4cbf05Sopenharmony_cienum { 1303f4cbf05Sopenharmony_ci ERR_OK = 0, 1313f4cbf05Sopenharmony_ci ERR_NO_MEMORY = BASE_ERR_OFFSET + ENOMEM, 1323f4cbf05Sopenharmony_ci ERR_INVALID_OPERATION = BASE_ERR_OFFSET + ENOSYS, 1333f4cbf05Sopenharmony_ci ERR_INVALID_VALUE = BASE_ERR_OFFSET + EINVAL, 1343f4cbf05Sopenharmony_ci ERR_NAME_NOT_FOUND = BASE_ERR_OFFSET + ENOENT, 1353f4cbf05Sopenharmony_ci ERR_PERMISSION_DENIED = BASE_ERR_OFFSET + EPERM, 1363f4cbf05Sopenharmony_ci ERR_NO_INIT = BASE_ERR_OFFSET + ENODEV, 1373f4cbf05Sopenharmony_ci ERR_ALREADY_EXISTS = BASE_ERR_OFFSET + EEXIST, 1383f4cbf05Sopenharmony_ci ERR_DEAD_OBJECT = BASE_ERR_OFFSET + EPIPE, 1393f4cbf05Sopenharmony_ci ERR_OVERFLOW = BASE_ERR_OFFSET + EOVERFLOW, 1403f4cbf05Sopenharmony_ci ERR_ENOUGH_DATA = BASE_ERR_OFFSET + ENODATA, 1413f4cbf05Sopenharmony_ci ERR_WOULD_BLOCK = BASE_ERR_OFFSET + EWOULDBLOCK, 1423f4cbf05Sopenharmony_ci ERR_TIMED_OUT = BASE_ERR_OFFSET + ETIMEDOUT 1433f4cbf05Sopenharmony_ci}; 1443f4cbf05Sopenharmony_ci 1453f4cbf05Sopenharmony_ci#define SUCCEEDED(errCode) ((errCode) == ERR_OK) 1463f4cbf05Sopenharmony_ci#define FAILED(errCode) ((errCode) != ERR_OK) 1473f4cbf05Sopenharmony_ci 1483f4cbf05Sopenharmony_ci} 1493f4cbf05Sopenharmony_ci 1503f4cbf05Sopenharmony_ci#endif 151