• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
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 SINGLE_VER_SYNC_ENGINE_H
17 #define SINGLE_VER_SYNC_ENGINE_H
18 
19 #include "sync_engine.h"
20 
21 namespace DistributedDB {
22 class SingleVerSyncEngine final : public SyncEngine {
23 public:
SingleVerSyncEngine()24     SingleVerSyncEngine() : needClearRemoteStaleData_(false) {};
25 
26     // If set true, remote stale data will be clear when remote db rebuilt.
27     void EnableClearRemoteStaleData(bool enable);
28 
29     // used by SingleVerKVSyncer when db online
30     int StartAutoSubscribeTimer() override;
31 
32     // used by SingleVerKVSyncer when remote/local db closed
33     void StopAutoSubscribeTimer() override;
34 
35     int SubscribeTimeOut(TimerId id);
36 
37     void SetIsNeedResetAbilitySync(const std::string &deviceId, bool isNeedReset);
38 
39     DISABLE_COPY_ASSIGN_MOVE(SingleVerSyncEngine);
40 protected:
~SingleVerSyncEngine()41     ~SingleVerSyncEngine() override {};
42 
43     // Create a context
44     ISyncTaskContext *CreateSyncTaskContext() override;
45 
46 private:
47     DECLARE_OBJECT_TAG(SingleVerSyncEngine);
48 #ifndef RUNNING_ON_TESTCASE
49     static constexpr int SUBSCRIBE_TRIGGER_TIME_OUT = 30 * 60 * 1000; // 30min
50 #else
51     static constexpr int SUBSCRIBE_TRIGGER_TIME_OUT = 5 * 60 * 1000; // 5min for test
52 #endif
53 
54     bool needClearRemoteStaleData_;
55 
56     // for subscribe timeout callback
57     std::mutex timerLock_;
58     TimerId subscribeTimerId_ = 0;
59 };
60 } // namespace DistributedDB
61 
62 #endif // SINGLE_VER_SYNC_ENGINE_H