tizen 2.3 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 <glib.h>
28 #include <dbus/dbus.h>
29 #include <aul.h>
30
31 #include "syspopup_core.h"
32 #include "syspopup_db.h"
33 #include "syspopup_api.h"
34 #include "simple_util.h"
35
36 API int syspopup_launch(char *popup_name, bundle *b)
37 {
38         syspopup_info_t *info = NULL;
39         int ret;
40         int is_bundle = 0;
41
42         if (popup_name == NULL) {
43                 _E("popup_name is NULL");
44                 return -1;
45         }
46
47         info = _syspopup_info_get(popup_name);
48         if (info == NULL || info->pkgname == NULL) {
49                 _E("info or info->pkgname is NULL");
50                 if (info)
51                         _syspopup_info_free(info);
52                 return -1;
53         }
54
55         if (b == NULL) {
56                 b = bundle_create();
57                 is_bundle = 1;
58         }
59
60         if (_syspopup_set_name_to_bundle(b, popup_name) < 0) {
61                 _E("bundle set error\n");
62                 _syspopup_info_free(info);
63
64                 if (is_bundle == 1) {
65                         bundle_free(b);
66                 }
67                 return -1;
68         }
69
70         ret = aul_launch_app(info->pkgname, b);
71         if (ret < 0) {
72                 _E("aul launch error - %d", ret);
73         }
74
75         if (is_bundle == 1) {
76                 bundle_free(b);
77         }
78
79         _syspopup_info_free(info);
80
81         return ret;
82 }
83
84 API int syspopup_destroy_all()
85 {
86         DBusMessage *message;
87         DBusError error;
88         DBusConnection *bus = NULL;
89
90         dbus_error_init(&error);
91         bus = dbus_bus_get_private(DBUS_BUS_SYSTEM, &error);
92         if (bus == NULL) {
93                 _E("Failed to connect to the D-BUS daemon: %s", error.message);
94                 dbus_error_free(&error);
95                 return -1;
96         }
97
98         message = dbus_message_new_signal(SYSPOPUP_DBUS_PATH,
99                                           SYSPOPUP_DBUS_SIGNAL_INTERFACE,
100                                           SYSPOPUP_DBUS_SP_TERM_SIGNAL);
101
102         if (dbus_connection_send(bus, message, NULL) == FALSE) {
103                 _E("dbus send error");
104                 return -1;
105         }
106
107         dbus_connection_flush(bus);
108         dbus_message_unref(message);
109
110         dbus_connection_close(bus);
111
112         _D("send signal done\n");
113
114         return 0;
115 }
116