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_VIRTUAL_DEVICE_H
17 #define KV_VIRTUAL_DEVICE_H
18 
19 #include "generic_virtual_device.h"
20 
21 #include "virtual_single_ver_sync_db_Interface.h"
22 namespace DistributedDB {
23 class KvVirtualDevice final : public GenericVirtualDevice {
24 public:
25     explicit KvVirtualDevice(const std::string &deviceId);
26     ~KvVirtualDevice() override;
27 
28     int GetData(const Key &key, VirtualDataItem &item);
29     int GetData(const Key &key, Value &value);
30     int PutData(const Key &key, const Value &value, const Timestamp &time, int flag);
31     int PutData(const Key &key, const Value &value);
32     int DeleteData(const Key &key);
33     int StartTransaction();
34     int Commit();
35     void SetSaveDataDelayTime(uint64_t milliDelayTime);
36     void DelayGetSyncData(uint64_t milliDelayTime);
37     void SetGetDataErrCode(int whichTime, int errCode, bool isGetDataControl);
38     void ResetDataControl();
39 
40     int Subscribe(QuerySyncObject query, bool wait, int id);
41     int UnSubscribe(QuerySyncObject query, bool wait, int id);
42     int UnSubscribe(const QuerySyncObject &query, bool wait, int id, const SyncOperation::UserCallback &callback);
43 
44     void SetSaveDataCallback(const std::function<void()> &callback);
45     void EraseWaterMark(const std::string &dev);
46 
47     void SetPushNotifier(const std::function<void(const std::string &)> &pushNotifier);
48 };
49 } // namespace DistributedDB
50 
51 #endif  // KV_VIRTUAL_DEVICE_H
52