• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
1 /*
2  * Copyright (c) 2023 Shenzhen Kaihong Digital Industry Development 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 "ipc_msg_adapter.h"
17 
18 namespace OHOS {
19 namespace Sharing {
20 
~IpcMsgAdapter()21 IpcMsgAdapter::~IpcMsgAdapter()
22 {
23     SHARING_LOGD("trace.");
24     peerProxy_ = nullptr;
25     localStub_ = nullptr;
26 }
27 
SendRequest(std::shared_ptr<BaseMsg> msg,std::shared_ptr<BaseMsg> & reply)28 int32_t IpcMsgAdapter::SendRequest(std::shared_ptr<BaseMsg> msg, std::shared_ptr<BaseMsg> &reply)
29 {
30     SHARING_LOGD("trace.");
31     if (peerProxy_ != nullptr) {
32         peerProxy_->DoIpcCommand(msg, reply);
33     } else {
34         SHARING_LOGE("peerProxy_ is nullptr.");
35     }
36 
37     return 0;
38 }
39 
OnRequest(std::shared_ptr<BaseMsg> msg,std::shared_ptr<BaseMsg> & reply)40 int32_t IpcMsgAdapter::OnRequest(std::shared_ptr<BaseMsg> msg, std::shared_ptr<BaseMsg> &reply)
41 {
42     SHARING_LOGD("trace.");
43 
44     auto listener = listener_.lock();
45     if (listener) {
46         listener->OnRequest(msg, reply);
47     } else {
48         SHARING_LOGE("listener_ is nullptr.");
49     }
50 
51     return 0;
52 }
53 
SetLocalStub(sptr<InterIpcStub> stub)54 void IpcMsgAdapter::SetLocalStub(sptr<InterIpcStub> stub)
55 {
56     SHARING_LOGD("trace.");
57     localStub_ = stub;
58     if (localStub_) {
59         localStub_->SetStubListener(shared_from_this());
60     }
61 }
62 
SetPeerProxy(sptr<IInterIpc> proxy)63 void IpcMsgAdapter::SetPeerProxy(sptr<IInterIpc> proxy)
64 {
65     SHARING_LOGD("trace.");
66     peerProxy_ = proxy;
67 }
68 
OnIpcRequest(std::shared_ptr<BaseMsg> msg,std::shared_ptr<BaseMsg> & reply)69 void IpcMsgAdapter::OnIpcRequest(std::shared_ptr<BaseMsg> msg, std::shared_ptr<BaseMsg> &reply)
70 {
71     SHARING_LOGD("trace.");
72     OnRequest(msg, reply);
73 }
74 
OnRemoteDied()75 void IpcMsgAdapter::OnRemoteDied()
76 {
77     SHARING_LOGD("on Adapter IpcStub remote died!");
78     auto listener = listener_.lock();
79     if (listener) {
80         listener->OnRemoteDied();
81     }
82 }
83 
SetCallingKey(std::string key)84 void IpcMsgAdapter::SetCallingKey(std::string key)
85 {
86     SHARING_LOGD("trace.");
87     key_ = key;
88 }
89 
GetCallingKey()90 std::string IpcMsgAdapter::GetCallingKey()
91 {
92     SHARING_LOGD("trace.");
93     return key_;
94 }
95 
SetPeerPid(int32_t pid)96 void IpcMsgAdapter::SetPeerPid(int32_t pid)
97 {
98     SHARING_LOGD("trace.");
99     peerPid_ = pid;
100 }
101 
GetPeerPid()102 int32_t IpcMsgAdapter::GetPeerPid()
103 {
104     SHARING_LOGD("trace.");
105     return peerPid_;
106 }
107 
108 } // namespace Sharing
109 } // namespace OHOS