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