1686862fbSopenharmony_ci/*
2686862fbSopenharmony_ci * Copyright (c) 2024 Huawei Device Co., Ltd.
3686862fbSopenharmony_ci * Licensed under the Apache License, Version 2.0 (the "License");
4686862fbSopenharmony_ci * you may not use this file except in compliance with the License.
5686862fbSopenharmony_ci * You may obtain a copy of the License at
6686862fbSopenharmony_ci *
7686862fbSopenharmony_ci *     http://www.apache.org/licenses/LICENSE-2.0
8686862fbSopenharmony_ci *
9686862fbSopenharmony_ci * Unless required by applicable law or agreed to in writing, software
10686862fbSopenharmony_ci * distributed under the License is distributed on an "AS IS" BASIS,
11686862fbSopenharmony_ci * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
12686862fbSopenharmony_ci * See the License for the specific language governing permissions and
13686862fbSopenharmony_ci * limitations under the License.
14686862fbSopenharmony_ci */
15686862fbSopenharmony_ci
16686862fbSopenharmony_ci#ifndef DSCHED_SYNC_E2E_H
17686862fbSopenharmony_ci#define DSCHED_SYNC_E2E_H
18686862fbSopenharmony_ci
19686862fbSopenharmony_ci#include "distributed_sched_utils.h"
20686862fbSopenharmony_ci#include "dtbschedmgr_device_info_storage.h"
21686862fbSopenharmony_ci#include "mission/distributed_bm_storage.h"
22686862fbSopenharmony_ci
23686862fbSopenharmony_cinamespace OHOS {
24686862fbSopenharmony_cinamespace DistributedSchedule {
25686862fbSopenharmony_ciusing namespace AppExecFwk;
26686862fbSopenharmony_ciusing namespace DistributedKv;
27686862fbSopenharmony_ci
28686862fbSopenharmony_ciclass DmsKvSyncCB : public OHOS::DistributedKv::KvStoreSyncCallback {
29686862fbSopenharmony_cipublic:
30686862fbSopenharmony_ci    DmsKvSyncCB();
31686862fbSopenharmony_ci    virtual ~DmsKvSyncCB();
32686862fbSopenharmony_ci    void SyncCompleted(const std::map<std::string, DistributedKv::Status> &result) override;
33686862fbSopenharmony_ci};
34686862fbSopenharmony_ci
35686862fbSopenharmony_ciclass DmsKvSyncE2E {
36686862fbSopenharmony_cipublic:
37686862fbSopenharmony_ci    DmsKvSyncE2E();
38686862fbSopenharmony_ci    ~DmsKvSyncE2E();
39686862fbSopenharmony_ci    static std::shared_ptr<DmsKvSyncE2E> GetInstance();
40686862fbSopenharmony_ci    bool PushAndPullData();
41686862fbSopenharmony_ci    bool PushAndPullData(const std::string &networkId);
42686862fbSopenharmony_ci    void SetDeviceCfg();
43686862fbSopenharmony_ci    bool CheckDeviceCfg();
44686862fbSopenharmony_ci    void SetSyncRecord(const std::string &networkId);
45686862fbSopenharmony_ci    void ClearSyncRecord(const std::string &networkId);
46686862fbSopenharmony_ci    bool IsSynchronized(const std::string &networkId);
47686862fbSopenharmony_ci    bool CheckCtrlRule();
48686862fbSopenharmony_ci    bool CheckBundleContinueConfig(const std::string &bundleName);
49686862fbSopenharmony_ci
50686862fbSopenharmony_ciprivate:
51686862fbSopenharmony_ci    void TryTwice(const std::function<DistributedKv::Status()> &func) const;
52686862fbSopenharmony_ci    bool CheckKvStore();
53686862fbSopenharmony_ci    DistributedKv::Status GetKvStore();
54686862fbSopenharmony_ci    bool IsValidPath(const std::string &inFilePath, std::string &realFilePath);
55686862fbSopenharmony_ci    bool UpdateWhiteList(const std::string &cfgJsonStr);
56686862fbSopenharmony_ci    int32_t LoadContinueConfig();
57686862fbSopenharmony_ci
58686862fbSopenharmony_ci    static std::mutex mutex_;
59686862fbSopenharmony_ci    static std::shared_ptr<DmsKvSyncE2E> instance_;
60686862fbSopenharmony_ci    const DistributedKv::AppId appId_ {DMS_BM_APP_ID};
61686862fbSopenharmony_ci    const DistributedKv::StoreId storeId_ {DISTRIBUTE_BM_STORE_ID};
62686862fbSopenharmony_ci    DistributedKv::DistributedKvDataManager dataManager_;
63686862fbSopenharmony_ci    std::shared_ptr<DistributedKv::SingleKvStore> kvStorePtr_;
64686862fbSopenharmony_ci    mutable std::mutex kvStorePtrMutex_;
65686862fbSopenharmony_ci    std::atomic<bool> isCfgDevices_ = false;
66686862fbSopenharmony_ci    std::map<std::string, bool> deviceSyncRecord_;
67686862fbSopenharmony_ci    std::atomic<bool> isForbidSendAndRecv_ = false;
68686862fbSopenharmony_ci    std::string continueCfgFullPath_ = "";
69686862fbSopenharmony_ci    std::vector<std::string> whiteList_;
70686862fbSopenharmony_ci};
71686862fbSopenharmony_ci}  // namespace DistributedSchedule
72686862fbSopenharmony_ci}  // namespace OHOS
73686862fbSopenharmony_ci#endif  // DSCHED_SYNC_E2E_H
74