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 #ifndef KV_STORE_SNAPSHOT_DELEGATE_IMPL_H
17 #define KV_STORE_SNAPSHOT_DELEGATE_IMPL_H
18 
19 #ifndef OMIT_MULTI_VER
20 #include "kv_store_delegate_impl.h"
21 
22 #include "ikvdb_snapshot.h"
23 
24 namespace DistributedDB {
25 class KvStoreSnapshotDelegateImpl final : public KvStoreSnapshotDelegate {
26 public:
27     KvStoreSnapshotDelegateImpl(IKvDBSnapshot *snapshot, KvStoreObserver *observer);
~KvStoreSnapshotDelegateImpl()28     ~KvStoreSnapshotDelegateImpl() override {};
29 
30     DISABLE_COPY_ASSIGN_MOVE(KvStoreSnapshotDelegateImpl);
31 
32     // Get a value from the snapshot with the given key.
33     // The return value is DBStatus and Value, these values will be passed to the callback.
34     void Get(const Key &key, const std::function<void(DBStatus, const Value &)> &callback) const override;
35 
36     // Get entries from the snapshot which keys start with keyPrefix.
37     // The return value is DBStatus and Entries, these values will be passed to the callback.
38     void GetEntries(const Key &keyPrefix,
39         const std::function<void(DBStatus, const std::vector<Entry> &)> &callback) const override;
40 
41     // Get the snapshot
42     void GetSnapshot(IKvDBSnapshot *&snapshot) const;
43 
44     // Get the observer
45     void GetObserver(KvStoreObserver *&observer) const;
46 
47 private:
48     IKvDBSnapshot * const snapShot_;
49     KvStoreObserver * const observer_;
50 };
51 } // namespace DistributedDB
52 
53 #endif // KV_STORE_SNAPSHOT_DELEGATE_IMPL_H
54 #endif