1 /*
2 * Copyright (c) 2025 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 #define LOG_TAG "CloudNotifierStub"
16
17 #include "cloud_notifier_stub.h"
18
19 #include <ipc_skeleton.h>
20
21 #include "cloud_service.h"
22 #include "itypes_util.h"
23 #include "logger.h"
24
25 namespace OHOS::CloudData {
26 using namespace Rdb;
CloudNotifierStub(const SyncCompleteHandler & completeNotifier)27 CloudNotifierStub::CloudNotifierStub(const SyncCompleteHandler &completeNotifier)
28 : IRemoteStub<CloudNotifierStubBroker>(), completeNotifier_(completeNotifier)
29 {
30 }
31
~CloudNotifierStub()32 CloudNotifierStub::~CloudNotifierStub() noexcept
33 {
34 }
35
CheckInterfaceToken(MessageParcel & data)36 bool CloudNotifierStub::CheckInterfaceToken(MessageParcel &data)
37 {
38 auto localDescriptor = GetDescriptor();
39 auto remoteDescriptor = data.ReadInterfaceToken();
40 if (remoteDescriptor != localDescriptor) {
41 LOG_ERROR("interface token is not equal.");
42 return false;
43 }
44 return true;
45 }
46
OnRemoteRequest(uint32_t code,MessageParcel & data,MessageParcel & reply,MessageOption & option)47 int CloudNotifierStub::OnRemoteRequest(uint32_t code, MessageParcel &data, MessageParcel &reply, MessageOption &option)
48 {
49 LOG_DEBUG("code:%{public}u, callingPid:%{public}d", code, IPCSkeleton::GetCallingPid());
50 if (!CheckInterfaceToken(data)) {
51 return CloudService::ERROR;
52 }
53
54 if (code < static_cast<uint32_t>(NotifierCode::CLOUD_NOTIFIER_CMD_MAX)) {
55 return (this->*HANDLES[code])(data, reply);
56 }
57
58 return IPCObjectStub::OnRemoteRequest(code, data, reply, option);
59 }
60
OnCompleteInner(MessageParcel & data,MessageParcel & reply)61 int32_t CloudNotifierStub::OnCompleteInner(MessageParcel &data, MessageParcel &reply)
62 {
63 uint32_t seqNum = 0;
64 Details result;
65 if (!ITypesUtil::Unmarshal(data, seqNum, result)) {
66 LOG_ERROR("read sync result failed.");
67 return CloudService::ERROR;
68 }
69 return OnComplete(seqNum, std::move(result));
70 }
71
OnComplete(uint32_t seqNum,Details && result)72 int32_t CloudNotifierStub::OnComplete(uint32_t seqNum, Details &&result)
73 {
74 if (completeNotifier_) {
75 completeNotifier_(seqNum, std::move(result));
76 }
77 return CloudService::SUCCESS;
78 }
79 } // namespace OHOS::CloudData
80