• 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 SYNC_ABLE_KVDB_CONNECTION_H
17 #define SYNC_ABLE_KVDB_CONNECTION_H
18 
19 #include "generic_kvdb_connection.h"
20 #include "intercepted_data.h"
21 #include "ref_object.h"
22 
23 namespace DistributedDB {
24 class SyncAbleKvDB;
25 struct PragmaSync;
26 struct PragmaRemotePushNotify;
27 struct PragmaSetEqualIdentifier;
28 
29 class SyncAbleKvDBConnection : public GenericKvDBConnection, public virtual RefObject {
30 public:
31     explicit SyncAbleKvDBConnection(SyncAbleKvDB *kvDB);
32     ~SyncAbleKvDBConnection() override;
33     DISABLE_COPY_ASSIGN_MOVE(SyncAbleKvDBConnection);
34 
35     // Pragma interface.
36     int Pragma(int cmd, void *parameter) override;
37 
38 protected:
39     int DisableManualSync();
40 
41     int EnableManualSync();
42 
43 private:
44     // Do pragma-sync action.
45     int PragmaParamCheck(int cmd, const void *parameter);
46     int PragmaSyncAction(const PragmaSync *syncParameter);
47     void InitPragmaFunc();
48 
49     // If enable is true, it will enable auto sync
50     int EnableAutoSync(bool enable);
51 
52     void OnSyncComplete(const std::map<std::string, int> &statuses,
53         const std::function<void(const std::map<std::string, int> &devicesMap)> &onComplete, bool wait);
54 
55     int GetQueuedSyncSize(int *queuedSyncSize) const;
56 
57     int SetQueuedSyncLimit(const int *queuedSyncLimit);
58 
59     int GetQueuedSyncLimit(int *queuedSyncLimit) const;
60 
61     int SetStaleDataWipePolicy(const WipePolicy *policy);
62 
63     int SetRemotePushFinishedNotify(PragmaRemotePushNotify *notifyParma);
64 
65     int SetSyncRetry(bool isRetry);
66     // Set an equal identifier for this database, After this called, send msg to the target will use this identifier
67     int SetEqualIdentifier(const PragmaSetEqualIdentifier *param);
68 
69     int SetPushDataInterceptor(const PushDataInterceptor &interceptor);
70 
71     std::mutex remotePushFinishedListenerLock_;
72     NotificationChain::Listener *remotePushFinishedListener_;
73     std::map<int, std::function<void(void *, int &errCode)>> pragmaFunc_{};
74 };
75 }
76 #endif // SYNC_ABLE_KVDB_CONNECTION_H
77