1 /* 2 * Copyright (c) 2023-2024 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 #ifndef SOCKET_TYPE_H 16 #define SOCKET_TYPE_H 17 #include <stdint.h> 18 19 #ifdef __cplusplus 20 extern "C" { 21 #endif 22 23 #define MAX_MAC_LEN 18 24 #define MAX_IP_LEN 46 25 #define MAX_PATH_LEN 4096 26 27 /** 28 * @brief Enumerates the data types. 29 * 30 * @since 2.0 31 * @version 2.0 32 */ 33 typedef enum { 34 DATA_TYPE_MESSAGE = 1, /**< Message */ 35 DATA_TYPE_BYTES, /**< Bytes */ 36 DATA_TYPE_FILE, /**< File */ 37 DATA_TYPE_RAW_STREAM, /**< Raw data stream */ 38 DATA_TYPE_VIDEO_STREAM, /**< Video data stream */ 39 DATA_TYPE_AUDIO_STREAM, /**< Audio data stream */ 40 DATA_TYPE_SLICE_STREAM, /**< Video slice stream */ 41 DATA_TYPE_RAW_STREAM_ENCRYPED, /**< Encryped raw stream data */ 42 DATA_TYPE_BUTT, 43 } TransDataType; 44 45 /** 46 * @brief Defines the description of the socket. 47 * 48 * @since 2.0 49 * @version 2.0 50 */ 51 typedef struct { 52 char *name; /**< My socket name, maximum length 255 bytes */ 53 char *peerName; /**< Peer socket name, maximum length 255 bytes */ 54 char *peerNetworkId; /**< Peer network ID, maximum length 64 bytes */ 55 char *pkgName; /**< Package name, maximum length 64 bytes */ 56 TransDataType dataType; /**< Data type */ 57 } SocketInfo; 58 59 /** 60 * @brief Defines the description of the socket. 61 * 62 * @since 2.0 63 * @version 2.0 64 */ 65 typedef struct { 66 char *name; /**< Peer socket name, maximum length 255 bytes */ 67 char *networkId; /**< Peer network ID, maximum length 64 bytes */ 68 char *pkgName; /**< Peer package name, maximum length 64 bytes */ 69 TransDataType dataType; /**< Data type of peer socket*/ 70 } PeerSocketInfo; 71 72 /** 73 * @brief Enumerates the reason of the shutdown event. 74 * 75 * @since 2.0 76 * @version 2.0 77 */ 78 typedef enum { 79 SHUTDOWN_REASON_UNKNOWN, /**< Shutdown for unknown reason */ 80 SHUTDOWN_REASON_LOCAL, /**< Shutdown by local process */ 81 SHUTDOWN_REASON_PEER, /**< Shutdown by peer process */ 82 SHUTDOWN_REASON_LNN_CHANGED, /**< Shutdown for LNN changed */ 83 SHUTDOWN_REASON_CONN_CHANGED, /**< Shutdown for CONN Changed */ 84 SHUTDOWN_REASON_TIMEOUT, /**< Shutdown for timeout */ 85 SHUTDOWN_REASON_SEND_FILE_ERR, /**< Shutdown for sending file error */ 86 SHUTDOWN_REASON_RECV_FILE_ERR, /**< Shutdown for receiving file error */ 87 SHUTDOWN_REASON_RECV_DATA_ERR, /**< Shutdown for receiving data error */ 88 SHUTDOWN_REASON_UNEXPECTED, /**< Shutdown for unexpected reason */ 89 SHUTDOWN_REASON_SERVICE_DIED, /**< Shutdown for death service */ 90 SHUTDOWN_REASON_LNN_OFFLINE, /**< Shutdown for offline */ 91 SHUTDOWN_REASON_LINK_DOWN, /**< Shutdown for link down */ 92 } ShutdownReason; 93 94 /** 95 * @brief Enumerates of the level of Round Trip Time. 96 * 97 * @since 2.0 98 * @version 2.0 99 */ 100 typedef enum { 101 RTT_LEVEL_DEFAULT = 0, /**< Default RTT level */ 102 RTT_LEVEL_LOW, /**< Low RTT level, perfer low round trip time. */ 103 } QosRttLevel; 104 105 /** 106 * @brief Enumerates the Qos transform reliability. 107 * 108 * @since 2.0 109 * @version 2.0 110 */ 111 typedef enum { 112 QOS_RELIABILITY_NONE = 1, /**< Unreliable */ 113 QOS_RELIABILITY_FULL, /**< Reliable */ 114 QOS_RELIABILITY_HALF, /**< Semi-reliable */ 115 QOS_RELIABILITY_BUTT, 116 } QosTransReliability; 117 118 /** 119 * @brief Enumerates the QoS Assurance Items. 120 * 121 * @since 2.0 122 * @version 2.0 123 */ 124 typedef enum { 125 QOS_TYPE_MIN_BW, /**< Minimum bandwidth. */ 126 QOS_TYPE_MAX_WAIT_TIMEOUT = 1, /**< Maximum timeout of Bind. */ 127 QOS_TYPE_MAX_LATENCY = 1, /**< Maximum latency. */ 128 QOS_TYPE_MIN_LATENCY, /**< Minimum latency. */ 129 QOS_TYPE_RTT_LEVEL, /**< Level of round trip time. */ 130 QOS_TYPE_MAX_BUFFER, /**< @reserved Maximum cache. */ 131 QOS_TYPE_FIRST_PACKAGE, /**< @reserved First packet size. */ 132 QOS_TYPE_MAX_IDLE_TIMEOUT, /**< Maximum idle time. */ 133 QOS_TYPE_TRANS_RELIABILITY, /**< @reserved Transmission reliability. */ 134 QOS_TYPE_BUTT, 135 } QosType; 136 137 /** 138 * @brief Defines the Qos Type-Value structure. 139 * 140 * @since 2.0 141 * @version 2.0 142 */ 143 typedef struct { 144 QosType qos; /**< Qos type {@link QosType} */ 145 int32_t value; /**< Value of Qos types */ 146 } QosTV; 147 148 /** 149 * @brief Enumerates the file priority. 150 * 151 * @since 2.0 152 * @version 2.0 153 */ 154 typedef enum { 155 FILE_PRIORITY_TYPE_DEFAUT = 0, /**< Default priority */ 156 FILE_PRIORITY_TYPE_LOW, /**< Low priority */ 157 } FilePriority; 158 159 /** 160 * @brief Enumerates the file types. 161 * 162 * @since 2.0 163 * @version 2.0 164 */ 165 typedef enum { 166 FILE_EVENT_SEND_PROCESS, /**< Sending file */ 167 FILE_EVENT_SEND_FINISH, /**< Send file end */ 168 FILE_EVENT_SEND_ERROR, /**< Send file failed */ 169 FILE_EVENT_RECV_UPDATE_PATH, /**< Update root directory*/ 170 FILE_EVENT_RECV_START, /**< Receive file start */ 171 FILE_EVENT_RECV_PROCESS, /**< Receiving file */ 172 FILE_EVENT_RECV_FINISH, /**< Receive file end */ 173 FILE_EVENT_RECV_ERROR, /**< Receive file failed */ 174 FILE_EVENT_TRANS_STATUS, /**< Transmission status of the files */ 175 FILE_EVENT_TRANS_LIMIT_CHANGED, /**< Transmission limit changed */ 176 FILE_EVENT_BUTT, 177 } FileEventType; 178 179 typedef struct { 180 char **files; /**< File path */ 181 uint32_t fileCnt; /**< Count of the files */ 182 } FileList; 183 184 typedef struct { 185 FileList completedList; /**< Completed file list */ 186 FileList notCompletedList; /**< Not completed file list */ 187 FileList notStartedList; /**< Not started file list */ 188 } FileStatusList; 189 190 typedef struct { 191 FileEventType type; /**< Event data type of the files*/ 192 const char **files; /**< File path*/ 193 uint32_t fileCnt; /**< Count of the files*/ 194 uint64_t bytesProcessed; /**< Send or receive bytes of the files*/ 195 uint64_t bytesTotal; /**< Total bytes of the files*/ 196 const char *(*UpdateRecvPath)(void); /**< Update file receiving directory*/ 197 FileStatusList statusList; /**< File status list */ 198 int32_t errorCode; /**< Error code */ 199 uint32_t rate; /**< Rate of the file transmission */ 200 FilePriority filePriority; /**< Priority of the file */ 201 } FileEvent; 202 203 /** 204 * @brief Defines the extended stream data. 205 * 206 * @since 2.0 207 * @version 2.0 208 */ 209 typedef struct { 210 int32_t type; /**< Extended data type {@link TransEnumEventType} */ 211 int64_t value; /**< Value of the extended data */ 212 } TV; 213 214 /** 215 * @brief Defines the frame information for stream transmission. 216 * 217 * @since 1.0 218 * @version 1.0 219 */ 220 typedef struct { 221 int32_t frameType; /**< Frame type, which can be I-frame or P-frame. */ 222 int64_t timeStamp; /**< Timestamp. */ 223 int32_t seqNum; /**< Sequence number. */ 224 int32_t seqSubNum; /**< Sequence number of the slice. */ 225 int32_t level; /**< Scalable video coding level. <b>0</b> stands for the base level, 226 <b>1</b> for level 1, and <b>2</b> for level 2. */ 227 int32_t bitMap; /**< Bitmap, which indicates the start or end slice of a frame. */ 228 int32_t tvCount; /**< Number of scalable tag-values (TVs). */ 229 TV *tvList; /**< Pointer to the TV list. */ 230 } StreamFrameInfo; 231 232 /** 233 * @brief Defines the stream data. 234 * 235 * @since 1.0 236 * @version 1.0 237 */ 238 typedef struct { 239 char *buf; /**< Pointer to the buffer for storing the stream data */ 240 int bufLen; /**< Length of the buffer */ 241 } StreamData; 242 243 /** 244 * @brief Enumerates the socket option types. 245 * 246 * @since 2.0 247 * @version 2.0 248 */ 249 typedef enum { 250 OPT_TYPE_MAX_BUFFER, /**< @reserved Maximum cache. */ 251 OPT_TYPE_FIRST_PACKAGE, /**< @reserved First packet size. */ 252 OPT_TYPE_MAX_IDLE_TIMEOUT, /**< @reserved Maximum idle time. */ 253 } OptType; 254 255 /** 256 * @brief Enumerates the socket option level types. 257 * 258 * @since 2.0 259 * @version 2.0 260 */ 261 typedef enum { 262 OPT_LEVEL_KERNEL, /**< @reserved Kernel level option. */ 263 OPT_LEVEL_SOFTBUS, /**< @reserved Softbus level option. */ 264 OPT_LEVEL_BUTT, 265 } OptLevel; 266 267 /** 268 * @brief Enumerate frame event status. 269 * 270 * @since 2.0 271 * @version 2.0 272 */ 273 typedef enum { 274 FRAME_UNSEND, 275 FRAME_SENDING, 276 FRAME_RETRING, 277 FRAME_RECEIVED, 278 FRAME_DROPPED, 279 FRAME_UNMANAGED, 280 } FrameEvtStatus; 281 282 typedef struct { 283 int32_t seq; 284 int32_t level; 285 int32_t subSeqNum; 286 FrameEvtStatus status; 287 uint32_t interval; /**< frame sending interval */ 288 uint32_t queueUsage; /**< send queue percentage of use */ 289 uint32_t cachedFrameCnt; /**< frame count in VTP */ 290 } FrameEvtCbInfo; 291 292 typedef int (*OnFrameEvt)(int fd, const FrameEvtCbInfo *info); 293 294 typedef struct { 295 int32_t socket; /**< Socket fd */ 296 const char *initFileName; /**< Init file name */ 297 char newFileName[MAX_PATH_LEN]; /**< New file name */ 298 } RenameParam; 299 300 typedef void (*OnRenameFileCallback)(RenameParam *renameParam); 301 #ifdef __cplusplus 302 } 303 #endif 304 #endif // SOCKET_TYPE_H