• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
1 /*
2  * Copyright (c) 2022 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 "dialog_callback_proxy.h"
17 #include "hilog_wrapper.h"
18 #include "message_parcel.h"
19 
20 namespace OHOS {
21 namespace Ace {
DialogCallbackProxy(const sptr<IRemoteObject> & remote)22 DialogCallbackProxy::DialogCallbackProxy(const sptr<IRemoteObject> &remote)
23     : IRemoteProxy<IDialogCallback>(remote)
24 {}
~DialogCallbackProxy()25 DialogCallbackProxy::~DialogCallbackProxy()
26 {}
27 
OnDialogCallback(int32_t id,const std::string & event,const std::string & params)28 void DialogCallbackProxy::OnDialogCallback(int32_t id, const std::string& event, const std::string& params)
29 {
30     auto remote = Remote();
31     if (remote == nullptr) {
32         HILOG_ERROR("%{public}s remote is nullptr", __func__);
33         return;
34     }
35 
36     OHOS::MessageParcel dataParcel;
37     OHOS::MessageParcel reply;
38     OHOS::MessageOption option;
39 
40     if (!dataParcel.WriteInterfaceToken(DialogCallbackProxy::GetDescriptor())) {
41         HILOG_ERROR("%{public}s dataParcel.WriteInterfaceToken(GetDescriptor()) return false", __func__);
42         return;
43     }
44     if (!dataParcel.WriteInt32(id)) {
45         HILOG_ERROR("fail to WriteInt32 id");
46         return;
47     }
48     if (!dataParcel.WriteString(event)) {
49         HILOG_ERROR("fail to WriteString event");
50         return;
51     }
52     if (!dataParcel.WriteString(params)) {
53         HILOG_ERROR("fail to WriteString params");
54         return;
55     }
56     int result = remote->SendRequest(IDialogCallback::UI_SERVICE_DIALOG_CALLBACK, dataParcel, reply, option);
57     if (result == ERR_NONE) {
58         HILOG_INFO("%{public}s SendRequest ok, retval is %{public}d", __func__, reply.ReadInt32());
59         return;
60     } else {
61         HILOG_ERROR("%{public}s SendRequest error, result=%{public}d", __func__, result);
62         return;
63     }
64 }
65 }  // namespace Ace
66 }  // namespace OHOS
67