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