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 "cloud/sync_event.h"
17
18 namespace OHOS::DistributedData {
EventInfo(int32_t mode,int32_t wait,bool retry,std::shared_ptr<GenQuery> query,GenAsync async)19 SyncEvent::EventInfo::EventInfo(int32_t mode, int32_t wait, bool retry, std::shared_ptr<GenQuery> query, GenAsync async)
20 : retry_(retry), mode_(mode), wait_(wait), query_(std::move(query)), asyncDetail_(std::move(async))
21 {
22 }
23
EventInfo(const SyncParam & syncParam,bool retry,std::shared_ptr<GenQuery> query,GenAsync async)24 SyncEvent::EventInfo::EventInfo(const SyncParam &syncParam, bool retry, std::shared_ptr<GenQuery> query, GenAsync async)
25 : retry_(retry), mode_(syncParam.mode), wait_(syncParam.wait), query_(std::move(query)),
26 asyncDetail_(std::move(async)), isCompensation_(syncParam.isCompensation), triggerMode_(syncParam.triggerMode),
27 prepareTraceId_(syncParam.prepareTraceId), user_(syncParam.user)
28 {
29 }
30
EventInfo(SyncEvent::EventInfo && info)31 SyncEvent::EventInfo::EventInfo(SyncEvent::EventInfo &&info) noexcept
32 {
33 operator=(std::move(info));
34 }
35
operator =(SyncEvent::EventInfo && info)36 SyncEvent::EventInfo &SyncEvent::EventInfo::operator=(SyncEvent::EventInfo &&info) noexcept
37 {
38 if (this == &info) {
39 return *this;
40 }
41 retry_ = info.retry_;
42 mode_ = info.mode_;
43 wait_ = info.wait_;
44 query_ = std::move(info.query_);
45 asyncDetail_ = std::move(info.asyncDetail_);
46 isCompensation_ = info.isCompensation_;
47 triggerMode_ = info.triggerMode_;
48 prepareTraceId_ = info.prepareTraceId_;
49 user_ = info.user_;
50 return *this;
51 }
52
SyncEvent(StoreInfo storeInfo,EventInfo info)53 SyncEvent::SyncEvent(StoreInfo storeInfo, EventInfo info)
54 : CloudEvent(CLOUD_SYNC, std::move(storeInfo)), info_(std::move(info))
55 {
56 }
57
SyncEvent(int32_t evtId,StoreInfo storeInfo,EventInfo info)58 SyncEvent::SyncEvent(int32_t evtId, StoreInfo storeInfo, EventInfo info)
59 : CloudEvent(evtId, std::move(storeInfo)), info_(std::move(info))
60 {
61 }
62
GetMode() const63 int32_t SyncEvent::GetMode() const
64 {
65 return info_.mode_;
66 }
67
GetWait() const68 int32_t SyncEvent::GetWait() const
69 {
70 return info_.wait_;
71 }
72
AutoRetry() const73 bool SyncEvent::AutoRetry() const
74 {
75 return info_.retry_;
76 }
77
GetQuery() const78 std::shared_ptr<GenQuery> SyncEvent::GetQuery() const
79 {
80 return info_.query_;
81 }
82
GetAsyncDetail() const83 GenAsync SyncEvent::GetAsyncDetail() const
84 {
85 return info_.asyncDetail_;
86 }
87
IsCompensation() const88 bool SyncEvent::IsCompensation() const
89 {
90 return info_.isCompensation_;
91 }
92
GetTriggerMode() const93 int32_t SyncEvent::GetTriggerMode() const
94 {
95 return info_.triggerMode_;
96 }
97
GetPrepareTraceId() const98 std::string SyncEvent::GetPrepareTraceId() const
99 {
100 return info_.prepareTraceId_;
101 }
102
GetUser() const103 int32_t SyncEvent::GetUser() const
104 {
105 return info_.user_;
106 }
107 } // namespace OHOS::DistributedData