• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
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 "session_mock.h"
17 
18 #include "client_trans_session_manager.h"
19 #include "client_trans_session_service.h"
20 #include "session.h"
21 #include "session_callback_mock.h"
22 
23 static ISessionListener g_innerSessionListener = {
24     .OnSessionOpened = InnerOnSessionOpened,
25     .OnSessionClosed = InnerOnSessionClosed,
26     .OnBytesReceived = InnerOnBytesReceived,
27     .OnMessageReceived = InnerOnMessageReceived,
28 };
29 
CreateSessionServerInner(const char * pkgName,const char * sessionName)30 int CreateSessionServerInner(const char *pkgName, const char *sessionName)
31 {
32     return CreateSessionServer(pkgName, sessionName, &g_innerSessionListener);
33 }
34 
RemoveSessionServerInner(const char * pkgName,const char * sessionName)35 int RemoveSessionServerInner(const char *pkgName, const char *sessionName)
36 {
37     return RemoveSessionServer(pkgName, sessionName);
38 }
39 
OpenSessionInner(const char * mySessionName,const char * peerSessionName,const char * peerNetworkId,const char * groupId,int flag)40 int OpenSessionInner(const char *mySessionName, const char *peerSessionName, const char *peerNetworkId,
41     const char *groupId, int flag)
42 {
43     SessionAttribute attr = {flag};
44     return OpenSessionSync(mySessionName, peerSessionName, peerNetworkId, groupId, &attr);
45 }
46 
CloseSessionInner(int sessionId)47 void CloseSessionInner(int sessionId)
48 {
49     return CloseSession(sessionId);
50 }
51 
GrantPermissionInner(int uid,int pid,const char * busName)52 int32_t GrantPermissionInner(int uid, int pid, const char *busName)
53 {
54     return ClientGrantPermission(uid, pid, busName);
55 }
56 
RemovePermissionInner(const char * busName)57 int32_t RemovePermissionInner(const char *busName)
58 {
59     return ClientRemovePermission(busName);
60 }
61 
SendBytesInner(int32_t sessionId,const void * data,uint32_t len)62 int32_t SendBytesInner(int32_t sessionId, const void *data, uint32_t len)
63 {
64     return SendBytes(sessionId, data, len);
65 }
66 
GetPeerUidInner(int32_t sessionId,int * data)67 int32_t GetPeerUidInner(int32_t sessionId, int *data)
68 {
69     return ClientGetSessionIntegerDataById(sessionId, data, KEY_PEER_UID);
70 }
71 
GetPeerPidInner(int32_t sessionId,int * data)72 int32_t GetPeerPidInner(int32_t sessionId, int *data)
73 {
74     return ClientGetSessionIntegerDataById(sessionId, data, KEY_PEER_PID);
75 }
76 
IsServerSideInner(int32_t sessionId,int * data)77 int32_t IsServerSideInner(int32_t sessionId, int *data)
78 {
79     return ClientGetSessionIntegerDataById(sessionId, data, KEY_IS_SERVER);
80 }
81 
GetMySessionNameInner(int32_t sessionId,char * data,uint16_t len)82 int32_t GetMySessionNameInner(int32_t sessionId, char *data, uint16_t len)
83 {
84     return ClientGetSessionDataById(sessionId, data, len, KEY_SESSION_NAME);
85 }
86 
GetPeerSessionNameInner(int32_t sessionId,char * data,uint16_t len)87 int32_t GetPeerSessionNameInner(int32_t sessionId, char *data, uint16_t len)
88 {
89     return ClientGetSessionDataById(sessionId, data, len, KEY_PEER_SESSION_NAME);
90 }
91 
GetPeerDeviceIdInner(int32_t sessionId,char * data,uint16_t len)92 int32_t GetPeerDeviceIdInner(int32_t sessionId, char *data, uint16_t len)
93 {
94     return ClientGetSessionDataById(sessionId, data, len, KEY_PEER_DEVICE_ID);
95 }
96 
GetPkgNameInner(int32_t sessionId,char * data,uint16_t len)97 int32_t GetPkgNameInner(int32_t sessionId, char *data, uint16_t len)
98 {
99     return ClientGetSessionDataById(sessionId, data, len, KEY_PKG_NAME);
100 }
101