1 /* 2 * Copyright (c) 2023 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 PROCESS_NOTIFIER_H 17 #define PROCESS_NOTIFIER_H 18 #include "icloud_syncer.h" 19 namespace DistributedDB { 20 class ProcessNotifier { 21 public: 22 explicit ProcessNotifier(ICloudSyncer *syncer); 23 ~ProcessNotifier(); 24 25 void Init(const std::vector<std::string> &tableName, const std::vector<std::string> &devices, 26 const std::vector<std::string> &users); 27 28 void UpdateProcess(const ICloudSyncer::InnerProcessInfo &process); 29 30 void NotifyProcess(const ICloudSyncer::CloudTaskInfo &taskInfo, const ICloudSyncer::InnerProcessInfo &process, 31 bool notifyWhenError = false); 32 33 std::vector<std::string> GetDevices() const; 34 35 uint32_t GetUploadBatchIndex(const std::string &tableName) const; 36 37 void ResetUploadBatchIndex(const std::string &tableName); 38 39 void UpdateUploadRetryInfo(const ICloudSyncer::InnerProcessInfo &process); 40 41 void GetLastUploadInfo(const std::string &tableName, Info &lastUploadInfo, 42 ICloudSyncer::UploadRetryInfo &retryInfo) const; 43 44 void GetDownloadInfoByTableName(ICloudSyncer::InnerProcessInfo &process); 45 46 void SetUser(const std::string &user); 47 48 void SetAllTableFinish(); 49 50 void UpdateAllTablesFinally(); 51 52 std::map<std::string, TableProcessInfo> GetCurrentTableProcess() const; 53 protected: 54 mutable std::mutex processMutex_; 55 SyncProcess syncProcess_; 56 std::map<std::string, SyncProcess> multiSyncProcess_; 57 std::vector<std::string> devices_; 58 ICloudSyncer *syncer_; 59 std::string user_; 60 std::map<std::string, uint32_t> processRetryInfo_; 61 private: 62 static void InitSyncProcess(const std::vector<std::string> &tableName, SyncProcess &syncProcess); 63 bool IsMultiUser() const; 64 65 /* update success count of previous upload batch after download retry. */ 66 void UpdateUploadInfoIfNeeded(const ICloudSyncer::InnerProcessInfo &process); 67 68 void UpdateTableInfoFinally(std::map<std::string, TableProcessInfo> &processInfo); 69 }; 70 } 71 #endif // PROCESS_NOTIFIER_H 72