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