• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
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     bool isLowLatency;
42     ProtocolType fdProtocol;
43     char peerIp[IP_LEN];
44     int32_t peerPort;
45     char pkgName[PKG_NAME_SIZE_MAX];
46     char peerDeviceId[DEVICE_ID_SIZE_MAX];
47 } TcpDirectChannelDetail;
48 
49 typedef struct {
50     ListNode node;
51     int32_t channelId;
52     TcpDirectChannelDetail detail;
53 } TcpDirectChannelInfo;
54 
55 int32_t ClientTransTdcOnChannelOpened(
56     const char *sessionName, const ChannelInfo *channel, SocketAccessInfo *accessInfo);
57 int32_t ClientTransTdcOnChannelOpenFailed(int32_t channelId, int32_t errCode);
58 
59 void TransTdcCloseChannel(int32_t channelId);
60 
61 int32_t TransTdcGetInfoById(int32_t channelId, TcpDirectChannelInfo *info);
62 int32_t TransTdcGetInfoByFd(int32_t fd, TcpDirectChannelInfo *info);
63 TcpDirectChannelInfo *TransTdcGetInfoIncFdRefById(int32_t channelId, TcpDirectChannelInfo *info, bool withSeq);
64 
65 int32_t TransTdcManagerInit(const IClientSessionCallBack *callback);
66 void TransTdcManagerDeinit(void);
67 
68 int32_t TransTdcGetSessionKey(int32_t channelId, char *key, unsigned int len);
69 int32_t TransTdcGetHandle(int32_t channelId, int *handle);
70 int32_t TransDisableSessionListener(int32_t channelId);
71 int32_t TransTdcSetListenerStateById(int32_t channelId, bool needStopListener);
72 
73 void TransUpdateFdState(int32_t channelId);
74 int32_t TransStopTimeSync(int32_t channelId);
75 
76 #ifdef __cplusplus
77 }
78 #endif
79 
80 #endif
81