• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
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 
39 namespace OHOS {
40 namespace Memory {
41 class MemmgrConfigManager {
42     DECLARE_SINGLE_INSTANCE_BASE(MemmgrConfigManager);
43 public:
44     bool Init();
45     void Dump(int fd);
46     bool ReadParamFromXml();
47     bool WriteReclaimRatiosConfigToKernel();
48     bool GetXmlLoaded();
49     AvailBufferConfig GetAvailBufferConfig();
50     SystemMemoryLevelConfig GetSystemMemoryLevelConfig();
51     const ReclaimConfig::ReclaimConfigSet& GetReclaimConfigSet();
52     const ReclaimPriorityConfig& GetReclaimPriorityConfig();
53     const KillConfig::KillLevelsMap& GetKillLevelsMap();
54     const KillConfig& GetKillConfig();
55     const NandLifeConfig& GetNandLifeConfig();
56     const SwitchConfig& GetSwitchConfig();
57 
58 private:
59     void InitDefaultConfig();
60     bool ParseXmlRootNode(const xmlNodePtr &rootNodePtr);
61     void ClearExistConfig();
62     void ParseReclaimNode(const xmlNodePtr &rootNodePtr);
63     bool xmlLoaded_ = false;
64     AvailBufferConfig availBufferConfig_;
65     KillConfig killConfig_;
66     SystemMemoryLevelConfig systemMemoryLevelConfig_;
67     NandLifeConfig nandLifeConfig_;
68     SwitchConfig switchConfig_;
69     ReclaimPriorityConfig reclaimPriorityConfig_;
70     ReclaimConfig reclaimConfig_;
71     void ClearReclaimConfigSet();
72     MemmgrConfigManager();
73     ~MemmgrConfigManager();
74 };
75 } // namespace Memory
76 } // namespace OHOS
77 #endif // OHOS_MEMORY_MEMMGR_COMMON_INCLUDE_MEMMGR_CONFIG_MANAGER_H
78