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