• 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_CLOUD_SYNC_SYSTEM_LOAD_H
17 #define OHOS_FILEMGMT_CLOUD_SYNC_SYSTEM_LOAD_H
18 
19 #include "data_sync_manager.h"
20 #include <functional>
21 #include "res_sched_systemload_notifier_client.h"
22 #include "res_type.h"
23 #include "sync_state_manager.h"
24 
25 namespace OHOS::FileManagement::CloudSync {
26 constexpr int32_t SYSTEMLOADLEVEL_HOT = ResourceSchedule::ResType::SystemloadLevel::HIGH;
27 constexpr int32_t SYSTEMLOADLEVEL_WARM = ResourceSchedule::ResType::SystemloadLevel::MEDIUM;
28 constexpr int32_t SYSTEMLOADLEVEL_NORMAL = ResourceSchedule::ResType::SystemloadLevel::NORMAL;
29 const std::string TEMPERATURE_SYSPARAM_SYNC = "persist.kernel.cloudsync.temperature_abnormal_sync";
30 const std::string TEMPERATURE_SYSPARAM_THUMB = "persist.kernel.cloudsync.temperature_abnormal_thumb";
31 
32 enum STOPPED_TYPE {
33     STOPPED_IN_SYNC = 0,
34     STOPPED_IN_THUMB = 1,
35     STOPPED_IN_OTHER = 2,
36 };
37 
38 class SystemLoadStatus {
39 public:
40     SystemLoadStatus() = default;
41     virtual ~SystemLoadStatus() = default;
42     static void RegisterSystemloadCallback(std::shared_ptr<CloudFile::DataSyncManager> dataSyncManager);
43     static void GetSystemloadLevel();
44     static bool IsLoadStatusUnderHot(STOPPED_TYPE process = STOPPED_IN_OTHER, int32_t level = SYSTEMLOADLEVEL_HOT);
45     static bool IsLoadStatusUnderNormal();
46     static void InitSystemload(std::shared_ptr<CloudFile::DataSyncManager> dataSyncManager);
47     static void Setload(int32_t load);
48     static inline int32_t loadstatus_ = 0;
49 };
50 
51 class SystemLoadListener : public ResourceSchedule::ResSchedSystemloadNotifierClient {
52 public:
53     SystemLoadListener() = default;
54     void OnSystemloadLevel(int32_t level) override;
55     void SetDataSycner(std::shared_ptr<CloudFile::DataSyncManager> dataSyncManager);
56 private:
57     std::shared_ptr<CloudFile::DataSyncManager> dataSyncManager_ = nullptr;
58 };
59 } // OHOS
60 
61 #endif // OHOS_FILEMGMT_CLOUD_SYNC_SYSTEM_LOAD_H