0140d20c780dedb168a257de75146d34fd43bdb8
[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
33 static void _print_help(const char *cmd)
34 {
35         fprintf(stderr, "Usage:\n");
36         fprintf(stderr, "\n");
37         fprintf(stderr, "[Add a desktop]\n");
38         fprintf(stderr, "       %s add <PACKAGE NAME>\n", cmd);
39         fprintf(stderr, "\n");
40         fprintf(stderr, "       Ex) %s add com.samsung.menu-screen\n", cmd);
41         fprintf(stderr, "\n");
42         fprintf(stderr, "[Update a desktop]\n");
43         fprintf(stderr, "       %s update <PACKAGE NAME>\n", cmd);
44         fprintf(stderr, "\n");
45         fprintf(stderr, "       Ex) %s update com.samsung.menu-screen\n", cmd);
46         fprintf(stderr, "\n");
47         fprintf(stderr, "[Remove a desktop]\n");
48         fprintf(stderr, "       %s remove <PACKAGE NAME>\n", cmd);
49         fprintf(stderr, "\n");
50         fprintf(stderr, "       Ex) %s remove com.samsung.menu-screen\n", cmd);
51         fprintf(stderr, "\n");
52 }
53
54
55
56 static ail_error_e _add_desktop(const char *package)
57 {
58         ail_error_e ret;
59
60         if (!package) {
61                 return AIL_ERROR_FAIL;
62         }
63
64         ret = ail_desktop_add(package);
65         if (ret != AIL_ERROR_OK) {
66                 return AIL_ERROR_FAIL;
67         }
68
69         return AIL_ERROR_OK;
70 }
71
72
73
74 static ail_error_e _update_desktop(const char *package)
75 {
76         ail_error_e ret;
77
78         if (!package) {
79                 return AIL_ERROR_FAIL;
80         }
81
82         ret = ail_desktop_update(package);
83         if (ret != AIL_ERROR_OK) {
84                 return AIL_ERROR_FAIL;
85         }
86
87         return AIL_ERROR_OK;
88 }
89
90
91
92 static ail_error_e _remove_desktop(const char *package)
93 {
94         ail_error_e ret;
95
96         if (!package) {
97                 return AIL_ERROR_FAIL;
98         }
99
100         ret = ail_desktop_remove(package);
101         if (ret != AIL_ERROR_OK) {
102                 return AIL_ERROR_FAIL;
103         }
104
105         return AIL_ERROR_OK;
106 }
107
108
109
110 int main(int argc, char** argv)
111 {
112         ail_error_e ret = AIL_ERROR_OK;
113
114         if (3 == argc) {
115                 if (!strncmp(argv[1], "add", 3)) {
116                         ret = _add_desktop(argv[2]);
117                 } else if (!strncmp(argv[1], "update", 6)) {
118                         ret = _update_desktop(argv[2]);
119                 } else if (!strncmp(argv[1], "remove", 6)) {
120                         ret = _remove_desktop(argv[2]);
121                 } else {
122                         fprintf(stderr, "%s is a invalid command\n", argv[1]);
123                 }
124         }
125         else {
126                 _print_help(argv[0]);
127                 return EXIT_FAILURE;
128         }
129
130         if (ret != AIL_ERROR_OK) {
131                 fprintf(stderr, "There are some problems\n");
132         }
133
134         return EXIT_SUCCESS;
135 }
136