1 /*
2 * Copyright (c) 2021 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 #include "client_trans_tcp_direct_callback.h"
17
18 #include <stddef.h>
19
20 #include "session.h"
21 #include "softbus_def.h"
22 #include "softbus_errcode.h"
23 #include "softbus_log.h"
24 #include "client_trans_tcp_direct_manager.h"
25 #include "client_trans_tcp_direct_message.h"
26
27 static IClientSessionCallBack g_sessionCb;
28
ClientTransTdcSetCallBack(const IClientSessionCallBack * cb)29 int32_t ClientTransTdcSetCallBack(const IClientSessionCallBack *cb)
30 {
31 if (cb == NULL) {
32 SoftBusLog(SOFTBUS_LOG_TRAN, SOFTBUS_LOG_ERROR, "ClientTransTdcSetCallBack cb null.");
33 return SOFTBUS_INVALID_PARAM;
34 }
35 g_sessionCb = *cb;
36 return SOFTBUS_OK;
37 }
38
ClientTransTdcOnSessionOpened(const char * sessionName,const ChannelInfo * channel)39 NO_SANITIZE("cfi") int32_t ClientTransTdcOnSessionOpened(const char *sessionName, const ChannelInfo *channel)
40 {
41 return g_sessionCb.OnSessionOpened(sessionName, channel, TYPE_BYTES);
42 }
43
ClientTransTdcOnSessionClosed(int32_t channelId)44 NO_SANITIZE("cfi") int32_t ClientTransTdcOnSessionClosed(int32_t channelId)
45 {
46 (void)TransDelDataBufNode(channelId);
47 (void)TransTdcCloseChannel(channelId);
48 return g_sessionCb.OnSessionClosed(channelId, CHANNEL_TYPE_TCP_DIRECT);
49 }
50
ClientTransTdcOnSessionOpenFailed(int32_t channelId,int32_t errCode)51 NO_SANITIZE("cfi") int32_t ClientTransTdcOnSessionOpenFailed(int32_t channelId, int32_t errCode)
52 {
53 return g_sessionCb.OnSessionOpenFailed(channelId, CHANNEL_TYPE_TCP_DIRECT, errCode);
54 }
55
ClientTransTdcOnDataReceived(int32_t channelId,const void * data,uint32_t len,SessionPktType type)56 NO_SANITIZE("cfi") int32_t ClientTransTdcOnDataReceived(int32_t channelId,
57 const void *data, uint32_t len, SessionPktType type)
58 {
59 return g_sessionCb.OnDataReceived(channelId, CHANNEL_TYPE_TCP_DIRECT, data, len, type);
60 }
61
62