• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
1 
2 /*
3  * Copyright (c) 2021 Huawei Device Co., Ltd.
4  * Licensed under the Apache License, Version 2.0 (the "License");
5  * you may not use this file except in compliance with the License.
6  * You may obtain a copy of the License at
7  *
8  *     http://www.apache.org/licenses/LICENSE-2.0
9  *
10  * Unless required by applicable law or agreed to in writing, software
11  * distributed under the License is distributed on an "AS IS" BASIS,
12  * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13  * See the License for the specific language governing permissions and
14  * limitations under the License.
15  */
16 
17 #ifndef I_SYNCER_H
18 #define I_SYNCER_H
19 
20 #include <functional>
21 #include <mutex>
22 #include <map>
23 
24 #include "distributeddb/result_set.h"
25 #include "isync_interface.h"
26 #include "types_export.h"
27 #include "query_sync_object.h"
28 #include "store_types.h"
29 
30 namespace DistributedDB {
31 struct SyncerBasicInfo {
32     bool isSyncActive = false;
33     bool isAutoSync = false;
34     bool isClearHistoryData = false;
35 };
36 class ISyncer {
37 public:
38     struct SyncParma {
39         std::vector<std::string> devices;
40         std::function<void(const std::map<std::string, int> &devicesMap)> onComplete;
41         SyncStatusCallback relationOnComplete;
42         std::function<void(void)> onFinalize;
43         int mode = 0;
44         bool wait = false;
45         bool isQuerySync = false;
46         QuerySyncObject syncQuery;
47     };
48 
~ISyncer()49     virtual ~ISyncer() {};
50 
51     // Init the Syncer modules
Initialize(ISyncInterface * syncInterface,bool isNeedActive)52     virtual int Initialize(ISyncInterface *syncInterface, bool isNeedActive)
53     {
54         return -E_NOT_SUPPORT;
55     }
56 
57     // Close
58     virtual int Close(bool isClosedOperation) = 0;
59 
60     // Sync function.
61     // param devices: The device id list.
62     // param mode: Sync mode, see SyncMode.
63     // param onComplete: The syncer finish callback. set by caller
64     // param onFinalize: will be callback when this Sync Operation finalized.
65     // return a Sync id. It will return a positive value if failed,
66     virtual int Sync(const std::vector<std::string> &devices, int mode,
67         const std::function<void(const std::map<std::string, int> &)> &onComplete,
68         const std::function<void(void)> &onFinalize, bool wait) = 0;
69 
70     // Sync function. use SyncParma to reduce parameter.
71     virtual int Sync(const SyncParma &param, uint64_t connectionId) = 0;
72 
73     // Remove the operation, with the given syncId, used to clean resource if sync finished or failed.
74     virtual int RemoveSyncOperation(int syncId) = 0;
75 
76     virtual int StopSync(uint64_t connectionId) = 0;
77 
78     // Get The current virtual timestamp
79     virtual uint64_t GetTimestamp() = 0;
80 
81     // Enable auto sync function
82     virtual void EnableAutoSync(bool enable) = 0;
83 
84     // delete specified device's watermark
85     virtual int EraseDeviceWaterMark(const std::string &deviceId, bool isNeedHash) = 0;
86 
87     // delete specified device's and table's watermark
88     virtual int EraseDeviceWaterMark(const std::string &deviceId, bool isNeedHash,
89         const std::string &tableName) = 0;
90 
91     // Local data changed callback
92     virtual void LocalDataChanged(int notifyEvent) = 0;
93 
94     // Get manual sync queue size
95     virtual int GetQueuedSyncSize(int *queuedSyncSize) const = 0;
96 
97     // Set manual sync queue limit
98     virtual int SetQueuedSyncLimit(const int *queuedSyncLimit) = 0;
99 
100     // Get manual sync queue limit
101     virtual int GetQueuedSyncLimit(int *queuedSyncLimit) const = 0;
102 
103     // Disable add new manual sync, for rekey
104     virtual int DisableManualSync(void) = 0;
105 
106     // Enable add new manual sync, for rekey
107     virtual int EnableManualSync(void) = 0;
108 
109     // Get local deviceId, is hashed
110     virtual int GetLocalIdentity(std::string &outTarget) const = 0;
111 
112     // Set stale data wipe policy
113     virtual int SetStaleDataWipePolicy(WipePolicy policy) = 0;
114 
115     // Set Manual Sync retry config
116     virtual int SetSyncRetry(bool isRetry) = 0;
117 
118     // Set an equal identifier for this database, After this called, send msg to the target will use this identifier
119     virtual int SetEqualIdentifier(const std::string &identifier, const std::vector<std::string> &targets) = 0;
120 
121     virtual void Dump(int fd) = 0;
122 
123     virtual SyncerBasicInfo DumpSyncerBasicInfo() = 0;
124 
125     virtual int RemoteQuery(const std::string &device, const RemoteCondition &condition,
126         uint64_t timeout, uint64_t connectionId, std::shared_ptr<ResultSet> &result) = 0;
127 
128     virtual int GetHashDeviceId(const std::string &clientId, std::string &hashDevId) = 0;
129 };
130 } // namespace DistributedDB
131 
132 #endif  // I_SYNCER_H
133