1 /*
2 * Copyright (c) 2023 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 TRANS_EVENT_CONVERTER_H
17 #define TRANS_EVENT_CONVERTER_H
18
19 #include "softbus_event_converter.h"
20
21 #ifdef __cplusplus
22 extern "C" {
23 #endif
24
25 #define TRANS_ASSIGNER(type, fieldName, field) \
26 static inline bool TransAssigner##fieldName( \
27 const char *eventName, HiSysEventParamType paramType, SoftbusEventForm *form, HiSysEventParam *param) \
28 { \
29 if (Assigner##type(form->transExtra->field, ¶m) && \
30 CopyString(param->name, eventName, MAX_LENGTH_OF_PARAM_NAME)) { \
31 param->t = paramType; \
32 return true; \
33 } \
34 return false; \
35 }
36
37 TRANS_ASSIGNER(Errcode, Result, result)
38 TRANS_ASSIGNER(Errcode, Errcode, errcode)
39 TRANS_ASSIGNER(AnonymizeString, SocketName, socketName)
40 TRANS_ASSIGNER(Int32, DataType, dataType)
41 TRANS_ASSIGNER(Int32, ChannelType, channelType)
42 TRANS_ASSIGNER(Int32, LaneId, laneId)
43 TRANS_ASSIGNER(Int32, PreferLinkType, preferLinkType)
44 TRANS_ASSIGNER(Int32, LaneTransType, laneTransType)
45 TRANS_ASSIGNER(Int32, ChannelId, channelId)
46 TRANS_ASSIGNER(Int32, RequestId, requestId)
47 TRANS_ASSIGNER(Int32, ConnectionId, connectionId)
48 TRANS_ASSIGNER(Int32, LinkType, linkType)
49 TRANS_ASSIGNER(Int32, AuthId, authId)
50 TRANS_ASSIGNER(Int32, SocketFd, socketFd)
51 TRANS_ASSIGNER(Int32, CostTime, costTime)
52 TRANS_ASSIGNER(Int32, ChannelScore, channelScore)
53 TRANS_ASSIGNER(Int32, PeerChannelId, peerChannelId)
54 TRANS_ASSIGNER(Int32, BtFlow, btFlow)
55 TRANS_ASSIGNER(AnonymizeString, PeerNetworkId, peerNetworkId)
56 TRANS_ASSIGNER(AnonymizeString, PeerUdid, peerUdid)
57 TRANS_ASSIGNER(String, PeerDevVer, peerDevVer)
58 TRANS_ASSIGNER(AnonymizeString, LocalUdid, localUdid)
59 TRANS_ASSIGNER(String, CallerPkg, callerPkg)
60 TRANS_ASSIGNER(String, CalleePkg, calleePkg)
61 TRANS_ASSIGNER(String, FirstTokenName, firstTokenName)
62 TRANS_ASSIGNER(Uint64, FirstTokenId, firstTokenId)
63 TRANS_ASSIGNER(Int32, FirstTokenType, firstTokenType)
64 TRANS_ASSIGNER(LongString, TrafficStats, trafficStats)
65 TRANS_ASSIGNER(Int32, OsType, osType)
66 TRANS_ASSIGNER(Int32, DeviceState, deviceState)
67 TRANS_ASSIGNER(Int32, BusinessId, businessId)
68 TRANS_ASSIGNER(Int32, BusinessType, businessType)
69 TRANS_ASSIGNER(Int32, SessionId, sessionId)
70 TRANS_ASSIGNER(Int32, MinBW, minBW)
71 TRANS_ASSIGNER(Int32, MaxLatency, maxLatency)
72 TRANS_ASSIGNER(Int32, MinLatency, minLatency)
73
74 #define TRANS_ASSIGNER_SIZE 36 // Size of TRANS_ASSIGNERS
75 static const HiSysEventParamAssigner TRANS_ASSIGNERS[] = {
76 { "STAGE_RES", HISYSEVENT_INT32, TransAssignerResult },
77 { "ERROR_CODE", HISYSEVENT_INT32, TransAssignerErrcode },
78 { "SOCKET_NAME", HISYSEVENT_STRING, TransAssignerSocketName },
79 { "DATA_TYPE", HISYSEVENT_INT32, TransAssignerDataType },
80 { "LOGIC_CHAN_TYPE", HISYSEVENT_INT32, TransAssignerChannelType },
81 { "LANE_ID", HISYSEVENT_INT32, TransAssignerLaneId },
82 { "PREFER_LINK_TYPE", HISYSEVENT_INT32, TransAssignerPreferLinkType},
83 { "LANE_TRANS_TYPE", HISYSEVENT_INT32, TransAssignerLaneTransType },
84 { "CHAN_ID", HISYSEVENT_INT32, TransAssignerChannelId },
85 { "REQ_ID", HISYSEVENT_INT32, TransAssignerRequestId },
86 { "CONN_ID", HISYSEVENT_INT32, TransAssignerConnectionId },
87 { "LINK_TYPE", HISYSEVENT_INT32, TransAssignerLinkType },
88 { "AUTH_ID", HISYSEVENT_INT32, TransAssignerAuthId },
89 { "SOCKET_FD", HISYSEVENT_INT32, TransAssignerSocketFd },
90 { "COST_TIME", HISYSEVENT_INT32, TransAssignerCostTime },
91 { "CHAN_SCORE", HISYSEVENT_INT32, TransAssignerChannelScore },
92 { "PEER_CHAN_ID", HISYSEVENT_INT32, TransAssignerPeerChannelId },
93 { "BT_FLOW", HISYSEVENT_INT32, TransAssignerBtFlow },
94 { "PEER_NET_ID", HISYSEVENT_STRING, TransAssignerPeerNetworkId },
95 { "PEER_UDID", HISYSEVENT_STRING, TransAssignerPeerUdid },
96 { "PEER_DEV_VER", HISYSEVENT_STRING, TransAssignerPeerDevVer },
97 { "LOCAL_UDID", HISYSEVENT_STRING, TransAssignerLocalUdid },
98 { "HOST_PKG", HISYSEVENT_STRING, TransAssignerCallerPkg },
99 { "TO_CALL_PKG", HISYSEVENT_STRING, TransAssignerCalleePkg },
100 { "FIRST_TOKEN_NAME", HISYSEVENT_STRING, TransAssignerFirstTokenName},
101 { "FIRST_TOKEN_ID", HISYSEVENT_UINT64, TransAssignerFirstTokenId },
102 { "FIRST_TOKEN_TYPE", HISYSEVENT_INT32, TransAssignerFirstTokenType},
103 { "TRAFFIC_STATS", HISYSEVENT_STRING, TransAssignerTrafficStats },
104 { "OS_TYPE", HISYSEVENT_INT32, TransAssignerOsType },
105 { "DEVICE_STATE", HISYSEVENT_INT32, TransAssignerDeviceState },
106 { "BUSINESS_ID", HISYSEVENT_INT32, TransAssignerBusinessId },
107 { "BUSINESS_TYPE", HISYSEVENT_INT32, TransAssignerBusinessType },
108 { "SESSION_ID", HISYSEVENT_INT32, TransAssignerSessionId },
109 { "MIN_BW", HISYSEVENT_INT32, TransAssignerMinBW },
110 { "MAX_LATENCY", HISYSEVENT_INT32, TransAssignerMaxLatency },
111 { "MIN_LATENCY", HISYSEVENT_INT32, TransAssignerMinLatency },
112 // Modification Note: remember updating TRANS_ASSIGNER_SIZE
113 };
114
115 #define TRANS_ALARM_ASSIGNER(type, fieldName, field) \
116 static inline bool TransAssigner##fieldName( \
117 const char *eventName, HiSysEventParamType paramType, SoftbusEventForm *form, HiSysEventParam *param) \
118 { \
119 if (Assigner##type(form->transAlarmExtra->field, ¶m) && \
120 CopyString(param->name, eventName, MAX_LENGTH_OF_PARAM_NAME)) { \
121 param->t = paramType; \
122 return true; \
123 } \
124 return false; \
125 }
126
127 TRANS_ALARM_ASSIGNER(Errcode, AlarmResult, result)
128 TRANS_ALARM_ASSIGNER(Errcode, AlarmReason, errcode)
129 TRANS_ALARM_ASSIGNER(Int32, CallerPid, callerPid)
130 TRANS_ALARM_ASSIGNER(Int32, AlarmLinkType, linkType)
131 TRANS_ALARM_ASSIGNER(Int32, MinBw, minBw)
132 TRANS_ALARM_ASSIGNER(Int32, MethodId, methodId)
133 TRANS_ALARM_ASSIGNER(Int32, Duration, duration)
134 TRANS_ALARM_ASSIGNER(Int32, CurFlow, curFlow)
135 TRANS_ALARM_ASSIGNER(Int32, LimitFlow, limitFlow)
136 TRANS_ALARM_ASSIGNER(Int32, LimitTime, limitTime)
137 TRANS_ALARM_ASSIGNER(Int32, OccupyRes, occupyRes)
138 TRANS_ALARM_ASSIGNER(Int32, SyncType, syncType)
139 TRANS_ALARM_ASSIGNER(Int32, SyncData, syncData)
140 TRANS_ALARM_ASSIGNER(Int32, RetryCount, retryCount)
141 TRANS_ALARM_ASSIGNER(Int32, RetryReason, retryReason)
142 TRANS_ALARM_ASSIGNER(String, ConflictName, conflictName)
143 TRANS_ALARM_ASSIGNER(String, ConflictedName, conflictedName)
144 TRANS_ALARM_ASSIGNER(String, OccupyedName, occupyedName)
145 TRANS_ALARM_ASSIGNER(String, PermissionName, permissionName)
146 TRANS_ALARM_ASSIGNER(AnonymizeString, AlarmSessionName, sessionName)
147
148 #define TRANS_ALARM_ASSIGNER_SIZE 20 // Size of g_transAlarmAssigners
149 static const HiSysEventParamAssigner g_transAlarmAssigners[] = {
150 { "STAGE_RES", HISYSEVENT_INT32, TransAssignerAlarmResult },
151 { "ERROR_CODE", HISYSEVENT_INT32, TransAssignerAlarmReason },
152 { "CALLER_PID", HISYSEVENT_INT32, TransAssignerCallerPid },
153 { "LINK_TYPE", HISYSEVENT_INT32, TransAssignerAlarmLinkType },
154 { "MIN_BW", HISYSEVENT_INT32, TransAssignerMinBw },
155 { "METHOD_ID", HISYSEVENT_INT32, TransAssignerMethodId },
156 { "DURATION", HISYSEVENT_INT32, TransAssignerDuration },
157 { "CUR_FLOW", HISYSEVENT_INT32, TransAssignerCurFlow },
158 { "LIMIT_FLOW", HISYSEVENT_INT32, TransAssignerLimitFlow },
159 { "LIMIT_TIME", HISYSEVENT_INT32, TransAssignerLimitTime },
160 { "OCCUPY_RES", HISYSEVENT_INT32, TransAssignerOccupyRes },
161 { "SYNC_TYPE", HISYSEVENT_INT32, TransAssignerSyncType },
162 { "SYNC_DATA", HISYSEVENT_INT32, TransAssignerSyncData },
163 { "RETRY_COUNT", HISYSEVENT_INT32, TransAssignerRetryCount },
164 { "RETRY_REASON", HISYSEVENT_INT32, TransAssignerRetryReason },
165 { "CONFLICT_NAME", HISYSEVENT_STRING, TransAssignerConflictName },
166 { "CONFLECTED_NAME", HISYSEVENT_STRING, TransAssignerConflictedName },
167 { "OCCUPYED_NAME", HISYSEVENT_STRING, TransAssignerOccupyedName },
168 { "PERMISSION_NAME", HISYSEVENT_STRING, TransAssignerPermissionName },
169 { "SESSION_NAME", HISYSEVENT_STRING, TransAssignerAlarmSessionName },
170 // Modification Note: remember updating TRANS_ALARM_ASSIGNER_SIZE
171 };
172
ConvertTransForm2Param(HiSysEventParam params[],size_t size,SoftbusEventForm * form)173 static inline size_t ConvertTransForm2Param(HiSysEventParam params[], size_t size, SoftbusEventForm *form)
174 {
175 size_t validSize = 0;
176 if (form == NULL || form->transExtra == NULL) {
177 return validSize;
178 }
179 for (size_t i = 0; i < size; ++i) {
180 HiSysEventParamAssigner assigner = TRANS_ASSIGNERS[i];
181 if (assigner.Assign(assigner.name, assigner.type, form, ¶ms[validSize])) {
182 ++validSize;
183 }
184 }
185 return validSize;
186 }
187
ConvertTransAlarmForm2Param(HiSysEventParam params[],size_t size,SoftbusEventForm * form)188 static inline size_t ConvertTransAlarmForm2Param(HiSysEventParam params[], size_t size, SoftbusEventForm *form)
189 {
190 size_t validSize = 0;
191 if (form == NULL || form->transAlarmExtra == NULL) {
192 return validSize;
193 }
194 for (size_t i = 0; i < size; ++i) {
195 HiSysEventParamAssigner assigner = g_transAlarmAssigners[i];
196 if (assigner.Assign(assigner.name, assigner.type, form, ¶ms[validSize])) {
197 ++validSize;
198 }
199 }
200 return validSize;
201 }
202
203 #ifdef __cplusplus
204 }
205 #endif /* __cplusplus */
206 #endif // TRANS_EVENT_CONVERTER_H
207