2 * Copyright 2014 Samsung Electronics Co., Ltd
4 * Licensed under the Flora License, Version 1.1 (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://floralicense.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.
19 #include <stdlib.h> /* malloc */
20 #include <string.h> /* strdup */
25 #include <sys/types.h>
31 #include <com-core_packet.h>
33 #include <widget_errno.h>
34 #include <widget_service.h>
35 #include <widget_service_internal.h>
36 #include <widget_cmd_list.h>
37 #include <widget_buffer.h>
41 #include "widget_viewer.h"
42 #include "widget_viewer_internal.h"
45 #include "master_rpc.h"
49 #define EAPI __attribute__((visibility("default")))
50 #if !defined(WIDGET_COUNT_OF_SIZE_TYPE)
51 #define WIDGET_COUNT_OF_SIZE_TYPE 13
58 static int default_launch_handler(widget_h handle, const char *appid, void *data);
62 int prevent_overwrite;
64 struct dlist *job_list;
67 int (*handle)(widget_h handle, const char *appid, void *data);
72 .prevent_overwrite = 0,
76 .handle = default_launch_handler,
81 static void widget_pixmap_acquired_cb(widget_h handle, const struct packet *result, void *data);
82 static void gbar_pixmap_acquired_cb(widget_h handle, const struct packet *result, void *data);
83 static void gbar_xpixmap_acquired_cb(widget_h handle, const struct packet *result, void *data);
84 static void widget_xpixmap_acquired_cb(widget_h handle, const struct packet *result, void *data);
86 static int default_launch_handler(widget_h handle, const char *appid, void *data)
90 ret = aul_launch_app(appid, NULL);
92 ErrPrint("Failed to launch an app %s (%d)\n", appid, ret);
96 app_control_h service;
98 DbgPrint("AUTO_LAUNCH [%s]\n", handle->common->widget.auto_launch);
100 ret = app_control_create(&service);
101 if (ret == APP_CONTROL_ERROR_NONE) {
102 app_control_set_package(service, handle->common->widget.auto_launch);
103 app_control_send_launch_request(service, NULL, NULL);
104 app_control_destroy(service);
106 ErrPrint("Failed to launch an app %s (%d)\n", handle->common->widget.auto_launch, ret);
110 return ret > 0 ? WIDGET_ERROR_NONE : WIDGET_ERROR_FAULT;
113 static inline void default_create_cb(widget_h handle, int ret, void *data)
115 DbgPrint("Default created event handle: %d\n", ret);
118 static inline void default_pinup_cb(widget_h handle, int ret, void *data)
120 DbgPrint("Default pinup event handle: %d\n", ret);
123 static inline void default_group_changed_cb(widget_h handle, int ret, void *data)
125 DbgPrint("Default group changed event handle: %d\n", ret);
128 static inline void default_period_changed_cb(widget_h handle, int ret, void *data)
130 DbgPrint("Default period changed event handle: %d\n", ret);
133 static inline void default_gbar_created_cb(widget_h handle, int ret, void *data)
135 DbgPrint("Default GBAR created event handle: %d\n", ret);
138 static inline void default_gbar_destroyed_cb(widget_h handle, int ret, void *data)
140 DbgPrint("Default GBAR destroyed event handle: %d\n", ret);
143 static inline void default_widget_size_changed_cb(widget_h handle, int ret, void *data)
145 DbgPrint("Default WIDGET size changed event handle: %d\n", ret);
148 static inline void default_update_mode_cb(widget_h handle, int ret, void *data)
150 DbgPrint("Default update mode set event handle: %d\n", ret);
153 static inline void default_access_event_cb(widget_h handle, int ret, void *data)
155 DbgPrint("Default access event handle: %d\n", ret);
158 static inline void default_key_event_cb(widget_h handle, int ret, void *data)
160 DbgPrint("Default key event handle: %d\n", ret);
163 static void update_mode_cb(widget_h handle, const struct packet *result, void *data)
168 ret = WIDGET_ERROR_FAULT;
170 } else if (packet_get(result, "i", &ret) != 1) {
171 ErrPrint("Invalid argument\n");
172 ret = WIDGET_ERROR_INVALID_PARAMETER;
177 ErrPrint("Resize request is failed: %d\n", ret);
184 handle->cbs.update_mode.cb(handle, ret, handle->cbs.update_mode.data);
185 handle->cbs.update_mode.cb = NULL;
186 handle->cbs.update_mode.data = NULL;
187 handle->common->request.update_mode = 0;
189 if (handle->common->state != WIDGET_STATE_DELETE) {
190 if (ret == (int)WIDGET_ERROR_NOT_EXIST && handle->refcnt == 2) {
191 _widget_invoke_event_handler(handle, WIDGET_EVENT_DELETED);
192 _widget_unref(handle, 1);
197 static void resize_cb(widget_h handle, const struct packet *result, void *data)
202 ret = WIDGET_ERROR_FAULT;
204 } else if (packet_get(result, "i", &ret) != 1) {
205 ErrPrint("Invalid argument\n");
206 ret = WIDGET_ERROR_INVALID_PARAMETER;
212 * In case of resize request,
213 * The widget handle will not have resized value right after this callback,
214 * It can only get the new size when it makes updates.
216 * So the user can only get the resized value(result) from the first update event
217 * after this request.
220 ErrPrint("Resize request is failed: %d\n", ret);
227 handle->cbs.size_changed.cb(handle, ret, handle->cbs.size_changed.data);
228 handle->cbs.size_changed.cb = NULL;
229 handle->cbs.size_changed.data = NULL;
230 handle->common->request.size_changed = 0;
232 if (handle->common->state != WIDGET_STATE_DELETE) {
233 if (ret == (int)WIDGET_ERROR_NOT_EXIST && handle->refcnt == 2) {
234 _widget_invoke_event_handler(handle, WIDGET_EVENT_DELETED);
235 _widget_unref(handle, 1);
240 static void text_signal_cb(widget_h handle, const struct packet *result, void *data)
244 struct cb_info *info = data;
249 _widget_destroy_cb_info(info);
252 ret = WIDGET_ERROR_FAULT;
253 } else if (packet_get(result, "i", &ret) != 1) {
254 ErrPrint("Invalid argument\n");
255 ret = WIDGET_ERROR_INVALID_PARAMETER;
259 cb(handle, ret, cbdata);
264 static void set_group_ret_cb(widget_h handle, const struct packet *result, void *data)
269 ret = WIDGET_ERROR_FAULT;
271 } else if (packet_get(result, "i", &ret) != 1) {
272 ErrPrint("Invalid argument\n");
273 ret = WIDGET_ERROR_INVALID_PARAMETER;
284 handle->cbs.group_changed.cb(handle, ret, handle->cbs.group_changed.data);
285 handle->cbs.group_changed.cb = NULL;
286 handle->cbs.group_changed.data = NULL;
287 handle->common->request.group_changed = 0;
289 if (handle->common->state != WIDGET_STATE_DELETE) {
290 if (ret == (int)WIDGET_ERROR_NOT_EXIST && handle->refcnt == 2) {
291 _widget_invoke_event_handler(handle, WIDGET_EVENT_DELETED);
292 _widget_unref(handle, 1);
297 static void period_ret_cb(widget_h handle, const struct packet *result, void *data)
302 ret = WIDGET_ERROR_FAULT;
304 } else if (packet_get(result, "i", &ret) != 1) {
305 ErrPrint("Invalid argument\n");
306 ret = WIDGET_ERROR_INVALID_PARAMETER;
317 handle->cbs.period_changed.cb(handle, ret, handle->cbs.period_changed.data);
318 handle->cbs.period_changed.cb = NULL;
319 handle->cbs.period_changed.data = NULL;
320 handle->common->request.period_changed = 0;
322 if (handle->common->state != WIDGET_STATE_DELETE) {
323 if (ret == (int)WIDGET_ERROR_NOT_EXIST && handle->refcnt == 2) {
324 _widget_invoke_event_handler(handle, WIDGET_EVENT_DELETED);
325 _widget_unref(handle, 1);
330 static void gbar_create_cb(widget_h handle, const struct packet *result, void *data)
335 ret = WIDGET_ERROR_FAULT;
337 } else if (packet_get(result, "i", &ret) != 1) {
338 ret = WIDGET_ERROR_INVALID_PARAMETER;
343 ErrPrint("Failed to create a GBAR[%d]\n", ret);
350 handle->cbs.gbar_created.cb(handle, ret, handle->cbs.gbar_created.data);
351 handle->cbs.gbar_created.cb = NULL;
352 handle->cbs.gbar_created.data = NULL;
353 handle->common->request.gbar_created = 0;
355 if (handle->common->state != WIDGET_STATE_DELETE) {
356 if (ret == (int)WIDGET_ERROR_NOT_EXIST && handle->refcnt == 2) {
357 _widget_invoke_event_handler(handle, WIDGET_EVENT_DELETED);
358 _widget_unref(handle, 1);
363 static void activated_cb(widget_h handle, const struct packet *result, void *data)
366 struct cb_info *info = data;
369 const char *pkgname = "";
373 _widget_destroy_cb_info(info);
376 ret = WIDGET_ERROR_FAULT;
377 } else if (packet_get(result, "is", &ret, &pkgname) != 2) {
378 ret = WIDGET_ERROR_INVALID_PARAMETER;
382 cb(handle, ret, cbdata);
386 static void gbar_destroy_cb(widget_h handle, const struct packet *result, void *data)
391 struct cb_info *info = data;
395 _widget_destroy_cb_info(info);
398 ErrPrint("Result is NIL (may connection lost)\n");
399 ret = WIDGET_ERROR_FAULT;
400 } else if (packet_get(result, "i", &ret) != 1) {
401 ErrPrint("Invalid parameter\n");
402 ret = WIDGET_ERROR_INVALID_PARAMETER;
405 if (ret == (int)WIDGET_ERROR_NONE) {
406 handle->cbs.gbar_destroyed.cb = cb;
407 handle->cbs.gbar_destroyed.data = cbdata;
409 handle->common->is_gbar_created = 0;
410 handle->common->request.gbar_destroyed = 0;
413 cb(handle, ret, cbdata);
418 static void _delete_cluster_cb(widget_h handle, const struct packet *result, void *data)
420 struct cb_info *info = data;
427 _widget_destroy_cb_info(info);
430 ret = WIDGET_ERROR_FAULT;
431 } else if (packet_get(result, "i", &ret) != 1) {
432 ret = WIDGET_ERROR_INVALID_PARAMETER;
436 cb(handle, ret, cbdata);
440 static void _delete_category_cb(widget_h handle, const struct packet *result, void *data)
442 struct cb_info *info = data;
449 _widget_destroy_cb_info(info);
452 ret = WIDGET_ERROR_FAULT;
453 } else if (packet_get(result, "i", &ret) != 1) {
454 ret = WIDGET_ERROR_INVALID_PARAMETER;
458 cb(handle, ret, cbdata);
462 static int _widget_acquire_widget_pixmap(widget_h handle, widget_ret_cb cb, void *data)
464 struct packet *packet;
465 struct cb_info *cbinfo;
467 unsigned int cmd = CMD_WIDGET_ACQUIRE_PIXMAP;
470 id = fb_id(handle->common->widget.fb);
471 if (!id || strncasecmp(id, SCHEMA_PIXMAP, strlen(SCHEMA_PIXMAP))) {
472 return WIDGET_ERROR_INVALID_PARAMETER;
475 packet = packet_create((const char *)&cmd, "ss", handle->common->pkgname, handle->common->id);
477 ErrPrint("Failed to build a param\n");
478 return WIDGET_ERROR_FAULT;
481 cbinfo = _widget_create_cb_info(cb, data);
483 packet_destroy(packet);
484 return WIDGET_ERROR_FAULT;
487 ret = master_rpc_async_request(handle, packet, 0, widget_pixmap_acquired_cb, cbinfo);
489 _widget_destroy_cb_info(cbinfo);
495 static void widget_pixmap_acquired_cb(widget_h handle, const struct packet *result, void *data)
498 int ret = WIDGET_ERROR_INVALID_PARAMETER;
501 struct cb_info *info = data;
505 _widget_destroy_cb_info(info);
508 pixmap = 0; /* PIXMAP 0 means error */
509 } else if (packet_get(result, "ii", &pixmap, &ret) != 2) {
513 if (ret == (int)WIDGET_ERROR_RESOURCE_BUSY) {
514 ret = _widget_acquire_widget_pixmap(handle, cb, cbdata);
515 DbgPrint("Busy, Try again: %d\n", ret);
517 } else if (ret == (int)WIDGET_ERROR_NOT_EXIST && handle->refcnt == 2) {
519 cb(handle, pixmap, cbdata);
522 if (handle->common->state != WIDGET_STATE_DELETE) {
523 _widget_invoke_event_handler(handle, WIDGET_EVENT_DELETED);
524 _widget_unref(handle, 1);
528 cb(handle, pixmap, cbdata);
533 static void widget_xpixmap_acquired_cb(widget_h handle, const struct packet *result, void *data)
536 int ret = WIDGET_ERROR_INVALID_PARAMETER;
539 struct cb_info *info = data;
543 _widget_destroy_cb_info(info);
547 } else if (packet_get(result, "ii", &pixmap, &ret) != 2) {
552 cb(handle, pixmap, cbdata);
555 if (handle->common->state != WIDGET_STATE_DELETE) {
556 if (ret == (int)WIDGET_ERROR_NOT_EXIST && handle->refcnt == 2) {
557 _widget_invoke_event_handler(handle, WIDGET_EVENT_DELETED);
558 _widget_unref(handle, 1);
563 static int widget_acquire_gbar_extra_pixmap(widget_h handle, int idx, widget_ret_cb cb, void *data)
565 struct packet *packet;
566 struct cb_info *cbinfo;
567 unsigned int cmd = CMD_GBAR_ACQUIRE_XPIXMAP;
570 packet = packet_create((const char *)&cmd, "ssi", handle->common->pkgname, handle->common->id, idx);
572 ErrPrint("Failed to build a param\n");
573 return WIDGET_ERROR_FAULT;
576 cbinfo = _widget_create_cb_info(cb, data);
578 packet_destroy(packet);
579 return WIDGET_ERROR_FAULT;
582 ret = master_rpc_async_request(handle, packet, 0, gbar_xpixmap_acquired_cb, cbinfo);
586 * Packet will be destroyed by master_rpc_async_request
588 _widget_destroy_cb_info(cbinfo);
594 static int widget_acquire_widget_extra_pixmap(widget_h handle, int idx, widget_ret_cb cb, void *data)
596 struct packet *packet;
597 struct cb_info *cbinfo;
598 unsigned int cmd = CMD_WIDGET_ACQUIRE_XPIXMAP;
601 packet = packet_create((const char *)&cmd, "ssi", handle->common->pkgname, handle->common->id, idx);
603 ErrPrint("Failed to build a param\n");
604 return WIDGET_ERROR_FAULT;
607 cbinfo = _widget_create_cb_info(cb, data);
609 packet_destroy(packet);
610 return WIDGET_ERROR_FAULT;
613 ret = master_rpc_async_request(handle, packet, 0, widget_xpixmap_acquired_cb, cbinfo);
617 * Packet will be destroyed by master_rpc_async_request
619 _widget_destroy_cb_info(cbinfo);
625 static int widget_acquire_gbar_pixmap(widget_h handle, widget_ret_cb cb, void *data)
627 struct packet *packet;
628 struct cb_info *cbinfo;
629 unsigned int cmd = CMD_GBAR_ACQUIRE_PIXMAP;
633 id = fb_id(handle->common->gbar.fb);
634 if (!id || strncasecmp(id, SCHEMA_PIXMAP, strlen(SCHEMA_PIXMAP))) {
635 return WIDGET_ERROR_INVALID_PARAMETER;
638 packet = packet_create((const char *)&cmd, "ss", handle->common->pkgname, handle->common->id);
640 ErrPrint("Failed to build a param\n");
641 return WIDGET_ERROR_FAULT;
644 cbinfo = _widget_create_cb_info(cb, data);
646 packet_destroy(packet);
647 return WIDGET_ERROR_FAULT;
650 ret = master_rpc_async_request(handle, packet, 0, gbar_pixmap_acquired_cb, cbinfo);
654 * Packet will be destroyed by master_rpc_async_request
656 _widget_destroy_cb_info(cbinfo);
662 static void gbar_xpixmap_acquired_cb(widget_h handle, const struct packet *result, void *data)
668 struct cb_info *info = data;
672 _widget_destroy_cb_info(info);
675 pixmap = 0; /* PIXMAP 0 means error */
676 ret = WIDGET_ERROR_FAULT;
677 } else if (packet_get(result, "ii", &pixmap, &ret) != 2) {
679 ret = WIDGET_ERROR_INVALID_PARAMETER;
683 DbgPrint("ret: %x, pixmap: %d\n", ret, pixmap);
684 cb(handle, pixmap, cbdata);
687 if (handle->common->state != WIDGET_STATE_DELETE) {
688 if (ret == (int)WIDGET_ERROR_NOT_EXIST && handle->refcnt == 2) {
689 _widget_invoke_event_handler(handle, WIDGET_EVENT_DELETED);
690 _widget_unref(handle, 1);
695 static void gbar_pixmap_acquired_cb(widget_h handle, const struct packet *result, void *data)
701 struct cb_info *info = data;
705 _widget_destroy_cb_info(info);
708 pixmap = 0; /* PIXMAP 0 means error */
709 ret = WIDGET_ERROR_FAULT;
710 } else if (packet_get(result, "ii", &pixmap, &ret) != 2) {
712 ret = WIDGET_ERROR_INVALID_PARAMETER;
715 if (ret == (int)WIDGET_ERROR_RESOURCE_BUSY) {
716 ret = widget_acquire_gbar_pixmap(handle, cb, cbdata);
717 DbgPrint("Busy, Try again: %d\n", ret);
719 } else if (ret == (int)WIDGET_ERROR_NOT_EXIST && handle->refcnt == 2) {
721 cb(handle, pixmap, cbdata);
724 if (handle->common->state != WIDGET_STATE_DELETE) {
725 _widget_invoke_event_handler(handle, WIDGET_EVENT_DELETED);
726 _widget_unref(handle, 1);
730 DbgPrint("ret: %d, pixmap: %d\n", ret, pixmap);
731 cb(handle, pixmap, cbdata);
736 static void pinup_done_cb(widget_h handle, const struct packet *result, void *data)
741 ret = WIDGET_ERROR_FAULT;
743 } else if (packet_get(result, "i", &ret) != 1) {
754 handle->cbs.pinup.cb(handle, ret, handle->cbs.pinup.data);
755 handle->cbs.pinup.cb = NULL;
756 handle->cbs.pinup.data = NULL;
757 handle->common->request.pinup = 0;
759 if (handle->common->state != WIDGET_STATE_DELETE) {
760 if (ret == (int)WIDGET_ERROR_NOT_EXIST && handle->refcnt == 2) {
761 _widget_invoke_event_handler(handle, WIDGET_EVENT_DELETED);
762 _widget_unref(handle, 1);
767 static void key_ret_cb(widget_h handle, const struct packet *result, void *data)
772 ret = WIDGET_ERROR_FAULT;
776 if (packet_get(result, "i", &ret) != 1) {
777 ret = WIDGET_ERROR_INVALID_PARAMETER;
781 if (ret != WIDGET_ERROR_NONE) {
787 handle->cbs.key_event.cb(handle, ret, handle->cbs.key_event.data);
788 handle->cbs.key_event.cb = NULL;
789 handle->cbs.key_event.data = NULL;
790 handle->common->request.key_event = 0;
792 if (handle->common->state != WIDGET_STATE_DELETE) {
793 if (ret == (int)WIDGET_ERROR_NOT_EXIST && handle->refcnt == 2) {
794 _widget_invoke_event_handler(handle, WIDGET_EVENT_DELETED);
795 _widget_unref(handle, 1);
800 static void access_ret_cb(widget_h handle, const struct packet *result, void *data)
805 ret = WIDGET_ERROR_FAULT;
809 if (packet_get(result, "i", &ret) != 1) {
810 ret = WIDGET_ERROR_INVALID_PARAMETER;
814 if (ret != WIDGET_ERROR_NONE) {
821 handle->cbs.access_event.cb(handle, ret, handle->cbs.access_event.data);
822 handle->cbs.access_event.cb = NULL;
823 handle->cbs.access_event.data = NULL;
824 handle->common->request.access_event = 0;
826 if (handle->common->state != WIDGET_STATE_DELETE) {
827 if (ret == (int)WIDGET_ERROR_NOT_EXIST && handle->refcnt == 2) {
828 _widget_invoke_event_handler(handle, WIDGET_EVENT_DELETED);
829 _widget_unref(handle, 1);
834 static int send_access_event(widget_h handle, const char *event, int x, int y, int type)
836 struct packet *packet;
839 timestamp = util_timestamp();
841 packet = packet_create(event, "ssdiii", handle->common->pkgname, handle->common->id, timestamp, x, y, type);
843 ErrPrint("Failed to build packet\n");
844 return WIDGET_ERROR_FAULT;
847 return master_rpc_async_request(handle, packet, 0, access_ret_cb, NULL);
850 static int send_key_event(widget_h handle, const char *event, unsigned int keycode, int device)
852 struct packet *packet;
855 timestamp = util_timestamp();
856 packet = packet_create(event, "ssdii", handle->common->pkgname, handle->common->id, timestamp, keycode, device);
858 ErrPrint("Failed to build packet\n");
859 return WIDGET_ERROR_FAULT;
862 return master_rpc_async_request(handle, packet, 0, key_ret_cb, NULL);
865 static int send_mouse_event(widget_h handle, const char *event, int x, int y, double ratio_w, double ratio_h, int device)
867 struct packet *packet;
870 timestamp = util_timestamp();
871 packet = packet_create_noack(event, "ssdiiiddi", handle->common->pkgname, handle->common->id, timestamp, x, y, INPUT_EVENT_SOURCE_VIEWER, ratio_w, ratio_h, device);
873 ErrPrint("Failed to build param\n");
874 return WIDGET_ERROR_FAULT;
877 return master_rpc_request_only(handle, packet);
880 static int initialize_widget(void *disp, int use_thread)
884 char filename[BUFSIZ];
885 snprintf(filename, sizeof(filename), "/tmp/%d.box.log", getpid());
886 __file_log_fp = fopen(filename, "w+t");
887 if (!__file_log_fp) {
888 __file_log_fp = fdopen(1, "w+t");
891 ret = widget_service_init();
892 if (ret != WIDGET_ERROR_NONE) {
897 if (ret != WIDGET_ERROR_NONE) {
898 widget_service_fini();
902 ret = client_init(use_thread);
903 if (ret != WIDGET_ERROR_NONE) {
905 widget_service_fini();
913 static inline char *_widget_pkgname(const char *pkgname)
917 widget = widget_service_get_widget_id(pkgname);
919 widget = strdup(pkgname);
925 static gboolean job_execute_cb(void *data)
927 struct job_item *item;
930 l = dlist_nth(s_info.job_list, 0);
932 s_info.job_timer = 0;
936 item = dlist_data(l);
937 s_info.job_list = dlist_remove(s_info.job_list, l);
940 item->cb(item->handle, item->ret, item->data);
941 _widget_unref(item->handle, 1);
948 static int job_add(widget_h handle, widget_ret_cb job_cb, int ret, void *data)
950 struct job_item *item;
953 ErrPrint("Invalid argument\n");
954 return WIDGET_ERROR_INVALID_PARAMETER;
957 item = malloc(sizeof(*item));
959 ErrPrint("Heap: %d\n", errno);
960 return WIDGET_ERROR_OUT_OF_MEMORY;
963 item->handle = _widget_ref(handle);
968 s_info.job_list = dlist_append(s_info.job_list, item);
970 if (!s_info.job_timer) {
971 s_info.job_timer = g_timeout_add(1, job_execute_cb, NULL);
972 if (!s_info.job_timer) {
973 ErrPrint("Failed to create a job timer\n");
977 return WIDGET_ERROR_NONE;
980 static void new_ret_cb(widget_h handle, const struct packet *result, void *data)
983 struct cb_info *info = data;
989 _widget_destroy_cb_info(info);
992 ret = WIDGET_ERROR_FAULT;
993 } else if (packet_get(result, "i", &ret) != 1) {
994 ret = WIDGET_ERROR_INVALID_PARAMETER;
998 handle->cbs.created.cb = cb;
999 handle->cbs.created.data = cbdata;
1003 * Don't go anymore ;)
1009 * It means the current instance is not created,
1010 * so user has to know about this.
1011 * notice it to user using "deleted" event.
1013 cb(handle, ret, cbdata);
1016 _widget_unref(handle, 1);
1019 static int create_real_instance(widget_h handle, widget_ret_cb cb, void *data)
1021 struct cb_info *cbinfo;
1022 struct packet *packet;
1023 struct widget_common *common;
1024 unsigned int cmd = CMD_NEW;
1027 common = handle->common;
1029 packet = packet_create((const char *)&cmd, "dssssdii",
1030 common->timestamp, common->pkgname, common->content,
1031 common->cluster, common->category,
1032 common->widget.period, common->widget.width, common->widget.height);
1034 ErrPrint("Failed to create a new packet\n");
1035 set_last_result(WIDGET_ERROR_FAULT);
1036 return WIDGET_ERROR_FAULT;
1039 cbinfo = _widget_create_cb_info(cb, data);
1041 ErrPrint("Failed to create a cbinfo\n");
1042 packet_destroy(packet);
1043 set_last_result(WIDGET_ERROR_OUT_OF_MEMORY);
1044 return WIDGET_ERROR_OUT_OF_MEMORY;
1049 * master_rpc_async_request will destroy the packet (decrease the refcnt)
1050 * So be aware the packet object after return from master_rpc_async_request.
1052 ret = master_rpc_async_request(handle, packet, 0, new_ret_cb, cbinfo);
1054 ErrPrint("Failed to send a new packet\n");
1055 _widget_destroy_cb_info(cbinfo);
1056 set_last_result(WIDGET_ERROR_FAULT);
1057 return WIDGET_ERROR_FAULT;
1059 handle->common->request.created = 1;
1060 return WIDGET_ERROR_NONE;
1063 static void create_cb(widget_h handle, int ret, void *data)
1065 struct cb_info *cbinfo = data;
1068 cbinfo->cb(handle, ret, cbinfo->data);
1071 _widget_destroy_cb_info(cbinfo);
1075 * Forcely generate "updated" event
1077 _widget_invoke_event_handler(handle, WIDGET_EVENT_WIDGET_UPDATED);
1080 static int create_fake_instance(widget_h handle, widget_ret_cb cb, void *data)
1082 struct cb_info *cbinfo;
1084 cbinfo = _widget_create_cb_info(cb, data);
1086 ErrPrint("Failed to create a cbinfo\n");
1087 return WIDGET_ERROR_OUT_OF_MEMORY;
1090 if (job_add(handle, create_cb, WIDGET_ERROR_NONE, cbinfo) != WIDGET_ERROR_NONE) {
1091 _widget_destroy_cb_info(cbinfo);
1094 return WIDGET_ERROR_NONE;
1097 static void refresh_for_paused_updating_cb(widget_h handle, int ret, void *data)
1099 if (handle->paused_updating == 0) {
1100 DbgPrint("Paused updates are cleared\n");
1104 DbgPrint("Pending updates are found\n");
1105 _widget_invoke_event_handler(handle, WIDGET_EVENT_WIDGET_UPDATED);
1108 static int _widget_set_visibility(widget_h handle, widget_visible_state_e state)
1110 struct packet *packet;
1111 int need_to_add_job = 0;
1112 unsigned int cmd = CMD_CHANGE_VISIBILITY;
1115 if (handle->common->visible != WIDGET_SHOW && state == WIDGET_SHOW) {
1116 need_to_add_job = !!handle->paused_updating;
1117 } else if (handle->common->visible == WIDGET_SHOW && state != WIDGET_SHOW) {
1118 if (!!_widget_find_widget_in_show(handle->common)) {
1119 return WIDGET_ERROR_NONE;
1121 } else if (handle->common->visible == WIDGET_SHOW && state == WIDGET_SHOW && handle->paused_updating) {
1122 if (job_add(handle, refresh_for_paused_updating_cb, WIDGET_ERROR_NONE, NULL) < 0) {
1123 ErrPrint("Unable to add a new job for refreshing box\n");
1126 return WIDGET_ERROR_NONE;
1130 * No need to send this to the master
1132 return WIDGET_ERROR_NONE;
1135 packet = packet_create_noack((const char *)&cmd, "ssi", handle->common->pkgname, handle->common->id, (int)state);
1137 ErrPrint("Failed to create a packet\n");
1138 return WIDGET_ERROR_FAULT;
1141 ret = master_rpc_request_only(handle, packet);
1142 if (ret == (int)WIDGET_ERROR_NONE) {
1143 DbgPrint("[%s] visibility is changed 0x[%x]\n", handle->common->pkgname, state);
1144 handle->common->visible = state;
1146 if (need_to_add_job) {
1147 if (job_add(handle, refresh_for_paused_updating_cb, WIDGET_ERROR_NONE, NULL) < 0) {
1148 ErrPrint("Unable to add a new job for refreshing box\n");
1156 static void _widget_update_visibility(struct widget_common *old_common)
1160 item = _widget_find_widget_in_show(old_common);
1162 item = _widget_get_widget_nth(old_common, 0);
1164 _widget_set_visibility(item, WIDGET_HIDE_WITH_PAUSE);
1166 ErrPrint("Unable to get the valid handle from common handle\n");
1169 _widget_set_visibility(item, WIDGET_SHOW);
1175 * The second parameter should be the "return value",
1176 * But in this case, we will use it for "type of deleting instance".
1178 static void _job_del_cb(widget_h handle, int type, void *data)
1180 struct cb_info *cbinfo = data;
1183 if (handle->visible == WIDGET_SHOW) {
1184 _widget_update_visibility(handle->common);
1188 data = cbinfo->data;
1189 _widget_destroy_cb_info(cbinfo);
1191 if (handle->common->state != WIDGET_STATE_CREATE) {
1192 DbgPrint("[%s] %d\n", handle->common->pkgname, handle->refcnt);
1194 cb(handle, WIDGET_ERROR_NONE, data);
1200 if (handle->common->refcnt == 1) {
1201 handle->common->delete_type = type;
1202 handle->common->state = WIDGET_STATE_DELETE;
1204 if (!handle->common->id) {
1207 * The id is not determined yet.
1208 * It means a user didn't receive created event yet.
1209 * Then just stop to delete procedure from here.
1210 * Because the "created" event handle will release this.
1211 * By the way, if the user adds any callback for getting return status of this,
1215 cb(handle, WIDGET_ERROR_NONE, data);
1219 DbgPrint("Send delete request [%s]\n", handle->common->id);
1220 _widget_send_delete(handle, type, cb, data);
1223 cb(handle, WIDGET_ERROR_NONE, data);
1226 DbgPrint("Before unref: %d\n", handle->common->refcnt);
1227 _widget_unref(handle, 1);
1231 static void _resize_job_cb(widget_h handle, int ret, void *data)
1233 struct cb_info *info = data;
1236 info->cb(handle, ret, info->data);
1243 * Forcely update the box
1245 _widget_invoke_event_handler(handle, WIDGET_EVENT_WIDGET_UPDATED);
1248 static void _turn_off_gbar_destroyed_flag_cb(widget_h handle, int ret, void *data)
1250 if (handle->common->request.gbar_destroyed) {
1254 DbgPrint("gbar_destroyed request is canceled\n");
1255 handle->common->request.gbar_destroyed = 0;
1256 cb = handle->cbs.gbar_destroyed.cb;
1257 data = handle->cbs.gbar_destroyed.data;
1258 handle->cbs.gbar_destroyed.cb = NULL;
1259 handle->cbs.gbar_destroyed.data = NULL;
1262 cb(handle, ret, data);
1267 static void _turn_off_gbar_created_flag_cb(widget_h handle, int ret, void *data)
1269 if (handle->common->request.gbar_created) {
1273 DbgPrint("gbar_created request is canceled\n");
1274 handle->common->request.gbar_created = 0;
1275 cb = handle->cbs.gbar_created.cb;
1276 data = handle->cbs.gbar_created.data;
1277 handle->cbs.gbar_created.cb = NULL;
1278 handle->cbs.gbar_created.data = NULL;
1281 cb(handle, ret, data);
1286 EAPI int widget_viewer_init(void *disp, int prevent_overwrite, double event_filter, int use_thread)
1288 if (s_info.init_count > 0) {
1289 s_info.init_count++;
1290 return WIDGET_ERROR_NONE;
1295 * Some application doesn't want to use the environment value.
1296 * So set them using arguments.
1298 s_info.prevent_overwrite = prevent_overwrite;
1299 conf_set_event_filter(event_filter);
1301 return initialize_widget(disp, use_thread);
1304 EAPI int widget_viewer_fini(void)
1306 if (s_info.init_count <= 0) {
1307 ErrPrint("Doesn't initialized\n");
1308 return WIDGET_ERROR_INVALID_PARAMETER;
1311 s_info.init_count--;
1312 if (s_info.init_count > 0) {
1313 ErrPrint("init count : %d\n", s_info.init_count);
1314 return WIDGET_ERROR_NONE;
1319 widget_service_fini();
1320 return WIDGET_ERROR_NONE;
1323 EAPI widget_h widget_viewer_add_widget(const char *pkgname, const char *content, const char *cluster, const char *category, double period, widget_size_type_e type, widget_ret_cb cb, void *data)
1330 if (!pkgname || !cluster || !category) {
1331 ErrPrint("Invalid arguments: pkgname[%p], cluster[%p], category[%p]\n",
1332 pkgname, cluster, category);
1333 set_last_result(WIDGET_ERROR_INVALID_PARAMETER);
1337 widgetid = _widget_pkgname(pkgname);
1339 ErrPrint("Invalid package: %s\n", pkgname);
1340 set_last_result(WIDGET_ERROR_INVALID_PARAMETER);
1344 if (widget_service_is_enabled(widgetid) == 0) {
1345 DbgPrint("Livebox [%s](%s) is disabled package\n", widgetid, pkgname);
1347 set_last_result(WIDGET_ERROR_DISABLED);
1351 if (type != WIDGET_SIZE_TYPE_UNKNOWN) {
1352 (void)widget_service_get_size(type, &w, &h);
1355 handle = calloc(1, sizeof(*handle));
1357 ErrPrint("Error: %d\n", errno);
1359 set_last_result(WIDGET_ERROR_OUT_OF_MEMORY);
1364 cb = default_create_cb;
1367 handle->common = _widget_find_sharable_common_handle(widgetid, content, w, h, cluster, category);
1368 if (!handle->common) {
1369 handle->common = _widget_create_common_handle(handle, widgetid, cluster, category);
1371 if (!handle->common) {
1372 ErrPrint("Failed to find common handle\n");
1377 if (!content || !strlen(content)) {
1381 * I know the content should not be modified. use it temporarly without "const"
1383 pc = widget_service_get_content_string(handle->common->pkgname);
1384 _widget_set_content(handle->common, pc);
1387 _widget_set_content(handle->common, content);
1390 _widget_set_period(handle->common, period);
1391 _widget_set_size(handle->common, w, h);
1392 _widget_common_ref(handle->common, handle);
1394 if (create_real_instance(handle, cb, data) < 0) {
1395 if (_widget_common_unref(handle->common, handle) == 0) {
1399 _widget_destroy_common_handle(handle->common);
1400 handle->common = NULL;
1408 _widget_common_ref(handle->common, handle);
1410 if (handle->common->request.created) {
1412 * If a box is in creating, wait its result too
1414 handle->cbs.created.cb = cb;
1415 handle->cbs.created.data = data;
1418 * or fire the fake created_event
1420 if (create_fake_instance(handle, cb, data) < 0) {
1421 if (_widget_common_unref(handle->common, handle) == 0) {
1425 _widget_destroy_common_handle(handle->common);
1433 handle->visible = WIDGET_HIDE_WITH_PAUSE;
1434 handle->state = WIDGET_STATE_CREATE;
1435 handle = _widget_ref(handle);
1440 EAPI int widget_viewer_get_period(widget_h handle, double *period)
1442 int ret = WIDGET_ERROR_NONE;
1443 double result_period = -1.0f;
1445 if (!handle || handle->state != WIDGET_STATE_CREATE || period == NULL) {
1446 ErrPrint("Handler is not valid\n");
1447 ret = WIDGET_ERROR_INVALID_PARAMETER;
1451 if (!handle->common || handle->common->state != WIDGET_STATE_CREATE) {
1452 ErrPrint("Invalid handle\n");
1453 ret = WIDGET_ERROR_INVALID_PARAMETER;
1457 if (!handle->common->id) {
1458 ErrPrint("Hnalder is not valid\n");
1459 ret = WIDGET_ERROR_INVALID_PARAMETER;
1463 result_period = handle->common->widget.period;
1467 *period = result_period;
1472 EAPI int widget_viewer_set_period(widget_h handle, double period, widget_ret_cb cb, void *data)
1474 struct packet *packet;
1475 unsigned int cmd = CMD_SET_PERIOD;
1478 if (!handle || handle->state != WIDGET_STATE_CREATE) {
1479 ErrPrint("Handler is not valid\n");
1480 return WIDGET_ERROR_INVALID_PARAMETER;
1483 if (!handle->common || handle->common->state != WIDGET_STATE_CREATE) {
1484 ErrPrint("Invalid handle\n");
1485 return WIDGET_ERROR_INVALID_PARAMETER;
1488 if (!handle->common->id) {
1489 ErrPrint("Handler is not valid\n");
1490 return WIDGET_ERROR_INVALID_PARAMETER;
1493 if (handle->common->request.period_changed) {
1494 ErrPrint("Previous request for changing period is not finished\n");
1495 return WIDGET_ERROR_RESOURCE_BUSY;
1498 if (!handle->common->is_user) {
1499 ErrPrint("CA Livebox is not able to change the period\n");
1500 return WIDGET_ERROR_PERMISSION_DENIED;
1503 if (handle->common->widget.period == period) {
1504 DbgPrint("No changes\n");
1505 return WIDGET_ERROR_ALREADY_EXIST;
1508 packet = packet_create((const char *)&cmd, "ssd", handle->common->pkgname, handle->common->id, period);
1510 ErrPrint("Failed to build a packet %s\n", handle->common->pkgname);
1511 return WIDGET_ERROR_FAULT;
1515 cb = default_period_changed_cb;
1518 ret = master_rpc_async_request(handle, packet, 0, period_ret_cb, NULL);
1519 if (ret == (int)WIDGET_ERROR_NONE) {
1520 handle->cbs.period_changed.cb = cb;
1521 handle->cbs.period_changed.data = data;
1522 handle->common->request.period_changed = 1;
1528 EAPI int widget_viewer_delete_widget(widget_h handle, widget_delete_type_e type, widget_ret_cb cb, void *data)
1530 struct cb_info *cbinfo;
1533 ErrPrint("Handler is NIL\n");
1534 return WIDGET_ERROR_INVALID_PARAMETER;
1537 if (handle->state != WIDGET_STATE_CREATE) {
1538 ErrPrint("Handler is already deleted\n");
1539 return WIDGET_ERROR_INVALID_PARAMETER;
1542 handle->state = WIDGET_STATE_DELETE;
1544 cbinfo = _widget_create_cb_info(cb, data);
1546 ErrPrint("Failed to create a cbinfo\n");
1547 return WIDGET_ERROR_OUT_OF_MEMORY;
1550 if (job_add(handle, _job_del_cb, type, cbinfo) != WIDGET_ERROR_NONE) {
1551 ErrPrint("Failed to add a new job\n");
1552 _widget_destroy_cb_info(cbinfo);
1553 return WIDGET_ERROR_FAULT;
1556 return WIDGET_ERROR_NONE;
1559 EAPI int widget_viewer_add_fault_handler(widget_fault_handler_cb widget_cb, void *data)
1562 return WIDGET_ERROR_INVALID_PARAMETER;
1565 return _widget_add_fault_handler(widget_cb, data);
1568 EAPI void *widget_viewer_remove_fault_handler(widget_fault_handler_cb widget_cb)
1574 return _widget_remove_fault_handler(widget_cb);
1577 EAPI int widget_viewer_add_event_handler(widget_event_handler_cb widget_cb, void *data)
1580 ErrPrint("Invalid argument widget_cb is nil\n");
1581 return WIDGET_ERROR_INVALID_PARAMETER;
1584 return _widget_add_event_handler(widget_cb, data);
1587 EAPI void *widget_viewer_remove_event_handler(widget_event_handler_cb widget_cb)
1593 return _widget_remove_event_handler(widget_cb);
1596 EAPI int widget_viewer_set_update_mode(widget_h handle, int active_update, widget_ret_cb cb, void *data)
1598 struct packet *packet;
1599 unsigned int cmd = CMD_UPDATE_MODE;
1602 if (!handle || handle->state != WIDGET_STATE_CREATE) {
1603 ErrPrint("Handler is Invalid\n");
1604 return WIDGET_ERROR_INVALID_PARAMETER;
1607 if (!handle->common || handle->common->state != WIDGET_STATE_CREATE) {
1608 ErrPrint("Handler is Invalid\n");
1609 return WIDGET_ERROR_INVALID_PARAMETER;
1612 if (!handle->common->id) {
1613 ErrPrint("Handler is Invalid\n");
1614 return WIDGET_ERROR_INVALID_PARAMETER;
1617 if (handle->common->request.update_mode) {
1618 ErrPrint("Previous update_mode cb is not finished yet\n");
1619 return WIDGET_ERROR_RESOURCE_BUSY;
1622 if (handle->common->is_active_update == active_update) {
1623 return WIDGET_ERROR_ALREADY_EXIST;
1626 if (!handle->common->is_user) {
1627 return WIDGET_ERROR_PERMISSION_DENIED;
1630 packet = packet_create((const char *)&cmd, "ssi", handle->common->pkgname, handle->common->id, active_update);
1632 return WIDGET_ERROR_FAULT;
1636 cb = default_update_mode_cb;
1639 ret = master_rpc_async_request(handle, packet, 0, update_mode_cb, NULL);
1640 if (ret == (int)WIDGET_ERROR_NONE) {
1641 handle->cbs.update_mode.cb = cb;
1642 handle->cbs.update_mode.data = data;
1643 handle->common->request.update_mode = 1;
1649 EAPI int widget_viewer_is_active_update(widget_h handle)
1651 if (!handle || handle->state != WIDGET_STATE_CREATE) {
1652 ErrPrint("Handler is Invalid\n");
1653 return WIDGET_ERROR_INVALID_PARAMETER;
1656 if (!handle->common || handle->common->state != WIDGET_STATE_CREATE) {
1657 ErrPrint("Handler is Invalid\n");
1658 return WIDGET_ERROR_INVALID_PARAMETER;
1661 if (!handle->common->id) {
1662 return WIDGET_ERROR_INVALID_PARAMETER;
1665 return handle->common->is_active_update;
1668 EAPI int widget_viewer_resize_widget(widget_h handle, widget_size_type_e type, widget_ret_cb cb, void *data)
1670 struct widget_common *common;
1677 * If this handle is host instance or link instance,
1678 * Create a new instance or find another linkable instance.
1681 if (!handle || handle->state != WIDGET_STATE_CREATE) {
1682 ErrPrint("Handler is not valid\n");
1683 return WIDGET_ERROR_INVALID_PARAMETER;
1686 if (!handle->common || handle->common->state != WIDGET_STATE_CREATE) {
1687 ErrPrint("Invalid handle\n");
1688 return WIDGET_ERROR_INVALID_PARAMETER;
1691 if (!handle->common->id) {
1692 ErrPrint("Handler is not valid\n");
1693 return WIDGET_ERROR_INVALID_PARAMETER;
1698 * resize operation should be separated by each handle.
1699 * If a handle is resizing, the other handle can request resize too.
1700 * So we should not use the common->request.size_changed flag.
1702 if (handle->cbs.size_changed.cb) {
1703 ErrPrint("Previous resize request is not finished yet\n");
1704 return WIDGET_ERROR_RESOURCE_BUSY;
1707 if (widget_service_get_size(type, &w, &h) != 0) {
1708 ErrPrint("Invalid size type\n");
1709 return WIDGET_ERROR_INVALID_PARAMETER;
1712 if (handle->common->widget.width == w && handle->common->widget.height == h) {
1713 DbgPrint("No changes\n");
1714 return WIDGET_ERROR_ALREADY_EXIST;
1717 if (!handle->common->is_user) {
1718 ErrPrint("CA Livebox is not able to be resized\n");
1719 return WIDGET_ERROR_PERMISSION_DENIED;
1722 if (handle->common->refcnt <= 1) {
1723 struct packet *packet;
1724 unsigned int cmd = CMD_RESIZE;
1726 /* Only 1 instance */
1727 packet = packet_create((const char *)&cmd, "ssii", handle->common->pkgname, handle->common->id, w, h);
1729 ErrPrint("Failed to build param\n");
1730 return WIDGET_ERROR_FAULT;
1734 cb = default_widget_size_changed_cb;
1737 ret = master_rpc_async_request(handle, packet, 0, resize_cb, NULL);
1738 if (ret == (int)WIDGET_ERROR_NONE) {
1739 handle->cbs.size_changed.cb = cb;
1740 handle->cbs.size_changed.data = data;
1741 handle->common->request.size_changed = 1;
1744 common = _widget_find_sharable_common_handle(handle->common->pkgname, handle->common->content, w, h, handle->common->cluster, handle->common->category);
1746 struct widget_common *old_common;
1749 * If the common handle is in resizing,
1750 * if user tries to resize a hander, then simply create new one even if the requested size is same with this.
1752 if (handle->common->request.size_changed) {
1757 old_common = handle->common;
1759 common = _widget_create_common_handle(handle, old_common->pkgname, old_common->cluster, old_common->category);
1761 ErrPrint("Failed to create common handle\n");
1762 return WIDGET_ERROR_FAULT;
1765 _widget_set_size(common, w, h);
1766 _widget_set_content(common, old_common->content);
1767 _widget_set_period(common, old_common->widget.period);
1771 * Disconnecting from old one.
1773 if (_widget_common_unref(old_common, handle) == 0) {
1778 ErrPrint("Common has no associated handle\n");
1781 _widget_common_ref(common, handle);
1784 * Connect to a new one
1786 handle->common = common;
1790 * Need to care, if it fails to create a common handle,
1791 * the resize operation will be failed.
1792 * in that case, we should reuse the old common handle
1794 ret = create_real_instance(handle, cb, data);
1796 _widget_common_unref(common, handle);
1797 _widget_destroy_common_handle(common);
1799 _widget_common_ref(old_common, handle);
1800 handle->common = old_common;
1803 * In this case, we should update visibility of old_common's widgetes
1805 if (handle->visible == WIDGET_SHOW) {
1806 _widget_update_visibility(old_common);
1810 struct cb_info *cbinfo;
1812 cbinfo = _widget_create_cb_info(cb, data);
1814 ErrPrint("Failed to create a cbinfo\n");
1815 ret = WIDGET_ERROR_OUT_OF_MEMORY;
1817 ret = job_add(handle, _resize_job_cb, WIDGET_ERROR_NONE, cbinfo);
1818 if (ret == (int)WIDGET_ERROR_NONE) {
1819 struct widget_common *old_common;
1821 old_common = handle->common;
1823 if (_widget_common_unref(handle->common, handle) == 0) {
1824 ErrPrint("Old common has no associated handle\n");
1827 _widget_common_ref(common, handle);
1828 handle->common = common;
1830 if (handle->visible == WIDGET_SHOW) {
1831 _widget_update_visibility(old_common); /* To update visibility: Show --> Paused */
1832 _widget_update_visibility(common); /* To update visibility: Paused --> Show */
1835 _widget_destroy_cb_info(cbinfo);
1844 EAPI int widget_viewer_send_click_event(widget_h handle, const char *event, double x, double y)
1846 struct packet *packet;
1848 unsigned int cmd = CMD_CLICKED;
1851 if (!handle || handle->state != WIDGET_STATE_CREATE) {
1852 ErrPrint("Handler is invalid\n");
1853 return WIDGET_ERROR_INVALID_PARAMETER;
1856 if (!handle->common || handle->common->state != WIDGET_STATE_CREATE) {
1857 ErrPrint("Handler is invalid\n");
1858 return WIDGET_ERROR_INVALID_PARAMETER;
1861 if (!event || (strcmp(event, WIDGET_VIEWER_CLICK_BUTTON_LEFT) && strcmp(event, WIDGET_VIEWER_CLICK_BUTTON_RIGHT) && strcmp(event, WIDGET_VIEWER_CLICK_BUTTON_CENTER))) {
1862 ErrPrint("Unknown event: (%s)\n", event);
1863 return WIDGET_ERROR_INVALID_PARAMETER;
1866 if (!handle->common->id) {
1867 ErrPrint("Handler is not valid\n");
1868 return WIDGET_ERROR_INVALID_PARAMETER;
1871 if (handle->common->widget.auto_launch) {
1872 if (s_info.launch.handle) {
1873 ret = s_info.launch.handle(handle, handle->common->widget.auto_launch, s_info.launch.data);
1875 ErrPrint("launch handle app %s (%d)\n", handle->common->widget.auto_launch, ret);
1880 timestamp = util_timestamp();
1881 DbgPrint("CLICKED: %lf\n", timestamp);
1883 packet = packet_create_noack((const char *)&cmd, "sssddd", handle->common->pkgname, handle->common->id, event, timestamp, x, y);
1885 ErrPrint("Failed to build param\n");
1886 return WIDGET_ERROR_FAULT;
1889 ret = master_rpc_request_only(handle, packet);
1893 EAPI int widget_viewer_has_glance_bar(widget_h handle)
1895 if (!handle || handle->state != WIDGET_STATE_CREATE) {
1896 ErrPrint("Handler is invalid\n");
1897 return WIDGET_ERROR_INVALID_PARAMETER;
1900 if (!handle->common || handle->common->state != WIDGET_STATE_CREATE) {
1901 ErrPrint("Handler is invalid\n");
1902 return WIDGET_ERROR_INVALID_PARAMETER;
1905 if (!handle->common->id) {
1906 ErrPrint("Handler is not valid\n");
1907 return WIDGET_ERROR_INVALID_PARAMETER;
1910 return !!handle->common->gbar.fb;
1913 EAPI int widget_viewer_glance_bar_is_created(widget_h handle)
1915 if (!handle || handle->state != WIDGET_STATE_CREATE) {
1916 ErrPrint("Handler is invalid\n");
1917 return WIDGET_ERROR_INVALID_PARAMETER;
1920 if (!handle->common || handle->common->state != WIDGET_STATE_CREATE) {
1921 ErrPrint("Handler is invalid\n");
1922 return WIDGET_ERROR_INVALID_PARAMETER;
1925 if (!handle->common->gbar.fb || !handle->common->id) {
1926 ErrPrint("Handler is not valid\n");
1927 return WIDGET_ERROR_INVALID_PARAMETER;
1930 return handle->common->is_gbar_created;
1933 EAPI int widget_viewer_create_glance_bar(widget_h handle, double x, double y, widget_ret_cb cb, void *data)
1935 struct packet *packet;
1936 unsigned int cmd = CMD_CREATE_GBAR;
1939 if (!handle || handle->state != WIDGET_STATE_CREATE) {
1940 ErrPrint("Handler is invalid\n");
1941 return WIDGET_ERROR_INVALID_PARAMETER;
1944 if (!handle->common || handle->common->state != WIDGET_STATE_CREATE) {
1945 ErrPrint("Handler is invalid\n");
1946 return WIDGET_ERROR_INVALID_PARAMETER;
1949 if (!handle->common->gbar.fb || !handle->common->id) {
1950 ErrPrint("Handler is not valid\n");
1951 return WIDGET_ERROR_INVALID_PARAMETER;
1956 * Only one handle can have a GBAR
1958 if (handle->common->is_gbar_created) {
1959 DbgPrint("GBAR is already created\n");
1960 return WIDGET_ERROR_NONE;
1963 if (handle->common->request.gbar_created) {
1964 ErrPrint("Previous request is not completed yet\n");
1965 return WIDGET_ERROR_RESOURCE_BUSY;
1970 * Turn off the gbar_destroyed request flag
1972 if (handle->common->request.gbar_destroyed) {
1973 if (job_add(handle, _turn_off_gbar_destroyed_flag_cb, WIDGET_ERROR_CANCELED, NULL) < 0) {
1974 ErrPrint("Failed to add gbar_destroyed job\n");
1978 packet = packet_create((const char *)&cmd, "ssdd", handle->common->pkgname, handle->common->id, x, y);
1980 ErrPrint("Failed to build param\n");
1981 return WIDGET_ERROR_FAULT;
1985 cb = default_gbar_created_cb;
1988 DbgPrint("PERF_WIDGET\n");
1989 ret = master_rpc_async_request(handle, packet, 0, gbar_create_cb, NULL);
1990 if (ret == (int)WIDGET_ERROR_NONE) {
1991 handle->cbs.gbar_created.cb = cb;
1992 handle->cbs.gbar_created.data = data;
1993 handle->common->request.gbar_created = 1;
1999 EAPI int widget_viewer_move_glance_bar(widget_h handle, double x, double y)
2001 struct packet *packet;
2002 unsigned int cmd = CMD_GBAR_MOVE;
2004 if (!handle || handle->state != WIDGET_STATE_CREATE) {
2005 ErrPrint("Handler is invalid\n");
2006 return WIDGET_ERROR_INVALID_PARAMETER;
2009 if (!handle->common || handle->common->state != WIDGET_STATE_CREATE) {
2010 ErrPrint("Handler is invalid\n");
2011 return WIDGET_ERROR_INVALID_PARAMETER;
2014 if (!handle->common->gbar.fb || !handle->common->id) {
2015 ErrPrint("Handler is not valid\n");
2016 return WIDGET_ERROR_INVALID_PARAMETER;
2019 if (!handle->common->is_gbar_created) {
2020 ErrPrint("GBAR is not created\n");
2021 return WIDGET_ERROR_INVALID_PARAMETER;
2024 packet = packet_create_noack((const char *)&cmd, "ssdd", handle->common->pkgname, handle->common->id, x, y);
2026 ErrPrint("Failed to build param\n");
2027 return WIDGET_ERROR_FAULT;
2030 return master_rpc_request_only(handle, packet);
2033 EAPI int widget_viewer_activate_faulted_widget(const char *pkgname, widget_ret_cb cb, void *data)
2035 struct packet *packet;
2036 struct cb_info *cbinfo;
2037 unsigned int cmd = CMD_ACTIVATE_PACKAGE;
2041 return WIDGET_ERROR_INVALID_PARAMETER;
2044 packet = packet_create((const char *)&cmd, "s", pkgname);
2046 ErrPrint("Failed to build a param\n");
2047 return WIDGET_ERROR_FAULT;
2050 cbinfo = _widget_create_cb_info(cb, data);
2052 ErrPrint("Unable to create cbinfo\n");
2053 packet_destroy(packet);
2054 return WIDGET_ERROR_FAULT;
2057 ret = master_rpc_async_request(NULL, packet, 0, activated_cb, cbinfo);
2059 _widget_destroy_cb_info(cbinfo);
2065 EAPI int widget_viewer_destroy_glance_bar(widget_h handle, widget_ret_cb cb, void *data)
2067 struct packet *packet;
2068 struct cb_info *cbinfo;
2069 unsigned int cmd = CMD_DESTROY_GBAR;
2072 if (!handle || handle->state != WIDGET_STATE_CREATE) {
2073 ErrPrint("Handler is invalid\n");
2074 return WIDGET_ERROR_INVALID_PARAMETER;
2077 if (!handle->common || handle->common->state != WIDGET_STATE_CREATE) {
2078 ErrPrint("Handler is invalid\n");
2079 return WIDGET_ERROR_INVALID_PARAMETER;
2082 if (!handle->common->gbar.fb || !handle->common->id) {
2083 ErrPrint("Handler is not valid\n");
2084 return WIDGET_ERROR_INVALID_PARAMETER;
2089 * Replace the callback check code.
2090 * Use the flag instead of callback.
2091 * the flag should be in the ADT "common"
2093 if (!handle->common->is_gbar_created && !handle->common->request.gbar_created) {
2094 ErrPrint("GBAR is not created\n");
2095 return WIDGET_ERROR_INVALID_PARAMETER;
2098 if (handle->common->request.gbar_destroyed) {
2099 ErrPrint("GBAR destroy request is already sent\n");
2100 return WIDGET_ERROR_ALREADY_EXIST;
2105 * Disable the gbar_created request flag
2107 if (handle->common->request.gbar_created) {
2108 if (job_add(handle, _turn_off_gbar_created_flag_cb, WIDGET_ERROR_CANCELED, NULL) < 0) {
2109 ErrPrint("Failed to add a new job\n");
2113 DbgPrint("[%s]\n", handle->common->pkgname);
2115 packet = packet_create((const char *)&cmd, "ss", handle->common->pkgname, handle->common->id);
2117 ErrPrint("Failed to build a param\n");
2118 return WIDGET_ERROR_FAULT;
2122 cb = default_gbar_destroyed_cb;
2125 cbinfo = _widget_create_cb_info(cb, data);
2127 packet_destroy(packet);
2128 return WIDGET_ERROR_FAULT;
2131 ret = master_rpc_async_request(handle, packet, 0, gbar_destroy_cb, cbinfo);
2133 _widget_destroy_cb_info(cbinfo);
2135 handle->common->request.gbar_destroyed = 1;
2141 EAPI int widget_viewer_feed_access_event(widget_h handle, widget_access_event_type_e type, widget_access_event_info_s info, widget_ret_cb cb, void *data)
2146 int ret = 0; /* re-used for sending event type */
2148 if (!handle || handle->state != WIDGET_STATE_CREATE) {
2149 ErrPrint("Handler is invalid\n");
2150 return WIDGET_ERROR_INVALID_PARAMETER;
2153 if (!handle->common || handle->common->state != WIDGET_STATE_CREATE) {
2154 ErrPrint("Handler is invalid\n");
2155 return WIDGET_ERROR_INVALID_PARAMETER;
2158 if (!handle->common->id) {
2159 ErrPrint("Handler is not valid\n");
2160 return WIDGET_ERROR_INVALID_PARAMETER;
2163 if (handle->common->request.access_event) {
2164 ErrPrint("Previous access event is not yet done\n");
2165 return WIDGET_ERROR_RESOURCE_BUSY;
2168 if (type & WIDGET_ACCESS_EVENT_GBAR_MASK) {
2169 if (!handle->common->is_gbar_created) {
2170 ErrPrint("GBAR is not created\n");
2171 return WIDGET_ERROR_INVALID_PARAMETER;
2174 w = handle->common->gbar.width;
2175 h = handle->common->gbar.height;
2177 switch (type & ~(WIDGET_ACCESS_EVENT_GBAR_MASK | WIDGET_ACCESS_EVENT_WIDGET_MASK)) {
2178 case WIDGET_ACCESS_EVENT_HIGHLIGHT:
2179 cmd = CMD_GBAR_ACCESS_HL;
2180 ret = (int)info->type;
2182 case WIDGET_ACCESS_EVENT_ACTIVATE:
2183 cmd = CMD_GBAR_ACCESS_ACTIVATE;
2185 case WIDGET_ACCESS_EVENT_ACTION:
2186 cmd = CMD_GBAR_ACCESS_ACTION;
2187 ret = (int)info->type;
2189 case WIDGET_ACCESS_EVENT_SCROLL:
2190 cmd = CMD_GBAR_ACCESS_SCROLL;
2191 ret = (int)info->type;
2193 case WIDGET_ACCESS_EVENT_VALUE_CHANGE:
2194 cmd = CMD_GBAR_ACCESS_VALUE_CHANGE;
2196 case WIDGET_ACCESS_EVENT_MOUSE:
2197 cmd = CMD_GBAR_ACCESS_MOUSE;
2198 ret = (int)info->type;
2200 case WIDGET_ACCESS_EVENT_BACK:
2201 cmd = CMD_GBAR_ACCESS_BACK;
2203 case WIDGET_ACCESS_EVENT_OVER:
2204 cmd = CMD_GBAR_ACCESS_OVER;
2206 case WIDGET_ACCESS_EVENT_READ:
2207 cmd = CMD_GBAR_ACCESS_READ;
2209 case WIDGET_ACCESS_EVENT_ENABLE:
2210 cmd = CMD_GBAR_ACCESS_ENABLE;
2214 return WIDGET_ERROR_INVALID_PARAMETER;
2217 } else if (type & WIDGET_ACCESS_EVENT_WIDGET_MASK) {
2218 w = handle->common->widget.width;
2219 h = handle->common->widget.height;
2220 switch (type & ~(WIDGET_ACCESS_EVENT_GBAR_MASK | WIDGET_ACCESS_EVENT_WIDGET_MASK)) {
2221 case WIDGET_ACCESS_EVENT_HIGHLIGHT:
2222 cmd = CMD_WIDGET_ACCESS_HL;
2223 ret = (int)info->type;
2225 case WIDGET_ACCESS_EVENT_ACTIVATE:
2226 cmd = CMD_WIDGET_ACCESS_ACTIVATE;
2228 case WIDGET_ACCESS_EVENT_ACTION:
2229 cmd = CMD_WIDGET_ACCESS_ACTION;
2230 ret = (int)info->type;
2232 case WIDGET_ACCESS_EVENT_SCROLL:
2233 cmd = CMD_WIDGET_ACCESS_SCROLL;
2234 ret = (int)info->type;
2236 case WIDGET_ACCESS_EVENT_VALUE_CHANGE:
2237 cmd = CMD_WIDGET_ACCESS_VALUE_CHANGE;
2239 case WIDGET_ACCESS_EVENT_MOUSE:
2240 cmd = CMD_WIDGET_ACCESS_MOUSE;
2241 ret = (int)info->type;
2243 case WIDGET_ACCESS_EVENT_BACK:
2244 cmd = CMD_WIDGET_ACCESS_BACK;
2246 case WIDGET_ACCESS_EVENT_OVER:
2247 cmd = CMD_WIDGET_ACCESS_OVER;
2249 case WIDGET_ACCESS_EVENT_READ:
2250 cmd = CMD_WIDGET_ACCESS_READ;
2252 case WIDGET_ACCESS_EVENT_ENABLE:
2253 cmd = CMD_WIDGET_ACCESS_ENABLE;
2257 return WIDGET_ERROR_INVALID_PARAMETER;
2260 ErrPrint("Invalid event type\n");
2261 return WIDGET_ERROR_INVALID_PARAMETER;
2265 cb = default_access_event_cb;
2268 ret = send_access_event(handle, (const char *)&cmd, info->x * w, info->y * h, ret);
2269 if (ret == (int)WIDGET_ERROR_NONE) {
2270 handle->cbs.access_event.cb = cb;
2271 handle->cbs.access_event.data = data;
2272 handle->common->request.access_event = 1;
2278 EAPI int widget_viewer_feed_mouse_event(widget_h handle, widget_mouse_event_type_e type, widget_mouse_event_info_s info)
2282 if (!handle || handle->state != WIDGET_STATE_CREATE) {
2283 ErrPrint("Handler is invalid\n");
2284 return WIDGET_ERROR_INVALID_PARAMETER;
2287 if (!handle->common || handle->common->state != WIDGET_STATE_CREATE) {
2288 ErrPrint("Handler is invalid\n");
2289 return WIDGET_ERROR_INVALID_PARAMETER;
2292 if (!handle->common->id) {
2293 ErrPrint("Handler is not valid\n");
2294 return WIDGET_ERROR_INVALID_PARAMETER;
2297 if (!(type & WIDGET_MOUSE_EVENT_MASK)) {
2298 ErrPrint("Invalid content event is used\n");
2299 return WIDGET_ERROR_INVALID_PARAMETER;
2302 if (type & WIDGET_MOUSE_EVENT_GBAR_MASK) {
2305 if (!handle->common->is_gbar_created) {
2306 ErrPrint("GBAR is not created\n");
2307 return WIDGET_ERROR_INVALID_PARAMETER;
2310 if (!handle->common->gbar.fb) {
2311 ErrPrint("Handler is not valid\n");
2312 return WIDGET_ERROR_INVALID_PARAMETER;
2315 if (type & WIDGET_MOUSE_EVENT_MOVE) {
2316 if (fabs(info->x - handle->common->gbar.x) < conf_event_filter() && fabs(info->y - handle->common->gbar.y) < conf_event_filter()) {
2317 return WIDGET_ERROR_RESOURCE_BUSY;
2319 } else if (type & WIDGET_MOUSE_EVENT_SET) {
2324 handle->common->gbar.x = info->x;
2325 handle->common->gbar.y = info->y;
2328 switch ((type & ~(WIDGET_MOUSE_EVENT_GBAR_MASK | WIDGET_MOUSE_EVENT_WIDGET_MASK))) {
2329 case WIDGET_MOUSE_EVENT_ENTER | WIDGET_MOUSE_EVENT_MASK:
2330 cmd = CMD_GBAR_MOUSE_ENTER;
2332 case WIDGET_MOUSE_EVENT_LEAVE | WIDGET_MOUSE_EVENT_MASK:
2333 cmd = CMD_GBAR_MOUSE_LEAVE;
2335 case WIDGET_MOUSE_EVENT_UP | WIDGET_MOUSE_EVENT_MASK:
2336 cmd = CMD_GBAR_MOUSE_UP;
2338 case WIDGET_MOUSE_EVENT_DOWN | WIDGET_MOUSE_EVENT_MASK:
2339 cmd = CMD_GBAR_MOUSE_DOWN;
2341 case WIDGET_MOUSE_EVENT_MOVE | WIDGET_MOUSE_EVENT_MASK:
2342 cmd = CMD_GBAR_MOUSE_MOVE;
2344 case WIDGET_MOUSE_EVENT_SET | WIDGET_MOUSE_EVENT_MASK:
2345 cmd = CMD_GBAR_MOUSE_SET;
2347 case WIDGET_MOUSE_EVENT_UNSET | WIDGET_MOUSE_EVENT_MASK:
2348 cmd = CMD_GBAR_MOUSE_UNSET;
2350 case WIDGET_MOUSE_EVENT_ON_SCROLL | WIDGET_MOUSE_EVENT_MASK:
2351 cmd = CMD_GBAR_MOUSE_ON_SCROLL;
2353 case WIDGET_MOUSE_EVENT_ON_HOLD | WIDGET_MOUSE_EVENT_MASK:
2354 cmd = CMD_GBAR_MOUSE_ON_HOLD;
2355 DbgPrint("Send ON_HOLD\n");
2357 case WIDGET_MOUSE_EVENT_OFF_SCROLL | WIDGET_MOUSE_EVENT_MASK:
2358 cmd = CMD_GBAR_MOUSE_OFF_SCROLL;
2360 case WIDGET_MOUSE_EVENT_OFF_HOLD | WIDGET_MOUSE_EVENT_MASK:
2361 cmd = CMD_GBAR_MOUSE_OFF_HOLD;
2364 ErrPrint("Invalid event type\n");
2365 return WIDGET_ERROR_INVALID_PARAMETER;
2368 } else if (type & WIDGET_MOUSE_EVENT_WIDGET_MASK) {
2371 if (!handle->common->widget.fb) {
2372 ErrPrint("Handler is not valid\n");
2373 return WIDGET_ERROR_INVALID_PARAMETER;
2376 if (handle->common->widget.auto_launch) {
2377 return WIDGET_ERROR_DISABLED;
2380 if (type & WIDGET_MOUSE_EVENT_MOVE) {
2381 if (fabs(info->x - handle->common->widget.x) < conf_event_filter() && fabs(info->y - handle->common->widget.y) < conf_event_filter()) {
2382 return WIDGET_ERROR_RESOURCE_BUSY;
2384 } else if (type & WIDGET_MOUSE_EVENT_SET) {
2389 handle->common->widget.x = info->x;
2390 handle->common->widget.y = info->y;
2393 switch ((type & ~(WIDGET_MOUSE_EVENT_GBAR_MASK | WIDGET_MOUSE_EVENT_WIDGET_MASK))) {
2394 case WIDGET_MOUSE_EVENT_ENTER | WIDGET_MOUSE_EVENT_MASK:
2395 cmd = CMD_WIDGET_MOUSE_ENTER;
2397 case WIDGET_MOUSE_EVENT_LEAVE | WIDGET_MOUSE_EVENT_MASK:
2398 cmd = CMD_WIDGET_MOUSE_LEAVE;
2400 case WIDGET_MOUSE_EVENT_UP | WIDGET_MOUSE_EVENT_MASK:
2401 cmd = CMD_WIDGET_MOUSE_UP;
2403 case WIDGET_MOUSE_EVENT_DOWN | WIDGET_MOUSE_EVENT_MASK:
2404 cmd = CMD_WIDGET_MOUSE_DOWN;
2406 case WIDGET_MOUSE_EVENT_MOVE | WIDGET_MOUSE_EVENT_MASK:
2407 if (!handle->common->widget.mouse_event) {
2408 return WIDGET_ERROR_INVALID_PARAMETER;
2410 cmd = CMD_WIDGET_MOUSE_MOVE;
2412 case WIDGET_MOUSE_EVENT_SET | WIDGET_MOUSE_EVENT_MASK:
2413 if (!handle->common->widget.mouse_event) {
2414 return WIDGET_ERROR_INVALID_PARAMETER;
2416 cmd = CMD_WIDGET_MOUSE_SET;
2418 case WIDGET_MOUSE_EVENT_UNSET | WIDGET_MOUSE_EVENT_MASK:
2419 if (!handle->common->widget.mouse_event) {
2420 return WIDGET_ERROR_INVALID_PARAMETER;
2422 cmd = CMD_WIDGET_MOUSE_UNSET;
2424 case WIDGET_MOUSE_EVENT_ON_SCROLL | WIDGET_MOUSE_EVENT_MASK:
2425 cmd = CMD_WIDGET_MOUSE_ON_SCROLL;
2427 case WIDGET_MOUSE_EVENT_ON_HOLD | WIDGET_MOUSE_EVENT_MASK:
2428 cmd = CMD_WIDGET_MOUSE_ON_HOLD;
2429 DbgPrint("Send ON_HOLD\n");
2431 case WIDGET_MOUSE_EVENT_OFF_SCROLL | WIDGET_MOUSE_EVENT_MASK:
2432 cmd = CMD_WIDGET_MOUSE_OFF_SCROLL;
2434 case WIDGET_MOUSE_EVENT_OFF_HOLD | WIDGET_MOUSE_EVENT_MASK:
2435 cmd = CMD_WIDGET_MOUSE_OFF_HOLD;
2438 ErrPrint("Invalid event type\n");
2439 return WIDGET_ERROR_INVALID_PARAMETER;
2442 ErrPrint("Invalid event type\n");
2443 return WIDGET_ERROR_INVALID_PARAMETER;
2446 return send_mouse_event(handle, (const char *)&cmd, info->x, info->y, info->ratio_w, info->ratio_h, info->device);
2449 EAPI int widget_viewer_feed_key_event(widget_h handle, widget_key_event_type_e type, widget_key_event_info_s info, widget_ret_cb cb, void *data)
2454 if (!handle || handle->state != WIDGET_STATE_CREATE) {
2455 ErrPrint("Handler is invalid\n");
2456 return WIDGET_ERROR_INVALID_PARAMETER;
2459 if (!handle->common || handle->common->state != WIDGET_STATE_CREATE) {
2460 ErrPrint("Handler is invalid\n");
2461 return WIDGET_ERROR_INVALID_PARAMETER;
2464 if (!handle->common->id) {
2465 ErrPrint("Handler is not valid\n");
2466 return WIDGET_ERROR_INVALID_PARAMETER;
2469 if (!(type & WIDGET_KEY_EVENT_MASK)) {
2470 ErrPrint("Invalid key event is used\n");
2471 return WIDGET_ERROR_INVALID_PARAMETER;
2474 if (handle->common->request.key_event) {
2475 ErrPrint("Previous key event is not completed yet\n");
2476 return WIDGET_ERROR_RESOURCE_BUSY;
2479 if (type & WIDGET_MOUSE_EVENT_GBAR_MASK) {
2480 if (!handle->common->is_gbar_created) {
2481 ErrPrint("GBAR is not created\n");
2482 return WIDGET_ERROR_INVALID_PARAMETER;
2485 if (!handle->common->gbar.fb) {
2486 ErrPrint("Handler is not valid\n");
2487 return WIDGET_ERROR_INVALID_PARAMETER;
2490 if (type & WIDGET_KEY_EVENT_DOWN) {
2493 * filtering the reproduced events if it is too fast
2495 } else if (type & WIDGET_KEY_EVENT_SET) {
2498 * What can I do for this case?
2503 * Must be short than 29 bytes.
2505 switch ((type & ~(WIDGET_MOUSE_EVENT_GBAR_MASK | WIDGET_MOUSE_EVENT_WIDGET_MASK))) {
2506 case WIDGET_KEY_EVENT_FOCUS_IN | WIDGET_KEY_EVENT_MASK:
2507 cmd = CMD_GBAR_KEY_FOCUS_IN;
2509 case WIDGET_KEY_EVENT_FOCUS_OUT | WIDGET_KEY_EVENT_MASK:
2510 cmd = CMD_GBAR_KEY_FOCUS_OUT;
2512 case WIDGET_KEY_EVENT_UP | WIDGET_KEY_EVENT_MASK:
2513 cmd = CMD_GBAR_KEY_UP;
2515 case WIDGET_KEY_EVENT_DOWN | WIDGET_KEY_EVENT_MASK:
2516 cmd = CMD_GBAR_KEY_DOWN;
2518 case WIDGET_KEY_EVENT_SET | WIDGET_KEY_EVENT_MASK:
2519 cmd = CMD_GBAR_KEY_SET;
2521 case WIDGET_KEY_EVENT_UNSET | WIDGET_KEY_EVENT_MASK:
2522 cmd = CMD_GBAR_KEY_UNSET;
2525 ErrPrint("Invalid event type\n");
2526 return WIDGET_ERROR_INVALID_PARAMETER;
2529 } else if (type & WIDGET_MOUSE_EVENT_WIDGET_MASK) {
2530 if (!handle->common->widget.fb) {
2531 ErrPrint("Handler is not valid\n");
2532 return WIDGET_ERROR_INVALID_PARAMETER;
2535 if (type & WIDGET_KEY_EVENT_DOWN) {
2538 * filtering the reproduced events if it is too fast
2540 } else if (type & WIDGET_KEY_EVENT_SET) {
2542 * What can I do for this case?
2546 switch ((type & ~(WIDGET_MOUSE_EVENT_GBAR_MASK | WIDGET_MOUSE_EVENT_WIDGET_MASK))) {
2547 case WIDGET_KEY_EVENT_FOCUS_IN | WIDGET_KEY_EVENT_MASK:
2548 cmd = CMD_WIDGET_KEY_FOCUS_IN;
2550 case WIDGET_KEY_EVENT_FOCUS_OUT | WIDGET_KEY_EVENT_MASK:
2551 cmd = CMD_WIDGET_KEY_FOCUS_OUT;
2553 case WIDGET_KEY_EVENT_UP | WIDGET_KEY_EVENT_MASK:
2554 cmd = CMD_WIDGET_KEY_UP;
2556 case WIDGET_KEY_EVENT_DOWN | WIDGET_KEY_EVENT_MASK:
2557 cmd = CMD_WIDGET_KEY_DOWN;
2559 case WIDGET_KEY_EVENT_SET | WIDGET_KEY_EVENT_MASK:
2560 cmd = CMD_WIDGET_KEY_SET;
2562 case WIDGET_KEY_EVENT_UNSET | WIDGET_KEY_EVENT_MASK:
2563 cmd = CMD_WIDGET_KEY_UNSET;
2566 ErrPrint("Invalid event type\n");
2567 return WIDGET_ERROR_INVALID_PARAMETER;
2570 ErrPrint("Invalid event type\n");
2571 return WIDGET_ERROR_INVALID_PARAMETER;
2575 cb = default_key_event_cb;
2578 ret = send_key_event(handle, (const char *)&cmd, info->keycode, info->device);
2579 if (ret == (int)WIDGET_ERROR_NONE) {
2580 handle->cbs.key_event.cb = cb;
2581 handle->cbs.key_event.data = data;
2582 handle->common->request.key_event = 1;
2588 EAPI const char *widget_viewer_get_filename(widget_h handle)
2590 if (!handle || handle->state != WIDGET_STATE_CREATE) {
2591 ErrPrint("Handler is invalid\n");
2595 if (!handle->common || handle->common->state != WIDGET_STATE_CREATE) {
2596 ErrPrint("Handler is invalid\n");
2600 if (!handle->common->id) {
2601 ErrPrint("Handler is not valid\n");
2605 if (handle->common->filename) {
2606 return handle->common->filename;
2610 set_last_result(WIDGET_ERROR_NONE);
2611 return util_uri_to_path(handle->common->id);
2614 EAPI int widget_viewer_get_glance_bar_size(widget_h handle, int *w, int *h)
2619 if (!handle || handle->state != WIDGET_STATE_CREATE) {
2620 ErrPrint("Handler is invalid\n");
2621 return WIDGET_ERROR_INVALID_PARAMETER;
2624 if (!handle->common || handle->common->state != WIDGET_STATE_CREATE) {
2625 ErrPrint("Handler is invalid\n");
2626 return WIDGET_ERROR_INVALID_PARAMETER;
2629 if (!handle->common->id) {
2630 ErrPrint("Handler is not valid\n");
2631 return WIDGET_ERROR_INVALID_PARAMETER;
2641 if (!handle->common->is_gbar_created) {
2642 *w = handle->common->gbar.default_width;
2643 *h = handle->common->gbar.default_height;
2645 *w = handle->common->gbar.width;
2646 *h = handle->common->gbar.height;
2649 return WIDGET_ERROR_NONE;
2652 EAPI int widget_viewer_get_size_type(widget_h handle, widget_size_type_e *size_type)
2656 int ret = WIDGET_ERROR_NONE;
2657 widget_size_type_e result_size_type = WIDGET_SIZE_TYPE_UNKNOWN;
2659 if (!handle || handle->state != WIDGET_STATE_CREATE || size_type == NULL) {
2660 ErrPrint("Handler is invalid\n");
2661 ret = WIDGET_ERROR_INVALID_PARAMETER;
2665 if (!handle->common || handle->common->state != WIDGET_STATE_CREATE) {
2666 ErrPrint("Handler is invalid\n");
2667 ret = WIDGET_ERROR_INVALID_PARAMETER;
2671 if (!handle->common->id) {
2672 ErrPrint("Handler is not valid\n");
2673 ret = WIDGET_ERROR_INVALID_PARAMETER;
2677 w = handle->common->widget.width;
2678 h = handle->common->widget.height;
2680 switch (handle->common->widget.type) {
2681 case WIDGET_TYPE_BUFFER:
2682 case WIDGET_TYPE_SCRIPT:
2683 if (!fb_is_created(handle->common->widget.fb)) {
2684 DbgPrint("FB is not created yet, but give its size to the caller: %dx%d\n", w, h);
2691 if ((ret = widget_service_get_size_type(w, h, &result_size_type)) != WIDGET_ERROR_NONE) {
2692 ErrPrint("widget_service_get_size_type failed : %d\n", ret);
2699 *size_type = result_size_type;
2705 EAPI int widget_viewer_set_group(widget_h handle, const char *cluster, const char *category, widget_ret_cb cb, void *data)
2707 struct packet *packet;
2708 unsigned int cmd = CMD_CHANGE_GROUP;
2712 ErrPrint("Handler is NIL\n");
2713 return WIDGET_ERROR_INVALID_PARAMETER;
2716 if (!cluster || !category || handle->state != WIDGET_STATE_CREATE) {
2717 ErrPrint("Invalid argument\n");
2718 return WIDGET_ERROR_INVALID_PARAMETER;
2721 if (!handle->common || handle->common->state != WIDGET_STATE_CREATE) {
2722 ErrPrint("Invalid argument\n");
2723 return WIDGET_ERROR_INVALID_PARAMETER;
2726 if (!handle->common->id) {
2727 ErrPrint("Invalid argument\n");
2728 return WIDGET_ERROR_INVALID_PARAMETER;
2731 if (handle->common->request.group_changed) {
2732 ErrPrint("Previous group changing request is not finished yet\n");
2733 return WIDGET_ERROR_RESOURCE_BUSY;
2736 if (!handle->common->is_user) {
2737 ErrPrint("CA Livebox is not able to change the group\n");
2738 return WIDGET_ERROR_PERMISSION_DENIED;
2741 if (!strcmp(handle->common->cluster, cluster) && !strcmp(handle->common->category, category)) {
2742 DbgPrint("No changes\n");
2743 return WIDGET_ERROR_ALREADY_EXIST;
2746 packet = packet_create((const char *)&cmd, "ssss", handle->common->pkgname, handle->common->id, cluster, category);
2748 ErrPrint("Failed to build a param\n");
2749 return WIDGET_ERROR_FAULT;
2753 cb = default_group_changed_cb;
2756 ret = master_rpc_async_request(handle, packet, 0, set_group_ret_cb, NULL);
2757 if (ret == (int)WIDGET_ERROR_NONE) {
2758 handle->cbs.group_changed.cb = cb;
2759 handle->cbs.group_changed.data = data;
2760 handle->common->request.group_changed = 1;
2766 EAPI int widget_viewer_get_group(widget_h handle, const char **cluster, const char **category)
2769 ErrPrint("Handler is NIL\n");
2770 return WIDGET_ERROR_INVALID_PARAMETER;
2773 if (!cluster || !category || handle->state != WIDGET_STATE_CREATE) {
2774 ErrPrint("Invalid argument\n");
2775 return WIDGET_ERROR_INVALID_PARAMETER;
2778 if (!handle->common || handle->common->state != WIDGET_STATE_CREATE) {
2779 ErrPrint("Invalid argument\n");
2780 return WIDGET_ERROR_INVALID_PARAMETER;
2783 if (!handle->common->id) {
2784 ErrPrint("Invalid argument\n");
2785 return WIDGET_ERROR_INVALID_PARAMETER;
2788 *cluster = handle->common->cluster;
2789 *category = handle->common->category;
2790 return WIDGET_ERROR_NONE;
2793 EAPI int widget_viewer_get_supported_sizes(widget_h handle, int *cnt, widget_size_type_e *size_list)
2798 if (!handle || !size_list) {
2799 ErrPrint("Invalid argument, handle(%p), size_list(%p)\n", handle, size_list);
2800 return WIDGET_ERROR_INVALID_PARAMETER;
2803 if (!cnt || handle->state != WIDGET_STATE_CREATE) {
2804 ErrPrint("Handler is not valid\n");
2805 return WIDGET_ERROR_INVALID_PARAMETER;
2808 if (!handle->common || handle->common->state != WIDGET_STATE_CREATE) {
2809 ErrPrint("Handler is not valid\n");
2810 return WIDGET_ERROR_INVALID_PARAMETER;
2813 if (!handle->common->id) {
2814 ErrPrint("Handler is not valid\n");
2815 return WIDGET_ERROR_INVALID_PARAMETER;
2818 for (j = i = 0; i < WIDGET_COUNT_OF_SIZE_TYPE; i++) {
2819 if (handle->common->widget.size_list & (0x01 << i)) {
2824 size_list[j++] = (widget_size_type_e)(0x01 << i);
2829 return WIDGET_ERROR_NONE;
2832 EAPI const char *widget_viewer_get_pkgname(widget_h handle)
2835 ErrPrint("Handler is NIL\n");
2836 set_last_result(WIDGET_ERROR_INVALID_PARAMETER);
2840 if (handle->state != WIDGET_STATE_CREATE) {
2841 ErrPrint("Handler is not valid\n");
2842 set_last_result(WIDGET_ERROR_INVALID_PARAMETER);
2846 if (!handle->common || handle->common->state != WIDGET_STATE_CREATE) {
2847 ErrPrint("Handler is not valid\n");
2848 set_last_result(WIDGET_ERROR_INVALID_PARAMETER);
2852 set_last_result(WIDGET_ERROR_NONE);
2853 return handle->common->pkgname;
2856 EAPI int widget_viewer_get_priority(widget_h handle, double *priority)
2858 int ret = WIDGET_ERROR_NONE;
2859 double result_priority = -1.0f;
2861 if (!handle || handle->state != WIDGET_STATE_CREATE || priority == NULL) {
2862 ErrPrint("Handler is invalid\n");
2863 ret = WIDGET_ERROR_INVALID_PARAMETER;
2867 if (!handle->common || handle->common->state != WIDGET_STATE_CREATE) {
2868 ErrPrint("Handler is invalid\n");
2869 ret = WIDGET_ERROR_INVALID_PARAMETER;
2873 if (!handle->common->id) {
2874 ErrPrint("Handler is not valid (%p)\n", handle);
2875 ret = WIDGET_ERROR_INVALID_PARAMETER;
2879 result_priority = handle->common->widget.priority;
2883 *priority = result_priority;
2888 EAPI int widget_delete_cluster(const char *cluster, widget_ret_cb cb, void *data)
2890 struct packet *packet;
2891 struct cb_info *cbinfo;
2892 unsigned int cmd = CMD_DELETE_CLUSTER;
2895 packet = packet_create((const char *)&cmd, "s", cluster);
2897 ErrPrint("Failed to build a param\n");
2898 return WIDGET_ERROR_FAULT;
2901 cbinfo = _widget_create_cb_info(cb, data);
2903 packet_destroy(packet);
2904 return WIDGET_ERROR_FAULT;
2907 ret = master_rpc_async_request(NULL, packet, 0, _delete_cluster_cb, cbinfo);
2909 _widget_destroy_cb_info(cbinfo);
2915 EAPI int widget_delete_category(const char *cluster, const char *category, widget_ret_cb cb, void *data)
2917 struct packet *packet;
2918 struct cb_info *cbinfo;
2919 unsigned int cmd = CMD_DELETE_CATEGORY;
2922 packet = packet_create((const char *)&cmd, "ss", cluster, category);
2924 ErrPrint("Failed to build a param\n");
2925 return WIDGET_ERROR_FAULT;
2928 cbinfo = _widget_create_cb_info(cb, data);
2930 packet_destroy(packet);
2931 return WIDGET_ERROR_FAULT;
2934 ret = master_rpc_async_request(NULL, packet, 0, _delete_category_cb, cbinfo);
2936 _widget_destroy_cb_info(cbinfo);
2942 EAPI int widget_viewer_get_type(widget_h handle, int gbar, widget_type_e *widget_type)
2944 int ret = WIDGET_ERROR_INVALID_PARAMETER;
2945 widget_type_e result_widget_type = WIDGET_CONTENT_TYPE_INVALID;
2947 if (!handle || handle->state != WIDGET_STATE_CREATE || widget_type == NULL) {
2948 ErrPrint("Handler is invalid\n");
2949 ret = WIDGET_ERROR_INVALID_PARAMETER;
2950 result_widget_type = WIDGET_CONTENT_TYPE_INVALID;
2954 if (!handle->common || handle->common->state != WIDGET_STATE_CREATE) {
2955 ErrPrint("Handler is invalid\n");
2956 ret = WIDGET_ERROR_INVALID_PARAMETER;
2957 result_widget_type = WIDGET_CONTENT_TYPE_INVALID;
2961 if (!handle->common->id) {
2962 ErrPrint("Handler is not valid\n");
2963 ret = WIDGET_ERROR_INVALID_PARAMETER;
2964 result_widget_type = WIDGET_CONTENT_TYPE_INVALID;
2969 switch (handle->common->gbar.type) {
2970 case GBAR_TYPE_TEXT:
2971 result_widget_type = WIDGET_CONTENT_TYPE_TEXT;
2973 case GBAR_TYPE_BUFFER:
2974 case GBAR_TYPE_SCRIPT:
2977 id = fb_id(handle->common->gbar.fb);
2978 if (id && !strncasecmp(id, SCHEMA_PIXMAP, strlen(SCHEMA_PIXMAP))) {
2979 result_widget_type = WIDGET_CONTENT_TYPE_RESOURCE_ID;
2983 result_widget_type = WIDGET_CONTENT_TYPE_BUFFER;
2985 case GBAR_TYPE_UIFW:
2986 result_widget_type = WIDGET_CONTENT_TYPE_UIFW;
2992 switch (handle->common->widget.type) {
2993 case WIDGET_TYPE_FILE:
2994 result_widget_type = WIDGET_CONTENT_TYPE_IMAGE;
2996 case WIDGET_TYPE_BUFFER:
2997 case WIDGET_TYPE_SCRIPT:
3000 id = fb_id(handle->common->widget.fb);
3001 if (id && !strncasecmp(id, SCHEMA_PIXMAP, strlen(SCHEMA_PIXMAP))) {
3002 result_widget_type = WIDGET_CONTENT_TYPE_RESOURCE_ID;
3006 result_widget_type = WIDGET_CONTENT_TYPE_BUFFER;
3008 case WIDGET_TYPE_TEXT:
3009 result_widget_type = WIDGET_CONTENT_TYPE_TEXT;
3011 case WIDGET_TYPE_UIFW:
3012 result_widget_type = WIDGET_CONTENT_TYPE_UIFW;
3021 *widget_type = result_widget_type;
3025 EAPI int widget_viewer_set_text_handler(widget_h handle, int gbar, struct widget_script_operators *ops)
3028 ErrPrint("Handler is NIL\n");
3029 return WIDGET_ERROR_INVALID_PARAMETER;
3032 if (handle->state != WIDGET_STATE_CREATE) {
3033 ErrPrint("Handler is not valid\n");
3034 return WIDGET_ERROR_INVALID_PARAMETER;
3038 memcpy(&handle->cbs.gbar_ops, ops, sizeof(*ops));
3040 memcpy(&handle->cbs.widget_ops, ops, sizeof(*ops));
3043 return WIDGET_ERROR_NONE;
3046 EAPI int widget_viewer_acquire_extra_resource_id(widget_h handle, int gbar, int idx, widget_ret_cb cb, void *data)
3049 return WIDGET_ERROR_INVALID_PARAMETER;
3052 if (!handle || handle->state != WIDGET_STATE_CREATE) {
3053 ErrPrint("Handler is invalid\n");
3054 return WIDGET_ERROR_INVALID_PARAMETER;
3057 if (!handle->common || handle->common->state != WIDGET_STATE_CREATE) {
3058 ErrPrint("Handler is invalid\n");
3059 return WIDGET_ERROR_INVALID_PARAMETER;
3062 if (!handle->common->id) {
3063 ErrPrint("Invalid handle\n");
3064 return WIDGET_ERROR_INVALID_PARAMETER;
3069 * This can be called from extra_resource_created event.
3070 * and it can be called before get the created event.
3071 * then we didn't know this handle's buffer type yet
3072 * so we cannot use its type to validate handle
3074 * handle->common.gbar.type == unknown
3076 if (!handle->common->gbar.extra_buffer) {
3077 return WIDGET_ERROR_NOT_EXIST;
3080 if (idx >= conf_extra_buffer_count()) {
3081 return WIDGET_ERROR_INVALID_PARAMETER;
3084 return widget_acquire_gbar_extra_pixmap(handle, idx, cb, data);
3087 * This can be called from extra_resource_created event.
3088 * and it can be called before get the created event.
3089 * then we didn't know this handle's buffer type yet
3090 * so we cannot use its type to validate handle
3092 * handle->common.widget.type == unknown
3094 if (!handle->common->widget.extra_buffer) {
3095 ErrPrint("Extra buffer is not prepared\n");
3096 return WIDGET_ERROR_NOT_EXIST;
3099 if (idx >= conf_extra_buffer_count()) {
3100 ErrPrint("Invalid parameter: %d / %d\n", idx, conf_extra_buffer_count());
3101 return WIDGET_ERROR_INVALID_PARAMETER;
3104 return widget_acquire_widget_extra_pixmap(handle, idx, cb, data);
3108 EAPI int widget_viewer_acquire_resource_id(widget_h handle, int gbar, widget_ret_cb cb, void *data)
3110 if (!handle || handle->state != WIDGET_STATE_CREATE) {
3111 ErrPrint("Handler is invalid\n");
3112 return WIDGET_ERROR_INVALID_PARAMETER;
3115 if (!handle->common || handle->common->state != WIDGET_STATE_CREATE) {
3116 ErrPrint("Handler is invalid\n");
3117 return WIDGET_ERROR_INVALID_PARAMETER;
3120 if (!handle->common->id) {
3121 ErrPrint("Invalid handle\n");
3122 return WIDGET_ERROR_INVALID_PARAMETER;
3126 if (handle->common->gbar.type != GBAR_TYPE_SCRIPT && handle->common->gbar.type != GBAR_TYPE_BUFFER) {
3127 ErrPrint("Handler is not valid type\n");
3128 return WIDGET_ERROR_INVALID_PARAMETER;
3131 return widget_acquire_gbar_pixmap(handle, cb, data);
3133 if (handle->common->widget.type != WIDGET_TYPE_SCRIPT && handle->common->widget.type != WIDGET_TYPE_BUFFER) {
3134 ErrPrint("Handler is not valid type\n");
3135 return WIDGET_ERROR_INVALID_PARAMETER;
3138 return _widget_acquire_widget_pixmap(handle, cb, data);
3144 * Do not check the state of handle and common-handle.
3145 * If this function is used in the deleted callback,
3146 * the handle and common-handle's state would be DELETE
3147 * if this function check the state of handles,
3148 * user cannot release the pixmap.
3150 EAPI int widget_viewer_release_resource_id(widget_h handle, int gbar, unsigned int resource_id)
3152 struct packet *packet;
3153 const char *pkgname;
3157 if (resource_id == 0 /* || handle->state != WIDGET_STATE_CREATE */) {
3158 ErrPrint("Pixmap is invalid [%d]\n", resource_id);
3159 return WIDGET_ERROR_INVALID_PARAMETER;
3166 * Even though the handle is NULL, we should send the release request to the master.
3167 * Because the resource_id resource can be released after the handle is destroyed.
3168 * Pixmap resource is used by client. and it cannot be guaranteed to release resource_id.
3169 * In some cases, the resource_id can be released after the handle is deleted.
3171 * Its implementation is up to the viewer app.
3172 * But we cannot force it to use only with valid handle.
3174 DbgPrint("Using NULL handle\n");
3179 * Master will try to find the buffer handle using given resource_id. if the pkgname and id is not valid.
3182 if (!handle->common /* || handle-common->state != WIDGET_STATE_CREATE */) {
3183 ErrPrint("Handler is invalid\n");
3184 return WIDGET_ERROR_INVALID_PARAMETER;
3187 if (!handle->common->id) {
3188 ErrPrint("Invalid handle\n");
3189 return WIDGET_ERROR_INVALID_PARAMETER;
3193 * This can be called from extra_resource_created event.
3194 * and it can be called before get the created event.
3195 * then we didn't know this handle's buffer type yet
3196 * so we cannot use its type to validate handle
3198 * handle->common.gbar.type == unknown
3201 pkgname = handle->common->pkgname;
3202 id = handle->common->id;
3205 cmd = CMD_GBAR_RELEASE_PIXMAP;
3210 * Even though the handle is NULL, we should send the release request to the master.
3211 * Because the resource_id resource can be released after the handle is destroyed.
3212 * Pixmap resource is used by client. and it cannot be guaranteed to release resource_id.
3213 * In some cases, the resource_id can be released after the handle is deleted.
3215 * Its implementation is up to the viewer app.
3216 * But we cannot force it to use only with valid handle.
3218 DbgPrint("Using NULL handle\n");
3223 * Master will try to find the buffer handle using given resource_id. if the pkgname and id is not valid.
3226 if (!handle->common /* || handle->common->state != WIDGET_STATE_CREATE */) {
3227 ErrPrint("Handler is invalid\n");
3228 return WIDGET_ERROR_INVALID_PARAMETER;
3231 if (!handle->common->id) {
3232 ErrPrint("Invalid handle\n");
3233 return WIDGET_ERROR_INVALID_PARAMETER;
3237 * This can be called from extra_resource_created event.
3238 * and it can be called before get the created event.
3239 * then we didn't know this handle's buffer type yet
3240 * so we cannot use its type to validate handle
3242 * handle->common.widget.type == unknown
3245 pkgname = handle->common->pkgname;
3246 id = handle->common->id;
3249 cmd = CMD_WIDGET_RELEASE_PIXMAP;
3252 packet = packet_create_noack((const char *)&cmd, "ssi", pkgname, id, resource_id);
3254 ErrPrint("Failed to build a param\n");
3255 return WIDGET_ERROR_FAULT;
3258 return master_rpc_request_only(handle, packet);
3261 EAPI unsigned int widget_extra_resource_id(const widget_h handle, int gbar, int idx)
3264 set_last_result(WIDGET_ERROR_INVALID_PARAMETER);
3268 if (!handle || handle->state != WIDGET_STATE_CREATE) {
3269 ErrPrint("Handler is invalid\n");
3270 set_last_result(WIDGET_ERROR_INVALID_PARAMETER);
3274 if (!handle->common || handle->common->state != WIDGET_STATE_CREATE) {
3275 ErrPrint("Handler is invalid\n");
3276 set_last_result(WIDGET_ERROR_INVALID_PARAMETER);
3280 if (!handle->common->id) {
3281 ErrPrint("Invalid handle\n");
3282 set_last_result(WIDGET_ERROR_INVALID_PARAMETER);
3288 * This can be called from extra_resource_created event.
3289 * and it can be called before get the created event.
3290 * then we didn't know this handle's buffer type yet
3291 * so we cannot use its type to validate handle
3293 * handle->common.gbar.type == unknown
3296 if (!handle->common->gbar.extra_buffer || handle->common->gbar.last_extra_buffer_idx < 0) {
3297 set_last_result(WIDGET_ERROR_NOT_EXIST);
3301 return handle->common->gbar.extra_buffer[handle->common->gbar.last_extra_buffer_idx];
3304 * This can be called from extra_resource_created event.
3305 * and it can be called before get the created event.
3306 * then we didn't know this handle's buffer type yet
3307 * so we cannot use its type to validate handle
3309 * handle->common.widget.type == unknown
3312 if (!handle->common->widget.extra_buffer || handle->common->widget.last_extra_buffer_idx < 0) {
3313 set_last_result(WIDGET_ERROR_NOT_EXIST);
3317 return handle->common->widget.extra_buffer[handle->common->widget.last_extra_buffer_idx];
3321 EAPI int widget_viewer_get_resource_id(const widget_h handle, int gbar, unsigned int *resouce_id)
3324 unsigned int pixmap = 0u;
3325 int ret = WIDGET_ERROR_NONE;
3327 if (!handle || handle->state != WIDGET_STATE_CREATE || resouce_id == NULL) {
3328 ErrPrint("Handler is invalid\n");
3329 ret = WIDGET_ERROR_INVALID_PARAMETER;
3333 if (!handle->common || handle->common->state != WIDGET_STATE_CREATE) {
3334 ErrPrint("Handler is invalid\n");
3335 ret = WIDGET_ERROR_INVALID_PARAMETER;
3339 if (!handle->common->id) {
3340 ErrPrint("Invalid handle\n");
3341 ret = WIDGET_ERROR_INVALID_PARAMETER;
3346 if (handle->common->gbar.type != GBAR_TYPE_SCRIPT && handle->common->gbar.type != GBAR_TYPE_BUFFER) {
3347 ErrPrint("Invalid handle\n");
3348 ret = WIDGET_ERROR_INVALID_PARAMETER;
3352 id = fb_id(handle->common->gbar.fb);
3353 if (id && sscanf(id, SCHEMA_PIXMAP "%u", &pixmap) != 1) {
3354 ErrPrint("PIXMAP Id is not valid\n");
3355 ret = WIDGET_ERROR_INVALID_PARAMETER;
3359 if (handle->common->widget.type != WIDGET_TYPE_SCRIPT && handle->common->widget.type != WIDGET_TYPE_BUFFER) {
3360 ErrPrint("Invalid handle\n");
3361 ret = WIDGET_ERROR_INVALID_PARAMETER;
3365 id = fb_id(handle->common->widget.fb);
3366 if (id && sscanf(id, SCHEMA_PIXMAP "%u", &pixmap) != 1) {
3367 ErrPrint("PIXMAP Id is not valid\n");
3368 ret = WIDGET_ERROR_INVALID_PARAMETER;
3374 *resouce_id = pixmap;
3379 EAPI void *widget_viewer_acquire_buffer(widget_h handle, int gbar)
3381 if (!handle || handle->state != WIDGET_STATE_CREATE) {
3382 ErrPrint("Handler is invalid\n");
3383 set_last_result(WIDGET_ERROR_INVALID_PARAMETER);
3387 if (!handle->common || handle->common->state != WIDGET_STATE_CREATE) {
3388 ErrPrint("Handler is invalid\n");
3389 set_last_result(WIDGET_ERROR_INVALID_PARAMETER);
3393 if (!handle->common->id) {
3394 ErrPrint("Invalid handle\n");
3395 set_last_result(WIDGET_ERROR_INVALID_PARAMETER);
3400 if (handle->common->gbar.type != GBAR_TYPE_SCRIPT && handle->common->gbar.type != GBAR_TYPE_BUFFER) {
3401 ErrPrint("Handler is not valid type\n");
3402 set_last_result(WIDGET_ERROR_INVALID_PARAMETER);
3406 return fb_acquire_buffer(handle->common->gbar.fb);
3408 if (handle->common->widget.type != WIDGET_TYPE_SCRIPT && handle->common->widget.type != WIDGET_TYPE_BUFFER) {
3409 ErrPrint("Handler is not valid type\n");
3410 set_last_result(WIDGET_ERROR_INVALID_PARAMETER);
3414 return fb_acquire_buffer(handle->common->widget.fb);
3418 EAPI int widget_viewer_release_buffer(void *buffer)
3420 return fb_release_buffer(buffer);
3423 EAPI int widget_viewer_get_buffer_reference_count(void *buffer)
3425 return fb_refcnt(buffer);
3428 EAPI int widget_viewer_get_buffer_size(widget_h handle, int gbar)
3430 if (!handle || handle->state != WIDGET_STATE_CREATE) {
3431 ErrPrint("Handler is invalid\n");
3432 set_last_result(WIDGET_ERROR_INVALID_PARAMETER);
3433 return WIDGET_ERROR_INVALID_PARAMETER;
3436 if (!handle->common || handle->common->state != WIDGET_STATE_CREATE) {
3437 ErrPrint("Handler is invalid\n");
3438 set_last_result(WIDGET_ERROR_INVALID_PARAMETER);
3439 return WIDGET_ERROR_INVALID_PARAMETER;
3442 if (!handle->common->id) {
3443 ErrPrint("Invalid handle\n");
3444 set_last_result(WIDGET_ERROR_INVALID_PARAMETER);
3445 return WIDGET_ERROR_INVALID_PARAMETER;
3449 return fb_size(handle->common->gbar.fb);
3451 return fb_size(handle->common->widget.fb);
3455 EAPI int widget_viewer_is_created_by_user(widget_h handle)
3457 if (!handle || handle->state != WIDGET_STATE_CREATE) {
3458 ErrPrint("Handler is invalid\n");
3459 set_last_result(WIDGET_ERROR_INVALID_PARAMETER);
3460 return WIDGET_ERROR_INVALID_PARAMETER;
3463 if (!handle->common || handle->common->state != WIDGET_STATE_CREATE) {
3464 ErrPrint("Handler is invalid\n");
3465 set_last_result(WIDGET_ERROR_INVALID_PARAMETER);
3466 return WIDGET_ERROR_INVALID_PARAMETER;
3469 if (!handle->common->id) {
3470 ErrPrint("Invalid handle\n");
3471 set_last_result(WIDGET_ERROR_INVALID_PARAMETER);
3472 return WIDGET_ERROR_INVALID_PARAMETER;
3475 return handle->common->is_user;
3478 EAPI int widget_viewer_set_pinup(widget_h handle, int flag, widget_ret_cb cb, void *data)
3480 struct packet *packet;
3481 unsigned int cmd = CMD_PINUP_CHANGED;
3484 if (!handle || handle->state != WIDGET_STATE_CREATE) {
3485 ErrPrint("Handler is invalid\n");
3486 return WIDGET_ERROR_INVALID_PARAMETER;
3489 if (!handle->common || handle->common->state != WIDGET_STATE_CREATE) {
3490 ErrPrint("Handler is invalid\n");
3491 return WIDGET_ERROR_INVALID_PARAMETER;
3494 if (!handle->common->id) {
3495 ErrPrint("Invalid handle\n");
3496 return WIDGET_ERROR_INVALID_PARAMETER;
3499 if (handle->common->request.pinup) {
3500 ErrPrint("Previous pinup request is not finished\n");
3501 return WIDGET_ERROR_RESOURCE_BUSY;
3504 if (handle->common->is_pinned_up == flag) {
3505 DbgPrint("No changes\n");
3506 return WIDGET_ERROR_ALREADY_EXIST;
3509 packet = packet_create((const char *)&cmd, "ssi", handle->common->pkgname, handle->common->id, flag);
3511 ErrPrint("Failed to build a param\n");
3512 return WIDGET_ERROR_FAULT;
3516 cb = default_pinup_cb;
3519 ret = master_rpc_async_request(handle, packet, 0, pinup_done_cb, NULL);
3520 if (ret == (int)WIDGET_ERROR_NONE) {
3521 handle->cbs.pinup.cb = cb;
3522 handle->cbs.pinup.data = data;
3523 handle->common->request.pinup = 1;
3529 EAPI int widget_viewer_is_pinned_up(widget_h handle)
3531 if (!handle || handle->state != WIDGET_STATE_CREATE) {
3532 ErrPrint("Handler is invalid\n");
3533 set_last_result(WIDGET_ERROR_INVALID_PARAMETER);
3534 return WIDGET_ERROR_INVALID_PARAMETER;
3537 if (!handle->common || handle->common->state != WIDGET_STATE_CREATE) {
3538 ErrPrint("Handler is invalid\n");
3539 set_last_result(WIDGET_ERROR_INVALID_PARAMETER);
3540 return WIDGET_ERROR_INVALID_PARAMETER;
3543 if (!handle->common->id) {
3544 ErrPrint("Invalid handle\n");
3545 set_last_result(WIDGET_ERROR_INVALID_PARAMETER);
3546 return WIDGET_ERROR_INVALID_PARAMETER;
3549 return handle->common->is_pinned_up;
3552 EAPI int widget_viewer_has_pinup(widget_h handle)
3554 if (!handle || handle->state != WIDGET_STATE_CREATE) {
3555 ErrPrint("Handler is invalid\n");
3556 set_last_result(WIDGET_ERROR_INVALID_PARAMETER);
3557 return WIDGET_ERROR_INVALID_PARAMETER;
3560 if (!handle->common || handle->common->state != WIDGET_STATE_CREATE) {
3561 ErrPrint("Handler is invalid\n");
3562 set_last_result(WIDGET_ERROR_INVALID_PARAMETER);
3563 return WIDGET_ERROR_INVALID_PARAMETER;
3566 if (!handle->common->id) {
3567 ErrPrint("Invalid handle\n");
3568 set_last_result(WIDGET_ERROR_INVALID_PARAMETER);
3569 return WIDGET_ERROR_INVALID_PARAMETER;
3572 return handle->common->widget.pinup_supported;
3575 EAPI int widget_viewer_set_data(widget_h handle, void *data)
3578 ErrPrint("Handler is NIL\n");
3579 return WIDGET_ERROR_INVALID_PARAMETER;
3582 if (handle->state != WIDGET_STATE_CREATE) {
3583 ErrPrint("Handler is invalid\n");
3584 return WIDGET_ERROR_INVALID_PARAMETER;
3587 handle->data = data;
3588 return WIDGET_ERROR_NONE;
3591 EAPI void *widget_viewer_get_data(widget_h handle)
3594 ErrPrint("Handler is NIL\n");
3595 set_last_result(WIDGET_ERROR_INVALID_PARAMETER);
3599 if (handle->state != WIDGET_STATE_CREATE) {
3600 ErrPrint("Handler is invalid\n");
3601 set_last_result(WIDGET_ERROR_INVALID_PARAMETER);
3605 return handle->data;
3608 EAPI const char *widget_viewer_get_content_string(widget_h handle)
3610 if (!handle || handle->state != WIDGET_STATE_CREATE) {
3611 ErrPrint("Handler is invalid\n");
3612 set_last_result(WIDGET_ERROR_INVALID_PARAMETER);
3616 if (!handle->common || handle->common->state != WIDGET_STATE_CREATE) {
3617 ErrPrint("Invalid handle\n");
3618 set_last_result(WIDGET_ERROR_INVALID_PARAMETER);
3622 set_last_result(WIDGET_ERROR_NONE);
3623 return handle->common->content;
3626 EAPI const char *widget_viewer_get_title_string(widget_h handle)
3628 if (!handle || handle->state != WIDGET_STATE_CREATE) {
3629 ErrPrint("Handler is invalid\n");
3630 set_last_result(WIDGET_ERROR_INVALID_PARAMETER);
3634 if (!handle->common || handle->common->state != WIDGET_STATE_CREATE) {
3635 ErrPrint("Invalid handle\n");
3636 set_last_result(WIDGET_ERROR_INVALID_PARAMETER);
3640 set_last_result(WIDGET_ERROR_NONE);
3641 return handle->common->title;
3644 EAPI int widget_viewer_emit_text_signal(widget_h handle, widget_text_signal_s event_info, widget_ret_cb cb, void *data)
3646 struct packet *packet;
3647 struct cb_info *cbinfo;
3648 unsigned int cmd = CMD_TEXT_SIGNAL;
3650 const char *signal_name;
3653 if (!handle || handle->state != WIDGET_STATE_CREATE) {
3654 ErrPrint("Handler is invalid\n");
3655 return WIDGET_ERROR_INVALID_PARAMETER;
3658 if (!handle->common || handle->common->state != WIDGET_STATE_CREATE) {
3659 ErrPrint("Handler is invalid\n");
3660 return WIDGET_ERROR_INVALID_PARAMETER;
3663 if (handle->common->widget.type != WIDGET_TYPE_TEXT && handle->common->gbar.type != GBAR_TYPE_TEXT) {
3664 DbgPrint("Not a text box, but send signal\n");
3667 if (!handle->common->id) {
3668 ErrPrint("Handler is not valid\n");
3669 return WIDGET_ERROR_INVALID_PARAMETER;
3673 ErrPrint("Invalid event info\n");
3674 return WIDGET_ERROR_INVALID_PARAMETER;
3677 signal_name = event_info->signal_name;
3682 source = event_info->source;
3687 packet = packet_create((const char *)&cmd, "ssssdddd",
3688 handle->common->pkgname, handle->common->id,
3689 signal_name, source,
3690 event_info->geometry.sx, event_info->geometry.sy,
3691 event_info->geometry.ex, event_info->geometry.ey);
3693 ErrPrint("Failed to build a param\n");
3694 return WIDGET_ERROR_FAULT;
3697 cbinfo = _widget_create_cb_info(cb, data);
3699 packet_destroy(packet);
3700 return WIDGET_ERROR_FAULT;
3703 ret = master_rpc_async_request(handle, packet, 0, text_signal_cb, cbinfo);
3705 _widget_destroy_cb_info(cbinfo);
3711 EAPI int widget_viewer_subscribe_group(const char *cluster, const char *category)
3713 struct packet *packet;
3714 unsigned int cmd = CMD_SUBSCRIBE;
3718 * Validate the group info using DB
3719 * If the group info is not valid, do not send this request
3722 packet = packet_create_noack((const char *)&cmd, "ss", cluster ? cluster : "", category ? category : "");
3724 ErrPrint("Failed to create a packet\n");
3725 return WIDGET_ERROR_FAULT;
3728 return master_rpc_request_only(NULL, packet);
3731 EAPI int widget_viewer_unsubscribe_group(const char *cluster, const char *category)
3733 struct packet *packet;
3734 unsigned int cmd = CMD_UNSUBSCRIBE;
3738 * Validate the group info using DB
3739 * If the group info is not valid, do not send this request
3740 * AND Check the subscribed or not too
3743 packet = packet_create_noack((const char *)&cmd, "ss", cluster ? cluster : "", category ? category : "");
3745 ErrPrint("Failed to create a packet\n");
3746 return WIDGET_ERROR_FAULT;
3749 return master_rpc_request_only(NULL, packet);
3752 EAPI int widget_viewer_subscribe_category(const char *category)
3754 struct packet *packet;
3755 unsigned int cmd = CMD_SUBSCRIBE_CATEGORY;
3758 return WIDGET_ERROR_INVALID_PARAMETER;
3761 packet = packet_create_noack((const char *)&cmd, "s", category);
3763 ErrPrint("Failed to create a packet\n");
3764 return WIDGET_ERROR_FAULT;
3767 return master_rpc_request_only(NULL, packet);
3770 EAPI int widget_viewer_unsubscribe_category(const char *category)
3772 struct packet *packet;
3773 unsigned int cmd = CMD_UNSUBSCRIBE_CATEGORY;
3776 return WIDGET_ERROR_INVALID_PARAMETER;
3779 packet = packet_create_noack((const char *)&cmd, "s", category);
3781 ErrPrint("Failed to create a packet\n");
3782 return WIDGET_ERROR_FAULT;
3785 return master_rpc_request_only(NULL, packet);
3788 EAPI int widget_viewer_refresh(widget_h handle, int force)
3790 struct packet *packet;
3791 unsigned int cmd = CMD_UPDATE;
3793 if (!handle || handle->state != WIDGET_STATE_CREATE) {
3794 ErrPrint("Handler is invalid\n");
3795 return WIDGET_ERROR_INVALID_PARAMETER;
3798 if (!handle->common || handle->common->state != WIDGET_STATE_CREATE) {
3799 ErrPrint("Handler is not valid\n");
3800 return WIDGET_ERROR_INVALID_PARAMETER;
3803 if (!handle->common->id) {
3804 ErrPrint("Handler is not valid\n");
3805 return WIDGET_ERROR_INVALID_PARAMETER;
3808 packet = packet_create_noack((const char *)&cmd, "ssi", handle->common->pkgname, handle->common->id, force);
3810 ErrPrint("Failed to create a packet\n");
3811 return WIDGET_ERROR_FAULT;
3814 return master_rpc_request_only(handle, packet);
3817 EAPI int widget_viewer_refresh_group(const char *cluster, const char *category, int force)
3819 struct packet *packet;
3820 unsigned int cmd = CMD_REFRESH_GROUP;
3822 if (!cluster || !category) {
3823 ErrPrint("Invalid argument\n");
3824 return WIDGET_ERROR_INVALID_PARAMETER;
3827 packet = packet_create_noack((const char *)&cmd, "ssi", cluster, category, force);
3829 ErrPrint("Failed to create a packet\n");
3830 return WIDGET_ERROR_FAULT;
3833 return master_rpc_request_only(NULL, packet);
3836 EAPI int widget_viewer_set_visibility(widget_h handle, widget_visible_state_e state)
3841 if (!handle || handle->state != WIDGET_STATE_CREATE) {
3842 ErrPrint("Handler is invalid\n");
3843 return WIDGET_ERROR_INVALID_PARAMETER;
3846 if (!handle->common || handle->common->state != WIDGET_STATE_CREATE) {
3847 ErrPrint("Handler is not valid\n");
3848 return WIDGET_ERROR_INVALID_PARAMETER;
3851 if (!handle->common->id) {
3852 ErrPrint("Handler is not valid\n");
3853 return WIDGET_ERROR_INVALID_PARAMETER;
3856 if (!handle->common->is_user) {
3857 /* System cluster widget cannot be changed its visible states */
3858 if (state == WIDGET_HIDE_WITH_PAUSE) {
3859 ErrPrint("CA Livebox is not able to change the visibility\n");
3860 return WIDGET_ERROR_PERMISSION_DENIED;
3864 if (handle->visible == state) {
3865 DbgPrint("%s has no changes\n", handle->common->pkgname);
3866 return WIDGET_ERROR_ALREADY_EXIST;
3869 old_state = handle->visible;
3870 handle->visible = state;
3872 ret = _widget_set_visibility(handle, state);
3874 handle->visible = old_state;
3880 EAPI widget_visible_state_e widget_viewer_get_visibility(widget_h handle)
3882 if (!handle || handle->state != WIDGET_STATE_CREATE) {
3883 ErrPrint("Handler is invalid\n");
3884 set_last_result(WIDGET_ERROR_INVALID_PARAMETER);
3885 return WIDGET_VISIBLE_ERROR;
3888 if (!handle->common || handle->common->state != WIDGET_STATE_CREATE) {
3889 ErrPrint("Handler is not valid\n");
3890 set_last_result(WIDGET_ERROR_INVALID_PARAMETER);
3891 return WIDGET_VISIBLE_ERROR;
3894 if (!handle->common->id) {
3895 ErrPrint("Handler is not valid\n");
3896 set_last_result(WIDGET_ERROR_INVALID_PARAMETER);
3897 return WIDGET_VISIBLE_ERROR;
3900 return handle->visible;
3903 EAPI int widget_viewer_notify_paused_status_of_viewer(void)
3905 struct packet *packet;
3906 unsigned int cmd = CMD_CLIENT_PAUSED;
3908 packet = packet_create_noack((const char *)&cmd, "d", util_timestamp());
3910 ErrPrint("Failed to create a pause packet\n");
3911 return WIDGET_ERROR_FAULT;
3914 return master_rpc_request_only(NULL, packet);
3917 EAPI int widget_viewer_notify_resumed_status_of_viewer(void)
3919 struct packet *packet;
3920 unsigned int cmd = CMD_CLIENT_RESUMED;
3922 packet = packet_create_noack((const char *)&cmd, "d", util_timestamp());
3924 ErrPrint("Failed to create a resume packet\n");
3925 return WIDGET_ERROR_FAULT;
3928 return master_rpc_request_only(NULL, packet);
3931 EAPI int widget_viewer_notify_orientation_of_viewer(int orientation)
3933 struct packet *packet;
3934 unsigned int cmd = CMD_ORIENTATION;
3936 if (orientation < 0 || orientation > 360) {
3937 ErrPrint("Invalid parameter: %d\n", orientation);
3938 return WIDGET_ERROR_INVALID_PARAMETER;
3941 packet = packet_create_noack((const char *)&cmd, "di", util_timestamp(), orientation);
3943 ErrPrint("Failed to create a orientation packet\n");
3944 return WIDGET_ERROR_FAULT;
3947 return master_rpc_request_only(NULL, packet);
3950 EAPI int widget_viewer_sync_buffer(widget_h handle, int gbar)
3952 if (!handle || handle->state != WIDGET_STATE_CREATE) {
3953 ErrPrint("Invalid handle\n");
3954 return WIDGET_ERROR_INVALID_PARAMETER;
3957 if (!handle->common || handle->common->state != WIDGET_STATE_CREATE) {
3958 ErrPrint("Invalid handle\n");
3959 return WIDGET_ERROR_INVALID_PARAMETER;
3962 if (!handle->common->id) {
3963 ErrPrint("Invalid handle\n");
3964 return WIDGET_ERROR_INVALID_PARAMETER;
3968 return _widget_sync_gbar_fb(handle->common);
3970 return _widget_sync_widget_fb(handle->common);
3974 EAPI const char *widget_viewer_get_alternative_icon(widget_h handle)
3976 if (!handle || handle->state != WIDGET_STATE_CREATE) {
3977 ErrPrint("Handler is not valid[%p]\n", handle);
3978 set_last_result(WIDGET_ERROR_INVALID_PARAMETER);
3982 if (!handle->common || handle->common->state != WIDGET_STATE_CREATE) {
3983 ErrPrint("Handler is not valid\n");
3984 set_last_result(WIDGET_ERROR_INVALID_PARAMETER);
3988 return handle->common->alt.icon;
3991 EAPI const char *widget_viewer_get_alternative_name(widget_h handle)
3993 if (!handle || handle->state != WIDGET_STATE_CREATE) {
3994 ErrPrint("Handler is not valid[%p]\n", handle);
3995 set_last_result(WIDGET_ERROR_INVALID_PARAMETER);
3999 if (!handle->common || handle->common->state != WIDGET_STATE_CREATE) {
4000 ErrPrint("Handler is not valid\n");
4001 set_last_result(WIDGET_ERROR_INVALID_PARAMETER);
4005 return handle->common->alt.name;
4008 EAPI int widget_viewer_acquire_buffer_lock(widget_h handle, int is_gbar)
4010 int ret = WIDGET_ERROR_NONE;
4012 if (!handle || handle->state != WIDGET_STATE_CREATE) {
4013 ErrPrint("Handler is not valid[%p]\n", handle);
4014 return WIDGET_ERROR_INVALID_PARAMETER;
4017 if (!handle->common || handle->common->state != WIDGET_STATE_CREATE) {
4018 ErrPrint("Handler is not valid\n");
4019 return WIDGET_ERROR_INVALID_PARAMETER;
4022 if (!handle->common->id) {
4023 ErrPrint("Handler is not valid[%p]\n", handle);
4024 return WIDGET_ERROR_INVALID_PARAMETER;
4028 ret = widget_service_acquire_lock(handle->common->gbar.lock);
4030 ret = widget_service_acquire_lock(handle->common->widget.lock);
4033 return ret == 0 ? WIDGET_ERROR_NONE : WIDGET_ERROR_FAULT;
4036 EAPI int widget_viewer_release_buffer_lock(widget_h handle, int is_gbar)
4038 int ret = WIDGET_ERROR_NONE;
4040 if (!handle || handle->state != WIDGET_STATE_CREATE) {
4041 ErrPrint("Invalid handle\n");
4042 return WIDGET_ERROR_INVALID_PARAMETER;
4045 if (!handle->common || handle->common->state != WIDGET_STATE_CREATE) {
4046 ErrPrint("Invalid handle\n");
4047 return WIDGET_ERROR_INVALID_PARAMETER;
4050 if (!handle->common->id) {
4051 ErrPrint("Handler is not valid[%p]\n", handle);
4052 return WIDGET_ERROR_INVALID_PARAMETER;
4056 ret = widget_service_release_lock(handle->common->gbar.lock);
4058 ret = widget_service_release_lock(handle->common->widget.lock);
4061 return ret == 0 ? WIDGET_ERROR_NONE : WIDGET_ERROR_FAULT;
4064 EAPI int widget_viewer_set_option(widget_option_type_e option, int state)
4066 int ret = WIDGET_ERROR_NONE;
4069 case WIDGET_OPTION_MANUAL_SYNC:
4070 conf_set_manual_sync(state);
4072 case WIDGET_OPTION_FRAME_DROP_FOR_RESIZE:
4073 conf_set_frame_drop_for_resizing(state);
4075 case WIDGET_OPTION_SHARED_CONTENT:
4076 conf_set_shared_content(state);
4078 case WIDGET_OPTION_DIRECT_UPDATE:
4079 if (s_info.init_count) {
4080 DbgPrint("Already intialized, this option is not applied\n");
4082 conf_set_direct_update(state);
4084 case WIDGET_OPTION_EXTRA_BUFFER_CNT:
4085 ErrPrint("Permission denied\n");
4086 ret = WIDGET_ERROR_PERMISSION_DENIED;
4089 ret = WIDGET_ERROR_INVALID_PARAMETER;
4096 EAPI int widget_viewer_get_option(widget_option_type_e option)
4100 set_last_result(WIDGET_ERROR_NONE);
4102 case WIDGET_OPTION_MANUAL_SYNC:
4103 ret = conf_manual_sync();
4105 case WIDGET_OPTION_FRAME_DROP_FOR_RESIZE:
4106 ret = conf_frame_drop_for_resizing();
4108 case WIDGET_OPTION_SHARED_CONTENT:
4109 ret = conf_shared_content();
4111 case WIDGET_OPTION_DIRECT_UPDATE:
4112 ret = conf_direct_update();
4114 case WIDGET_OPTION_EXTRA_BUFFER_CNT:
4115 ret = conf_extra_buffer_count();
4118 ret = WIDGET_ERROR_INVALID_PARAMETER;
4119 set_last_result(WIDGET_ERROR_INVALID_PARAMETER);
4126 EAPI int widget_viewer_set_auto_launch_handler(widget_auto_launch_handler_cb widget_launch_handler, void *data)
4128 s_info.launch.handle = widget_launch_handler;
4129 s_info.launch.data = data;
4131 return WIDGET_ERROR_NONE;
4134 EAPI int widget_viewer_get_damaged_region(widget_h handle, int gbar, const widget_damage_region_s *region)
4136 if (!handle || handle->state != WIDGET_STATE_CREATE) {
4137 ErrPrint("Invalid handle\n");
4138 return WIDGET_ERROR_INVALID_PARAMETER;
4141 if (!handle->common || handle->common->state != WIDGET_STATE_CREATE) {
4142 ErrPrint("Invalid handle\n");
4143 return WIDGET_ERROR_INVALID_PARAMETER;
4146 if (!handle->common->id) {
4147 ErrPrint("Handler is not valid[%p]\n", handle);
4148 return WIDGET_ERROR_INVALID_PARAMETER;
4152 region = &handle->common->widget.last_damage;
4154 region = &handle->common->gbar.last_damage;
4157 return WIDGET_ERROR_NONE;
4160 EAPI int widget_viewer_get_affected_extra_buffer(widget_h handle, int gbar, int *idx, unsigned int *resource_id)
4163 unsigned int _resource_id;
4165 if (!handle || handle->state != WIDGET_STATE_CREATE) {
4166 ErrPrint("Invalid handle\n");
4167 return WIDGET_ERROR_INVALID_PARAMETER;
4170 if (!handle->common || handle->common->state != WIDGET_STATE_CREATE) {
4171 ErrPrint("Invalid handle\n");
4172 return WIDGET_ERROR_INVALID_PARAMETER;
4175 if (!handle->common->id) {
4176 ErrPrint("Handler is not valid[%p]\n", handle);
4177 return WIDGET_ERROR_INVALID_PARAMETER;
4185 resource_id = &_resource_id;
4189 if (!handle->common->gbar.extra_buffer || handle->common->gbar.last_extra_buffer_idx < 0) {
4190 return WIDGET_ERROR_NOT_EXIST;
4193 *idx = handle->common->gbar.last_extra_buffer_idx;
4194 *resource_id = handle->common->gbar.extra_buffer[*idx];
4196 if (!handle->common->widget.extra_buffer || handle->common->widget.last_extra_buffer_idx < 0) {
4197 return WIDGET_ERROR_NOT_EXIST;
4200 *idx = handle->common->widget.last_extra_buffer_idx;
4201 *resource_id = handle->common->widget.extra_buffer[*idx];
4204 return WIDGET_ERROR_NONE;
4207 EAPI int widget_viewer_get_instance_id(widget_h handle, char **instance_id)
4209 if (!handle || handle->state != WIDGET_STATE_CREATE || !instance_id) {
4210 ErrPrint("Invalid handle\n");
4211 return WIDGET_ERROR_INVALID_PARAMETER;
4214 if (!handle->common || handle->common->state != WIDGET_STATE_CREATE) {
4215 ErrPrint("Invalid handle\n");
4216 return WIDGET_ERROR_INVALID_PARAMETER;
4219 if (!handle->common->id) {
4220 ErrPrint("Handler is not valid[%p]\n", handle);
4221 return WIDGET_ERROR_INVALID_PARAMETER;
4224 *instance_id = strdup(handle->common->id);
4225 if (!*instance_id) {
4226 ErrPrint("Out of memory: %d\n", errno);
4227 return WIDGET_ERROR_OUT_OF_MEMORY;
4230 return WIDGET_ERROR_NONE;