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