Fix build issue for x64
[platform/core/appfw/ail.git] / tool / src / main.c.tail
1
2
3 static void _print_help(const char *cmd)
4 {
5         int i;
6
7         fprintf(stderr, "Usage:\n");
8         fprintf(stderr, "\n");
9         fprintf(stderr, "[Get appinfo value]\n");
10         fprintf(stderr, "       %s get <PACKAGE NAME> <COLUMN NAME>\n", cmd);
11         fprintf(stderr, "\n");
12         fprintf(stderr, "       <COLUMN NAME>\n");
13
14         for (i = 0; prop_tbl[i]; i++) {
15                 fprintf(stderr, "          %s\n", prop_tbl[i]);
16         }
17
18         fprintf(stderr, "\n");
19         fprintf(stderr, "       Ex) %s get com.samsung.menu-screen X_SLP_SERVICE\n", cmd);
20         fprintf(stderr, "\n");
21 }
22
23
24
25 static int _get_property(const char *property)
26 {
27         int i;
28
29         if (!property) {
30                 return 0;
31         }
32
33         for (i = 0; prop_tbl[i]; i++) {
34                 if (!strcasecmp(prop_tbl[i], property)) {
35                         return i;
36                 }
37         }
38
39         fprintf(stderr, "%s is not found\n", property);
40
41         return -1;
42 }
43
44
45
46 static ail_error_e _get_appinfo(const char *package, const char *property)
47 {
48         ail_appinfo_h handle;
49         ail_error_e ret;
50         int prop, ival;
51         bool bval;
52         char *str;
53         struct element e;
54         struct element *p;
55         int t;
56
57         ret = ail_package_get_appinfo(package, &handle);
58         if (ret != AIL_ERROR_OK) {
59                 return AIL_ERROR_FAIL;
60         }
61
62         prop = _get_property(property);
63         if (prop < 0) {
64                 return AIL_ERROR_FAIL;
65         }
66
67         e.prop = prop;
68         p = &e;
69         ELEMENT_TYPE(p,t);
70
71         if (t == VAL_TYPE_STR) {
72                 ret = ail_appinfo_get_str(handle, prop, &str);
73                 if (ret != AIL_ERROR_OK) {
74                         return AIL_ERROR_FAIL;
75                 }
76                 fprintf(stderr, "Package[%s], Property[%s] : %s\n", package, property, str);
77         } else if (t == VAL_TYPE_INT) {
78                 ret = ail_appinfo_get_int(handle, prop, &ival);
79                 if (ret != AIL_ERROR_OK) {
80                         return AIL_ERROR_FAIL;
81                 }
82                 fprintf(stderr, "Package[%s], Property[%s] : %d\n", package, property, ival);
83         } else if (t == VAL_TYPE_BOOL) {
84                 ret = ail_appinfo_get_bool(handle, prop, &bval);
85                 if (ret != AIL_ERROR_OK) {
86                         return AIL_ERROR_FAIL;
87                 }
88                 fprintf(stderr, "Package[%s], Property[%s] : %d\n", package, property, bval);
89         }
90
91         ret = ail_package_destroy_appinfo(handle);
92         if (ret != AIL_ERROR_OK) {
93                 return AIL_ERROR_FAIL;
94         }
95
96         return AIL_ERROR_OK;
97 }
98
99 int main(int argc, char** argv)
100 {
101         ail_error_e ret = AIL_ERROR_OK;
102
103         
104         if (4 == argc) {
105                 if (!strncmp(argv[1], "get", 3)) {
106                         ret = _get_appinfo(argv[2], argv[3]);
107                 }
108         }
109         else {
110                 _print_help(argv[0]);
111                 return EXIT_FAILURE;
112         }
113
114         if (ret != AIL_ERROR_OK) {
115                 fprintf(stderr, "There are some problems\n");
116         }
117
118         return EXIT_SUCCESS;
119 }
120
121