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 "domain_account_callback_proxy.h"
17
18 #include <securec.h>
19 #include "account_error_no.h"
20 #include "account_log_wrapper.h"
21
22 namespace OHOS {
23 namespace AccountSA {
DomainAccountCallbackProxy(const sptr<IRemoteObject> & object)24 DomainAccountCallbackProxy::DomainAccountCallbackProxy(const sptr<IRemoteObject> &object)
25 : IRemoteProxy<IDomainAccountCallback>(object)
26 {}
27
~DomainAccountCallbackProxy()28 DomainAccountCallbackProxy::~DomainAccountCallbackProxy()
29 {}
30
SendRequest(DomainAccountCallbackInterfaceCode code,MessageParcel & data)31 ErrCode DomainAccountCallbackProxy::SendRequest(DomainAccountCallbackInterfaceCode code, MessageParcel &data)
32 {
33 sptr<IRemoteObject> remote = Remote();
34 if (remote == nullptr) {
35 ACCOUNT_LOGE("remote is nullptr, code = %{public}d", code);
36 return ERR_ACCOUNT_COMMON_NULL_PTR_ERROR;
37 }
38 MessageParcel reply;
39 MessageOption option(MessageOption::TF_ASYNC);
40 return remote->SendRequest(static_cast<uint32_t>(code), data, reply, option);
41 }
42
OnResult(const int32_t errCode,Parcel & parcel)43 void DomainAccountCallbackProxy::OnResult(const int32_t errCode, Parcel &parcel)
44 {
45 MessageParcel data;
46 if (!data.WriteInterfaceToken(GetDescriptor())) {
47 ACCOUNT_LOGE("fail to write descriptor");
48 return;
49 }
50 if (!data.WriteInt32(errCode)) {
51 ACCOUNT_LOGE("failed to write errCode");
52 return;
53 }
54 uint32_t size = parcel.GetDataSize();
55 if (!data.WriteUint32(size)) {
56 ACCOUNT_LOGE("failed to write size");
57 return;
58 }
59 if (!data.WriteBuffer(reinterpret_cast<const uint8_t *>(parcel.GetData()), size)) {
60 ACCOUNT_LOGE("failed to write buffer");
61 return;
62 }
63 ErrCode result = SendRequest(DomainAccountCallbackInterfaceCode::DOMAIN_ACCOUNT_CALLBACK_ON_RESULT, data);
64 if (result != ERR_OK) {
65 ACCOUNT_LOGE("fail to send request, error code: %{public}d", result);
66 } else {
67 ACCOUNT_LOGI("SendRequest successfully.");
68 }
69 }
70 } // namespace AccountSA
71 } // namespace OHOS
72