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 I_KV_DB_H
17 #define I_KV_DB_H
18 
19 #include <functional>
20 #include <string>
21 
22 #include "ref_object.h"
23 #include "macro_utils.h"
24 #include "kvdb_properties.h"
25 #include "ikvdb_connection.h"
26 
27 namespace DistributedDB {
28 class IKvDB : public virtual RefObject {
29 public:
30     IKvDB() = default;
~IKvDB()31     ~IKvDB() override {}
32     DISABLE_COPY_ASSIGN_MOVE(IKvDB);
33 
34     // Open the database.
35     virtual int Open(const KvDBProperties &kvDBProp) = 0;
36 
37     // Get the properties object of this database.
38     virtual const KvDBProperties &GetMyProperties() const = 0;
39 
40     // Create a db connection.
41     virtual IKvDBConnection *GetDBConnection(int &errCode) = 0;
42 
43     // Register callback invoked when all connections released.
44     virtual void OnClose(const std::function<void(void)> &func) = 0;
45 
46     virtual void WakeUpSyncer() = 0;
47 
48     virtual void SetCorruptHandler(const DatabaseCorruptHandler &handler) = 0;
49 
50     virtual int RemoveKvDB(const KvDBProperties &properties) = 0;
51     virtual int GetKvDBSize(const KvDBProperties &properties, uint64_t &size) const = 0;
52 
53     virtual void EnableAutonomicUpgrade() = 0;
54 
55     virtual int CheckIntegrity() const = 0;
56 
57     virtual std::string GetStorePath() const = 0;
58 
59     virtual void Dump(int fd) = 0;
60 
61     virtual void MarkRebuild() = 0;
62 };
63 } // namespace DistributedDB
64 
65 #endif // I_KV_DB_H
66