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_SYNCER_H
17 #define KV_SYNCER_H
18 
19 #include "single_ver_syncer.h"
20 
21 namespace DistributedDB {
22 class SingleVerKVSyncer : public SingleVerSyncer {
23 public:
24     SingleVerKVSyncer();
25     ~SingleVerKVSyncer() override;
26 
27     // Enable auto sync function
28     void EnableAutoSync(bool enable) override;
29 
30     // Local data changed callback
31     void LocalDataChanged(int notifyEvent) override;
32 
33     // Remote data changed callback
34     void RemoteDataChanged(const std::string &device) override;
35 
36     void TriggerSubscribe(const std::string &device, const QuerySyncObject &query);
37 
38     SyncerBasicInfo DumpSyncerBasicInfo() override;
39 
40 protected:
41     int SyncConditionCheck(const SyncParma &param, const ISyncEngine *engine, ISyncInterface *storage) const override;
42 
43     // Init the Sync engine
44     int InitSyncEngine(ISyncInterface *syncInterface) override;
45 
46     void TriggerAddSubscribeAsync(ISyncInterface *syncInterface);
47 private:
48     // if trigger full sync, no need to trigger query sync again
49     bool TryFullSync(const std::vector<std::string> &devices);
50 
51     void TriggerSubQuerySync(const std::vector<std::string> &devices);
52 
53     bool autoSyncEnable_;
54     std::atomic<bool> triggerSyncTask_;
55 };
56 } // namespace DistributedDB
57 
58 #endif  // KV_SYNCER_H
59