4 * Copyright (c) 2000 - 2011 Samsung Electronics Co., Ltd. All rights reserved.
6 * Contact: Jayoun Lee <airjany@samsung.com>, Sewook Park <sewook7.park@samsung.com>,
7 * Jaeho Lee <jaeho81.lee@samsung.com>
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
13 * http://www.apache.org/licenses/LICENSE-2.0
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.
27 #include <dbus/dbus.h>
28 #include <dbus/dbus-glib-lowlevel.h>
29 #include "syspopup_core.h"
30 #include "simple_util.h"
32 #define SYSPOPUP_NAME "_INTERNAL_SYSPOPUP_NAME_"
34 static syspopup *syspopup_head = NULL;
36 static int initialized = 0;
37 static DBusConnection *bus;
38 static int noti_fd = -1;
41 static void (*_term_handler) (void *data);
42 static gboolean(*_timeout_handler) (void *data);
44 syspopup *_syspopup_get_head()
49 int _syspopup_add_new(syspopup *sp)
55 sp->next = syspopup_head;
61 syspopup *_syspopup_find(const char *name)
67 if (strcmp(tmp->name, name) == 0)
75 syspopup *_syspopup_find_by_id(int id)
87 static void __syspopup_free(syspopup *sp)
91 if (sp->dupped_bundle != NULL)
92 bundle_free(sp->dupped_bundle);
96 void _syspopup_del(int id)
101 target = _syspopup_find_by_id(id);
103 if (syspopup_head == NULL || target == NULL)
106 if (syspopup_head == target) {
107 syspopup_head = target->next;
108 __syspopup_free(target);
114 if (tmp->next == target) {
115 tmp->next = target->next;
116 __syspopup_free(target);
124 static DBusHandlerResult
125 __sys_popup_dbus_signal_filter(DBusConnection *conn, DBusMessage *message,
129 const char *interface;
133 dbus_error_init(&error);
135 interface = dbus_message_get_interface(message);
136 if (interface == NULL) {
137 _E("reject by security issue - no interface\n");
138 return DBUS_HANDLER_RESULT_NOT_YET_HANDLED;
141 if (dbus_message_is_signal(message, interface,
142 SYSPOPUP_DBUS_SP_TERM_SIGNAL)) {
146 _D("term handler has been called");
149 return DBUS_HANDLER_RESULT_HANDLED;
154 int _syspopup_init(void (*term_handler) (void *),
155 gboolean(*timeout_handler) (void *))
158 char rule[MAX_LOCAL_BUFSZ];
163 _term_handler = term_handler;
164 _timeout_handler = timeout_handler;
166 dbus_error_init(&error);
167 bus = dbus_bus_get_private(DBUS_BUS_SYSTEM, &error);
169 _E("Failed to connect to the D-BUS daemon: %s", error.message);
170 dbus_error_free(&error);
173 dbus_connection_setup_with_g_main(bus, NULL);
175 snprintf(rule, MAX_LOCAL_BUFSZ,
176 "path='%s',type='signal',interface='%s'", SYSPOPUP_DBUS_PATH,
177 SYSPOPUP_DBUS_SIGNAL_INTERFACE);
178 /* listening to messages */
179 dbus_bus_add_match(bus, rule, &error);
180 if (dbus_error_is_set(&error)) {
181 _E("Fail to rule set: %s", error.message);
182 dbus_error_free(&error);
186 if (dbus_connection_add_filter(bus,
187 __sys_popup_dbus_signal_filter, NULL, NULL) == FALSE)
190 _D("syspopup signal initialized");
196 int _syspopup_reset_timeout(syspopup *sp, syspopup_info_t *info)
199 _E("no initialized");
203 _E("syspopup is NULL");
207 _E("syspopup info is NULL");
211 if (sp->timeout_id != 0)
212 g_source_remove(sp->timeout_id);
214 if(info->timeout > 0) {
215 sp->timeout_id = g_timeout_add_seconds(info->timeout, _timeout_handler,
217 _D("add timeout - timeout : id=%d,timeout=%d(sec)", sp->id,
224 int _syspopup_set_term_type(syspopup *sp, syspopup_info_t *info)
226 sp->term_act = info->term_act;
230 int _syspopup_set_endkey_type(syspopup *sp, syspopup_info_t *info)
232 sp->endkey_act = info->endkey_act;
236 const char *_syspopup_get_name_from_bundle(bundle *b)
240 if (getuid() != 0 && getuid() != 5000) {
241 _E("syspopup permission error");
246 _E("bundle is NULL");
250 name = bundle_get_val(b, SYSPOPUP_NAME);
252 _E("this is no bundle for syspopup");
257 int _syspopup_set_name_to_bundle(bundle *b, char *popup_name)
259 if ((b == NULL) || (popup_name == NULL))
261 bundle_add(b, SYSPOPUP_NAME, popup_name);