• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
1 /*
2  * Copyright (c) 2024 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 "ui_extension/host_data_handler.h"
17 
18 #include "window_manager_hilog.h"
19 
20 namespace OHOS::Rosen::Extension {
GetRemoteProxy()21 sptr<ISessionStage> HostDataHandler::GetRemoteProxy()
22 {
23     std::lock_guard lock(mutex_);
24     if (remoteProxy_ == nullptr) {
25         return nullptr;
26     }
27     return iface_cast<ISessionStage>(remoteProxy_);
28 }
29 
SendData(const AAFwk::Want & toSend,AAFwk::Want & reply,const DataTransferConfig & config)30 DataHandlerErr HostDataHandler::SendData(const AAFwk::Want& toSend, AAFwk::Want& reply,
31                                          const DataTransferConfig& config)
32 {
33     auto proxy = GetRemoteProxy();
34     if (proxy == nullptr) {
35         TLOGE(WmsLogTag::WMS_UIEXT, "nullptr, %{public}s", config.ToString().c_str());
36         return DataHandlerErr::NULL_PTR;
37     }
38 
39     MessageParcel sendParcel;
40     MessageOption option(config.needSyncSend ? MessageOption::TF_SYNC : MessageOption::TF_ASYNC);
41     auto err = PrepareSendData(sendParcel, config, toSend);
42     if (err != DataHandlerErr::OK) {
43         return err;
44     }
45 
46     MessageParcel replyParcel;
47     auto ret = proxy->SendExtensionData(sendParcel, replyParcel, option);
48     if (ret != WSError::WS_OK) {
49         TLOGE(WmsLogTag::WMS_UIEXT, "SendExtensionData failed, %{public}s", config.ToString().c_str());
50         return DataHandlerErr::IPC_SEND_FAILED;
51     }
52 
53     return ParseReply(replyParcel, reply, config);
54 }
55 
WriteInterfaceToken(MessageParcel & data)56 bool HostDataHandler::WriteInterfaceToken(MessageParcel& data)
57 {
58     return data.WriteInterfaceToken(ISessionStage::GetDescriptor());
59 }
60 
61 }  // namespace OHOS::Rosen::Extension
62