• 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 I_SYNC_ENGINE_H
17 #define I_SYNC_ENGINE_H
18 
19 #include <map>
20 #include <mutex>
21 
22 #include "ikvdb_sync_interface.h"
23 #include "meta_data.h"
24 #include "ref_object.h"
25 #include "sync_operation.h"
26 
27 namespace DistributedDB {
28 class ISyncEngine : public virtual RefObject {
29 public:
30     // Do some init things
31     virtual int Initialize(ISyncInterface *syncInterface, std::shared_ptr<Metadata> &metadata,
32         const std::function<void(std::string)> &onRemoteDataChanged,
33         const std::function<void(std::string)> &offlineChanged,
34         const std::function<void(const InternalSyncParma &param)> &queryAutoSyncCallback) = 0;
35 
36     // Do some things, when db close.
37     virtual int Close() = 0;
38 
39     // Alloc and Add sync SyncTarget
40     // return E_OK if operator success.
41     virtual int AddSyncOperation(SyncOperation *operation) = 0;
42 
43     // Clear the SyncTarget matched the syncId.
44     virtual void RemoveSyncOperation(int syncId) = 0;
45 
46     // notify other devices data has changed
47     virtual void BroadCastDataChanged() const = 0;
48 
49     // Get Online devices
50     virtual void GetOnlineDevices(std::vector<std::string> &devices) const = 0;
51 
52     // Register the device connect callback, this function must be called after Engine initted
53     virtual void RegConnectCallback() = 0;
54 
55     // Get the database identifier
56     virtual std::string GetLabel() const = 0;
57 
58     // Set Manual Sync retry config
59     virtual void SetSyncRetry(bool isRetry) = 0;
60 
61     // Set an equal identifier for this database, After this called, send msg to the target will use this identifier
62     virtual int SetEqualIdentifier(const std::string &identifier, const std::vector<std::string> &targets) = 0;
63 
64     // Set record device equal identifier when called in import/rekey scene when restart syncer
65     virtual void SetEqualIdentifier() = 0;
66 
67     virtual void SetEqualIdentifierMap(const std::string &identifier, const std::vector<std::string> &targets) = 0;
68 
69     // Add auto subscribe timer when start sync engine, used for auto subscribe failed subscribe task when db online
70     virtual int StartAutoSubscribeTimer() = 0;
71 
72     // Stop auto subscribe timer when start sync engine
73     virtual void StopAutoSubscribeTimer() = 0;
74 
75     // Check if number of subscriptions out of limit
76     virtual int SubscribeLimitCheck(const std::vector<std::string> &devices, QuerySyncObject &query) const = 0;
77 
78     // Check if the Sync Engine is active, some times synchronization is not allowed
79     virtual bool IsEngineActive() const = 0;
80 
81     virtual void SchemaChange() = 0;
82 
83     virtual void Dump(int fd) = 0;
84 
85     virtual int RemoteQuery(const std::string &device, const RemoteCondition &condition,
86         uint64_t timeout, uint64_t connectionId, std::shared_ptr<ResultSet> &result) = 0;
87 
88     virtual void NotifyConnectionClosed(uint64_t connectionId) = 0;
89 
90     virtual void NotifyUserChange() = 0;
91 
92     virtual void AbortMachineIfNeed(uint32_t syncId) = 0;
93 
94 protected:
~ISyncEngine()95     virtual ~ISyncEngine() {};
96 };
97 } // namespace DistributedDB
98 
99 #endif // I_SYNC_ENGINE_H