2 * Copyright 2012 Samsung Electronics Co., Ltd
4 * Licensed under the Flora License, Version 1.0 (the "License");
5 * you may not use this file except in compliance with the License.
6 * You may obtain a copy of the License at
8 * http://www.tizenopensource.org/license
10 * Unless required by applicable law or agreed to in writing, software
11 * distributed under the License is distributed on an "AS IS" BASIS,
12 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13 * See the License for the specific language governing permissions and
14 * limitations under the License.
22 #include <Elementary.h>
33 #include "critical_log.h"
37 #include "so_handler.h"
42 Ecore_Timer *ping_timer;
47 static int method_new(struct event_arg *arg, int *width, int *height, double *priority, void *data)
50 DbgPrint("Create: pkgname[%s], id[%s], content[%s], timeout[%d], has_script[%d], period[%lf], cluster[%s], category[%s], skip[%d], abi[%s], size: %dx%d\n",
53 arg->info.lb_create.content,
54 arg->info.lb_create.timeout,
55 arg->info.lb_create.has_script,
56 arg->info.lb_create.period,
57 arg->info.lb_create.cluster, arg->info.lb_create.category,
58 arg->info.lb_create.skip_need_to_create,
59 arg->info.lb_create.abi,
60 arg->info.lb_create.width,
61 arg->info.lb_create.height);
63 ret = lb_create(arg->pkgname, arg->id,
64 arg->info.lb_create.content,
65 arg->info.lb_create.timeout,
66 arg->info.lb_create.has_script,
67 arg->info.lb_create.period,
68 arg->info.lb_create.cluster,
69 arg->info.lb_create.category,
70 width, height, priority,
71 arg->info.lb_create.skip_need_to_create,
72 arg->info.lb_create.abi,
73 &arg->info.lb_create.out_content,
74 &arg->info.lb_create.out_title);
77 if (arg->info.lb_create.width > 0 && arg->info.lb_create.height > 0) {
78 if (*width != arg->info.lb_create.width || *height != arg->info.lb_create.height) {
80 tmp = lb_resize(arg->pkgname, arg->id, arg->info.lb_create.width, arg->info.lb_create.height);
81 DbgPrint("Resize[%dx%d] returns: %d\n", arg->info.lb_create.width, arg->info.lb_create.height, tmp);
85 arg->info.lb_create.out_is_pinned_up = (lb_is_pinned_up(arg->pkgname, arg->id) == 1);
91 static int method_renew(struct event_arg *arg, void *data)
98 DbgPrint("Re-create: pkgname[%s], id[%s], content[%s], timeout[%d], has_script[%d], period[%lf], cluster[%s], category[%s], abi[%s]\n",
99 arg->pkgname, arg->id,
100 arg->info.lb_recreate.content,
101 arg->info.lb_recreate.timeout,
102 arg->info.lb_recreate.has_script,
103 arg->info.lb_recreate.period,
104 arg->info.lb_recreate.cluster,
105 arg->info.lb_recreate.category,
106 arg->info.lb_recreate.abi);
108 ret = lb_create(arg->pkgname, arg->id,
109 arg->info.lb_recreate.content,
110 arg->info.lb_recreate.timeout,
111 arg->info.lb_recreate.has_script,
112 arg->info.lb_recreate.period,
113 arg->info.lb_recreate.cluster,
114 arg->info.lb_recreate.category,
117 arg->info.lb_recreate.abi,
118 &arg->info.lb_recreate.out_content,
119 &arg->info.lb_recreate.out_title);
121 if (w != arg->info.lb_recreate.width || h != arg->info.lb_recreate.height) {
123 tmp = lb_resize(arg->pkgname, arg->id, arg->info.lb_recreate.width, arg->info.lb_recreate.height);
124 DbgPrint("Resize[%dx%d] returns: %d\n", arg->info.lb_recreate.width, arg->info.lb_recreate.height, tmp);
126 DbgPrint("No need to change the size: %dx%d\n", w, h);
129 arg->info.lb_recreate.out_is_pinned_up = (lb_is_pinned_up(arg->pkgname, arg->id) == 1);
135 static int method_delete(struct event_arg *arg, void *data)
138 DbgPrint("pkgname[%s] id[%s]\n", arg->pkgname, arg->id);
139 ret = lb_destroy(arg->pkgname, arg->id);
143 static int method_content_event(struct event_arg *arg, void *data)
146 struct event_info info;
148 info = arg->info.content_event.info;
150 ret = lb_script_event(arg->pkgname, arg->id,
151 arg->info.content_event.emission, arg->info.content_event.source,
156 static int method_clicked(struct event_arg *arg, void *data)
160 DbgPrint("pkgname[%s] id[%s] event[%s] timestamp[%lf] x[%lf] y[%lf]\n",
161 arg->pkgname, arg->id,
162 arg->info.clicked.event, arg->info.clicked.timestamp,
163 arg->info.clicked.x, arg->info.clicked.y);
164 ret = lb_clicked(arg->pkgname, arg->id,
165 arg->info.clicked.event,
166 arg->info.clicked.timestamp, arg->info.clicked.x, arg->info.clicked.y);
171 static int method_text_signal(struct event_arg *arg, void *data)
174 struct event_info info;
176 info = arg->info.text_signal.info;
178 DbgPrint("pkgname[%s] id[%s] emission[%s] source[%s]\n", arg->pkgname, arg->id, arg->info.text_signal.emission, arg->info.text_signal.source);
179 ret = lb_script_event(arg->pkgname, arg->id,
180 arg->info.text_signal.emission, arg->info.text_signal.source,
186 static int method_resize(struct event_arg *arg, void *data)
190 DbgPrint("pkgname[%s] id[%s] w[%d] h[%d]\n", arg->pkgname, arg->id, arg->info.resize.w, arg->info.resize.h);
191 ret = lb_resize(arg->pkgname, arg->id, arg->info.resize.w, arg->info.resize.h);
196 static int method_set_period(struct event_arg *arg, void *data)
199 DbgPrint("pkgname[%s] id[%s] period[%lf]\n", arg->pkgname, arg->id, arg->info.set_period.period);
200 ret = lb_set_period(arg->pkgname, arg->id, arg->info.set_period.period);
204 static int method_change_group(struct event_arg *arg, void *data)
207 DbgPrint("pkgname[%s] id[%s] cluster[%s] category[%s]\n", arg->pkgname, arg->id, arg->info.change_group.cluster, arg->info.change_group.category);
208 ret = lb_change_group(arg->pkgname, arg->id, arg->info.change_group.cluster, arg->info.change_group.category);
212 static int method_pinup(struct event_arg *arg, void *data)
214 DbgPrint("pkgname[%s] id[%s] state[%d]\n", arg->pkgname, arg->id, arg->info.pinup.state);
215 arg->info.pinup.content_info = lb_pinup(arg->pkgname, arg->id, arg->info.pinup.state);
216 return arg->info.pinup.content_info ? 0 : -ENOTSUP;
219 static int method_update_content(struct event_arg *arg, void *data)
223 if (!arg->id || !strlen(arg->id)) {
224 DbgPrint("pkgname[%s] cluster[%s] category[%s]\n", arg->pkgname, arg->info.update_content.cluster, arg->info.update_content.category);
225 ret = lb_update_all(arg->pkgname, arg->info.update_content.cluster, arg->info.update_content.category);
227 DbgPrint("Update [%s]\n", arg->id);
228 ret = lb_update(arg->pkgname, arg->id);
234 static int method_pause(struct event_arg *arg, void *data)
237 if (s_info.ping_timer)
238 ecore_timer_freeze(s_info.ping_timer);
240 sqlite3_release_memory(SQLITE_FLUSH_MAX);
245 static int method_resume(struct event_arg *arg, void *data)
248 if (s_info.ping_timer)
249 ecore_timer_thaw(s_info.ping_timer);
253 static Eina_Bool send_ping_cb(void *data)
255 provider_send_ping();
256 return ECORE_CALLBACK_RENEW;
259 static int method_disconnected(struct event_arg *arg, void *data)
261 if (s_info.ping_timer) {
262 ecore_timer_del(s_info.ping_timer);
263 s_info.ping_timer = NULL;
270 static int method_connected(struct event_arg *arg, void *data)
273 ret = provider_send_hello();
275 s_info.ping_timer = ecore_timer_add(DEFAULT_PING_TIME, send_ping_cb, NULL);
276 if (!s_info.ping_timer)
277 ErrPrint("Failed to add a ping timer\n");
283 static int method_pd_created(struct event_arg *arg, void *data)
287 ret = lb_open_pd(arg->pkgname);
288 DbgPrint("%s Open PD: %d\n", arg->pkgname, ret);
293 static int method_pd_destroyed(struct event_arg *arg, void *data)
297 ret = lb_close_pd(arg->pkgname);
298 DbgPrint("%s Close PD: %d\n", arg->pkgname, ret);
303 static int method_pd_move(struct event_arg *arg, void *data)
306 struct event_info info;
308 memset(&info, 0, sizeof(info));
309 info.pointer.x = arg->info.pd_move.x;
310 info.pointer.y = arg->info.pd_move.y;
311 info.pointer.down = 0;
313 ret = lb_script_event(arg->pkgname, arg->id,
314 "pd,move", util_uri_to_path(arg->id), &info);
318 static int method_lb_pause(struct event_arg *arg, void *data)
320 return lb_pause(arg->pkgname, arg->id);
323 static int method_lb_resume(struct event_arg *arg, void *data)
325 return lb_resume(arg->pkgname, arg->id);
328 HAPI int client_init(const char *name)
330 struct event_handler table = {
331 .lb_create = method_new,
332 .lb_recreate = method_renew,
333 .lb_destroy = method_delete,
334 .content_event = method_content_event,
335 .clicked = method_clicked,
336 .text_signal = method_text_signal,
337 .resize = method_resize,
338 .set_period = method_set_period,
339 .change_group = method_change_group,
340 .pinup = method_pinup,
341 .update_content = method_update_content,
342 .pause = method_pause,
343 .resume = method_resume,
344 .disconnected = method_disconnected,
345 .connected = method_connected,
346 .pd_create = method_pd_created,
347 .pd_destroy = method_pd_destroyed,
348 .pd_move = method_pd_move,
349 .lb_pause = method_lb_pause,
350 .lb_resume = method_lb_resume,
355 return provider_init(ecore_x_display_get(), name, &table, NULL);
358 HAPI int client_fini(void)
360 (void)provider_fini();