1 /*
2  * Copyright (c) 2022 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  * miscservices under the License is miscservices 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 #ifndef SOFTBUS_HISYSEVT_CONNREPORTER_H
16 #define SOFTBUS_HISYSEVT_CONNREPORTER_H
17 
18 #include "softbus_adapter_hisysevent.h"
19 
20 #ifdef __cplusplus
21 #if __cplusplus
22 extern "C" {
23 #endif
24 #endif
25 
26 #define DEFAULT_PID 0
27 
28 typedef enum {
29     SOFTBUS_EVT_CONN_SUCC,
30     SOFTBUS_EVT_CONN_FAIL,
31 } SoftBusConnStatus;
32 
33 typedef enum {
34     SOFTBUS_HISYSEVT_CONN_TYPE_BR = 0,
35     SOFTBUS_HISYSEVT_CONN_TYPE_BLE = 1,
36     SOFTBUS_HISYSEVT_CONN_TYPE_TCP = 2,
37     SOFTBUS_HISYSEVT_CONN_TYPE_P2P = 3,
38     SOFTBUS_HISYSEVT_CONN_TYPE_HML = 4,
39     SOFTBUS_HISYSEVT_CONN_TYPE_COC = 5,
40     SOFTBUS_HISYSEVT_CONN_TYPE_BUTT = 6,
41 } SoftBusConnType;
42 
43 typedef enum {
44     NEGOTIATION_STEP = 0,
45     GROUP_CREATE_STEP = 1,
46     CONN_GROUP_STEP = 2,
47     STEP_BUTT = 3,
48 } ProcessStep;
49 
50 typedef enum {
51     SOFTBUS_HISYSEVT_CONN_OK,
52     SOFTBUS_HISYSEVT_CONN_MANAGER_OP_NOT_SUPPORT,
53     SOFTBUS_HISYSEVT_BLE_NOT_INIT,
54     SOFTBUS_HISYSEVT_BLE_GATTSERVER_INIT_FAIL,
55     SOFTBUS_HISYSEVT_BLE_GATTCLIENT_INIT_FAIL,
56     SOFTBUS_HISYSEVT_BLE_TRANS_INIT_FAIL,
57     SOFTBUS_HISYSEVT_BLE_QUEUE_INIT_FAIL,
58     SOFTBUS_HISYSEVT_BLE_CONNECT_FAIL,
59     SOFTBUS_HISYSEVT_BLE_DISCONNECT_FAIL,
60     SOFTBUS_HISYSEVT_BLE_SEND_FAIL,
61     SOFTBUS_HISYSEVT_BLE_RECV_INVALID_DATA,
62     SOFTBUS_HISYSEVT_BLE_RECV_INVALID_DEVICE,
63     SOFTBUS_HISYSEVT_BLE_GATTSERVER_START_FAIL,
64     SOFTBUS_HISYSEVT_BLE_GATTSERVER_STOP_FAIL,
65     SOFTBUS_HISYSEVT_BLE_GATTCLIENT_UPDATA_STATE_ERR,
66     SOFTBUS_HISYSEVT_BLE_GATTCLIENT_SEARCH_SERVICES_ERR,
67     SOFTBUS_HISYSEVT_TCP_CONNECTION_SOCKET_ERR,
68     SOFTBUS_HISYSEVT_CONN_ERRCODE_BUTT,
69 } SoftBusConnErrCode;
70 
71 typedef struct {
72     uint64_t totalTime;
73     uint64_t negotiationTime;
74     uint64_t groupCreateTime;
75     uint64_t connGroupTime;
76 } ProcessStepTime;
77 
78 typedef struct {
79     uint32_t reqId;
80     uint64_t startTime;
81     uint32_t connectTraceId;
82     bool reuse;
83 } ConnectStatistics;
84 
85 int32_t SoftBusRecordPIdAndPkgName(uint32_t pId, const char *pkgName);
86 
87 int32_t SoftbusRecordConnResult(uint32_t pId, SoftBusConnType connType, SoftBusConnStatus status,
88                                 uint64_t costTime, int32_t errCode);
89 
90 int32_t SoftbusRecordProccessDuration(uint32_t pId, SoftBusConnType connType, SoftBusConnStatus status,
91                                       ProcessStepTime *stepTime, int32_t errCode);
92 
93 uint32_t SoftbusGetConnectTraceId();
94 
95 int32_t InitConnStatisticSysEvt(void);
96 
97 void DeinitConnStatisticSysEvt(void);
98 
99 #ifdef __cplusplus
100 #if __cplusplus
101 }
102 #endif /* __cplusplus */
103 #endif /* __cplusplus */
104 
105 #endif /* SOFTBUS_HISYSEVT_DISCREPORTER_H */