1/* 2 * Copyright (c) 2022 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_MEMORY_MEMMGR_COMMON_INCLUDE_MEMMGR_CONFIG_MANAGER_H 17#define OHOS_MEMORY_MEMMGR_COMMON_INCLUDE_MEMMGR_CONFIG_MANAGER_H 18 19#include <map> 20#include <string> 21#include <set> 22#include <memory> 23#include "event_handler.h" 24#include "libxml/parser.h" 25#include "libxml/xpath.h" 26#include "kernel_interface.h" 27#include "single_instance.h" 28#include "reclaim_strategy_constants.h" 29#include "reclaim_priority_constants.h" 30#include "memory_level_constants.h" 31#include "avail_buffer_config.h" 32#include "kill_config.h" 33#include "nand_life_config.h" 34#include "reclaim_config.h" 35#include "reclaim_priority_config.h" 36#include "system_memory_level_config.h" 37#include "switch_config.h" 38#include "purgeablemem_config.h" 39 40namespace OHOS { 41namespace Memory { 42class MemmgrConfigManager { 43 DECLARE_SINGLE_INSTANCE_BASE(MemmgrConfigManager); 44public: 45 bool Init(); 46 void Dump(int fd); 47 bool ReadParamFromXml(); 48 bool WriteReclaimRatiosConfigToKernel(); 49 bool GetXmlLoaded(); 50 AvailBufferConfig GetAvailBufferConfig(); 51 SystemMemoryLevelConfig GetSystemMemoryLevelConfig(); 52 const ReclaimConfig::ReclaimConfigSet& GetReclaimConfigSet(); 53 const ReclaimPriorityConfig& GetReclaimPriorityConfig(); 54 const KillConfig::KillLevelsMap& GetKillLevelsMap(); 55 const KillConfig& GetKillConfig(); 56 const NandLifeConfig& GetNandLifeConfig(); 57 const SwitchConfig& GetSwitchConfig(); 58 const PurgeablememConfig &GetPurgeablememConfig(); 59 60private: 61 void InitDefaultConfig(); 62 bool ParseXmlRootNode(const xmlNodePtr &rootNodePtr); 63 void ClearExistConfig(); 64 void ParseReclaimNode(const xmlNodePtr &rootNodePtr); 65 bool xmlLoaded_ = false; 66 AvailBufferConfig availBufferConfig_; 67 KillConfig killConfig_; 68 SystemMemoryLevelConfig systemMemoryLevelConfig_; 69 NandLifeConfig nandLifeConfig_; 70 SwitchConfig switchConfig_; 71 ReclaimPriorityConfig reclaimPriorityConfig_; 72 ReclaimConfig reclaimConfig_; 73 PurgeablememConfig purgeablememConfig_; 74 void ClearReclaimConfigSet(); 75 MemmgrConfigManager(); 76 ~MemmgrConfigManager(); 77}; 78} // namespace Memory 79} // namespace OHOS 80#endif // OHOS_MEMORY_MEMMGR_COMMON_INCLUDE_MEMMGR_CONFIG_MANAGER_H 81