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 OHOS_IPC_DBINDER_ERROR_CODE_H
17 #define OHOS_IPC_DBINDER_ERROR_CODE_H
18
19 #include <cmath>
20 #include <string>
21
22 #ifdef HIVIEWDFX_HISYSEVENT_SUPPORT
23 #include "hisysevent.h"
24 #endif
25
26 namespace OHOS {
27 class DbinderErrorCode {
28 public:
29 static const int SYSTEM_ENVIRONMENT_ERROR = 950000601;
30 static const int NETWORK_ERROR = 950000602;
31 static const int SKELETON_ERROR = 950000603;
32 static const int DBINDER_SERVICE_ERROR = 950000604;
33 static const int TRANSMISSION_ERROR = 950000605;
34 static const int COMMON_DRIVER_ERROR = 950000606;
35 static const int KERNEL_DRIVER_ERROR = 950000607;
36 static const int SOCKET_DRIVER_ERROR = 950000608;
37
38 static constexpr char DSOFTBUS_DOMAIN[] = "DSOFTBUS";
39 static constexpr char DSOFTBUS_EVENT_NAME[] = "IPC_BEHAVIOR";
40 static constexpr char DSOFTBUS_PKG_NAME[] = "dsoftbus_ipc";
41
42 inline static constexpr const char *ERROR_TYPE = "ErrType";
43 inline static constexpr const char *ERROR_CODE = "ErrCode";
44
45 // 601
46 enum SystemEnvironmentError {
47 CREATE_EPOLL = 1,
48 BIND_EPOLL,
49 REMOVE_EPOLL,
50 };
51
52 // 602
53 enum NetworkError {
54 WRONG_DEVICE_ID = 1,
55 WRONG_SUBSCRIPTION,
56 };
57
58 // 603
59 enum SkeletonError {
60 WRONG_KERNEL_DRIVER = 1,
61 WRONG_SOCKET_DRIVER,
62 WRONG_TYPE_PROXY,
63 UPDATE_SESSION_FAILURE,
64 RELEASE_FD_FAILURE,
65 RELEASE_SESSION_FAILURE,
66 UNKNOWN_CMD,
67 };
68
69 // 604
70 enum DbinderServiceError {
71 START_DBS_FAILURE = 1,
72 CLOSE_DBS_FAILURE,
73 WRONG_INPUT_PARAMETER,
74 LOCAL_OBJECT_SEND_MESSAGE_FAILURE,
75 RECEIVE_MESSAGE_FAILURE,
76 INVOKE_LISTENER_FAILURE,
77 ALLOCATE_INDEX_FAILURE,
78 REMOTE_OBJECT_SEND_MESSAGE_FAILURE,
79 INITIATE_DATABUS_FAILURE,
80 DATABUS_SEND_FAILURE,
81 DATABUS_RECEIVE_FAILURE,
82 CLOSE_DATABUS_FAILURE,
83 OPERATE_MESSAGE_FAILURE,
84 };
85
86 // 605
87 enum TransmissionError {
88 RECEIVE_PKT_LOSS = 1,
89 SEND_PKT_LOSS,
90 HANDLE_OVERMUCH_THREADS,
91 OVERSIZE_PKT,
92 };
93
94 // 606
95 enum CommonDriverType {
96 IPC_DRIVER = 1,
97 RPC_DRIVER,
98 };
99 enum CommonDriverError {
100 TRANSACT_DATA_FAILURE = 1,
101 HANDLE_RECV_DATA_FAILURE,
102 SET_DEATH_RECIPIENT_FAILURE,
103 REMOVE_DEATH_RECIPIENT_FAILURE,
104 HANDLE_DEATH_RECIPIENT_FAILURE,
105 FLATTEN_OBJECT_FAILURE,
106 UNFLATTEN_OBJECT_FAILURE,
107 };
108
109 // 607
110 enum KernelDriverError {
111 INITIATE_IPC_DRIVER_FAILURE = 1,
112 OPEN_IPC_DRIVER_FAILURE,
113 WRITE_IPC_DRIVER_FAILURE,
114 };
115
116 // 608
117 enum SocketDriverError {
118 OPEN_RPC_DRIVER_FAILURE = 1,
119 CONNECT_RPC_REMOTE_FAILURE,
120 SEND_RPC_DATA_FAILURE,
121 RECEIVE_RPC_DATA_FAILURE,
122 INVOKE_RPC_THREAD_FAILURE,
123 };
124
125 // BIZ_SCENE
126 enum IpcEventScene {
127 IPC_COMMUNICATION = 1,
128 };
129
130 // BIZ_STAGE
131 enum IpcEventStage {
132 IPC_MESSAGE_RPOCESS = 1,
133 };
134
135 // STAGE_RES
136 enum IpcEventResult {
137 IPC_RESULT_IDLE = 0,
138 IPC_RESULT_OK,
139 IPC_RESULT_FAILED,
140 IPC_RESULT_CANCELED,
141 IPC_RESULT_UNKNOWN,
142 };
143 };
144
DfxReportFailEvent(int type,int errorCode,const char * func)145 inline void DfxReportFailEvent(int type, int errorCode, const char *func)
146 {
147 if (type == 0 || errorCode == 0) {
148 return;
149 }
150 #ifdef HIVIEWDFX_HISYSEVENT_SUPPORT
151 HiSysEventWrite(DbinderErrorCode::DSOFTBUS_DOMAIN, DbinderErrorCode::DSOFTBUS_EVENT_NAME,
152 OHOS::HiviewDFX::HiSysEvent::EventType::BEHAVIOR, "ORG_PKG", DbinderErrorCode::DSOFTBUS_PKG_NAME, "FUNC", func,
153 "BIZ_SCENE", DbinderErrorCode::IPC_COMMUNICATION, "BIZ_STAGE", DbinderErrorCode::IPC_MESSAGE_RPOCESS,
154 "STAGE_RES", DbinderErrorCode::IPC_RESULT_FAILED, "ERROR_CODE", abs(errorCode), "TYPE", type);
155 #endif
156 }
157
DfxReportFailListenEvent(int type,int listenFd,int errorCode,const char * func)158 inline void DfxReportFailListenEvent(int type, int listenFd, int errorCode, const char *func)
159 {
160 if (type == 0 || errorCode == 0) {
161 return;
162 }
163 #ifdef HIVIEWDFX_HISYSEVENT_SUPPORT
164 HiSysEventWrite(DbinderErrorCode::DSOFTBUS_DOMAIN, DbinderErrorCode::DSOFTBUS_EVENT_NAME,
165 OHOS::HiviewDFX::HiSysEvent::EventType::BEHAVIOR, "ORG_PKG", DbinderErrorCode::DSOFTBUS_PKG_NAME, "FUNC", func,
166 "BIZ_SCENE", DbinderErrorCode::IPC_COMMUNICATION, "BIZ_STAGE", DbinderErrorCode::IPC_MESSAGE_RPOCESS,
167 "STAGE_RES", DbinderErrorCode::IPC_RESULT_FAILED, "ERROR_CODE", abs(errorCode), "LISTEN_FD", listenFd, "TYPE",
168 type);
169 #endif
170 }
171
DfxReportFailHandleEvent(int type,int handle,int errorCode,const char * func)172 inline void DfxReportFailHandleEvent(int type, int handle, int errorCode, const char *func)
173 {
174 if (type == 0 || errorCode == 0) {
175 return;
176 }
177 #ifdef HIVIEWDFX_HISYSEVENT_SUPPORT
178 HiSysEventWrite(DbinderErrorCode::DSOFTBUS_DOMAIN, DbinderErrorCode::DSOFTBUS_EVENT_NAME,
179 OHOS::HiviewDFX::HiSysEvent::EventType::BEHAVIOR, "ORG_PKG", DbinderErrorCode::DSOFTBUS_PKG_NAME, "FUNC", func,
180 "BIZ_SCENE", DbinderErrorCode::IPC_COMMUNICATION, "BIZ_STAGE", DbinderErrorCode::IPC_MESSAGE_RPOCESS,
181 "STAGE_RES", DbinderErrorCode::IPC_RESULT_FAILED, "ERROR_CODE", abs(errorCode), "HANDLE", handle, "TYPE", type);
182 #endif
183 }
184
DfxReportFailDeviceEvent(int type,const std::string & device,int errorCode,const char * func)185 inline void DfxReportFailDeviceEvent(int type, const std::string &device, int errorCode, const char *func)
186 {
187 if (type == 0 || device.empty() || errorCode == 0) {
188 return;
189 }
190 #ifdef HIVIEWDFX_HISYSEVENT_SUPPORT
191 HiSysEventWrite(DbinderErrorCode::DSOFTBUS_DOMAIN, DbinderErrorCode::DSOFTBUS_EVENT_NAME,
192 OHOS::HiviewDFX::HiSysEvent::EventType::BEHAVIOR, "ORG_PKG", DbinderErrorCode::DSOFTBUS_PKG_NAME, "FUNC", func,
193 "BIZ_SCENE", DbinderErrorCode::IPC_COMMUNICATION, "BIZ_STAGE", DbinderErrorCode::IPC_MESSAGE_RPOCESS,
194 "STAGE_RES", DbinderErrorCode::IPC_RESULT_FAILED, "ERROR_CODE", abs(errorCode), "DEVICE", device, "TYPE", type);
195 #endif
196 }
197
DfxReportEvent(int type,int stageRes,const char * func)198 inline void DfxReportEvent(int type, int stageRes, const char *func)
199 {
200 if (type == 0) {
201 return;
202 }
203 #ifdef HIVIEWDFX_HISYSEVENT_SUPPORT
204 HiSysEventWrite(DbinderErrorCode::DSOFTBUS_DOMAIN, DbinderErrorCode::DSOFTBUS_EVENT_NAME,
205 OHOS::HiviewDFX::HiSysEvent::EventType::BEHAVIOR, "ORG_PKG", DbinderErrorCode::DSOFTBUS_PKG_NAME, "FUNC", func,
206 "BIZ_SCENE", DbinderErrorCode::IPC_COMMUNICATION, "BIZ_STAGE", DbinderErrorCode::IPC_MESSAGE_RPOCESS,
207 "STAGE_RES", stageRes, "TYPE", type);
208 #endif
209 }
210
DfxReportDeviceEvent(int type,int stageRes,const std::string & device,const char * func)211 inline void DfxReportDeviceEvent(int type, int stageRes, const std::string &device, const char *func)
212 {
213 if (type == 0 || device.empty()) {
214 return;
215 }
216 #ifdef HIVIEWDFX_HISYSEVENT_SUPPORT
217 HiSysEventWrite(DbinderErrorCode::DSOFTBUS_DOMAIN, DbinderErrorCode::DSOFTBUS_EVENT_NAME,
218 OHOS::HiviewDFX::HiSysEvent::EventType::BEHAVIOR, "ORG_PKG", DbinderErrorCode::DSOFTBUS_PKG_NAME, "FUNC", func,
219 "BIZ_SCENE", DbinderErrorCode::IPC_COMMUNICATION, "BIZ_STAGE", DbinderErrorCode::IPC_MESSAGE_RPOCESS,
220 "STAGE_RES", stageRes, "DEVICE", device, "TYPE", type);
221 #endif
222 }
223
224 } // namespace OHOS
225 #endif // OHOS_IPC_DBINDER_ERROR_CODE_H
226