1 /* 2 * Copyright (c) 2024 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 DSCHED_SYNC_E2E_H 17 #define DSCHED_SYNC_E2E_H 18 19 #include "distributed_sched_utils.h" 20 #include "dtbschedmgr_device_info_storage.h" 21 #include "mission/distributed_bm_storage.h" 22 23 namespace OHOS { 24 namespace DistributedSchedule { 25 using namespace AppExecFwk; 26 using namespace DistributedKv; 27 28 class DmsKvSyncCB : public OHOS::DistributedKv::KvStoreSyncCallback { 29 public: 30 DmsKvSyncCB(); 31 virtual ~DmsKvSyncCB(); 32 void SyncCompleted(const std::map<std::string, DistributedKv::Status> &result) override; 33 }; 34 35 class DmsKvSyncE2E { 36 public: 37 DmsKvSyncE2E(); 38 ~DmsKvSyncE2E(); 39 static std::shared_ptr<DmsKvSyncE2E> GetInstance(); 40 bool PushAndPullData(); 41 bool PushAndPullData(const std::string &networkId); 42 void SetDeviceCfg(); 43 bool CheckDeviceCfg(); 44 void SetSyncRecord(const std::string &networkId); 45 void ClearSyncRecord(const std::string &networkId); 46 bool IsSynchronized(const std::string &networkId); 47 bool CheckCtrlRule(); 48 bool CheckBundleContinueConfig(const std::string &bundleName); 49 50 private: 51 void TryTwice(const std::function<DistributedKv::Status()> &func) const; 52 bool CheckKvStore(); 53 DistributedKv::Status GetKvStore(); 54 bool IsValidPath(const std::string &inFilePath, std::string &realFilePath); 55 bool UpdateWhiteList(const std::string &cfgJsonStr); 56 int32_t LoadContinueConfig(); 57 58 static std::mutex mutex_; 59 static std::shared_ptr<DmsKvSyncE2E> instance_; 60 const DistributedKv::AppId appId_ {DMS_BM_APP_ID}; 61 const DistributedKv::StoreId storeId_ {DISTRIBUTE_BM_STORE_ID}; 62 DistributedKv::DistributedKvDataManager dataManager_; 63 std::shared_ptr<DistributedKv::SingleKvStore> kvStorePtr_; 64 mutable std::mutex kvStorePtrMutex_; 65 std::atomic<bool> isCfgDevices_ = false; 66 std::map<std::string, bool> deviceSyncRecord_; 67 std::atomic<bool> isForbidSendAndRecv_ = false; 68 std::string continueCfgFullPath_ = ""; 69 std::vector<std::string> whiteList_; 70 }; 71 } // namespace DistributedSchedule 72 } // namespace OHOS 73 #endif // DSCHED_SYNC_E2E_H 74