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