1 /* 2 * Copyright (c) 2021-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 CLIENT_TRANS_TCP_DIRECT_MANAGER_H 17 #define CLIENT_TRANS_TCP_DIRECT_MANAGER_H 18 19 #include "client_trans_session_callback.h" 20 #include "client_trans_tcp_direct_message.h" 21 #include "softbus_sequence_verification.h" 22 23 #ifdef __cplusplus 24 extern "C" { 25 #endif 26 27 typedef struct { 28 int32_t fd; 29 int32_t channelType; 30 int32_t businessType; 31 bool needStopListener; 32 bool needRelease; 33 int32_t fdRefCnt; 34 int apiVersion; 35 int32_t sequence; 36 SeqVerifyInfo verifyInfo; 37 char sessionKey[SESSION_KEY_LENGTH]; 38 char myIp[IP_LEN]; 39 SoftBusMutex fdLock; 40 SoftBusList *pendingPacketsList; 41 } TcpDirectChannelDetail; 42 43 typedef struct { 44 ListNode node; 45 int32_t channelId; 46 TcpDirectChannelDetail detail; 47 } TcpDirectChannelInfo; 48 49 int32_t ClientTransTdcOnChannelOpened(const char *sessionName, const ChannelInfo *channel); 50 int32_t ClientTransTdcOnChannelOpenFailed(int32_t channelId, int32_t errCode); 51 52 void TransTdcCloseChannel(int32_t channelId); 53 54 TcpDirectChannelInfo *TransTdcGetInfoById(int32_t channelId, TcpDirectChannelInfo *info); 55 TcpDirectChannelInfo *TransTdcGetInfoByFd(int32_t fd, TcpDirectChannelInfo *info); 56 TcpDirectChannelInfo *TransTdcGetInfoByIdWithIncSeq(int32_t channelId, TcpDirectChannelInfo *info); 57 58 int32_t TransTdcManagerInit(const IClientSessionCallBack *callback); 59 void TransTdcManagerDeinit(void); 60 61 int32_t TransTdcGetSessionKey(int32_t channelId, char *key, unsigned int len); 62 int32_t TransTdcGetHandle(int32_t channelId, int *handle); 63 int32_t TransDisableSessionListener(int32_t channelId); 64 int32_t TransTdcSetListenerStateById(int32_t channelId, bool needStopListener); 65 66 void TransUpdateFdState(int32_t channelId); 67 68 #ifdef __cplusplus 69 } 70 #endif 71 72 #endif 73