1 /* 2 * Copyright (c) 2021-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 16 #ifndef CLIENT_TRANS_UDP_MANAGER_H 17 #define CLIENT_TRANS_UDP_MANAGER_H 18 19 #include <stdint.h> 20 21 #include "client_trans_session_callback.h" 22 #include "session.h" 23 #include "softbus_def.h" 24 25 #ifdef __cplusplus 26 extern "C" { 27 #endif 28 29 typedef struct { 30 void (*OnStreamReceived)(int32_t channelId, const StreamData *data, const StreamData *ext, 31 const StreamFrameInfo *param); 32 int32_t (*OnFileGetSessionId)(int32_t channelId, int32_t *sessionId); 33 void (*OnMessageReceived)(void); 34 int32_t (*OnUdpChannelOpened)(int32_t channelId); 35 void (*OnUdpChannelClosed)(int32_t channelId, ShutdownReason reason); 36 void (*OnQosEvent)(int channelId, int eventId, int tvCount, const QosTv *tvList); 37 int32_t (*OnIdleTimeoutReset)(int32_t sessionId); 38 int32_t (*OnRawStreamEncryptDefOptGet)(const char *sessionName, bool *isEncrypt); 39 int32_t (*OnRawStreamEncryptOptGet)(int32_t channelId, bool *isEncrypt); 40 } UdpChannelMgrCb; 41 42 typedef struct { 43 bool isServer; 44 int32_t peerUid; 45 int32_t peerPid; 46 char mySessionName[SESSION_NAME_SIZE_MAX]; 47 char peerSessionName[SESSION_NAME_SIZE_MAX]; 48 char peerDeviceId[DEVICE_ID_SIZE_MAX]; 49 char groupId[GROUP_ID_SIZE_MAX]; 50 char myIp[IP_LEN]; 51 } sessionNeed; 52 53 typedef struct { 54 ListNode node; 55 int32_t channelId; 56 int32_t dfileId; 57 int32_t businessType; 58 bool isEnable; 59 sessionNeed info; 60 int32_t routeType; 61 int32_t sessionId; 62 OnRenameFileCallback onRenameFile; 63 } UdpChannel; 64 65 int32_t ClientTransUdpMgrInit(IClientSessionCallBack *callback); 66 void ClientTransUdpMgrDeinit(void); 67 68 int32_t TransOnUdpChannelOpened(const char *sessionName, const ChannelInfo *channel, int32_t *udpPort); 69 int32_t TransOnUdpChannelOpenFailed(int32_t channelId, int32_t errCode); 70 int32_t TransOnUdpChannelClosed(int32_t channelId, ShutdownReason reason); 71 int32_t TransOnUdpChannelQosEvent(int32_t channelId, int32_t eventId, int32_t tvCount, const QosTv *tvList); 72 int32_t TransOnUdpChannelBind(int32_t channelId, int32_t channelType); 73 74 int32_t ClientTransCloseUdpChannel(int32_t channelId, ShutdownReason reason); 75 76 int32_t TransUdpChannelSendStream(int32_t channelId, const StreamData *data, const StreamData *ext, 77 const StreamFrameInfo *param); 78 79 int32_t TransUdpChannelSendFile(int32_t channelId, const char *sFileList[], const char *dFileList[], uint32_t fileCnt); 80 81 int32_t TransGetUdpChannelByFileId(int32_t dfileId, UdpChannel *udpChannel); 82 83 int32_t TransGetUdpChannel(int32_t channelId, UdpChannel *udpChannel); 84 85 void TransUdpDeleteFileListener(const char *sessionName); 86 87 int32_t TransUdpOnCloseAckReceived(int32_t channelId); 88 89 int32_t ClientEmitFileEvent(int32_t channelId); 90 91 int32_t TransLimitChange(int32_t channelId, uint8_t tos); 92 93 int32_t TransSetUdpChanelSessionId(int32_t channelId, int32_t sessionId); 94 95 int32_t TransUdpChannelSetStreamMultiLayer(int32_t channelId, const void *optValue); 96 97 int32_t TransSetUdpChannelRenameHook(int32_t channelId, OnRenameFileCallback onRenameFile); 98 #ifdef __cplusplus 99 } 100 #endif 101 #endif // CLIENT_TRANS_UDP_MANAGER_H