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
25 static IClientSessionCallBack g_sessionCb;
26
ClientTransTdcSetCallBack(const IClientSessionCallBack * cb)27 int32_t ClientTransTdcSetCallBack(const IClientSessionCallBack *cb)
28 {
29 if (cb == NULL) {
30 SoftBusLog(SOFTBUS_LOG_TRAN, SOFTBUS_LOG_ERROR, "ClientTransTdcSetCallBack cb null.");
31 return SOFTBUS_INVALID_PARAM;
32 }
33 g_sessionCb = *cb;
34 return SOFTBUS_OK;
35 }
36
ClientTransTdcOnSessionOpened(const char * sessionName,const ChannelInfo * channel)37 int32_t ClientTransTdcOnSessionOpened(const char *sessionName, const ChannelInfo *channel)
38 {
39 return g_sessionCb.OnSessionOpened(sessionName, channel, TYPE_BYTES);
40 }
41
ClientTransTdcOnSessionClosed(int32_t channelId)42 int32_t ClientTransTdcOnSessionClosed(int32_t channelId)
43 {
44 return g_sessionCb.OnSessionClosed(channelId, CHANNEL_TYPE_TCP_DIRECT);
45 }
46
ClientTransTdcOnSessionOpenFailed(int32_t channelId,int32_t errCode)47 int32_t ClientTransTdcOnSessionOpenFailed(int32_t channelId, int32_t errCode)
48 {
49 return g_sessionCb.OnSessionOpenFailed(channelId, CHANNEL_TYPE_TCP_DIRECT, errCode);
50 }
51
ClientTransTdcOnDataReceived(int32_t channelId,const void * data,uint32_t len,SessionPktType type)52 int32_t ClientTransTdcOnDataReceived(int32_t channelId,
53 const void *data, uint32_t len, SessionPktType type)
54 {
55 return g_sessionCb.OnDataReceived(channelId, CHANNEL_TYPE_TCP_DIRECT, data, len, type);
56 }
57
58