1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
628
629
630
631
632
633
634
635
636
637
638
639
640
641
642
643
644
645
646
647
648
649
650
651
652
653
654
655
656
657
658
659
660
661
662
663
664
665
666
667
668
669
670
671
672
673
674
675
676
677
678
679
680
681
682
683
684
685
686
687
688
689
690
691
692
693
694
695
696
697
698
699
700
701
702
703
704
705
706
707
708
709
710
711
712
713
714
715
716
717
718
719
720
721
722
723
724
725
726
727
728
729
730
731
732
733
734
735
736
737
738
739
740
741
742
743
744
745
746
747
748
749
750
751
752
753
754
755
756
757
758
759
760
761
762
763
764
765
766
767
768
769
770
771
772
773
774
775
776
777
778
779
780
781
782
783
784
785
786
787
788
789
790
791
792
793
794
795
796
797
798
799
800
801
802
803
804
805
806
807
808
809
810
811
812
813
814
815
816
817
818
819
820
821
822
823
824
825
826
827
828
829
830
831
832
833
834
835
836
837
838
839
840
841
842
843
844
845
846
847
848
849
850
851
852
853
854
855
856
857
858
859
860
861
862
863
864
865
866
867
868
869
870
871
872
873
874
875
876
877
878
879
880
881
882
883
884
885
886
887
888
889
890
891
892
893
894
895
896
897
898
899
900
901
902
903
904
905
906
907
908
909
910
911
912
913
914
915
916
917
918
919
920
921
922
923
924
925
926
927
928
929
930
931
932
933
934
935
936
937
938
939
940
941
942
943
944
945
946
947
948
949
950
951
952
953
954
955
956
957
958
959
960
961
962
963
964
965
966
967
968
969
970
971
972
973
974
975
976
977
978
979
980
981
982
983
984
985
986
987
988
989
990
991
992
993
994
995
996
997
998
999
1000
1001
1002
1003
1004
1005
1006
1007
1008
1009
1010
1011
1012
1013
1014
1015
1016
1017
1018
1019
1020
1021
1022
1023
1024
1025
1026
1027
1028
1029
1030
1031
1032
1033
1034
1035
1036
1037
1038
1039
1040
1041
1042
1043
1044
1045
1046
1047
1048
1049
1050
1051
1052
1053
1054
1055
1056
1057
1058
1059
1060
1061
1062
1063
1064
1065
1066
1067
1068
1069
1070
1071
1072
1073
1074
1075
1076
1077
1078
1079
1080
1081
1082
1083
1084
1085
1086
1087
1088
1089
1090
1091
1092
1093
1094
1095
1096
1097
1098
1099
1100
1101
1102
1103
1104
1105
1106
1107
1108
1109
1110
1111
1112
1113
1114
1115
1116
1117
1118
1119
1120
1121
1122
1123
1124
1125
1126
1127
1128
1129
1130
1131
1132
1133
1134
1135
1136
1137
1138
1139
1140
1141
1142
1143
1144
1145
1146
1147
1148
1149
1150
1151
1152
1153
1154
1155
1156
1157
1158
1159
1160
1161
1162
1163
1164
1165
1166
1167
1168
1169
1170
1171
1172
1173
1174
1175
1176
1177
1178
1179
1180
1181
1182
1183
1184
1185
1186
1187
1188
1189
1190
1191
1192
1193
1194
1195
1196
1197
1198
1199
1200
1201
1202
1203
1204
1205
1206
1207
1208
1209
1210
1211
1212
1213
1214
1215
1216
1217
1218
1219
1220
1221
1222
1223
1224
1225
1226
1227
1228
1229
1230
1231
1232
1233
1234
1235
1236
1237
1238
1239
1240
1241
1242
1243
1244
1245
1246
1247
1248
1249
1250
1251
1252
1253
1254
1255
1256
1257
1258
1259
1260
1261
1262
1263
1264
1265
1266
1267
1268
1269
1270
1271
1272
1273
1274
1275
1276
1277
1278
1279
1280
1281
1282
1283
1284
1285
1286
1287
1288
1289
1290
1291
1292
1293
1294
1295
1296
1297
1298
1299
1300
1301
1302
1303
1304
1305
1306
1307
1308
1309
1310
1311
1312
1313
1314
1315
1316
1317
1318
1319
1320
1321
1322
1323
1324
1325
1326
1327
1328
1329
1330
1331
1332
1333
1334
1335
1336
1337
1338
1339
1340
1341
1342
1343
1344
1345
1346
1347
1348
1349
1350
1351
1352
1353
1354
1355
1356
1357
1358
1359
1360
1361
1362
1363
1364
1365
1366
1367
1368
1369
1370
1371
1372
1373
1374
1375
1376
1377
1378
1379
1380
1381
1382
1383
1384
1385
1386
1387
1388
1389
1390
1391
1392
1393
1394
1395
1396
1397
1398
1399
1400
1401
1402
1403
1404
1405
1406
1407
1408
1409
1410
1411
1412
1413
1414
1415
1416
1417
1418
1419
1420
1421
1422
1423
1424
1425
1426
1427
1428
1429
1430
1431
1432
1433
1434
1435
1436
1437
1438
1439
1440
1441
1442
1443
1444
1445
1446
1447
1448
1449
1450
1451
1452
1453
1454
1455
1456
1457
1458
1459
1460
1461
1462
1463
1464
1465
1466
1467
1468
1469
1470
1471
1472
1473
1474
1475
1476
1477
1478
1479
1480
1481
1482
1483
1484
1485
1486
1487
1488
1489
1490
1491
1492
1493
1494
1495
1496
1497
1498
1499
1500
1501
1502
1503
1504
1505
1506
1507
1508
1509
1510
1511
1512
1513
1514
1515
1516
1517
1518
1519
1520
1521
1522
1523
1524
1525
1526
1527
1528
1529
1530
1531
1532
1533
1534
1535
1536
1537
1538
1539
1540
1541
1542
1543
1544
1545
1546
1547
1548
1549
1550
1551
1552
1553
1554
1555
1556
1557
1558
1559
1560
1561
1562
1563
1564
1565
1566
1567
1568
1569
1570
1571
1572
1573
1574
1575
1576
1577
1578
1579
1580
1581
1582
1583
1584
1585
1586
1587
1588
1589
1590
1591
1592
1593
1594
1595
1596
1597
1598
1599
1600
1601
1602
1603
1604
1605
1606
1607
1608
1609
1610
1611
1612
1613
1614
1615
1616
1617
1618
1619
1620
1621
1622
1623
1624
1625
1626
1627
1628
1629
1630
1631
1632
1633
1634
1635
1636
1637
1638
1639
1640
1641
1642
1643
1644
1645
1646
1647
1648
1649
1650
1651
1652
1653
1654
1655
1656
1657
1658
1659
1660
1661
1662
1663
1664
1665
1666
1667
1668
1669
1670
1671
1672
1673
1674
1675
1676
1677
1678
1679
1680
1681
1682
1683
1684
1685
1686
1687
1688
1689
1690
1691
1692
1693
1694
1695
1696
1697
1698
1699
1700
1701
1702
1703
1704
1705
1706
1707
1708
1709
1710
1711
1712
1713
1714
1715
1716
1717
1718
1719
1720
1721
1722
1723
1724
1725
1726
1727
1728
1729
1730
1731
1732
1733
1734
1735
1736
1737
1738
1739
1740
1741
1742
1743
1744
1745
1746
1747
1748
1749
1750
1751
1752
1753
1754
1755
1756
1757
1758
1759
1760
1761
1762
1763
1764
1765
1766
1767
1768
1769
1770
1771
1772
1773
1774
1775
1776
1777
1778
1779
1780
1781
1782
1783
1784
1785
1786
1787
1788
1789
1790
1791
1792
1793
1794
1795
1796
1797
1798
1799
1800
1801
1802
1803
1804
1805
1806
1807
1808
1809
1810
1811
1812
1813
1814
1815
1816
1817
1818
1819
1820
1821
1822
1823
1824
1825
1826
1827
1828
1829
1830
1831
1832
1833
1834
1835
1836
1837
1838
1839
1840
1841
1842
1843
1844
1845
1846
1847
1848
1849
1850
1851
1852
1853
1854
1855
1856
1857
1858
1859
1860
1861
1862
1863
1864
1865
1866
1867
1868
1869
1870
1871
1872
1873
1874
1875
1876
1877
1878
1879
1880
1881
1882
1883
1884
1885
1886
1887
1888
1889
1890
1891
1892
1893
1894
1895
1896
1897
1898
1899
1900
1901
1902
1903
1904
1905
1906
1907
1908
1909
1910
1911
1912
1913
1914
1915
1916
1917
1918
1919
1920
1921
1922
1923
1924
1925
1926
1927
1928
1929
1930
1931
1932
1933
1934
1935
1936
1937
1938
1939
1940
1941
1942
1943
1944
1945
1946
1947
1948
1949
1950
1951
1952
1953
1954
1955
1956
1957
1958
1959
1960
1961
1962
1963
1964
1965
1966
1967
1968
1969
1970
1971
1972
1973
1974
1975
1976
1977
1978
1979
1980
1981
1982
1983
1984
1985
1986
1987
1988
1989
1990
1991
1992
1993
1994
1995
1996
1997
1998
1999
2000
2001
2002
2003
2004
2005
2006
2007
2008
2009
2010
2011
2012
2013
2014
2015
2016
2017
2018
2019
2020
2021
2022
2023
2024
2025
2026
2027
2028
2029
2030
2031
2032
2033
2034
2035
2036
2037
|
/*
* Copyright 2013 Samsung Electronics Co., Ltd
*
* Licensed under the Flora License, Version 1.1 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://floralicense.org/license/
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/
#include <stdio.h>
#include <ctype.h>
#include <errno.h>
#include <string.h>
#include <stdlib.h>
#include <unistd.h> // access
#include <sqlite3.h>
#include <fcntl.h>
#include <sys/types.h>
#include <sys/stat.h>
#include <dirent.h>
#include <sys/ioctl.h>
#include <linux/input.h>
#include <dlog.h>
#include <widget_errno.h>
#include <unicode/uloc.h>
#include "widget_conf.h"
#include "util.h"
#include "debug.h"
#define BASE_SHARE_DIR "/opt/usr/share/live_magazine/"
#define DEFAULT_INPUT_NODE "/dev/input/event2"
#define DEV_PATH "/dev/input/"
#define PROC_INPUT_DEVICES "/proc/bus/input/devices"
#define MAX_LINE_BUFFER 256
#define NODE_PREFIX "event"
#define CR 13
#define LF 10
#define MAX_ABI 256
#define MAX_PKGNAME 512
static const char *CONF_DEFAULT_SERVICES = "[widget],[shortcut],[notification],[badge],[utility],[file]";
static const char *CONF_DEFAULT_EMERGENCY_DISK = "source=tmpfs;type=tmpfs;option=size=6M";
static const char *CONF_DEFAULT_PATH_CONF = "/opt/usr/live/%s/etc/%s.conf";
static const char *CONF_DEFAULT_PATH_IMAGE = BASE_SHARE_DIR;
static const char *CONF_DEFAULT_PATH_LOG = BASE_SHARE_DIR"log";
static const char *CONF_DEFAULT_PATH_READER = BASE_SHARE_DIR"reader";
static const char *CONF_DEFAULT_PATH_ALWAYS = BASE_SHARE_DIR"always";
static const char *CONF_DEFAULT_PATH_SCRIPT = "/opt/usr/live/%s/res/script/%s.edj";
static const char *CONF_DEFAULT_PATH_ROOT = "/opt/usr/live/";
static const char *CONF_DEFAULT_PATH_SCRIPT_PORT = "/usr/share/data-provider-master/plugin-script/";
static const char *CONF_DEFAULT_PATH_DB = "/opt/dbspace/.widget.db";
static const char *CONF_DEFAULT_PATH_INPUT = DEFAULT_INPUT_NODE;
static const char *CONF_DEFAULT_SCRIPT_TYPE = "edje";
static const char *CONF_DEFAULT_ABI = "c";
static const char *CONF_DEFAULT_GBAR_GROUP = "disclosure";
static const char *CONF_DEFAULT_LAUNCH_BUNDLE_NAME = "name";
static const char *CONF_DEFAULT_LAUNCH_BUNDLE_SECURED = "secured";
static const char *CONF_DEFAULT_LAUNCH_BUNDLE_ABI = "abi";
static const char *CONF_DEFAULT_LAUNCH_BUNDLE_HW_ACCELERATION = "hw-acceleration";
static const char *CONF_DEFAULT_CONTENT = "default";
static const char *CONF_DEFAULT_TITLE = "";
static const char *CONF_DEFAULT_EMPTY_CONTENT = "";
static const char *CONF_DEFAULT_EMPTY_TITLE = "";
static const char *CONF_DEFAULT_REPLACE_TAG = "/APPID/";
static const char *CONF_DEFAULT_PROVIDER_METHOD = "pixmap";
static const char *CONF_DEFAULT_CATEGORY_LIST = "http://tizen.org/category/wearable_clock";
static const char *CONF_DEFAULT_APP_ABI = "app";
static const char *CONF_DEFAULT_SDK_VIEWER = "org.tizen.widget_viewer_sdk";
static const int CONF_DEFAULT_WIDTH = 0;
static const int CONF_DEFAULT_HEIGHT = 0;
static const int CONF_DEFAULT_BASE_WIDTH = 720;
static const int CONF_DEFAULT_BASE_HEIGHT = 1280;
static const double CONF_DEFAULT_MINIMUM_PERIOD = 1.0f;
static const double CONF_DEFAULT_PERIOD = -1.0f;
static const double CONF_DEFAULT_PACKET_TIME = 0.0001f;
static const unsigned long CONF_DEFAULT_MINIMUM_SPACE = 5242880;
static const double CONF_DEFAULT_SLAVE_TTL = 30.0f;
static const double CONF_DEFAULT_SLAVE_ACTIVATE_TIME = 30.0f;
static const double CONF_DEFAULT_SLAVE_RELAUNCH_TIME = 3.0f;
static const int CONF_DEFAULT_SLAVE_RELAUNCH_COUNT = 3;
static const int CONF_DEFAULT_MAX_LOG_LINE = 1000;
static const int CONF_DEFAULT_MAX_LOG_FILE = 3;
static const int CONF_DEFAULT_SQLITE_FLUSH_MAX = 1048576;
static const double CONF_DEFAULT_PING_TIME = 240.0f;
static const int CONF_DEFAULT_SLAVE_MAX_LOAD = 30;
static const int CONF_DEFAULT_USE_SW_BACKEND = 0;
static const int CONF_DEFAULT_DEBUG_MODE = 0;
static const int CONF_DEFAULT_OVERWRITE_CONTENT = 0;
static const int CONF_DEFAULT_COM_CORE_THREAD = 1;
static const int CONF_DEFAULT_USE_XMONITOR = 0;
static const int CONF_DEFAULT_PREMULTIPLIED = 1;
static const double CONF_DEFAULT_SCALE_WIDTH_FACTOR = 1.0f;
static const double CONF_DEFAULT_SCALE_HEIGHT_FACTOR = 1.0f;
static const double CONF_DEFAULT_GBAR_REQUEST_TIMEOUT = 5.0f;
static const int CONF_DEFAULT_PIXELS = sizeof(int);
static const int CONF_DEFAULT_AUTO_ALIGN = 1;
static const int CONF_DEFAULT_USE_EVENT_TIME = 1;
static const int CONF_DEFAULT_CHECK_LCD = 1;
static const int CONF_DEFAULT_EXTRA_BUFFER_COUNT = 1;
static const int CONF_DEFAULT_USE_GETTIMEOFDAY = 0;
static const int CONF_DEFAULT_SLAVE_EVENT_BOOST_ON = 0;
static const int CONF_DEFAULT_SLAVE_EVENT_BOOST_OFF = 0;
static const double CONF_DEFAULT_EVENT_FILTER = 0.5f;
static const int CONF_DEFAULT_SLAVE_LIMIT_TO_TTL = 0;
static const int CONF_DEFAULT_SLAVE_AUTO_CACHE_FLUSH = 0;
static const int CONF_DEFAULT_REACTIVATE_ON_PAUSE = 1;
static const double CONF_DEFAULT_FAULT_DETECT_IN_TIME = 0.0f;
static const int CONF_DEFAULT_FAULT_DETECT_COUNT = 0;
static const double CONF_DEFAULT_VISIBILITY_CHANGE_DELAY = 0.0f;
static const int CONF_DEFAULT_CLICK_REGION = 22;
#define CONF_PATH_FORMAT "/usr/share/data-provider-master/%dx%d/conf.ini"
#if !defined(EVIOCGNAME)
#define EVIOCGNAME(len) _IOC(_IOC_READ, 'E', 0x06, len)
#endif
int errno;
struct widget_conf {
unsigned int width;
unsigned int height;
unsigned int base_width;
unsigned int base_height;
double minimum_period;
struct {
char *script;
char *abi;
char *gbar_group;
double period;
int pixels;
} default_conf;
struct {
char *name;
char *secured;
char *abi;
char *hw_acceleration;
} launch_key;
double default_packet_time;
char *empty_content;
char *empty_title;
char *default_content;
char *default_title;
unsigned long minimum_space;
char *replace_tag;
double slave_ttl;
double slave_activate_time;
double slave_relaunch_time;
int slave_relaunch_count;
int max_log_line;
int max_log_file;
unsigned long sqlite_flush_max;
struct {
char *conf;
char *image;
char *script;
char *root;
char *script_port;
char *slave_log;
char *reader;
char *always;
char *db;
char *input;
} path;
int max_size_type;
int slave_max_load;
double ping_time;
char *vconf_sys_cluster;
int max_pended_ctx_events;
int use_sw_backend;
char *provider_method;
int debug_mode;
int overwrite_content;
int com_core_thread;
int use_xmonitor;
int premultiplied;
double scale_width_factor;
double scale_height_factor;
double gbar_request_timeout;
char *emergency_disk;
char *services;
int auto_align;
int use_event_time;
int check_lcd;
int extra_buffer_count;
int use_gettimeofday;
int slave_event_boost_on;
int slave_event_boost_off;
double event_filter;
int slave_limit_to_ttl;
int frame_skip;
int slave_auto_cache_flush;
char *category_list;
double fault_detect_in_time;
int fault_detect_count;
int reactivate_on_pause;
char *app_abi;
double visibility_change_delay;
int click_region;
char *sdk_viewer;
};
static struct widget_conf s_conf;
static struct info {
int conf_loaded;
} s_info = {
.conf_loaded = 0,
};
static void visibility_change_delay_handler(char *buffer)
{
if (sscanf(buffer, "%lf", &s_conf.visibility_change_delay) != 1) {
ErrPrint("Unable to parse the visibility change delay [%s]\n", buffer);
s_conf.visibility_change_delay = 0.0f;
}
}
static void app_abi_handler(char *buffer)
{
s_conf.app_abi = strdup(buffer);
if (!s_conf.app_abi) {
ErrPrint("strdup: %d\n", errno);
}
}
static void sdk_viewer_handler(char *buffer)
{
s_conf.sdk_viewer = strdup(buffer);
if (!s_conf.sdk_viewer) {
ErrPrint("strdup: %d\n", errno);
}
}
static void detect_fault_handler(char *buffer)
{
if (sscanf(buffer, "%d,%lf", &s_conf.fault_detect_count, &s_conf.fault_detect_in_time) != 2) {
ErrPrint("Unable to parse the detect_fault [%s]\n", buffer);
s_conf.fault_detect_count = CONF_DEFAULT_FAULT_DETECT_COUNT;
s_conf.fault_detect_in_time = CONF_DEFAULT_FAULT_DETECT_IN_TIME;
}
}
static void reactivate_on_pause_handler(char *buffer)
{
s_conf.reactivate_on_pause = !strcasecmp(buffer, "true");
}
static void category_list_handler(char *buffer)
{
s_conf.category_list = strdup(buffer);
if (!s_conf.category_list) {
ErrPrint("strdup: %d\n", errno);
s_conf.category_list = (char *)CONF_DEFAULT_CATEGORY_LIST;
}
}
static void slave_auto_cache_flush_handler(char *buffer)
{
s_conf.slave_auto_cache_flush = !strcasecmp(buffer, "true");
}
static void frame_skip_handler(char *buffer)
{
if (sscanf(buffer, "%d", &s_conf.frame_skip) != 1) {
ErrPrint("Unable to get frame skip: %d\n", s_conf.frame_skip);
}
}
static void slave_limit_to_ttl_handler(char *buffer)
{
s_conf.slave_limit_to_ttl = !strcasecmp(buffer, "true");
}
static void event_filter_handler(char *buffer)
{
if (sscanf(buffer, "%lf", &s_conf.event_filter) != 1) {
ErrPrint("Unable to get event filter: %lf\n", s_conf.event_filter);
}
}
static void slave_event_boost_on_handler(char *buffer)
{
if (sscanf(buffer, "%d", &s_conf.slave_event_boost_on) != 1) {
ErrPrint("Unable to get boost on: %d\n", s_conf.slave_event_boost_on);
}
}
static void slave_event_boost_off_handler(char *buffer)
{
if (sscanf(buffer, "%d", &s_conf.slave_event_boost_off) != 1) {
ErrPrint("Unable to get boost on: %d\n", s_conf.slave_event_boost_off);
}
}
static void extra_buffer_count_handler(char *buffer)
{
if (sscanf(buffer, "%d", &s_conf.extra_buffer_count) != 1) {
ErrPrint("Extra buffer count is not valid: [%s], remained %d\n", buffer, s_conf.extra_buffer_count);
}
}
static void use_xmonitor(char *buffer)
{
s_conf.use_xmonitor = !strcasecmp(buffer, "true");
}
static void emergency_disk_handler(char *buffer)
{
s_conf.emergency_disk = strdup(buffer);
if (!s_conf.emergency_disk) {
ErrPrint("Heap: %d\n", errno);
}
}
static void check_lcd_handler(char *buffer)
{
s_conf.check_lcd = !strcasecmp(buffer, "true");
}
static void use_gettimeofday_handler(char *buffer)
{
s_conf.use_gettimeofday = !strcasecmp(buffer, "true");
}
static void use_event_time_handler(char *buffer)
{
s_conf.use_event_time = !strcasecmp(buffer, "true");
}
static void auto_align_handler(char *buffer)
{
s_conf.auto_align = !strcasecmp(buffer, "true");
}
static void services_handler(char *buffer)
{
s_conf.services = strdup(buffer);
if (!s_conf.services) {
ErrPrint("Heap: %d\n", errno);
}
}
static void use_sw_backend_handler(char *buffer)
{
s_conf.use_sw_backend = !strcasecmp(buffer, "true");
}
static void provider_method_handler(char *buffer)
{
s_conf.provider_method = strdup(buffer);
if (!s_conf.provider_method) {
ErrPrint("Heap: %d\n", errno);
}
}
static void debug_mode_handler(char *buffer)
{
s_conf.debug_mode = !strcasecmp(buffer, "true");
}
static void overwrite_content_handler(char *buffer)
{
s_conf.overwrite_content = !strcasecmp(buffer, "true");
}
static void com_core_thread_handler(char *buffer)
{
s_conf.com_core_thread = !strcasecmp(buffer, "true");
}
static void base_width_handler(char *buffer)
{
if (sscanf(buffer, "%d", &s_conf.base_width) != 1) {
if (!strncasecmp(buffer, "screen", strlen("screen"))) {
s_conf.base_width = s_conf.width;
DbgPrint("Base width: %u (screen)\n", s_conf.base_width);
} else {
ErrPrint("Failed to parse the base_width\n");
}
}
}
static void base_height_handler(char *buffer)
{
if (sscanf(buffer, "%d", &s_conf.base_height) != 1) {
if (!strncasecmp(buffer, "screen", strlen("screen"))) {
s_conf.base_height = s_conf.height;
DbgPrint("Base height: %u (screen)\n", s_conf.base_height);
} else {
ErrPrint("Failed to parse the base_height\n");
}
}
}
static void minimum_period_handler(char *buffer)
{
if (sscanf(buffer, "%lf", &s_conf.minimum_period) != 1) {
ErrPrint("Failed to parse the minimum_period\n");
}
DbgPrint("Minimum period: %lf\n", s_conf.minimum_period);
}
static void pixels_handler(char *buffer)
{
if (sscanf(buffer, "%d", &s_conf.default_conf.pixels) != 1) {
ErrPrint("Failed to parse the minimum_period\n");
}
DbgPrint("Default pixels: %lf\n", s_conf.default_conf.pixels);
}
static void script_handler(char *buffer)
{
s_conf.default_conf.script = strdup(buffer);
if (!s_conf.default_conf.script) {
ErrPrint("Heap: %d\n", errno);
}
}
static void default_abi_handler(char *buffer)
{
s_conf.default_conf.abi = strdup(buffer);
if (!s_conf.default_conf.abi) {
ErrPrint("Heap: %d\n", errno);
}
}
static void default_group_handler(char *buffer)
{
s_conf.default_conf.gbar_group = strdup(buffer);
if (!s_conf.default_conf.gbar_group) {
ErrPrint("Heap: %d\n", errno);
}
}
static void default_period_handler(char *buffer)
{
if (sscanf(buffer, "%lf", &s_conf.default_conf.period) != 1) {
ErrPrint("Failed to parse the default_period\n");
}
DbgPrint("Default Period: %lf\n", s_conf.default_conf.period);
}
static void default_packet_time_handler(char *buffer)
{
if (sscanf(buffer, "%lf", &s_conf.default_packet_time) != 1) {
ErrPrint("Failed to parse the default_packet_time\n");
}
DbgPrint("Default packet time: %lf\n", s_conf.default_packet_time);
}
static void default_content_handler(char *buffer)
{
s_conf.default_content = strdup(buffer);
if (!s_conf.default_content) {
ErrPrint("Heap: %d\n", errno);
}
}
static void default_title_handler(char *buffer)
{
s_conf.default_title = strdup(buffer);
if (!s_conf.default_title) {
ErrPrint("Heap: %d\n", errno);
}
}
static void minimum_space_handler(char *buffer)
{
if (sscanf(buffer, "%lu", &s_conf.minimum_space) != 1) {
ErrPrint("Failed to parse the minimum_space\n");
}
}
static void replace_tag_handler(char *buffer)
{
s_conf.replace_tag = strdup(buffer);
if (!s_conf.replace_tag) {
ErrPrint("Heap: %d\n", errno);
}
}
static void slave_ttl_handler(char *buffer)
{
if (sscanf(buffer, "%lf", &s_conf.slave_ttl) != 1) {
ErrPrint("Failed to parse the slave_ttl\n");
}
DbgPrint("Slave TTL: %lf\n", s_conf.slave_ttl);
}
static void slave_activate_time_handler(char *buffer)
{
if (sscanf(buffer, "%lf", &s_conf.slave_activate_time) != 1) {
ErrPrint("Failed to parse the slave_activate_time\n");
}
DbgPrint("Slave activate time: %lf\n", s_conf.slave_activate_time);
}
static void slave_relaunch_time_handler(char *buffer)
{
if (sscanf(buffer, "%lf", &s_conf.slave_relaunch_time) != 1) {
ErrPrint("Failed to parse the slave_activate_time\n");
}
DbgPrint("Slave relaunch time: %lf\n", s_conf.slave_relaunch_time);
}
static void slave_relaunch_count_handler(char *buffer)
{
if (sscanf(buffer, "%d", &s_conf.slave_relaunch_count) != 1) {
ErrPrint("Failed to parse the max_log_line\n");
}
}
static void max_log_line_handler(char *buffer)
{
if (sscanf(buffer, "%d", &s_conf.max_log_line) != 1) {
ErrPrint("Failed to parse the max_log_line\n");
}
}
static void max_log_file_handler(char *buffer)
{
if (sscanf(buffer, "%d", &s_conf.max_log_file) != 1) {
ErrPrint("Failed to parse the max_log_file\n");
}
}
static void sqlite_flush_max_handler(char *buffer)
{
if (sscanf(buffer, "%lu", &s_conf.sqlite_flush_max) != 1) {
ErrPrint("Failed to parse the sqlite_flush_max\n");
}
}
static void db_path_handler(char *buffer)
{
s_conf.path.db = strdup(buffer);
if (!s_conf.path.db) {
ErrPrint("Heap: %d\n", errno);
}
}
static void reader_path_handler(char *buffer)
{
s_conf.path.reader = strdup(buffer);
if (!s_conf.path.reader) {
ErrPrint("Heap: %d\n", errno);
}
}
static void always_path_handler(char *buffer)
{
s_conf.path.always = strdup(buffer);
if (!s_conf.path.always) {
ErrPrint("Heap: %d\n", errno);
}
}
static void log_path_handler(char *buffer)
{
s_conf.path.slave_log = strdup(buffer);
if (!s_conf.path.slave_log) {
ErrPrint("Heap: %d\n", errno);
}
}
static void script_port_path_handler(char *buffer)
{
s_conf.path.script_port = strdup(buffer);
if (!s_conf.path.script_port) {
ErrPrint("Heap: %d\n", errno);
}
}
static void share_path_handler(char *buffer)
{
s_conf.path.image = strdup(buffer);
if (!s_conf.path.image) {
ErrPrint("Heap: %d\n", errno);
}
}
static void click_region_handler(char *buffer)
{
if (sscanf(buffer, "%d", &s_conf.click_region) != 1) {
ErrPrint("Failed to parse the click_region\n");
}
}
static char *parse_handler(const char *buffer)
{
const char *node_prefix = NODE_PREFIX;
int idx = 0;
const char *ptr;
int node_idx = 0;
char *node = NULL;
ptr = buffer;
while (*ptr) {
if (ptr[idx] == node_prefix[idx]) {
idx++;
} else if (idx > 0 && node_prefix[idx] == '\0') {
if (sscanf(ptr + idx, "%d", &node_idx) == 1) {
int node_len;
node_len = idx + strlen(DEV_PATH) + 10;
/* Gotcha */
node = malloc(node_len);
if (node) {
int len;
len = snprintf(node, node_len - 1, DEV_PATH "%s%d", node_prefix, node_idx);
if (len < 0) {
ErrPrint("snprintf: %d\n", errno);
free(node);
node = NULL;
} else {
node[len] = '\0';
DbgPrint("NODE FOUND: %s\n", node);
}
} else {
ErrPrint("malloc: %d\n", errno);
}
break;
} else {
DbgPrint("Invalid format: [%s] / [%s]\n", ptr, ptr + idx);
ptr++;
idx = 0;
}
} else {
ptr++;
idx = 0;
}
}
return node;
}
static char *find_input_device_by_path(const char *name)
{
DIR *dir;
struct dirent *entry;
char path[PATH_MAX];
char *ptr;
int len;
int fd;
char dev_name[PATH_MAX];
char *return_path = NULL;
int ret;
dir = opendir(DEV_PATH);
if (!dir) {
ErrPrint("opendir: %d\n", errno);
return NULL;
}
strncpy(path, DEV_PATH, sizeof(path) - 1);
len = strlen(DEV_PATH);
ptr = path + len;
len = PATH_MAX - len - 1;
while ((entry = readdir(dir))) {
if (entry->d_name[0] == '.' &&
(entry->d_name[1] == '\0' || (entry->d_name[1] == '.' && entry->d_name[2] == '\0')))
{
continue;
}
strncpy(ptr, entry->d_name, len);
ptr[len] = '\0';
fd = open(path, O_RDONLY);
if (fd < 0) {
ErrPrint("open[%s]: %d\n", path, errno);
continue;
}
ret = ioctl(fd, EVIOCGNAME(sizeof(dev_name) - 1), &dev_name);
if (ret < 0) {
ErrPrint("ioctl: %d\n", errno);
}
if (close(fd) < 0) {
ErrPrint("close: %d\n", errno);
}
if (ret == 0 && !strcasecmp(name, dev_name)) {
return_path = strdup(path);
if (!return_path) {
ErrPrint("strdup: %d\n", errno);
}
DbgPrint("Found node: [%s]\n", return_path);
break;
}
}
if (closedir(dir) < 0) {
ErrPrint("closedir: %d\n", errno);
}
return return_path;
}
static char *find_input_device(const char *name)
{
int fd;
char *node = NULL;
char ch;
int row;
int col;
int idx;
enum state {
STATE_BEGIN,
STATE_ID,
STATE_NAME,
STATE_PHYSICAL,
STATE_SYSFS,
STATE_UNIQ,
STATE_HANDLER,
STATE_BITMAPS,
STATE_ERROR,
} state;
char name_buffer[MAX_LINE_BUFFER] = { 0, };
char handler_buffer[MAX_LINE_BUFFER] = { 0, };
fd = open(PROC_INPUT_DEVICES, O_RDONLY);
if (fd < 0) {
ErrPrint("open: %d\n", errno);
return NULL;
}
state = STATE_BEGIN;
row = 1;
col = 1;
idx = -1;
while (state != STATE_ERROR && node == NULL && read(fd, &ch, sizeof(ch)) == sizeof(ch)) {
if (ch == LF) {
row++;
col = 1;
switch (state) {
case STATE_NAME:
state = STATE_BEGIN;
if (idx > 0) {
/* Remove last double-quotes */
if (name_buffer[idx - 1] == '"') {
idx--;
}
name_buffer[idx] = '\0';
idx = -1;
DbgPrint("Name: [%s]\n", name_buffer);
}
break;
case STATE_HANDLER:
state = STATE_BEGIN;
if (idx > 0) {
handler_buffer[idx] = '\0';
idx = -1;
DbgPrint("Handler: [%s]\n", handler_buffer);
}
break;
case STATE_BEGIN:
DbgPrint("name: [%s], name_buffer[%s]\n", name, name_buffer);
if (!strcasecmp(name, name_buffer)) {
node = parse_handler(handler_buffer);
}
break;
default:
/* Ignore other attributes */
state = STATE_BEGIN;
idx = -1;
break;
}
continue;
}
col++;
switch (state) {
case STATE_BEGIN:
switch (ch) {
case 'I':
state = STATE_ID;
break;
case 'N':
state = STATE_NAME;
break;
case 'P':
state = STATE_PHYSICAL;
break;
case 'S':
state = STATE_SYSFS;
break;
case 'U':
state = STATE_UNIQ;
break;
case 'H':
state = STATE_HANDLER;
break;
case 'B':
state = STATE_BITMAPS;
break;
default:
state = STATE_ERROR;
break;
}
break;
case STATE_NAME:
if (ch == '=') {
idx = 0;
} else if (idx == MAX_LINE_BUFFER - 1) {
ErrPrint("Out of buffer\n");
} else if (idx == 0 && ch == '"') {
/* Ignore the first quotes */
} else if (idx >= 0) {
name_buffer[idx++] = ch;
}
break;
case STATE_HANDLER:
if (ch == '=') {
idx = 0;
} else if (idx == MAX_LINE_BUFFER - 1) {
ErrPrint("Out of buffer\n");
} else if (idx >= 0) {
handler_buffer[idx++] = ch;
}
break;
case STATE_ID:
case STATE_PHYSICAL:
case STATE_SYSFS:
case STATE_UNIQ:
case STATE_BITMAPS:
/* Ignore other attributes */
break;
default:
break;
}
}
if (state == STATE_ERROR) {
ErrPrint("Invalid state: ROW[%d] COL[%d]\n", row, col);
}
if (close(fd) < 0) {
ErrPrint("close: %d\n", errno);
}
return node;
}
static void input_path_handler(char *buffer)
{
if (buffer[0] == '/') {
DbgPrint("Specifying the input device\n");
s_conf.path.input = strdup(buffer);
if (!s_conf.path.input) {
ErrPrint("Heap: %d\n", errno);
}
} else {
DbgPrint("Find the input device (%s)\n", buffer);
s_conf.path.input = find_input_device_by_path(buffer);
if (s_conf.path.input == NULL) {
ErrPrint("Fallback to find node by path\n");
s_conf.path.input = find_input_device(buffer);
if (!s_conf.path.input) {
ErrPrint("Fallback to raw string\n");
s_conf.path.input = strdup(buffer);
if (!s_conf.path.input) {
ErrPrint("Heap: %d\n", errno);
}
}
}
}
}
static void ping_time_handler(char *buffer)
{
if (sscanf(buffer, "%lf", &s_conf.ping_time) != 1) {
ErrPrint("Failed to parse the ping_time\n");
}
DbgPrint("Default ping time: %lf\n", s_conf.ping_time);
}
static void slave_max_loader(char *buffer)
{
if (sscanf(buffer, "%d", &s_conf.slave_max_load) != 1) {
ErrPrint("Failed to parse the slave_max_load\n");
}
}
static void premultiplied_handler(char *buffer)
{
if (sscanf(buffer, "%d", &s_conf.premultiplied) != 1) {
ErrPrint("Failed to parse the premultiplied color\n");
}
DbgPrint("Premultiplied: %d\n", s_conf.premultiplied);
}
static void gbar_request_timeout_handler(char *buffer)
{
if (sscanf(buffer, "%lf", &s_conf.gbar_request_timeout) != 1) {
ErrPrint("Failed to parse the request_timeout\n");
}
DbgPrint("Default GBAR request timeout: %lf\n", s_conf.gbar_request_timeout);
}
EAPI void widget_conf_init(void)
{
if (s_info.conf_loaded) {
DbgPrint("Already initialized.\n");
return;
}
s_conf.width = CONF_DEFAULT_WIDTH;
s_conf.height = CONF_DEFAULT_HEIGHT;
s_conf.base_width = CONF_DEFAULT_BASE_WIDTH;
s_conf.base_height = CONF_DEFAULT_BASE_HEIGHT;
s_conf.minimum_period = CONF_DEFAULT_MINIMUM_PERIOD;
s_conf.default_conf.period = CONF_DEFAULT_PERIOD;
s_conf.default_conf.pixels = CONF_DEFAULT_PIXELS;
s_conf.minimum_space = CONF_DEFAULT_MINIMUM_SPACE;
s_conf.default_packet_time = CONF_DEFAULT_PACKET_TIME;
s_conf.slave_ttl = CONF_DEFAULT_SLAVE_TTL;
s_conf.slave_activate_time = CONF_DEFAULT_SLAVE_ACTIVATE_TIME;
s_conf.slave_relaunch_time = CONF_DEFAULT_SLAVE_RELAUNCH_TIME;
s_conf.slave_relaunch_count = CONF_DEFAULT_SLAVE_RELAUNCH_COUNT;
s_conf.max_log_line = CONF_DEFAULT_MAX_LOG_LINE;
s_conf.max_log_file = CONF_DEFAULT_MAX_LOG_FILE;
s_conf.sqlite_flush_max = CONF_DEFAULT_SQLITE_FLUSH_MAX;
s_conf.ping_time = CONF_DEFAULT_PING_TIME;
s_conf.slave_max_load = CONF_DEFAULT_SLAVE_MAX_LOAD;
s_conf.use_sw_backend = CONF_DEFAULT_USE_SW_BACKEND;
s_conf.debug_mode = CONF_DEFAULT_DEBUG_MODE;
s_conf.overwrite_content = CONF_DEFAULT_OVERWRITE_CONTENT;
s_conf.com_core_thread = CONF_DEFAULT_COM_CORE_THREAD;
s_conf.use_xmonitor = CONF_DEFAULT_USE_XMONITOR;
s_conf.scale_width_factor = CONF_DEFAULT_SCALE_WIDTH_FACTOR;
s_conf.scale_height_factor = CONF_DEFAULT_SCALE_HEIGHT_FACTOR;
s_conf.gbar_request_timeout = CONF_DEFAULT_GBAR_REQUEST_TIMEOUT;
s_conf.premultiplied = CONF_DEFAULT_PREMULTIPLIED;
s_conf.default_conf.script = (char *)CONF_DEFAULT_SCRIPT_TYPE;
s_conf.default_conf.abi = (char *)CONF_DEFAULT_ABI;
s_conf.default_conf.gbar_group = (char *)CONF_DEFAULT_GBAR_GROUP;
s_conf.launch_key.name = (char *)CONF_DEFAULT_LAUNCH_BUNDLE_NAME;
s_conf.launch_key.secured = (char *)CONF_DEFAULT_LAUNCH_BUNDLE_SECURED;
s_conf.launch_key.abi = (char *)CONF_DEFAULT_LAUNCH_BUNDLE_ABI;
s_conf.launch_key.hw_acceleration = (char *)CONF_DEFAULT_LAUNCH_BUNDLE_HW_ACCELERATION;
s_conf.empty_content = (char *)CONF_DEFAULT_EMPTY_CONTENT;
s_conf.empty_title = (char *)CONF_DEFAULT_EMPTY_TITLE;
s_conf.default_content = (char *)CONF_DEFAULT_CONTENT;
s_conf.default_title = (char *)CONF_DEFAULT_TITLE;
s_conf.replace_tag = (char *)CONF_DEFAULT_REPLACE_TAG;
s_conf.path.conf = (char *)CONF_DEFAULT_PATH_CONF;
s_conf.path.image = (char *)CONF_DEFAULT_PATH_IMAGE;
s_conf.path.slave_log = (char *)CONF_DEFAULT_PATH_LOG;
s_conf.path.reader = (char *)CONF_DEFAULT_PATH_READER;
s_conf.path.always = (char *)CONF_DEFAULT_PATH_ALWAYS;
s_conf.path.script = (char *)CONF_DEFAULT_PATH_SCRIPT;
s_conf.path.root = (char *)CONF_DEFAULT_PATH_ROOT;
s_conf.path.script_port = (char *)CONF_DEFAULT_PATH_SCRIPT_PORT;
s_conf.path.db = (char *)CONF_DEFAULT_PATH_DB;
s_conf.path.input = (char *)CONF_DEFAULT_PATH_INPUT;
s_conf.provider_method = (char *)CONF_DEFAULT_PROVIDER_METHOD;
s_conf.emergency_disk = (char *)CONF_DEFAULT_EMERGENCY_DISK;
s_conf.services = (char *)CONF_DEFAULT_SERVICES;
s_conf.category_list = (char *)CONF_DEFAULT_CATEGORY_LIST;
s_conf.auto_align = CONF_DEFAULT_AUTO_ALIGN;
s_conf.use_event_time = CONF_DEFAULT_USE_EVENT_TIME;
s_conf.check_lcd = CONF_DEFAULT_CHECK_LCD;
s_conf.extra_buffer_count = CONF_DEFAULT_EXTRA_BUFFER_COUNT;
s_conf.use_gettimeofday = CONF_DEFAULT_USE_GETTIMEOFDAY;
s_conf.slave_event_boost_on = CONF_DEFAULT_SLAVE_EVENT_BOOST_ON;
s_conf.slave_event_boost_off = CONF_DEFAULT_SLAVE_EVENT_BOOST_OFF;
s_conf.event_filter = CONF_DEFAULT_EVENT_FILTER;
s_conf.slave_limit_to_ttl = CONF_DEFAULT_SLAVE_LIMIT_TO_TTL;
s_conf.slave_auto_cache_flush = CONF_DEFAULT_SLAVE_AUTO_CACHE_FLUSH;
s_conf.fault_detect_count = CONF_DEFAULT_FAULT_DETECT_COUNT;
s_conf.fault_detect_in_time = CONF_DEFAULT_FAULT_DETECT_IN_TIME;
s_conf.reactivate_on_pause = CONF_DEFAULT_REACTIVATE_ON_PAUSE;
s_conf.app_abi = (char *)CONF_DEFAULT_APP_ABI;
s_conf.visibility_change_delay = CONF_DEFAULT_VISIBILITY_CHANGE_DELAY;
s_conf.click_region = CONF_DEFAULT_CLICK_REGION;
s_conf.sdk_viewer = (char *)CONF_DEFAULT_SDK_VIEWER;
}
/*
* Find proper configuration and install(link) it to conf path.
*/
static char *conf_path(void)
{
char *path;
int length;
length = strlen(CONF_PATH_FORMAT) + 12; // 12 == RESERVED SPACE
path = calloc(1, length);
if (!path) {
ErrPrint("calloc: %d\n", errno);
return NULL;
}
snprintf(path, length, CONF_PATH_FORMAT, s_conf.width, s_conf.height);
DbgPrint("Selected conf file: %s\n", path);
if (access(path, F_OK) != 0) {
ErrPrint("Fallback to default, access: %d\n", errno);
strncpy(path, DEFAULT_MASTER_CONF, length);
if (access(path, F_OK) != 0) {
ErrPrint("Serious error - there is no conf file, use default setting: %d\n", errno);
free(path);
path = NULL;
}
}
return path;
}
EAPI int widget_conf_load(void)
{
char *conf_file;
FILE *fp;
int c;
enum state {
START,
SPACE,
TOKEN,
VALUE,
ERROR,
COMMENT,
END
} state;
int ch_idx;
int token_idx;
int buffer_idx;
int quote;
int linelen;
char buffer[256];
static const struct token_parser {
const char *name;
void (*handler)(char *buffer);
} token_handler[] = {
{
.name = "base_width",
.handler = base_width_handler,
},
{
.name = "base_height",
.handler = base_height_handler,
},
{
.name = "minimum_period",
.handler = minimum_period_handler,
},
{
.name = "script",
.handler = script_handler,
},
{
.name = "pixels",
.handler = pixels_handler,
},
{
.name = "default_abi",
.handler = default_abi_handler,
},
{
.name = "default_group",
.handler = default_group_handler,
},
{
.name = "default_period",
.handler = default_period_handler,
},
{
.name = "default_packet_time",
.handler = default_packet_time_handler,
},
{
.name = "default_content",
.handler = default_content_handler,
},
{
.name = "default_title",
.handler = default_title_handler,
},
{
.name = "minimum_space",
.handler = minimum_space_handler,
},
{
.name = "replace_tag",
.handler = replace_tag_handler,
},
{
.name = "slave_ttl",
.handler = slave_ttl_handler,
},
{
.name = "slave_activate_time",
.handler = slave_activate_time_handler,
},
{
.name = "slave_relaunch_time",
.handler = slave_relaunch_time_handler,
},
{
.name = "slave_relaunch_count",
.handler = slave_relaunch_count_handler,
},
{
.name = "max_log_line",
.handler = max_log_line_handler,
},
{
.name = "max_log_file",
.handler = max_log_file_handler,
},
{
.name = "sqilte_flush_max",
.handler = sqlite_flush_max_handler,
},
{
.name = "db_path",
.handler = db_path_handler,
},
{
.name = "log_path",
.handler = log_path_handler,
},
{
.name = "reader_path",
.handler = reader_path_handler,
},
{
.name = "always_path",
.handler = always_path_handler,
},
{
.name = "share_path",
.handler = share_path_handler,
},
{
.name = "script_port_path",
.handler = script_port_path_handler,
},
{
.name = "ping_interval",
.handler = ping_time_handler,
},
{
.name = "slave_max_load",
.handler = slave_max_loader,
},
{
.name = "use_sw_backend",
.handler = use_sw_backend_handler,
},
{
.name = "emergency_disk",
.handler = emergency_disk_handler,
},
{
.name = "services",
.handler = services_handler,
},
{
.name = "auto_align",
.handler = auto_align_handler,
},
{
.name = "use_event_time",
.handler = use_event_time_handler,
},
{
.name = "use_gettimeofday",
.handler = use_gettimeofday_handler,
},
{
.name = "check_lcd",
.handler = check_lcd_handler,
},
{
.name = "use_xmonitor",
.handler = use_xmonitor,
},
{
.name = "provider_method",
.handler = provider_method_handler,
},
{
.name = "debug_mode",
.handler = debug_mode_handler,
},
{
.name = "overwrite_content",
.handler = overwrite_content_handler,
},
{
.name = "com_core_thread",
.handler = com_core_thread_handler,
},
{
.name = "input",
.handler = input_path_handler,
},
{
.name = "gbar_request_timeout",
.handler = gbar_request_timeout_handler,
},
{
.name = "premultiplied",
.handler = premultiplied_handler,
},
{
.name = "extra_buffer_count",
.handler = extra_buffer_count_handler,
},
{
.name = "slave_event_boost_on",
.handler = slave_event_boost_on_handler,
},
{
.name = "slave_event_boost_off",
.handler = slave_event_boost_off_handler,
},
{
.name = "event_filter",
.handler = event_filter_handler,
},
{
.name = "slave_limit_to_ttl",
.handler = slave_limit_to_ttl_handler,
},
{
.name = "frame_skip",
.handler = frame_skip_handler,
},
{
.name = "slave_auto_cache_flush",
.handler = slave_auto_cache_flush_handler,
},
{
.name = "category_list",
.handler = category_list_handler,
},
{
.name = "detect_fault",
.handler = detect_fault_handler,
},
{
.name = "reactivate_on_pause",
.handler = reactivate_on_pause_handler,
},
{
.name = "app_abi",
.handler = app_abi_handler,
},
{
.name = "sdk_viewer",
.handler = sdk_viewer_handler,
},
{
.name = "visibility_change_delay",
.handler = visibility_change_delay_handler,
},
{
.name = "click_region",
.handler = click_region_handler,
},
{
.name = NULL,
.handler = NULL,
},
};
if (s_info.conf_loaded) {
ErrPrint("Already loaded\n");
return WIDGET_ERROR_ALREADY_EXIST;
}
util_screen_size_get(&s_conf.width, &s_conf.height);
conf_file = conf_path();
if (!conf_file) {
return WIDGET_ERROR_IO_ERROR;
}
fp = fopen(conf_file, "rt");
free(conf_file);
if (!fp) {
ErrPrint("Error: %d\n", errno);
return WIDGET_ERROR_IO_ERROR;
}
state = START;
ch_idx = 0;
token_idx = -1;
buffer_idx = 0;
quote = 0;
linelen = 0;
do {
c = getc(fp);
if ((c == EOF) && (state == VALUE)) {
DbgPrint("[%s:%d] VALUE state EOF\n", __func__, __LINE__);
state = END;
}
switch (state) {
case COMMENT:
if (c == CR || c == LF || c == EOF) {
buffer[buffer_idx] = '\0';
state = START;
token_idx = -1;
ch_idx = 0;
buffer_idx = 0;
linelen = -1; /* Will be ZERO by follwing increment code */
quote = 0;
} else {
buffer[buffer_idx++] = c;
if (buffer_idx == (sizeof(buffer) - 1)) {
buffer[buffer_idx] = '\0';
buffer_idx = 0;
}
}
break;
case START:
if (linelen == 0 && c == '#') {
state = COMMENT;
} else if (isspace(c)) {
/* Ignore empty space */
} else {
state = TOKEN;
ungetc(c, fp);
}
break;
case SPACE:
if (c == '=') {
state = VALUE;
} else if (!isspace(c)) {
state = ERROR;
}
break;
case VALUE:
if (c == '"') {
if (quote == 1) {
buffer[buffer_idx] = '\0';
state = END;
} else if (buffer_idx != 0) {
buffer[buffer_idx++] = c;
if (buffer_idx >= sizeof(buffer)) {
state = ERROR;
}
} else {
quote = 1;
}
} else if (isspace(c)) {
if (buffer_idx == 0) {
/* Ignore */
} else if (quote == 1) {
buffer[buffer_idx++] = c;
if (buffer_idx >= sizeof(buffer)) {
state = ERROR;
}
} else {
buffer[buffer_idx] = '\0';
ungetc(c, fp);
state = END;
}
} else {
buffer[buffer_idx++] = c;
if (buffer_idx >= sizeof(buffer)) {
state = ERROR;
}
}
break;
case TOKEN:
if (c == '=') {
if (token_idx < 0) {
state = ERROR;
} else {
state = VALUE;
}
} else if (isspace(c)) {
if (token_idx < 0) {
break;
}
if (token_handler[token_idx].name[ch_idx] != '\0') {
state = ERROR;
} else {
state = SPACE;
}
} else {
if (token_idx < 0) {
/* Now start to find a token! */
token_idx = 0;
}
if (token_handler[token_idx].name[ch_idx] == c) {
ch_idx++;
} else {
ungetc(c, fp);
while (ch_idx-- > 0)
ungetc(token_handler[token_idx].name[ch_idx], fp);
token_idx++;
if (token_handler[token_idx].name == NULL) {
state = ERROR;
} else {
ch_idx = 0;
}
}
}
break;
case ERROR:
if (c == CR || c == LF || c == EOF) {
state = START;
token_idx = -1;
buffer_idx = 0;
ch_idx = 0;
linelen = -1;
quote = 0;
}
break;
case END:
if (c == LF || c == CR || c == EOF) {
state = START;
if (token_idx >= 0 && token_handler[token_idx].handler) {
buffer[buffer_idx] = '\0';
token_handler[token_idx].handler(buffer);
}
token_idx = -1;
ch_idx = 0;
buffer_idx = 0;
linelen = -1;
quote = 0;
/* Finish */
} else if (isspace(c)) {
/* ignore */
} else {
state = ERROR;
}
break;
default:
/* ?? */
break;
}
linelen++;
} while (c != EOF);
if (fclose(fp) != 0) {
ErrPrint("fclose: %d\n", errno);
}
s_conf.scale_width_factor = (double)s_conf.width / (double)WIDGET_CONF_BASE_W;
s_conf.scale_height_factor = (double)s_conf.height / (double)WIDGET_CONF_BASE_H;
s_info.conf_loaded = 1;
return WIDGET_ERROR_NONE;
}
EAPI void widget_conf_reset(void)
{
s_conf.width = CONF_DEFAULT_WIDTH;
s_conf.height = CONF_DEFAULT_HEIGHT;
s_conf.base_width = CONF_DEFAULT_BASE_WIDTH;
s_conf.base_height = CONF_DEFAULT_BASE_HEIGHT;
s_conf.minimum_period = CONF_DEFAULT_MINIMUM_PERIOD;
s_conf.default_conf.period = CONF_DEFAULT_PERIOD;
s_conf.minimum_space = CONF_DEFAULT_MINIMUM_SPACE;
s_conf.default_packet_time = CONF_DEFAULT_PACKET_TIME;
s_conf.slave_ttl = CONF_DEFAULT_SLAVE_TTL;
s_conf.slave_activate_time = CONF_DEFAULT_SLAVE_ACTIVATE_TIME;
s_conf.slave_relaunch_time = CONF_DEFAULT_SLAVE_RELAUNCH_TIME;
s_conf.slave_relaunch_count = CONF_DEFAULT_SLAVE_RELAUNCH_COUNT;
s_conf.max_log_line = CONF_DEFAULT_MAX_LOG_LINE;
s_conf.max_log_file = CONF_DEFAULT_MAX_LOG_FILE;
s_conf.sqlite_flush_max = CONF_DEFAULT_SQLITE_FLUSH_MAX;
s_conf.ping_time = CONF_DEFAULT_PING_TIME;
s_conf.slave_max_load = CONF_DEFAULT_SLAVE_MAX_LOAD;
s_conf.use_sw_backend = CONF_DEFAULT_USE_SW_BACKEND;
s_conf.debug_mode = CONF_DEFAULT_DEBUG_MODE;
s_conf.overwrite_content = CONF_DEFAULT_OVERWRITE_CONTENT;
s_conf.com_core_thread = CONF_DEFAULT_COM_CORE_THREAD;
s_conf.use_xmonitor = CONF_DEFAULT_USE_XMONITOR;
s_conf.scale_width_factor = CONF_DEFAULT_SCALE_WIDTH_FACTOR;
s_conf.scale_height_factor = CONF_DEFAULT_SCALE_HEIGHT_FACTOR;
s_conf.gbar_request_timeout = CONF_DEFAULT_GBAR_REQUEST_TIMEOUT;
s_conf.premultiplied = CONF_DEFAULT_PREMULTIPLIED;
s_conf.default_conf.pixels = CONF_DEFAULT_PIXELS;
s_conf.auto_align = CONF_DEFAULT_AUTO_ALIGN;
s_conf.use_event_time = CONF_DEFAULT_USE_EVENT_TIME;
s_conf.check_lcd = CONF_DEFAULT_CHECK_LCD;
s_conf.extra_buffer_count = CONF_DEFAULT_EXTRA_BUFFER_COUNT;
s_conf.use_gettimeofday = CONF_DEFAULT_USE_GETTIMEOFDAY;
s_conf.slave_event_boost_on = CONF_DEFAULT_SLAVE_EVENT_BOOST_ON;
s_conf.slave_event_boost_off = CONF_DEFAULT_SLAVE_EVENT_BOOST_OFF;
s_conf.event_filter = CONF_DEFAULT_EVENT_FILTER;
s_conf.slave_limit_to_ttl = CONF_DEFAULT_SLAVE_LIMIT_TO_TTL;
s_conf.slave_auto_cache_flush = CONF_DEFAULT_SLAVE_AUTO_CACHE_FLUSH;
s_conf.fault_detect_count = CONF_DEFAULT_FAULT_DETECT_COUNT;
s_conf.fault_detect_in_time = CONF_DEFAULT_FAULT_DETECT_IN_TIME;
s_conf.reactivate_on_pause = CONF_DEFAULT_REACTIVATE_ON_PAUSE;
if (s_conf.sdk_viewer != CONF_DEFAULT_SDK_VIEWER) {
free(s_conf.sdk_viewer);
s_conf.sdk_viewer = (char *)CONF_DEFAULT_SDK_VIEWER;
}
if (s_conf.app_abi != CONF_DEFAULT_APP_ABI) {
free(s_conf.app_abi);
s_conf.app_abi = (char *)CONF_DEFAULT_APP_ABI;
}
if (s_conf.category_list != CONF_DEFAULT_CATEGORY_LIST) {
free(s_conf.category_list);
s_conf.category_list = (char *)CONF_DEFAULT_CATEGORY_LIST;
}
if (s_conf.default_conf.script != CONF_DEFAULT_SCRIPT_TYPE) {
free(s_conf.default_conf.script);
s_conf.default_conf.script = (char *)CONF_DEFAULT_SCRIPT_TYPE;
}
if (s_conf.default_conf.abi != CONF_DEFAULT_ABI) {
free(s_conf.default_conf.abi);
s_conf.default_conf.abi = (char *)CONF_DEFAULT_ABI;
}
if (s_conf.default_conf.gbar_group != CONF_DEFAULT_GBAR_GROUP) {
free(s_conf.default_conf.gbar_group);
s_conf.default_conf.gbar_group = (char *)CONF_DEFAULT_GBAR_GROUP;
}
if (s_conf.launch_key.name != CONF_DEFAULT_LAUNCH_BUNDLE_NAME) {
free(s_conf.launch_key.name);
s_conf.launch_key.name = (char *)CONF_DEFAULT_LAUNCH_BUNDLE_NAME;
}
if (s_conf.launch_key.secured != CONF_DEFAULT_LAUNCH_BUNDLE_SECURED) {
free(s_conf.launch_key.secured);
s_conf.launch_key.secured = (char *)CONF_DEFAULT_LAUNCH_BUNDLE_SECURED;
}
if (s_conf.launch_key.abi != CONF_DEFAULT_LAUNCH_BUNDLE_ABI) {
free(s_conf.launch_key.abi);
s_conf.launch_key.abi = (char *)CONF_DEFAULT_LAUNCH_BUNDLE_ABI;
}
if (s_conf.launch_key.hw_acceleration != CONF_DEFAULT_LAUNCH_BUNDLE_HW_ACCELERATION) {
free(s_conf.launch_key.hw_acceleration);
s_conf.launch_key.hw_acceleration = (char *)CONF_DEFAULT_LAUNCH_BUNDLE_HW_ACCELERATION;
}
if (s_conf.empty_content != CONF_DEFAULT_EMPTY_CONTENT) {
free(s_conf.empty_content);
s_conf.empty_content = (char *)CONF_DEFAULT_EMPTY_CONTENT;
}
if (s_conf.empty_title != CONF_DEFAULT_EMPTY_TITLE) {
free(s_conf.empty_title);
s_conf.empty_title = (char *)CONF_DEFAULT_EMPTY_TITLE;
}
if (s_conf.default_content != CONF_DEFAULT_CONTENT) {
free(s_conf.default_content);
s_conf.default_content = (char *)CONF_DEFAULT_CONTENT;
}
if (s_conf.default_title != CONF_DEFAULT_TITLE) {
free(s_conf.default_title);
s_conf.default_title = (char *)CONF_DEFAULT_TITLE;
}
if (s_conf.replace_tag != CONF_DEFAULT_REPLACE_TAG) {
free(s_conf.replace_tag);
s_conf.replace_tag = (char *)CONF_DEFAULT_REPLACE_TAG;
}
if (s_conf.path.conf != CONF_DEFAULT_PATH_CONF) {
free(s_conf.path.conf);
s_conf.path.conf = (char *)CONF_DEFAULT_PATH_CONF;
}
if (s_conf.path.image != CONF_DEFAULT_PATH_IMAGE) {
free(s_conf.path.image);
s_conf.path.image = (char *)CONF_DEFAULT_PATH_IMAGE;
}
if (s_conf.path.slave_log != CONF_DEFAULT_PATH_LOG) {
free(s_conf.path.slave_log);
s_conf.path.slave_log = (char *)CONF_DEFAULT_PATH_LOG;
}
if (s_conf.path.reader != CONF_DEFAULT_PATH_READER) {
free(s_conf.path.reader);
s_conf.path.reader = (char *)CONF_DEFAULT_PATH_READER;
}
if (s_conf.path.always != CONF_DEFAULT_PATH_ALWAYS) {
free(s_conf.path.always);
s_conf.path.always = (char *)CONF_DEFAULT_PATH_ALWAYS;
}
if (s_conf.path.script != CONF_DEFAULT_PATH_SCRIPT) {
free(s_conf.path.script);
s_conf.path.script = (char *)CONF_DEFAULT_PATH_SCRIPT;
}
if (s_conf.path.root != CONF_DEFAULT_PATH_ROOT) {
free(s_conf.path.root);
s_conf.path.root = (char *)CONF_DEFAULT_PATH_ROOT;
}
if (s_conf.path.script_port != CONF_DEFAULT_PATH_SCRIPT_PORT) {
free(s_conf.path.script_port);
s_conf.path.script_port = (char *)CONF_DEFAULT_PATH_SCRIPT_PORT;
}
if (s_conf.path.db != CONF_DEFAULT_PATH_DB) {
free(s_conf.path.db);
s_conf.path.db = (char *)CONF_DEFAULT_PATH_DB;
}
if (s_conf.path.input != CONF_DEFAULT_PATH_INPUT) {
free(s_conf.path.input);
s_conf.path.input = (char *)CONF_DEFAULT_PATH_INPUT;
}
if (s_conf.provider_method != CONF_DEFAULT_PROVIDER_METHOD) {
free(s_conf.provider_method);
s_conf.provider_method = (char *)CONF_DEFAULT_PROVIDER_METHOD;
}
if (s_conf.emergency_disk != CONF_DEFAULT_EMERGENCY_DISK) {
free(s_conf.emergency_disk);
s_conf.emergency_disk = (char *)CONF_DEFAULT_EMERGENCY_DISK;
}
if (s_conf.services != CONF_DEFAULT_SERVICES) {
free(s_conf.services);
s_conf.services = (char *)CONF_DEFAULT_SERVICES;
}
s_conf.click_region = CONF_DEFAULT_CLICK_REGION;
s_info.conf_loaded = 0;
}
EAPI const int const widget_conf_extra_buffer_count(void)
{
return s_conf.extra_buffer_count;
}
EAPI const int const widget_conf_use_xmonitor(void)
{
return s_conf.use_xmonitor;
}
EAPI const char * const widget_conf_emergency_disk(void)
{
return s_conf.emergency_disk;
}
EAPI const int const widget_conf_check_lcd(void)
{
return s_conf.check_lcd;
}
EAPI const int const widget_conf_use_event_time(void)
{
return s_conf.use_event_time;
}
EAPI const int const widget_conf_auto_align(void)
{
return s_conf.auto_align;
}
EAPI const char * const widget_conf_services(void)
{
return s_conf.services;
}
EAPI const int const widget_conf_use_sw_backend(void)
{
return s_conf.use_sw_backend;
}
EAPI const char * const widget_conf_provider_method(void)
{
return s_conf.provider_method;
}
EAPI const int const widget_conf_debug_mode(void)
{
return s_conf.debug_mode;
}
EAPI const int const widget_conf_overwrite_content(void)
{
return s_conf.overwrite_content;
}
EAPI const int const widget_conf_com_core_thread(void)
{
return s_conf.com_core_thread;
}
EAPI const unsigned int const widget_conf_base_width(void)
{
return s_conf.base_width;
}
EAPI const unsigned int const widget_conf_base_height(void)
{
return s_conf.base_height;
}
EAPI const double const widget_conf_minimum_period(void)
{
return s_conf.minimum_period;
}
EAPI const int const widget_conf_default_pixels(void)
{
return s_conf.default_conf.pixels;
}
EAPI const char * const widget_conf_default_script(void)
{
return s_conf.default_conf.script;
}
EAPI const char * const widget_conf_default_abi(void)
{
return s_conf.default_conf.abi;
}
EAPI const char * const widget_conf_default_gbar_group(void)
{
return s_conf.default_conf.gbar_group;
}
EAPI const double const widget_conf_default_period(void)
{
return s_conf.default_conf.period;
}
EAPI const double const widget_conf_default_packet_time(void)
{
return s_conf.default_packet_time;
}
EAPI const char * const widget_conf_default_content(void)
{
return s_conf.default_content;
}
EAPI const char * const widget_conf_default_title(void)
{
return s_conf.default_title;
}
EAPI const unsigned long const widget_conf_minimum_space(void)
{
return s_conf.minimum_space;
}
EAPI const char * const widget_conf_replace_tag(void)
{
return s_conf.replace_tag;
}
EAPI const double const widget_conf_slave_ttl(void)
{
return s_conf.slave_ttl;
}
EAPI const double const widget_conf_slave_activate_time(void)
{
return s_conf.slave_activate_time;
}
EAPI const double const widget_conf_slave_relaunch_time(void)
{
return s_conf.slave_relaunch_time;
}
EAPI const int const widget_conf_slave_relaunch_count(void)
{
return s_conf.slave_relaunch_count;
}
EAPI const int const widget_conf_max_log_line(void)
{
return s_conf.max_log_line;
}
EAPI const int const widget_conf_max_log_file(void)
{
return s_conf.max_log_file;
}
EAPI const unsigned long const widget_conf_sqlite_flush_max(void)
{
return s_conf.sqlite_flush_max;
}
EAPI const char * const widget_conf_db_path(void)
{
return s_conf.path.db;
}
EAPI const char * const widget_conf_reader_path(void)
{
return s_conf.path.reader;
}
EAPI const char * const widget_conf_always_path(void)
{
return s_conf.path.always;
}
EAPI const char * const widget_conf_log_path(void)
{
return s_conf.path.slave_log;
}
EAPI const char * const widget_conf_script_port(void)
{
return s_conf.path.script_port;
}
EAPI const char * const widget_conf_script_path(void)
{
return s_conf.path.script;
}
EAPI const char * const widget_conf_share_path(void)
{
return s_conf.path.image;
}
EAPI const char * const widget_conf_input_path(void)
{
return s_conf.path.input;
}
EAPI const double const widget_conf_ping_time(void)
{
return s_conf.ping_time;
}
EAPI const int const widget_conf_slave_max_load(void)
{
return s_conf.slave_max_load;
}
EAPI const int const widget_conf_premultiplied_alpha(void)
{
return s_conf.premultiplied;
}
EAPI const double const widget_conf_gbar_request_timeout(void)
{
return s_conf.gbar_request_timeout;
}
EAPI const double const widget_conf_scale_width_factor(void)
{
return s_conf.scale_width_factor;
}
EAPI const double const widget_conf_scale_height_factor(void)
{
return s_conf.scale_height_factor;
}
EAPI const char * const widget_conf_launch_key_name(void)
{
return s_conf.launch_key.name;
}
EAPI const char * const widget_conf_launch_key_secured(void)
{
return s_conf.launch_key.secured;
}
EAPI const char * const widget_conf_launch_key_abi(void)
{
return s_conf.launch_key.abi;
}
EAPI const char * const widget_conf_launch_key_hw_acceleration(void)
{
return s_conf.launch_key.hw_acceleration;
}
EAPI const char * const widget_conf_empty_content(void)
{
return s_conf.empty_content;
}
EAPI const char * const widget_conf_empty_title(void)
{
return s_conf.empty_title;
}
EAPI const char * const widget_conf_path(void)
{
return s_conf.path.conf;
}
EAPI const char * const widget_conf_root_path(void)
{
return s_conf.path.root;
}
EAPI const int const widget_conf_is_loaded(void)
{
return s_info.conf_loaded;
}
EAPI const int const widget_conf_use_gettimeofday(void)
{
return s_conf.use_gettimeofday;
}
EAPI const int const widget_conf_slave_event_boost_on(void)
{
return s_conf.slave_event_boost_on;
}
EAPI const int const widget_conf_slave_event_boost_off(void)
{
return s_conf.slave_event_boost_off;
}
EAPI const double const widget_conf_event_filter(void)
{
return s_conf.event_filter;
}
EAPI const int const widget_conf_slave_limit_to_ttl(void)
{
return s_conf.slave_limit_to_ttl;
}
EAPI const int const widget_conf_frame_skip(void)
{
return s_conf.frame_skip;
}
EAPI const int const widget_conf_slave_auto_cache_flush(void)
{
return s_conf.slave_auto_cache_flush;
}
EAPI const char * const widget_conf_category_list(void)
{
return s_conf.category_list;
}
EAPI double widget_conf_fault_detect_in_time(void)
{
return s_conf.fault_detect_in_time;
}
EAPI int widget_conf_fault_detect_count(void)
{
return s_conf.fault_detect_count;
}
EAPI int widget_conf_reactivate_on_pause(void)
{
return s_conf.reactivate_on_pause;
}
EAPI const char * const widget_conf_app_abi(void)
{
return s_conf.app_abi;
}
EAPI double widget_conf_visibility_change_delay(void)
{
return s_conf.visibility_change_delay;
}
EAPI int widget_conf_click_region(void)
{
return s_conf.click_region;
}
EAPI const char * const widget_conf_sdk_viewer(void)
{
return s_conf.sdk_viewer;
}
/* End of a file */
|