1 /* 2 * Copyright (c) 2021 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 "kv_store_changed_data_impl.h" 17 18 namespace DistributedDB { ~KvStoreChangedDataImpl()19KvStoreChangedDataImpl::~KvStoreChangedDataImpl() 20 { 21 observerData_ = nullptr; 22 } 23 GetEntriesInserted() const24const std::list<Entry> &KvStoreChangedDataImpl::GetEntriesInserted() const 25 { 26 std::lock_guard<std::mutex> lock(mutex_); 27 if (insertedEntries_.empty() && observerData_ != nullptr) { 28 int errCode; 29 insertedEntries_ = observerData_->GetInsertedEntries(errCode); 30 } 31 32 return insertedEntries_; 33 } 34 GetEntriesUpdated() const35const std::list<Entry> &KvStoreChangedDataImpl::GetEntriesUpdated() const 36 { 37 std::lock_guard<std::mutex> lock(mutex_); 38 if (updatedEntries_.empty() && observerData_ != nullptr) { 39 int errCode; 40 updatedEntries_ = observerData_->GetUpdatedEntries(errCode); 41 } 42 43 return updatedEntries_; 44 } 45 GetEntriesDeleted() const46const std::list<Entry> &KvStoreChangedDataImpl::GetEntriesDeleted() const 47 { 48 std::lock_guard<std::mutex> lock(mutex_); 49 if (deletedEntries_.empty() && observerData_ != nullptr) { 50 int errCode; 51 deletedEntries_ = observerData_->GetDeletedEntries(errCode); 52 } 53 54 return deletedEntries_; 55 } 56 IsCleared() const57bool KvStoreChangedDataImpl::IsCleared() const 58 { 59 if (observerData_ != nullptr) { 60 return observerData_->IsCleared(); 61 } 62 63 return false; 64 } 65 } // namespace DistributedDB 66 67