4 * Copyright (c) 2013 Samsung Electronics Co., Ltd.
6 * Licensed under the Apache License, Version 2.0 (the License);
7 * you may not use this file except in compliance with the License.
8 * You may obtain a copy of the License at
10 * http://www.apache.org/licenses/LICENSE-2.0
12 * Unless required by applicable law or agreed to in writing, software
13 * distributed under the License is distributed on an "AS IS" BASIS,
14 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
15 * See the License for the specific language governing permissions and
16 * limitations under the License.
20 #ifndef __CONFIG_PARSER_H__
21 #define __CONFIG_PARSER_H__
28 #endif /* __cplusplus */
31 #define CONF_FILE_SUFFIX ".conf"
33 #define LIMITER_CONF_FILE RD_CONFIG_FILE(limiter)
34 #define OPTIMIZER_CONF_FILE RD_CONFIG_FILE(optimizer)
35 #define LIMITER_CONF_DIR RD_CONFIG_PATH"/limiter.conf.d"
36 #define PROC_CONF_DIR RD_CONFIG_PATH"/process.conf.d"
40 #define PER_PROCESS_SECTION "PerProcess"
41 #define MEMORY_GROUP_LIMIT_SECTION "MemoryGroupLimit"
42 #define MEMORY_LEVEL_THRESHOLD_SECTION "MemoryLevelThreshold"
43 #define MEMORY_APP_TYPE_LIMIT_SECTION "MemoryAppTypeLimit"
44 #define MEMORY_APP_STATUS_LIMIT_SECTION "MemoryAppStatusLimit"
45 #define CPU_AFFINITY_SECTION "CpuAffinity"
48 #define SWAP_SECTION "Swap"
49 #define ZRAM_SECTION "Zram"
50 #define ZSWAP_SECTION "Zswap"
51 #define FILE_SWAP_SECTION "FileSwap"
52 #define DEDUP_SECTION "Dedup"
53 #define KSM_SECTION "Ksm"
54 #define COMPACTION_SECTION "Compaction"
56 /* configuration name */
58 #define SERVICE_NAME_CONF "Service"
59 #define APP_NAME_CONF "App"
60 #define CPU_CGROUP_NAME_CONF "CpuGroup"
61 #define MEM_CGROUP_NAME_CONF "MemGroup"
62 #define MEM_LIMIT_ACTION_NAME_CONF "MemLimitAction"
63 #define CPU_PRIORITY_NAME_CONF "CpuPriority"
64 #define ACTION_ON_FAILURE_NAME_CONF "ActionOnFailure"
65 #define WATCHDOG_ACTION_NAME_CONF "WatchdogAction"
66 #define VIP_GROUP_LIMIT_CONF "VipGroupLimit"
67 #define HIGH_GROUP_LIMIT_CONF "HighGroupLimit"
68 #define MEDIUM_GROUP_LIMIT_CONF "MediumGroupLimit"
69 #define LOWEST_GROUP_LIMIT_CONF "LowestGroupLimit"
70 #define MEDIUM_LEVEL_CONF "MediumLevel"
71 #define LOW_LEVEL_CONF "LowLevel"
72 #define CRITICAL_LEVEL_CONF "CriticalLevel"
73 #define OOM_LEVEL_CONF "OomLevel"
74 #define OOM_POPUP_CONF "OomPopup"
75 #define SERVICE_PER_APP_LIMIT_ACTION "ServicePerAppLimitAction"
76 #define WIDGET_PER_APP_LIMIT_ACTION "WidgetPerAppLimitAction"
77 #define GUI_PER_APP_LIMIT_ACTION "GUIPerAppLimitAction"
78 #define BACKGROUND_PER_APP_LIMIT_ACTION "BackgroundPerAppLimitAction"
79 #define FOREGROUND_APPS "ForegroundApps"
82 #define ENABLE_CONF "Enable"
83 #define RECLAIM_AT_BOOT_CONF "ReclaimAtBoot"
84 #define TYPE_CONF "Type"
85 #define VIP_GROUP_SWAPPINESS_CONF "VipGroupSwappiness"
86 #define HIGH_GROUP_SWAPPINESS_CONF "HighGroupSwappiness"
87 #define MEDIUM_GROUP_SWAPPINESS_CONF "MediumGroupSwappiness"
88 #define LOWEST_GROUP_SWAPPINESS_CONF "LowestGroupSwappiness"
89 #define COMP_ALGORITHM_CONF "CompAlgorithm"
90 #define RATIO_CONF "Ratio"
91 #define CRYPT_TYPE_CONF "CryptType"
92 #define FILE_SIZE_CONF "FileSize"
93 #define POOL_RATIO_CONF "PoolRatio"
94 #define POOL_TYPE_CONF "PoolType"
95 #define DEDUP_AT_BOOT_CONF "DedupAtBoot"
96 #define SCAN_ON_LOWMEM_CONF "ScanOnLowmem"
97 #define MODE_CONF "Mode"
98 #define PAGES_TO_SCAN_CONF "PagesToScan"
99 #define PAGES_TO_SCAN_WITH_BOOST_CONF "PagesToScanWithBoost"
100 #define FRAG_LEVEL_CONF "FragLevel"
102 /* configuration value */
103 #define CGROUP_VIP_VALUE_CONF "vip"
104 #define CGROUP_HIGH_VALUE_CONF "high"
105 #define CGROUP_MEDIUM_VALUE_CONF "medium"
106 #define CGROUP_LOW_VALUE_CONF "lowest"
107 #define ACTION_BROADCAST_VALUE_CONF "broadcast"
108 #define ACTION_RECLAIM_VALUE_CONF "reclaim"
109 #define ACTION_KILL_VALUE_CONF "kill"
110 #define ACTION_REBOOT_VALUE_CONF "reboot"
111 #define ACTION_IGNORE_VALUE_CONF "ignore"
114 #define MATCH(a, b) (!strncmp(a, b, strlen(a) + 1) ? 1 : 0)
115 #define SET_CONF(a, b) (a = (b > 0.0 ? b : a))
124 struct parse_result {
131 * @brief Parse config file and call callback\n
132 * @param[in] file_name conf file.
133 * @param[in] cb cb is called when conf file is parsed line by line.
134 * @param[in] user_data user data is passed to cb.
135 * @return 0 on success, negative if failed
137 int config_parse(const char *file_name, int cb(struct parse_result *result,
138 void *user_data), void *user_data);
140 /* Prototype for a parser for a specific configuration setting */
141 typedef int (*ConfigParserCallback)(
142 const char *filename,
150 typedef int (*ConfigParseFunc)(const char *path, void *data);
152 /* Wraps information for parsing a specific configuration variable, to
153 * be stored in a simple array */
154 typedef struct ConfigTableItem {
155 const char *section; /* Section */
156 const char *lvalue; /* Name of the variable */
157 ConfigParserCallback cb; /* Function that is called to
158 * parse the variable's
160 int ltype; /* Distinguish different
161 * variables passed to the
163 void *data; /* Where to store the
167 void remove_app_conf_info_list(void);
168 void remove_service_conf_info_list(void);
169 GSList *get_app_conf_info_list(void);
170 GSList *get_service_conf_info_list(void);
171 void resourced_parse_vendor_configs(void);
172 void resourced_free_vendor_configs(void);
175 #endif /* __cplusplus */