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 const std::string TEMPERATURE_SYSPARAM_SYNC = "persist.kernel.cloudsync.temperature_abnormal_sync"; 29 const std::string TEMPERATURE_SYSPARAM_THUMB = "persist.kernel.cloudsync.temperature_abnormal_thumb"; 30 31 enum STOPPED_TYPE { 32 STOPPED_IN_SYNC = 0, 33 STOPPED_IN_THUMB = 1, 34 STOPPED_IN_OTHER = 2, 35 }; 36 37 class SystemLoadStatus { 38 public: 39 SystemLoadStatus() = default; 40 virtual ~SystemLoadStatus() = default; 41 static void RegisterSystemloadCallback(std::shared_ptr<CloudFile::DataSyncManager> dataSyncManager); 42 static void GetSystemloadLevel(); 43 static bool IsLoadStatusUnderHot(STOPPED_TYPE process = STOPPED_IN_OTHER); 44 static void InitSystemload(std::shared_ptr<CloudFile::DataSyncManager> dataSyncManager); 45 static void Setload(int32_t load); 46 static inline int32_t loadstatus_ = 0; 47 }; 48 49 class SystemLoadListener : public ResourceSchedule::ResSchedSystemloadNotifierClient { 50 public: 51 SystemLoadListener() = default; 52 void OnSystemloadLevel(int32_t level) override; 53 void SetDataSycner(std::shared_ptr<CloudFile::DataSyncManager> dataSyncManager); 54 private: 55 std::shared_ptr<CloudFile::DataSyncManager> dataSyncManager_ = nullptr; 56 }; 57 } // OHOS 58 59 #endif // OHOS_FILEMGMT_CLOUD_SYNC_SYSTEM_LOAD_H