Remove useless source code
[platform/core/system/resourced.git] / src / common / config-parser.h
1 /*
2  * resourced
3  *
4  * Copyright (c) 2013 Samsung Electronics Co., Ltd.
5  *
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
9  *
10  *     http://www.apache.org/licenses/LICENSE-2.0
11  *
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.
17  */
18
19
20 #ifndef __CONFIG_PARSER_H__
21 #define __CONFIG_PARSER_H__
22
23 #include <stdio.h>
24 #include <stdbool.h>
25
26 #ifdef __cplusplus
27 extern "C" {
28 #endif /* __cplusplus */
29
30
31 #define CONF_FILE_SUFFIX                        ".conf"
32
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"
37
38 /* section name */
39 /* limiter.conf */
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"
46
47 /* optimizer.conf */
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"
55
56 /* configuration name */
57 /* limiter.conf */
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"
80
81 /* optimizer.cnof */
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"
101
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"
112
113
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))
116
117 enum config_type {
118         LIMITER_CONFIG,
119         OPTIMIZER_CONFIG,
120         MONITOR_CONFIG,
121         PROCESS_CONFIG,
122 };
123
124 struct parse_result {
125         char *section;
126         char *name;
127         char *value;
128 };
129
130 /**
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
136  */
137 int config_parse(const char *file_name, int cb(struct parse_result *result,
138                         void *user_data), void *user_data);
139
140 /* Prototype for a parser for a specific configuration setting */
141 typedef int (*ConfigParserCallback)(
142                 const char *filename,
143                 unsigned line,
144                 const char *section,
145                 const char *lvalue,
146                 int ltype,
147                 const char *rvalue,
148                 void *data);
149
150 typedef int (*ConfigParseFunc)(const char *path, void *data);
151
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
159                                          * value */
160         int ltype;                      /* Distinguish different
161                                          * variables passed to the
162                                          * same callback */
163         void *data;                     /* Where to store the
164                                          * variable's data */
165 } ConfigTableItem;
166
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);
173 #ifdef __cplusplus
174 }
175 #endif /* __cplusplus */
176
177 #endif