1 /*
2 * Copyright (c) 2021-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 "want_sender_proxy.h"
17
18 #include "hilog_tag_wrapper.h"
19
20 namespace OHOS {
21 namespace AAFwk {
WriteInterfaceToken(MessageParcel & data)22 bool WantSenderProxy::WriteInterfaceToken(MessageParcel &data)
23 {
24 if (!data.WriteInterfaceToken(WantSenderProxy::GetDescriptor())) {
25 TAG_LOGE(AAFwkTag::WANTAGENT, "write interface token failed");
26 return false;
27 }
28 return true;
29 }
30
Send(SenderInfo & senderInfo)31 void WantSenderProxy::Send(SenderInfo &senderInfo)
32 {
33 MessageParcel data;
34 MessageParcel reply;
35 MessageOption option(MessageOption::TF_SYNC);
36 if (!WriteInterfaceToken(data)) {
37 return;
38 }
39 if (!data.WriteParcelable(&senderInfo)) {
40 TAG_LOGE(AAFwkTag::WANTAGENT, "fail to WriteParcelable value");
41 return;
42 }
43 sptr<IRemoteObject> remote = Remote();
44 if (remote == nullptr) {
45 TAG_LOGE(AAFwkTag::WANTAGENT, "remote is NULL");
46 return;
47 }
48 int32_t ret = remote->SendRequest(static_cast<uint32_t>(IWantSender::WANT_SENDER_SEND), data, reply, option);
49 if (ret != NO_ERROR) {
50 TAG_LOGE(AAFwkTag::WANTAGENT, "error code: %{public}d", ret);
51 }
52 }
53 } // namespace AAFwk
54 } // namespace OHOS
55