1 /*
2  * Copyright (c) 2023 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 "form_host_delegate_proxy.h"
17 
18 #include "appexecfwk_errors.h"
19 #include "fms_log_wrapper.h"
20 #include "form_mgr_errors.h"
21 #include "ipc_types.h"
22 
23 namespace OHOS {
24 namespace AppExecFwk {
RouterEvent(const int64_t formId,const Want & want)25 int32_t FormHostDelegateProxy::RouterEvent(const int64_t formId, const Want &want)
26 {
27     MessageParcel data;
28     if (!WriteInterfaceToken(data)) {
29         HILOG_ERROR("Write to interface token error");
30         return ERR_APPEXECFWK_PARCEL_ERROR;
31     }
32     if (!data.WriteInt64(formId)) {
33         HILOG_ERROR("Write to formId error");
34         return ERR_APPEXECFWK_PARCEL_ERROR;
35     }
36     if (!data.WriteParcelable(&want)) {
37         HILOG_ERROR("Write to want error");
38         return ERR_APPEXECFWK_PARCEL_ERROR;
39     }
40 
41     MessageParcel reply;
42     MessageOption option;
43     int error = Remote()->SendRequest(static_cast<uint32_t>(IFormHostDelegate::Message::FORM_ROUTER_PROXY_MGR),
44         data, reply, option);
45     if (error != ERR_OK) {
46         HILOG_ERROR("SendRequest:%{public}d failed", error);
47         return ERR_APPEXECFWK_FORM_SEND_FMS_MSG;
48     }
49     return reply.ReadInt32();
50 }
51 
WriteInterfaceToken(MessageParcel & data)52 bool FormHostDelegateProxy::WriteInterfaceToken(MessageParcel &data)
53 {
54     if (!data.WriteInterfaceToken(FormHostDelegateProxy::GetDescriptor())) {
55         HILOG_ERROR("write interface token failed");
56         return false;
57     }
58     return true;
59 }
60 } // namespace AppExecFwk
61 } // namespace OHOS
62