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.
28 #include "syspopup_core.h"
29 #include "simple_util.h"
31 #define SYSPOPUP_NAME "_INTERNAL_SYSPOPUP_NAME_"
33 static syspopup *syspopup_head = NULL;
35 static int initialized = 0;
36 static int noti_fd = -1;
39 static void (*_term_handler) (void *data);
40 static gboolean(*_timeout_handler) (void *data);
42 syspopup *_syspopup_get_head()
47 int _syspopup_add_new(syspopup *sp)
53 sp->next = syspopup_head;
59 syspopup *_syspopup_find(const char *name)
65 if (strcmp(tmp->name, name) == 0)
73 syspopup *_syspopup_find_by_id(int id)
85 static void __syspopup_free(syspopup *sp)
89 if (sp->dupped_bundle != NULL)
90 bundle_free(sp->dupped_bundle);
94 void _syspopup_del(int id)
99 target = _syspopup_find_by_id(id);
101 if (syspopup_head == NULL || target == NULL)
104 if (syspopup_head == target) {
105 syspopup_head = target->next;
106 __syspopup_free(target);
112 if (tmp->next == target) {
113 tmp->next = target->next;
114 __syspopup_free(target);
121 int _syspopup_init(void (*term_handler) (void *),
122 gboolean(*timeout_handler) (void *))
127 _term_handler = term_handler;
128 _timeout_handler = timeout_handler;
130 noti_fd = heynoti_init();
132 _E("heynoti add failed\n");
136 if (heynoti_subscribe_file(noti_fd, SYSPOPUP_TERM_NOTI_PATH,
138 IN_CLOSE_WRITE | IN_DELETE_SELF) < 0) {
139 _E("heynoti subscribe file failed");
142 if (heynoti_attach_handler(noti_fd) < 0)
143 _E("heynoti attach failed");
150 int _syspopup_reset_timeout(syspopup *sp, syspopup_info_t *info)
153 _E("no initialized");
157 _E("syspopup is NULL");
161 _E("syspopup info is NULL");
165 if (sp->timeout_id != 0)
166 g_source_remove(sp->timeout_id);
167 sp->timeout_id = g_timeout_add_seconds(info->timeout, _timeout_handler,
169 _D("add timeout - timeout : id=%d,timeout=%d(sec)", sp->id,
175 int _syspopup_set_term_type(syspopup *sp, syspopup_info_t *info)
177 sp->term_act = info->term_act;
181 int _syspopup_set_endkey_type(syspopup *sp, syspopup_info_t *info)
183 sp->endkey_act = info->endkey_act;
187 const char *_syspopup_get_name_from_bundle(bundle *b)
191 if (getuid() != 0 && getuid() != 5000) {
192 _E("syspopup permission error");
197 _E("bundle is NULL");
201 name = bundle_get_val(b, SYSPOPUP_NAME);
203 _E("this is no bundle for syspopup");
208 int _syspopup_set_name_to_bundle(bundle *b, char *popup_name)
210 if ((b == NULL) || (popup_name == NULL))
212 bundle_add(b, SYSPOPUP_NAME, popup_name);