• 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 "dbinder_session_object.h"
17 
18 #include "ipc_process_skeleton.h"
19 #include "ISessionService.h"
20 #include "ipc_debug.h"
21 #include "log_tags.h"
22 
23 namespace OHOS {
24 static constexpr OHOS::HiviewDFX::HiLogLabel LOG_LABEL = { LOG_CORE, LOG_ID_RPC, "dbinder_session_object" };
25 
DBinderSessionObject(std::shared_ptr<Session> session,const std::string & serviceName,const std::string & serverDeviceId,uint64_t stubIndex,IPCObjectProxy * proxy,uint32_t tokenId)26 DBinderSessionObject::DBinderSessionObject(std::shared_ptr<Session> session, const std::string &serviceName,
27     const std::string &serverDeviceId, uint64_t stubIndex, IPCObjectProxy *proxy, uint32_t tokenId)
28     : session_(session), serviceName_(serviceName), serverDeviceId_(serverDeviceId),
29     stubIndex_(stubIndex), proxy_(proxy), tokenId_(tokenId)
30 {}
31 
~DBinderSessionObject()32 DBinderSessionObject::~DBinderSessionObject()
33 {
34     session_ = nullptr;
35     buff_ = nullptr;
36 }
37 
CloseDatabusSession()38 void DBinderSessionObject::CloseDatabusSession()
39 {
40     std::shared_ptr<ISessionService> manager = ISessionService::GetInstance();
41     if (session_ != nullptr && manager != nullptr) {
42         ZLOGI(LOG_LABEL, "close softbus session:%{public}" PRIu64 "", session_->GetChannelId());
43         (void)manager->CloseSession(session_);
44     }
45 }
46 
SetBusSession(std::shared_ptr<Session> session)47 void DBinderSessionObject::SetBusSession(std::shared_ptr<Session> session)
48 {
49     session_ = session;
50 }
51 
GetBusSession() const52 std::shared_ptr<Session> DBinderSessionObject::GetBusSession() const
53 {
54     return session_;
55 }
56 
GetSessionBuff()57 std::shared_ptr<BufferObject> DBinderSessionObject::GetSessionBuff()
58 {
59     if (buff_ == nullptr) {
60         std::lock_guard<std::mutex> lockGuard(buffMutex_);
61         if (buff_ == nullptr) {
62             std::shared_ptr<BufferObject> temp = std::make_shared<BufferObject>();
63             buff_ = temp;
64         }
65     }
66 
67     return buff_;
68 }
69 
SetServiceName(const std::string & serviceName)70 void DBinderSessionObject::SetServiceName(const std::string &serviceName)
71 {
72     serviceName_ = serviceName;
73 }
74 
GetServiceName() const75 std::string DBinderSessionObject::GetServiceName() const
76 {
77     return serviceName_;
78 }
79 
SetDeviceId(const std::string & serverDeviceId)80 void DBinderSessionObject::SetDeviceId(const std::string &serverDeviceId)
81 {
82     serverDeviceId_ = serverDeviceId;
83 }
84 
GetDeviceId() const85 std::string DBinderSessionObject::GetDeviceId() const
86 {
87     return serverDeviceId_;
88 }
89 
SetProxy(IPCObjectProxy * proxy)90 void DBinderSessionObject::SetProxy(IPCObjectProxy *proxy)
91 {
92     proxy_ = proxy;
93 }
94 
GetProxy() const95 IPCObjectProxy *DBinderSessionObject::GetProxy() const
96 {
97     return proxy_;
98 }
99 
GetStubIndex() const100 uint64_t DBinderSessionObject::GetStubIndex() const
101 {
102     return stubIndex_;
103 }
104 
GetFlatSessionLen()105 uint32_t DBinderSessionObject::GetFlatSessionLen()
106 {
107     return sizeof(struct FlatDBinderSession);
108 }
109 
GetSessionHandle() const110 uint32_t DBinderSessionObject::GetSessionHandle() const
111 {
112     if (session_ != nullptr) {
113         return IPCProcessSkeleton::ConvertChannelID2Int(session_->GetChannelId());
114     }
115     return 0;
116 }
117 
GetTokenId() const118 uint32_t DBinderSessionObject::GetTokenId() const
119 {
120     return tokenId_;
121 }
122 } // namespace OHOS
123