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 int GetSyncDataSize(const std::string &device, size_t &size) const override; 39 40 protected: 41 int DisableManualSync(); 42 43 int EnableManualSync(); 44 45 private: 46 // Do pragma-sync action. 47 int PragmaParamCheck(int cmd, const void *parameter); 48 int PragmaSyncAction(const PragmaSync *syncParameter); 49 void InitPragmaFunc(); 50 51 // If enable is true, it will enable auto sync 52 int EnableAutoSync(bool enable); 53 54 void OnSyncComplete(const std::map<std::string, int> &statuses, 55 const std::function<void(const std::map<std::string, int> &devicesMap)> &onComplete, bool wait); 56 57 int GetQueuedSyncSize(int *queuedSyncSize) const; 58 59 int SetQueuedSyncLimit(const int *queuedSyncLimit); 60 61 int GetQueuedSyncLimit(int *queuedSyncLimit) const; 62 63 int SetStaleDataWipePolicy(const WipePolicy *policy); 64 65 int SetRemotePushFinishedNotify(PragmaRemotePushNotify *notifyParma); 66 67 int SetSyncRetry(bool isRetry); 68 // Set an equal identifier for this database, After this called, send msg to the target will use this identifier 69 int SetEqualIdentifier(const PragmaSetEqualIdentifier *param); 70 71 int SetPushDataInterceptor(const PushDataInterceptor &interceptor); 72 73 std::mutex remotePushFinishedListenerLock_; 74 NotificationChain::Listener *remotePushFinishedListener_; 75 std::map<int, std::function<void(void *, int &errCode)>> pragmaFunc_{}; 76 }; 77 } 78 #endif // SYNC_ABLE_KVDB_CONNECTION_H 79