• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
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 OHOS_FILEMGMT_SYNC_STATE_MANAGER_H
17 #define OHOS_FILEMGMT_SYNC_STATE_MANAGER_H
18 
19 #include <atomic>
20 #include <shared_mutex>
21 
22 #include "data_sync_const.h"
23 namespace OHOS::FileManagement::CloudSync {
24 enum class SyncState : int32_t {
25     INIT = 0,
26     SYNCING,
27     CLEANING,
28     SYNC_FAILED,
29     SYNC_SUCCEED,
30     CLEAN_SUCCEED,
31     DISABLE_CLOUD,
32     DISABLE_CLOUD_SUCCEED,
33 };
34 
35 enum class Action : int32_t {
36     STOP = 0,
37     START,
38     FORCE_START,
39     CHECK,
40 };
41 
42 class SyncStateManager {
43 public:
44     Action UpdateSyncState(SyncState newState);
45     bool CheckAndSetPending(bool forceFlag, SyncTriggerType triggerType);
46     void SetCleaningFlag();
47     bool GetStopSyncFlag();
48     void SetStopSyncFlag();
49     void SetDisableCloudFlag();
50     SyncState GetSyncState() const;
51     bool GetForceFlag() const;
52 
53 private:
54     mutable std::shared_mutex syncMutex_;
55     SyncState state_{SyncState::INIT};
56     Action nextAction_{Action::STOP};
57     std::atomic_bool isForceSync_{false};
58     std::atomic_bool stopSyncFlag_{false};
59 };
60 
61 } // namespace OHOS::FileManagement::CloudSync
62 
63 #endif // OHOS_FILEMGMT_SYNC_STATE_MANAGER_H
64