2 * Copyright 2012 Samsung Electronics Co., Ltd
4 * Licensed under the Flora License, Version 1.0 (the "License");
5 * you may not use this file except in compliance with the License.
6 * You may obtain a copy of the License at
8 * http://www.tizenopensource.org/license
10 * Unless required by applicable law or agreed to in writing, software
11 * distributed under the License is distributed on an "AS IS" BASIS,
12 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13 * See the License for the specific language governing permissions and
14 * limitations under the License.
27 HAPI struct conf g_conf = {
34 .minimum_period = 1.0f,
36 .default_conf.script = "edje",
37 .default_conf.abi = "c",
38 .default_conf.pd_group = "disclosure",
39 .default_conf.period = -1.0f,
41 .launch_key.name = "name",
42 .launch_key.secured = "secured",
43 .launch_key.abi = "abi",
45 .default_packet_time = 0.0001f,
50 .default_content = "default",
53 .minimum_space = 5242880,
55 .replace_tag = "/APPID/",
62 .sqlite_flush_max = 1048576,
65 .image = "/opt/usr/share/live_magazine/",
66 .slave_log = "/opt/usr/share/live_magazine/log",
67 .root = "/opt/usr/live/",
68 .script_port = "/opt/usr/live/script_port/",
69 .db = "/opt/dbspace/.livebox.db",
72 * This is not loaded from the conf file
74 .conf = "/opt/usr/live/%s/etc/%s.conf",
75 .script = "/opt/usr/live/%s/res/script/%s.edj",
76 .module = "/opt/usr/live/%s/libexec/liblive-%s.so",
83 .provider_method = "pixmap",
85 .overwrite_content = 0,
89 static void conf_update_size(void)
91 ecore_x_window_size_get(0, &g_conf.width, &g_conf.height);
94 static void use_sw_backend_handler(char *buffer)
96 g_conf.use_sw_backend = !strcasecmp(buffer, "true");
97 DbgPrint("SW Backend: %d\n", g_conf.use_sw_backend);
100 static void provider_method_handler(char *buffer)
102 g_conf.provider_method = strdup(buffer);
103 if (!g_conf.provider_method)
104 ErrPrint("Heap: %s\n", strerror(errno));
106 DbgPrint("Method: %s\n", g_conf.provider_method);
109 static void debug_mode_handler(char *buffer)
111 g_conf.debug_mode = !strcasecmp(buffer, "true");
112 DbgPrint("Debug mode: %d\n", g_conf.debug_mode);
115 static void overwrite_content_handler(char *buffer)
117 g_conf.overwrite_content = !strcasecmp(buffer, "true");
118 DbgPrint("Overwrite Content: %d\n", g_conf.overwrite_content);
121 static void com_core_thread_handler(char *buffer)
123 g_conf.com_core_thread = !strcasecmp(buffer, "true");
124 DbgPrint("Com core thread: %d\n", g_conf.com_core_thread);
127 static void base_width_handler(char *buffer)
129 if (sscanf(buffer, "%d", &g_conf.base_width) != 1)
130 ErrPrint("Failed to parse the base_width\n");
132 DbgPrint("Base width: %d\n", g_conf.base_width);
135 static void base_height_handler(char *buffer)
137 if (sscanf(buffer, "%d", &g_conf.base_height) != 1)
138 ErrPrint("Failed to parse the base_height\n");
139 DbgPrint("Base height: %d\n", g_conf.base_height);
142 static void minimum_period_handler(char *buffer)
144 if (sscanf(buffer, "%lf", &g_conf.minimum_period) != 1)
145 ErrPrint("Failed to parse the minimum_period\n");
146 DbgPrint("Minimum period: %lf\n", g_conf.minimum_period);
149 static void script_handler(char *buffer)
151 g_conf.default_conf.script = strdup(buffer);
152 if (!g_conf.default_conf.script)
153 ErrPrint("Heap: %s\n", strerror(errno));
154 DbgPrint("Default script: %s\n", g_conf.default_conf.script);
157 static void default_abi_handler(char *buffer)
159 g_conf.default_conf.abi = strdup(buffer);
160 if (!g_conf.default_conf.abi)
161 ErrPrint("Heap: %s\n", strerror(errno));
162 DbgPrint("Default ABI: %s\n", g_conf.default_conf.abi);
165 static void default_group_handler(char *buffer)
167 g_conf.default_conf.pd_group = strdup(buffer);
168 if (!g_conf.default_conf.pd_group)
169 ErrPrint("Heap: %s\n", strerror(errno));
170 DbgPrint("Default PD Group: %s\n", g_conf.default_conf.pd_group);
173 static void default_period_handler(char *buffer)
175 if (sscanf(buffer, "%lf", &g_conf.default_conf.period) != 1)
176 ErrPrint("Failed to parse the default_period\n");
177 DbgPrint("Default Period: %lf\n", g_conf.default_conf.period);
180 static void default_packet_time_handler(char *buffer)
182 if (sscanf(buffer, "%lf", &g_conf.default_packet_time) != 1)
183 ErrPrint("Failed to parse the default_packet_time\n");
184 DbgPrint("Default packet time: %lf\n", g_conf.default_packet_time);
187 static void default_content_handler(char *buffer)
189 g_conf.default_content = strdup(buffer);
190 if (!g_conf.default_content)
191 ErrPrint("Heap: %s\n", strerror(errno));
192 DbgPrint("Default content: %s\n", g_conf.default_content);
195 static void default_title_handler(char *buffer)
197 g_conf.default_title = strdup(buffer);
198 if (!g_conf.default_title)
199 ErrPrint("Heap: %s\n", strerror(errno));
200 DbgPrint("Default title: %s\n", g_conf.default_title);
203 static void minimum_space_handler(char *buffer)
205 if (sscanf(buffer, "%lu", &g_conf.minimum_space) != 1)
206 ErrPrint("Failed to parse the minimum_space\n");
207 DbgPrint("Minimum space: %lu\n", g_conf.minimum_space);
210 static void replace_tag_handler(char *buffer)
212 g_conf.replace_tag = strdup(buffer);
213 if (!g_conf.replace_tag)
214 ErrPrint("Heap: %s\n", strerror(errno));
215 DbgPrint("Replace Tag: %s\n", g_conf.replace_tag);
218 static void slave_ttl_handler(char *buffer)
220 if (sscanf(buffer, "%lf", &g_conf.slave_ttl) != 1)
221 ErrPrint("Failed to parse the slave_ttl\n");
222 DbgPrint("Slave TTL: %s\n", g_conf.slave_ttl);
225 static void max_log_line_handler(char *buffer)
227 if (sscanf(buffer, "%d", &g_conf.max_log_line) != 1)
228 ErrPrint("Failed to parse the max_log_line\n");
229 DbgPrint("Max log line: %d\n", g_conf.max_log_line);
232 static void max_log_file_handler(char *buffer)
234 if (sscanf(buffer, "%d", &g_conf.max_log_file) != 1)
235 ErrPrint("Failed to parse the max_log_file\n");
236 DbgPrint("Max log file: %d\n", g_conf.max_log_file);
239 static void sqlite_flush_max_handler(char *buffer)
241 if (sscanf(buffer, "%lu", &g_conf.sqlite_flush_max) != 1)
242 ErrPrint("Failed to parse the sqlite_flush_max\n");
243 DbgPrint("Flush size: %lu\n", g_conf.sqlite_flush_max);
246 static void db_path_handler(char *buffer)
248 g_conf.path.db = strdup(buffer);
250 ErrPrint("Heap: %s\n", strerror(errno));
251 DbgPrint("DB Path: %s\n", g_conf.path.db);
254 static void log_path_handler(char *buffer)
256 g_conf.path.slave_log = strdup(buffer);
257 if (!g_conf.path.slave_log)
258 ErrPrint("Heap: %s\n", strerror(errno));
259 DbgPrint("LOG Path: %s\n", g_conf.path.slave_log);
262 static void script_port_path_handler(char *buffer)
264 g_conf.path.script_port = strdup(buffer);
265 if (!g_conf.path.script_port)
266 ErrPrint("Heap: %s\n", strerror(errno));
267 DbgPrint("Script Port PATH: %s\n", g_conf.path.script_port);
270 static void share_path_handler(char *buffer)
272 g_conf.path.image = strdup(buffer);
273 if (!g_conf.path.image)
274 ErrPrint("Heap: %s\n", strerror(errno));
275 DbgPrint("Shared folder: %s\n", g_conf.path.image);
278 static void ping_time_handler(char *buffer)
280 if (sscanf(buffer, "%lf", &g_conf.ping_time) != 1)
281 ErrPrint("Failed to parse the ping_time\n");
282 g_conf.ping_time /= 2.0f; /*!< Half */
283 DbgPrint("Default ping time: %lf\n", g_conf.ping_time);
286 static void slave_max_loader(char *buffer)
288 if (sscanf(buffer, "%d", &g_conf.slave_max_load) != 1)
289 ErrPrint("Failed to parse the slave_max_load\n");
290 DbgPrint("Max load: %d\n", g_conf.slave_max_load);
293 HAPI int conf_loader(void)
312 static const struct token_parser {
314 void (*handler)(char *buffer);
315 } token_handler[] = {
317 .name = "base_width",
318 .handler = base_width_handler,
321 .name = "base_height",
322 .handler = base_height_handler,
325 .name = "minimum_period",
326 .handler = minimum_period_handler,
330 .handler = script_handler,
333 .name = "default_abi",
334 .handler = default_abi_handler,
337 .name = "default_group",
338 .handler = default_group_handler,
341 .name = "default_period",
342 .handler = default_period_handler,
345 .name = "default_packet_time",
346 .handler = default_packet_time_handler,
349 .name = "default_content",
350 .handler = default_content_handler,
353 .name = "default_title",
354 .handler = default_title_handler,
357 .name = "minimum_space",
358 .handler = minimum_space_handler,
361 .name = "replace_tag",
362 .handler = replace_tag_handler,
366 .handler = slave_ttl_handler,
369 .name = "max_log_line",
370 .handler = max_log_line_handler,
373 .name = "max_log_file",
374 .handler = max_log_file_handler,
377 .name = "sqilte_flush_max",
378 .handler = sqlite_flush_max_handler,
382 .handler = db_path_handler,
386 .handler = log_path_handler,
389 .name = "share_path",
390 .handler = share_path_handler,
393 .name = "script_port_path",
394 .handler = script_port_path_handler,
397 .name = "ping_interval",
398 .handler = ping_time_handler,
401 .name = "slave_max_load",
402 .handler = slave_max_loader,
405 .name = "use_sw_backend",
406 .handler = use_sw_backend_handler,
409 .name = "provider_method",
410 .handler = provider_method_handler,
413 .name = "debug_mode",
414 .handler = debug_mode_handler,
417 .name = "overwrite_content",
418 .handler = overwrite_content_handler,
421 .name = "com_core_thread",
422 .handler = com_core_thread_handler,
432 fp = fopen("/usr/share/data-provider-master/conf.ini", "rt");
434 ErrPrint("Error: %s\n", strerror(errno));
446 if ((c == EOF) && (state == VALUE)) {
447 LOGD("[%s:%d] VALUE state EOF\n", __func__, __LINE__);
453 if (c == CR || c == LF || c == EOF) {
454 buffer[buffer_idx] = '\0';
460 linelen = -1; /* Will be ZERO by follwing increment code */
463 buffer[buffer_idx++] = c;
464 if (buffer_idx == (sizeof(buffer) - 1)) {
465 buffer[buffer_idx] = '\0';
471 if (linelen == 0 && c == '#') {
473 } else if (isspace(c)) {
474 /* Ignore empty space */
483 else if (!isspace(c))
489 buffer[buffer_idx] = '\0';
491 } else if (buffer_idx != 0) {
492 buffer[buffer_idx++] = c;
493 if (buffer_idx >= sizeof(buffer))
498 } else if (isspace(c)) {
499 if (buffer_idx == 0) {
501 } else if (quote == 1) {
502 buffer[buffer_idx++] = c;
503 if (buffer_idx >= sizeof(buffer))
506 buffer[buffer_idx] = '\0';
511 buffer[buffer_idx++] = c;
512 if (buffer_idx >= sizeof(buffer))
522 } else if (isspace(c)) {
526 if (token_handler[token_idx].name[ch_idx] != '\0')
532 /* Now start to find a token! */
536 if (token_handler[token_idx].name[ch_idx] == c) {
541 ungetc(token_handler[token_idx].name[ch_idx], fp);
545 if (token_handler[token_idx].name == NULL)
553 if (c == CR || c == LF || c == EOF) {
563 if (c == LF || c == CR || c == EOF) {
566 if (token_idx >= 0 && token_handler[token_idx].handler) {
567 buffer[buffer_idx] = '\0';
568 DbgPrint("BUFFER: [%s]\n", buffer);
569 token_handler[token_idx].handler(buffer);
578 } else if (isspace(c)) {