• 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 "quick_fix_status_callback_proxy.h"
17 
18 #include "app_log_tag_wrapper.h"
19 #include "app_log_wrapper.h"
20 #include "appexecfwk_errors.h"
21 #include "ipc_types.h"
22 #include "parcel.h"
23 #include "parcel_macro.h"
24 #include "quick_fix_status_callback_interface.h"
25 
26 namespace OHOS {
27 namespace AppExecFwk {
QuickFixStatusCallbackProxy(const sptr<IRemoteObject> & object)28 QuickFixStatusCallbackProxy::QuickFixStatusCallbackProxy(const sptr<IRemoteObject> &object)
29     : IRemoteProxy<IQuickFixStatusCallback>(object)
30 {
31     LOG_I(BMS_TAG_DEFAULT, "create QuickFixStatusCallbackProxy");
32 }
33 
~QuickFixStatusCallbackProxy()34 QuickFixStatusCallbackProxy::~QuickFixStatusCallbackProxy()
35 {
36     LOG_I(BMS_TAG_DEFAULT, "destroy QuickFixStatusCallbackProxy");
37 }
38 
OnPatchDeployed(const std::shared_ptr<QuickFixResult> & result)39 void QuickFixStatusCallbackProxy::OnPatchDeployed(const std::shared_ptr<QuickFixResult> &result)
40 {
41     MessageParcel data;
42     MessageParcel reply;
43     WRITE_PARCEL_AND_RETURN(InterfaceToken, data, QuickFixStatusCallbackProxy::GetDescriptor());
44     WRITE_PARCEL_AND_RETURN(Parcelable, data, result.get());
45     if (!SendTransactCmd(QuickFixStatusCallbackInterfaceCode::ON_PATCH_DEPLOYED, data, reply)) {
46         LOG_E(BMS_TAG_DEFAULT, "fail to OnPatchDeployed due to transact command fail");
47     }
48 }
49 
OnPatchSwitched(const std::shared_ptr<QuickFixResult> & result)50 void QuickFixStatusCallbackProxy::OnPatchSwitched(const std::shared_ptr<QuickFixResult> &result)
51 {
52     MessageParcel data;
53     MessageParcel reply;
54     WRITE_PARCEL_AND_RETURN(InterfaceToken, data, QuickFixStatusCallbackProxy::GetDescriptor());
55     WRITE_PARCEL_AND_RETURN(Parcelable, data, result.get());
56     if (!SendTransactCmd(QuickFixStatusCallbackInterfaceCode::ON_PATCH_SWITCHED, data, reply)) {
57         LOG_E(BMS_TAG_DEFAULT, "fail to OnPatchSwitched due to transact command fail");
58     }
59 }
60 
OnPatchDeleted(const std::shared_ptr<QuickFixResult> & result)61 void QuickFixStatusCallbackProxy::OnPatchDeleted(const std::shared_ptr<QuickFixResult> &result)
62 {
63     MessageParcel data;
64     MessageParcel reply;
65     WRITE_PARCEL_AND_RETURN(InterfaceToken, data, QuickFixStatusCallbackProxy::GetDescriptor());
66     WRITE_PARCEL_AND_RETURN(Parcelable, data, result.get());
67     if (!SendTransactCmd(QuickFixStatusCallbackInterfaceCode::ON_PATCH_DELETED, data, reply)) {
68         LOG_E(BMS_TAG_DEFAULT, "fail to OnPatchDeleted due to transact command fail");
69     }
70 }
71 
SendTransactCmd(QuickFixStatusCallbackInterfaceCode code,MessageParcel & data,MessageParcel & reply)72 bool QuickFixStatusCallbackProxy::SendTransactCmd(
73     QuickFixStatusCallbackInterfaceCode code, MessageParcel &data, MessageParcel &reply)
74 {
75     MessageOption option(MessageOption::TF_SYNC);
76 
77     sptr<IRemoteObject> remote = Remote();
78     if (remote == nullptr) {
79         LOG_E(BMS_TAG_DEFAULT, "fail to send transact cmd %{public}hhd due to remote object", code);
80         return false;
81     }
82     int32_t result = remote->SendRequest(static_cast<uint32_t>(code), data, reply, option);
83     if (result != NO_ERROR) {
84         LOG_E(BMS_TAG_DEFAULT, "receive error transact code %{public}d in transact cmd %{public}hhd", result, code);
85         return false;
86     }
87     return true;
88 }
89 } // AppExecFwk
90 } // OHOS
91