Merge "Move internal header to src directory" into tizen
[platform/core/api/app-manager.git] / tool / main.c
1 /*
2 Copyright (c) 2011 Samsung Electronics Co., Ltd All Rights Reserved
3 PROPRIETARY/CONFIDENTIAL
4 This software is the confidential and proprietary information of
5 SAMSUNG ELECTRONICS ("Confidential Information"). You agree and acknowledge that
6 this software is owned by Samsung and you
7 shall not disclose such Confidential Information and shall
8 use it only in accordance with the terms of the license agreement
9 you entered into with SAMSUNG ELECTRONICS.  SAMSUNG make no
10 representations or warranties about the suitability
11 of the software, either express or implied, including but not
12 limited to the implied warranties of merchantability, fitness for
13 a particular purpose, or non-infringement.
14 SAMSUNG shall not be liable for any damages suffered by licensee arising out of or
15 related to this software.
16 */
17
18 #include <stdio.h>
19 #include <stdlib.h>
20 #include <string.h>
21 #include <unistd.h>
22 #include <sys/stat.h>
23 #include <sys/types.h>
24 #include <fcntl.h>
25
26 #include <app_manager.h>
27
28
29
30 static void _print_help(const char *cmd)
31 {
32         fprintf(stderr, "Usage:\n");
33         fprintf(stderr, "\n");
34         fprintf(stderr, "[Get appinfo value]\n");
35         fprintf(stderr, "    %s <app_id>\n", cmd);
36         fprintf(stderr, "\n");
37         fprintf(stderr, "Ex) %s com.samsung.memo\n", cmd);
38         fprintf(stderr, "\n");
39 }
40
41
42
43 static int _get_appinfo(const char *app_id)
44 {
45         app_info_h app_info;
46         int ret;
47         char *appid = NULL;
48         char *label = NULL;
49         char *icon = NULL;
50         char *package = NULL;
51         char *type = NULL;
52
53         ret = app_manager_get_app_info(app_id, &app_info);
54         if (ret != APP_MANAGER_ERROR_NONE) {
55                 fprintf(stderr, "No corresponding app_id for [%s]\n", app_id);
56                 return APP_MANAGER_ERROR_NO_SUCH_APP;
57         }
58
59         app_info_get_app_id(app_info, &appid);
60         app_info_get_label(app_info, &label);
61         app_info_get_icon(app_info, &icon);
62         app_info_get_package(app_info, &package);
63         app_info_get_type(app_info, &type);
64
65         fprintf(stderr, "appid   = [%s]\n", appid);
66         fprintf(stderr, "label   = [%s]\n", label);
67         fprintf(stderr, "icon    = [%s]\n", icon);
68         fprintf(stderr, "package = [%s]\n", package);
69         fprintf(stderr, "type    = [%s]\n", type);
70
71         ret = app_info_destroy(app_info);
72         if (ret != APP_MANAGER_ERROR_NONE) {
73                 return APP_MANAGER_ERROR_IO_ERROR;
74         }
75
76         free(appid);
77         free(label);
78         free(icon);
79         free(package);
80         free(type);
81
82         return APP_MANAGER_ERROR_NONE;
83 }
84
85 int main(int argc, char** argv)
86 {
87         int ret = APP_MANAGER_ERROR_NONE;
88
89         if (2 == argc) {
90                 ret = _get_appinfo(argv[1]);
91         }
92         else {
93                 _print_help(argv[0]);
94                 return EXIT_FAILURE;
95         }
96
97         if (ret != APP_MANAGER_ERROR_NONE) {
98                 fprintf(stderr, "There are some problems\n");
99         }
100
101         return EXIT_SUCCESS;
102 }
103
104