Fix Prevent and remove compile warning messages
[platform/core/appfw/ail.git] / tool / src / ail_desktop.c
1 /*
2  * ail
3  *
4  * Copyright (c) 2000 - 2011 Samsung Electronics Co., Ltd. All rights reserved.
5  *
6  * Contact: Jayoun Lee <airjany@samsung.com>, Sewook Park <sewook7.park@samsung.com>, Jaeho Lee <jaeho81.lee@samsung.com>
7  *
8  * Licensed under the Apache License, Version 2.0 (the "License");
9  * you may not use this file except in compliance with the License.
10  * You may obtain a copy of the License at
11  *
12  * http://www.apache.org/licenses/LICENSE-2.0
13  *
14  * Unless required by applicable law or agreed to in writing, software
15  * distributed under the License is distributed on an "AS IS" BASIS,
16  * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
17  * See the License for the specific language governing permissions and
18  * limitations under the License.
19  *
20  */
21
22 #include <stdio.h>
23 #include <stdlib.h>
24 #include <string.h>
25 #include <unistd.h>
26 #include <sys/stat.h>
27 #include <sys/types.h>
28 #include <fcntl.h>
29
30 #include <ail.h>
31
32 static void _print_help(const char *cmd)
33 {
34         fprintf(stderr, "Usage:\n");
35         fprintf(stderr, "\n");
36         fprintf(stderr, "[Add a desktop]\n");
37         fprintf(stderr, "       %s add <PACKAGE NAME>\n", cmd);
38         fprintf(stderr, "\n");
39         fprintf(stderr, "       Ex) %s add com.samsung.menu-screen\n", cmd);
40         fprintf(stderr, "\n");
41         fprintf(stderr, "[Update a desktop]\n");
42         fprintf(stderr, "       %s update <PACKAGE NAME>\n", cmd);
43         fprintf(stderr, "\n");
44         fprintf(stderr, "       Ex) %s update com.samsung.menu-screen\n", cmd);
45         fprintf(stderr, "\n");
46         fprintf(stderr, "[Remove a desktop]\n");
47         fprintf(stderr, "       %s remove <PACKAGE NAME>\n", cmd);
48         fprintf(stderr, "\n");
49         fprintf(stderr, "       Ex) %s remove com.samsung.menu-screen\n", cmd);
50         fprintf(stderr, "\n");
51 }
52
53 static ail_error_e _add_desktop(const char *package)
54 {
55         ail_error_e ret;
56
57         if (!package)
58                 return AIL_ERROR_FAIL;
59
60         ret = ail_desktop_add(package);
61         if (ret != AIL_ERROR_OK)
62                 return AIL_ERROR_FAIL;
63
64         return AIL_ERROR_OK;
65 }
66
67 static ail_error_e _update_desktop(const char *package)
68 {
69         ail_error_e ret;
70
71         if (!package)
72                 return AIL_ERROR_FAIL;
73
74         ret = ail_desktop_update(package);
75         if (ret != AIL_ERROR_OK)
76                 return AIL_ERROR_FAIL;
77
78         return AIL_ERROR_OK;
79 }
80
81 static ail_error_e _remove_desktop(const char *package)
82 {
83         ail_error_e ret;
84
85         if (!package)
86                 return AIL_ERROR_FAIL;
87
88         ret = ail_desktop_remove(package);
89         if (ret != AIL_ERROR_OK)
90                 return AIL_ERROR_FAIL;
91
92         return AIL_ERROR_OK;
93 }
94
95 int main(int argc, char **argv)
96 {
97         ail_error_e ret = AIL_ERROR_OK;
98
99         if (3 == argc) {
100                 if (!strncmp(argv[1], "add", 3))
101                         ret = _add_desktop(argv[2]);
102                 else if (!strncmp(argv[1], "update", 6))
103                         ret = _update_desktop(argv[2]);
104                 else if (!strncmp(argv[1], "remove", 6))
105                         ret = _remove_desktop(argv[2]);
106                 else
107                         fprintf(stderr, "%s is a invalid command\n", argv[1]);
108         } else {
109                 _print_help(argv[0]);
110                 return EXIT_FAILURE;
111         }
112
113         if (ret != AIL_ERROR_OK)
114                 fprintf(stderr, "There are some problems\n");
115
116         return EXIT_SUCCESS;
117 }