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 "softbus_proxychannel_callback.h"
17
18 #include "softbus_def.h"
19 #include "softbus_errcode.h"
20
21 static IServerChannelCallBack g_channelCb;
22
TransProxySetCallBack(const IServerChannelCallBack * cb)23 int32_t TransProxySetCallBack(const IServerChannelCallBack *cb)
24 {
25 if (cb == NULL) {
26 return SOFTBUS_INVALID_PARAM;
27 }
28 g_channelCb = *cb;
29 return SOFTBUS_OK;
30 }
31
TransProxyOnChannelOpened(const char * pkgName,int32_t pid,const char * sessionName,const ChannelInfo * channel)32 int32_t TransProxyOnChannelOpened(const char *pkgName, int32_t pid, const char *sessionName,
33 const ChannelInfo *channel)
34 {
35 return g_channelCb.OnChannelOpened(pkgName, pid, sessionName, channel);
36 }
37
TransProxyOnChannelClosed(const char * pkgName,int32_t pid,int32_t channelId)38 int32_t TransProxyOnChannelClosed(const char *pkgName, int32_t pid, int32_t channelId)
39 {
40 return g_channelCb.OnChannelClosed(pkgName, pid, channelId, CHANNEL_TYPE_PROXY, MESSAGE_TYPE_NOMAL);
41 }
42
TransProxyOnChannelBind(const char * pkgName,int32_t pid,int32_t channelId)43 int32_t TransProxyOnChannelBind(const char *pkgName, int32_t pid, int32_t channelId)
44 {
45 return g_channelCb.OnChannelBind(pkgName, pid, channelId, CHANNEL_TYPE_PROXY);
46 }
47
TransProxyOnChannelOpenFailed(const char * pkgName,int32_t pid,int32_t channelId,int32_t errCode)48 int32_t TransProxyOnChannelOpenFailed(const char *pkgName, int32_t pid, int32_t channelId,
49 int32_t errCode)
50 {
51 return g_channelCb.OnChannelOpenFailed(pkgName, pid, channelId, CHANNEL_TYPE_PROXY, errCode);
52 }
53
TransProxyOnMsgReceived(const char * pkgName,int32_t pid,int32_t channelId,TransReceiveData * receiveData)54 int32_t TransProxyOnMsgReceived(const char *pkgName, int32_t pid, int32_t channelId,
55 TransReceiveData *receiveData)
56 {
57 return g_channelCb.OnDataReceived(pkgName, pid, channelId, CHANNEL_TYPE_PROXY, receiveData);
58 }
59
TransProxyGetPkgName(const char * sessionName,char * pkgName,uint16_t len)60 int32_t TransProxyGetPkgName(const char *sessionName, char *pkgName, uint16_t len)
61 {
62 return g_channelCb.GetPkgNameBySessionName(sessionName, pkgName, len);
63 }
64
TransProxyGetUidAndPidBySessionName(const char * sessionName,int32_t * uid,int32_t * pid)65 int32_t TransProxyGetUidAndPidBySessionName(const char *sessionName, int32_t *uid, int32_t *pid)
66 {
67 return g_channelCb.GetUidAndPidBySessionName(sessionName, uid, pid);
68 }
69