tizen beta release
[framework/base/syspopup.git] / syspopup-caller / syspopup_caller.c
1 /*
2  * syspopup
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>,
7  * Jaeho Lee <jaeho81.lee@samsung.com>
8  *
9  * Licensed under the Apache License, Version 2.0 (the "License");
10  * you may not use this file except in compliance with the License.
11  * You may obtain a copy of the License at
12  *
13  * http://www.apache.org/licenses/LICENSE-2.0
14  *
15  * Unless required by applicable law or agreed to in writing, software
16  * distributed under the License is distributed on an "AS IS" BASIS,
17  * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
18  * See the License for the specific language governing permissions and
19  * limitations under the License.
20  *
21  */
22
23
24 #include <sys/types.h>
25 #include <sys/stat.h>
26 #include <fcntl.h>
27 #include <aul.h>
28
29 #include "syspopup_core.h"
30 #include "syspopup_db.h"
31 #include "syspopup_api.h"
32 #include "simple_util.h"
33
34 API int syspopup_launch(char *popup_name, bundle *b)
35 {
36         syspopup_info_t *info = NULL;
37         int ret;
38         int is_bundle = 0;
39
40         if (popup_name == NULL) {
41                 _E("popup_name is NULL");
42                 return -1;
43         }
44
45         info = _syspopup_info_get(popup_name);
46         if (info == NULL || info->pkgname == NULL) {
47                 _E("info or info->pkgname is NULL");
48                 if(info)
49                         _syspopup_info_free(info);
50                 return -1;
51         }
52
53         if (b == NULL) {
54                 b = bundle_create();
55                 is_bundle = 1;
56         }
57
58         if (_syspopup_set_name_to_bundle(b, popup_name) < 0) {
59                 _E("bundle set error\n");
60                 _syspopup_info_free(info);
61
62                 if (is_bundle == 1) {
63                         bundle_free(b);
64                 }
65                 return -1;
66         }
67
68         ret = aul_launch_app(info->pkgname, b);
69         if (ret < 0) {
70                 _E("aul launch error - %d", ret);
71         }
72
73         if (is_bundle == 1) {
74                 bundle_free(b);
75         }
76
77         _syspopup_info_free(info);
78
79         return ret;
80 }
81
82 API int syspopup_destroy_all()
83 {
84         int fd;
85         fd = open(SYSPOPUP_TERM_NOTI_PATH, O_CREAT | O_TRUNC | O_RDWR, 0644);
86         close(fd);
87         return 0;
88 }
89