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 uint32_t GetLastUploadSuccessCount(const std::string &tableName) const; 40 41 void GetDownloadInfoByTableName(ICloudSyncer::InnerProcessInfo &process); 42 43 void SetUser(const std::string &user); 44 45 void SetAllTableFinish(); 46 47 std::map<std::string, TableProcessInfo> GetCurrentTableProcess() const; 48 protected: 49 mutable std::mutex processMutex_; 50 SyncProcess syncProcess_; 51 std::map<std::string, SyncProcess> multiSyncProcess_; 52 std::vector<std::string> devices_; 53 ICloudSyncer *syncer_; 54 std::string user_; 55 private: 56 void InitSyncProcess(const std::vector<std::string> &tableName, SyncProcess &syncProcess); 57 bool IsMultiUser() const; 58 }; 59 } 60 #endif // PROCESS_NOTIFIER_H 61