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 <dynamicbox_service.h>
34 #include <dynamicbox_errno.h>
35 #include <dynamicbox_cmd_list.h>
36 #include <dynamicbox_buffer.h>
40 #include "dynamicbox.h"
41 #include "dynamicbox_internal.h"
44 #include "master_rpc.h"
48 #define EAPI __attribute__((visibility("default")))
54 static int default_launch_handler(dynamicbox_h handler, const char *appid, void *data);
58 int prevent_overwrite;
60 struct dlist *job_list;
63 int (*handler)(dynamicbox_h handler, const char *appid, void *data);
68 .prevent_overwrite = 0,
72 .handler = default_launch_handler,
77 static void dbox_pixmap_acquired_cb(dynamicbox_h handler, const struct packet *result, void *data);
78 static void gbar_pixmap_acquired_cb(dynamicbox_h handler, const struct packet *result, void *data);
79 static void gbar_xpixmap_acquired_cb(dynamicbox_h handler, const struct packet *result, void *data);
80 static void dbox_xpixmap_acquired_cb(dynamicbox_h handler, const struct packet *result, void *data);
82 static int default_launch_handler(dynamicbox_h handler, const char *appid, void *data)
86 ret = aul_launch_app(appid, NULL);
88 ErrPrint("Failed to launch an app %s (%d)\n", appid, ret);
92 app_control_h service;
94 DbgPrint("AUTO_LAUNCH [%s]\n", handler->common->dbox.auto_launch);
96 ret = app_control_create(&service);
97 if (ret == APP_CONTROL_ERROR_NONE) {
98 app_control_set_package(service, handler->common->dbox.auto_launch);
99 app_control_send_launch_request(service, NULL, NULL);
100 app_control_destroy(service);
102 ErrPrint("Failed to launch an app %s (%d)\n", handler->common->dbox.auto_launch, ret);
106 return ret > 0 ? DBOX_STATUS_ERROR_NONE : DBOX_STATUS_ERROR_FAULT;
109 static inline void default_create_cb(dynamicbox_h handler, int ret, void *data)
111 DbgPrint("Default created event handler: %d\n", ret);
114 static inline void default_pinup_cb(dynamicbox_h handler, int ret, void *data)
116 DbgPrint("Default pinup event handler: %d\n", ret);
119 static inline void default_group_changed_cb(dynamicbox_h handler, int ret, void *data)
121 DbgPrint("Default group changed event handler: %d\n", ret);
124 static inline void default_period_changed_cb(dynamicbox_h handler, int ret, void *data)
126 DbgPrint("Default period changed event handler: %d\n", ret);
129 static inline void default_gbar_created_cb(dynamicbox_h handler, int ret, void *data)
131 DbgPrint("Default GBAR created event handler: %d\n", ret);
134 static inline void default_gbar_destroyed_cb(dynamicbox_h handler, int ret, void *data)
136 DbgPrint("Default GBAR destroyed event handler: %d\n", ret);
139 static inline void default_dbox_size_changed_cb(dynamicbox_h handler, int ret, void *data)
141 DbgPrint("Default DBOX size changed event handler: %d\n", ret);
144 static inline void default_update_mode_cb(dynamicbox_h handler, int ret, void *data)
146 DbgPrint("Default update mode set event handler: %d\n", ret);
149 static inline void default_access_event_cb(dynamicbox_h handler, int ret, void *data)
151 DbgPrint("Default access event handler: %d\n", ret);
154 static inline void default_key_event_cb(dynamicbox_h handler, int ret, void *data)
156 DbgPrint("Default key event handler: %d\n", ret);
159 static void update_mode_cb(dynamicbox_h handler, const struct packet *result, void *data)
164 ret = DBOX_STATUS_ERROR_FAULT;
166 } else if (packet_get(result, "i", &ret) != 1) {
167 ErrPrint("Invalid argument\n");
168 ret = DBOX_STATUS_ERROR_INVALID_PARAMETER;
173 ErrPrint("Resize request is failed: %d\n", ret);
180 handler->cbs.update_mode.cb(handler, ret, handler->cbs.update_mode.data);
181 handler->cbs.update_mode.cb = NULL;
182 handler->cbs.update_mode.data = NULL;
183 handler->common->request.update_mode = 0;
185 if (handler->common->state != DBOX_STATE_DELETE) {
186 if (ret == (int)DBOX_STATUS_ERROR_NOT_EXIST && handler->refcnt == 2) {
187 dbox_invoke_event_handler(handler, DBOX_EVENT_DELETED);
188 dbox_unref(handler, 1);
193 static void resize_cb(dynamicbox_h handler, const struct packet *result, void *data)
198 ret = DBOX_STATUS_ERROR_FAULT;
200 } else if (packet_get(result, "i", &ret) != 1) {
201 ErrPrint("Invalid argument\n");
202 ret = DBOX_STATUS_ERROR_INVALID_PARAMETER;
208 * In case of resize request,
209 * The dynamicbox handler will not have resized value right after this callback,
210 * It can only get the new size when it makes updates.
212 * So the user can only get the resized value(result) from the first update event
213 * after this request.
216 ErrPrint("Resize request is failed: %d\n", ret);
223 handler->cbs.size_changed.cb(handler, ret, handler->cbs.size_changed.data);
224 handler->cbs.size_changed.cb = NULL;
225 handler->cbs.size_changed.data = NULL;
226 handler->common->request.size_changed = 0;
228 if (handler->common->state != DBOX_STATE_DELETE) {
229 if (ret == (int)DBOX_STATUS_ERROR_NOT_EXIST && handler->refcnt == 2) {
230 dbox_invoke_event_handler(handler, DBOX_EVENT_DELETED);
231 dbox_unref(handler, 1);
236 static void text_signal_cb(dynamicbox_h handler, const struct packet *result, void *data)
240 struct cb_info *info = data;
241 dynamicbox_ret_cb cb;
245 dbox_destroy_cb_info(info);
248 ret = DBOX_STATUS_ERROR_FAULT;
249 } else if (packet_get(result, "i", &ret) != 1) {
250 ErrPrint("Invalid argument\n");
251 ret = DBOX_STATUS_ERROR_INVALID_PARAMETER;
255 cb(handler, ret, cbdata);
260 static void set_group_ret_cb(dynamicbox_h handler, const struct packet *result, void *data)
265 ret = DBOX_STATUS_ERROR_FAULT;
267 } else if (packet_get(result, "i", &ret) != 1) {
268 ErrPrint("Invalid argument\n");
269 ret = DBOX_STATUS_ERROR_INVALID_PARAMETER;
280 handler->cbs.group_changed.cb(handler, ret, handler->cbs.group_changed.data);
281 handler->cbs.group_changed.cb = NULL;
282 handler->cbs.group_changed.data = NULL;
283 handler->common->request.group_changed = 0;
285 if (handler->common->state != DBOX_STATE_DELETE) {
286 if (ret == (int)DBOX_STATUS_ERROR_NOT_EXIST && handler->refcnt == 2) {
287 dbox_invoke_event_handler(handler, DBOX_EVENT_DELETED);
288 dbox_unref(handler, 1);
293 static void period_ret_cb(dynamicbox_h handler, const struct packet *result, void *data)
298 ret = DBOX_STATUS_ERROR_FAULT;
300 } else if (packet_get(result, "i", &ret) != 1) {
301 ErrPrint("Invalid argument\n");
302 ret = DBOX_STATUS_ERROR_INVALID_PARAMETER;
313 handler->cbs.period_changed.cb(handler, ret, handler->cbs.period_changed.data);
314 handler->cbs.period_changed.cb = NULL;
315 handler->cbs.period_changed.data = NULL;
316 handler->common->request.period_changed = 0;
318 if (handler->common->state != DBOX_STATE_DELETE) {
319 if (ret == (int)DBOX_STATUS_ERROR_NOT_EXIST && handler->refcnt == 2) {
320 dbox_invoke_event_handler(handler, DBOX_EVENT_DELETED);
321 dbox_unref(handler, 1);
326 static void gbar_create_cb(dynamicbox_h handler, const struct packet *result, void *data)
331 ret = DBOX_STATUS_ERROR_FAULT;
333 } else if (packet_get(result, "i", &ret) != 1) {
334 ret = DBOX_STATUS_ERROR_INVALID_PARAMETER;
339 ErrPrint("Failed to create a GBAR[%d]\n", ret);
346 handler->cbs.gbar_created.cb(handler, ret, handler->cbs.gbar_created.data);
347 handler->cbs.gbar_created.cb = NULL;
348 handler->cbs.gbar_created.data = NULL;
349 handler->common->request.gbar_created = 0;
351 if (handler->common->state != DBOX_STATE_DELETE) {
352 if (ret == (int)DBOX_STATUS_ERROR_NOT_EXIST && handler->refcnt == 2) {
353 dbox_invoke_event_handler(handler, DBOX_EVENT_DELETED);
354 dbox_unref(handler, 1);
359 static void activated_cb(dynamicbox_h handler, const struct packet *result, void *data)
362 struct cb_info *info = data;
364 dynamicbox_ret_cb cb;
365 const char *pkgname = "";
369 dbox_destroy_cb_info(info);
372 ret = DBOX_STATUS_ERROR_FAULT;
373 } else if (packet_get(result, "is", &ret, &pkgname) != 2) {
374 ret = DBOX_STATUS_ERROR_INVALID_PARAMETER;
378 cb(handler, ret, cbdata);
382 static void gbar_destroy_cb(dynamicbox_h handler, const struct packet *result, void *data)
385 dynamicbox_ret_cb cb;
387 struct cb_info *info = data;
391 dbox_destroy_cb_info(info);
394 ErrPrint("Result is NIL (may connection lost)\n");
395 ret = DBOX_STATUS_ERROR_FAULT;
396 } else if (packet_get(result, "i", &ret) != 1) {
397 ErrPrint("Invalid parameter\n");
398 ret = DBOX_STATUS_ERROR_INVALID_PARAMETER;
401 if (ret == (int)DBOX_STATUS_ERROR_NONE) {
402 handler->cbs.gbar_destroyed.cb = cb;
403 handler->cbs.gbar_destroyed.data = cbdata;
405 handler->common->is_gbar_created = 0;
406 handler->common->request.gbar_destroyed = 0;
409 cb(handler, ret, cbdata);
414 static void delete_cluster_cb(dynamicbox_h handler, const struct packet *result, void *data)
416 struct cb_info *info = data;
418 dynamicbox_ret_cb cb;
423 dbox_destroy_cb_info(info);
426 ret = DBOX_STATUS_ERROR_FAULT;
427 } else if (packet_get(result, "i", &ret) != 1) {
428 ret = DBOX_STATUS_ERROR_INVALID_PARAMETER;
432 cb(handler, ret, cbdata);
436 static void delete_category_cb(dynamicbox_h handler, const struct packet *result, void *data)
438 struct cb_info *info = data;
440 dynamicbox_ret_cb cb;
445 dbox_destroy_cb_info(info);
448 ret = DBOX_STATUS_ERROR_FAULT;
449 } else if (packet_get(result, "i", &ret) != 1) {
450 ret = DBOX_STATUS_ERROR_INVALID_PARAMETER;
454 cb(handler, ret, cbdata);
458 static int dbox_acquire_dbox_pixmap(dynamicbox_h handler, dynamicbox_ret_cb cb, void *data)
460 struct packet *packet;
461 struct cb_info *cbinfo;
463 unsigned int cmd = CMD_DBOX_ACQUIRE_PIXMAP;
466 id = fb_id(handler->common->dbox.fb);
467 if (!id || strncasecmp(id, SCHEMA_PIXMAP, strlen(SCHEMA_PIXMAP))) {
468 return DBOX_STATUS_ERROR_INVALID_PARAMETER;
471 packet = packet_create((const char *)&cmd, "ss", handler->common->pkgname, handler->common->id);
473 ErrPrint("Failed to build a param\n");
474 return DBOX_STATUS_ERROR_FAULT;
477 cbinfo = dbox_create_cb_info(cb, data);
479 packet_destroy(packet);
480 return DBOX_STATUS_ERROR_FAULT;
483 ret = master_rpc_async_request(handler, packet, 0, dbox_pixmap_acquired_cb, cbinfo);
485 dbox_destroy_cb_info(cbinfo);
491 static void dbox_pixmap_acquired_cb(dynamicbox_h handler, const struct packet *result, void *data)
494 int ret = DBOX_STATUS_ERROR_INVALID_PARAMETER;
495 dynamicbox_ret_cb cb;
497 struct cb_info *info = data;
501 dbox_destroy_cb_info(info);
504 pixmap = 0; /* PIXMAP 0 means error */
505 } else if (packet_get(result, "ii", &pixmap, &ret) != 2) {
509 if (ret == (int)DBOX_STATUS_ERROR_BUSY) {
510 ret = dbox_acquire_dbox_pixmap(handler, cb, cbdata);
511 DbgPrint("Busy, Try again: %d\n", ret);
513 } else if (ret == (int)DBOX_STATUS_ERROR_NOT_EXIST && handler->refcnt == 2) {
515 cb(handler, pixmap, cbdata);
518 if (handler->common->state != DBOX_STATE_DELETE) {
519 dbox_invoke_event_handler(handler, DBOX_EVENT_DELETED);
520 dbox_unref(handler, 1);
524 cb(handler, pixmap, cbdata);
529 static void dbox_xpixmap_acquired_cb(dynamicbox_h handler, const struct packet *result, void *data)
532 int ret = DBOX_STATUS_ERROR_INVALID_PARAMETER;
533 dynamicbox_ret_cb cb;
535 struct cb_info *info = data;
539 dbox_destroy_cb_info(info);
543 } else if (packet_get(result, "ii", &pixmap, &ret) != 2) {
548 cb(handler, pixmap, cbdata);
551 if (handler->common->state != DBOX_STATE_DELETE) {
552 if (ret == (int)DBOX_STATUS_ERROR_NOT_EXIST && handler->refcnt == 2) {
553 dbox_invoke_event_handler(handler, DBOX_EVENT_DELETED);
554 dbox_unref(handler, 1);
559 static int dbox_acquire_gbar_extra_pixmap(dynamicbox_h handler, int idx, dynamicbox_ret_cb cb, void *data)
561 struct packet *packet;
562 struct cb_info *cbinfo;
563 unsigned int cmd = CMD_GBAR_ACQUIRE_XPIXMAP;
566 packet = packet_create((const char *)&cmd, "ssi", handler->common->pkgname, handler->common->id, idx);
568 ErrPrint("Failed to build a param\n");
569 return DBOX_STATUS_ERROR_FAULT;
572 cbinfo = dbox_create_cb_info(cb, data);
574 packet_destroy(packet);
575 return DBOX_STATUS_ERROR_FAULT;
578 ret = master_rpc_async_request(handler, packet, 0, gbar_xpixmap_acquired_cb, cbinfo);
582 * Packet will be destroyed by master_rpc_async_request
584 dbox_destroy_cb_info(cbinfo);
590 static int dbox_acquire_dbox_extra_pixmap(dynamicbox_h handler, int idx, dynamicbox_ret_cb cb, void *data)
592 struct packet *packet;
593 struct cb_info *cbinfo;
594 unsigned int cmd = CMD_DBOX_ACQUIRE_XPIXMAP;
597 packet = packet_create((const char *)&cmd, "ssi", handler->common->pkgname, handler->common->id, idx);
599 ErrPrint("Failed to build a param\n");
600 return DBOX_STATUS_ERROR_FAULT;
603 cbinfo = dbox_create_cb_info(cb, data);
605 packet_destroy(packet);
606 return DBOX_STATUS_ERROR_FAULT;
609 ret = master_rpc_async_request(handler, packet, 0, dbox_xpixmap_acquired_cb, cbinfo);
613 * Packet will be destroyed by master_rpc_async_request
615 dbox_destroy_cb_info(cbinfo);
621 static int dbox_acquire_gbar_pixmap(dynamicbox_h handler, dynamicbox_ret_cb cb, void *data)
623 struct packet *packet;
624 struct cb_info *cbinfo;
625 unsigned int cmd = CMD_GBAR_ACQUIRE_PIXMAP;
629 id = fb_id(handler->common->gbar.fb);
630 if (!id || strncasecmp(id, SCHEMA_PIXMAP, strlen(SCHEMA_PIXMAP))) {
631 return DBOX_STATUS_ERROR_INVALID_PARAMETER;
634 packet = packet_create((const char *)&cmd, "ss", handler->common->pkgname, handler->common->id);
636 ErrPrint("Failed to build a param\n");
637 return DBOX_STATUS_ERROR_FAULT;
640 cbinfo = dbox_create_cb_info(cb, data);
642 packet_destroy(packet);
643 return DBOX_STATUS_ERROR_FAULT;
646 ret = master_rpc_async_request(handler, packet, 0, gbar_pixmap_acquired_cb, cbinfo);
650 * Packet will be destroyed by master_rpc_async_request
652 dbox_destroy_cb_info(cbinfo);
658 static void gbar_xpixmap_acquired_cb(dynamicbox_h handler, const struct packet *result, void *data)
662 dynamicbox_ret_cb cb;
664 struct cb_info *info = data;
668 dbox_destroy_cb_info(info);
671 pixmap = 0; /* PIXMAP 0 means error */
672 ret = DBOX_STATUS_ERROR_FAULT;
673 } else if (packet_get(result, "ii", &pixmap, &ret) != 2) {
675 ret = DBOX_STATUS_ERROR_INVALID_PARAMETER;
679 DbgPrint("ret: %x, pixmap: %d\n", ret, pixmap);
680 cb(handler, pixmap, cbdata);
683 if (handler->common->state != DBOX_STATE_DELETE) {
684 if (ret == (int)DBOX_STATUS_ERROR_NOT_EXIST && handler->refcnt == 2) {
685 dbox_invoke_event_handler(handler, DBOX_EVENT_DELETED);
686 dbox_unref(handler, 1);
691 static void gbar_pixmap_acquired_cb(dynamicbox_h handler, const struct packet *result, void *data)
695 dynamicbox_ret_cb cb;
697 struct cb_info *info = data;
701 dbox_destroy_cb_info(info);
704 pixmap = 0; /* PIXMAP 0 means error */
705 ret = DBOX_STATUS_ERROR_FAULT;
706 } else if (packet_get(result, "ii", &pixmap, &ret) != 2) {
708 ret = DBOX_STATUS_ERROR_INVALID_PARAMETER;
711 if (ret == (int)DBOX_STATUS_ERROR_BUSY) {
712 ret = dbox_acquire_gbar_pixmap(handler, cb, cbdata);
713 DbgPrint("Busy, Try again: %d\n", ret);
715 } else if (ret == (int)DBOX_STATUS_ERROR_NOT_EXIST && handler->refcnt == 2) {
717 cb(handler, pixmap, cbdata);
720 if (handler->common->state != DBOX_STATE_DELETE) {
721 dbox_invoke_event_handler(handler, DBOX_EVENT_DELETED);
722 dbox_unref(handler, 1);
726 DbgPrint("ret: %d, pixmap: %d\n", ret, pixmap);
727 cb(handler, pixmap, cbdata);
732 static void pinup_done_cb(dynamicbox_h handler, const struct packet *result, void *data)
737 ret = DBOX_STATUS_ERROR_FAULT;
739 } else if (packet_get(result, "i", &ret) != 1) {
750 handler->cbs.pinup.cb(handler, ret, handler->cbs.pinup.data);
751 handler->cbs.pinup.cb = NULL;
752 handler->cbs.pinup.data = NULL;
753 handler->common->request.pinup = 0;
755 if (handler->common->state != DBOX_STATE_DELETE) {
756 if (ret == (int)DBOX_STATUS_ERROR_NOT_EXIST && handler->refcnt == 2) {
757 dbox_invoke_event_handler(handler, DBOX_EVENT_DELETED);
758 dbox_unref(handler, 1);
763 static void key_ret_cb(dynamicbox_h handler, const struct packet *result, void *data)
768 ret = DBOX_STATUS_ERROR_FAULT;
772 if (packet_get(result, "i", &ret) != 1) {
773 ret = DBOX_STATUS_ERROR_INVALID_PARAMETER;
777 if (ret != DBOX_STATUS_ERROR_NONE) {
783 handler->cbs.key_event.cb(handler, ret, handler->cbs.key_event.data);
784 handler->cbs.key_event.cb = NULL;
785 handler->cbs.key_event.data = NULL;
786 handler->common->request.key_event = 0;
788 if (handler->common->state != DBOX_STATE_DELETE) {
789 if (ret == (int)DBOX_STATUS_ERROR_NOT_EXIST && handler->refcnt == 2) {
790 dbox_invoke_event_handler(handler, DBOX_EVENT_DELETED);
791 dbox_unref(handler, 1);
796 static void access_ret_cb(dynamicbox_h handler, const struct packet *result, void *data)
801 ret = DBOX_STATUS_ERROR_FAULT;
805 if (packet_get(result, "i", &ret) != 1) {
806 ret = DBOX_STATUS_ERROR_INVALID_PARAMETER;
810 if (ret != DBOX_STATUS_ERROR_NONE) {
817 handler->cbs.access_event.cb(handler, ret, handler->cbs.access_event.data);
818 handler->cbs.access_event.cb = NULL;
819 handler->cbs.access_event.data = NULL;
820 handler->common->request.access_event = 0;
822 if (handler->common->state != DBOX_STATE_DELETE) {
823 if (ret == (int)DBOX_STATUS_ERROR_NOT_EXIST && handler->refcnt == 2) {
824 dbox_invoke_event_handler(handler, DBOX_EVENT_DELETED);
825 dbox_unref(handler, 1);
830 static int send_access_event(dynamicbox_h handler, const char *event, int x, int y, int type)
832 struct packet *packet;
835 timestamp = util_timestamp();
837 packet = packet_create(event, "ssdiii", handler->common->pkgname, handler->common->id, timestamp, x, y, type);
839 ErrPrint("Failed to build packet\n");
840 return DBOX_STATUS_ERROR_FAULT;
843 return master_rpc_async_request(handler, packet, 0, access_ret_cb, NULL);
846 static int send_key_event(dynamicbox_h handler, const char *event, unsigned int keycode)
848 struct packet *packet;
851 timestamp = util_timestamp();
852 packet = packet_create(event, "ssdi", handler->common->pkgname, handler->common->id, timestamp, keycode);
854 ErrPrint("Failed to build packet\n");
855 return DBOX_STATUS_ERROR_FAULT;
858 return master_rpc_async_request(handler, packet, 0, key_ret_cb, NULL);
861 static int send_mouse_event(dynamicbox_h handler, const char *event, int x, int y)
863 struct packet *packet;
866 timestamp = util_timestamp();
867 packet = packet_create_noack(event, "ssdii", handler->common->pkgname, handler->common->id, timestamp, x, y);
869 ErrPrint("Failed to build param\n");
870 return DBOX_STATUS_ERROR_FAULT;
873 return master_rpc_request_only(handler, packet);
876 static int initialize_dynamicbox(void *disp, int use_thread)
880 char filename[BUFSIZ];
881 snprintf(filename, sizeof(filename), "/tmp/%d.box.log", getpid());
882 __file_log_fp = fopen(filename, "w+t");
883 if (!__file_log_fp) {
884 __file_log_fp = fdopen(1, "w+t");
887 ret = dynamicbox_service_init();
888 if (ret != DBOX_STATUS_ERROR_NONE) {
893 if (ret != DBOX_STATUS_ERROR_NONE) {
894 dynamicbox_service_fini();
898 ret = client_init(use_thread);
899 if (ret != DBOX_STATUS_ERROR_NONE) {
901 dynamicbox_service_fini();
909 static inline char *dbox_pkgname(const char *pkgname)
913 dbox = dynamicbox_service_dbox_id(pkgname);
915 dbox = strdup(pkgname);
921 static gboolean job_execute_cb(void *data)
923 struct job_item *item;
926 l = dlist_nth(s_info.job_list, 0);
928 s_info.job_timer = 0;
932 item = dlist_data(l);
933 s_info.job_list = dlist_remove(s_info.job_list, l);
936 item->cb(item->handle, item->ret, item->data);
937 dbox_unref(item->handle, 1);
944 static int job_add(dynamicbox_h handle, dynamicbox_ret_cb job_cb, int ret, void *data)
946 struct job_item *item;
949 ErrPrint("Invalid argument\n");
950 return DBOX_STATUS_ERROR_INVALID_PARAMETER;
953 item = malloc(sizeof(*item));
955 ErrPrint("Heap: %s\n", strerror(errno));
956 return DBOX_STATUS_ERROR_OUT_OF_MEMORY;
959 item->handle = dbox_ref(handle);
964 s_info.job_list = dlist_append(s_info.job_list, item);
966 if (!s_info.job_timer) {
967 s_info.job_timer = g_timeout_add(1, job_execute_cb, NULL);
968 if (!s_info.job_timer) {
969 ErrPrint("Failed to create a job timer\n");
973 return DBOX_STATUS_ERROR_NONE;
976 static void new_ret_cb(dynamicbox_h handler, const struct packet *result, void *data)
979 struct cb_info *info = data;
980 dynamicbox_ret_cb cb;
985 dbox_destroy_cb_info(info);
988 ret = DBOX_STATUS_ERROR_FAULT;
989 } else if (packet_get(result, "i", &ret) != 1) {
990 ret = DBOX_STATUS_ERROR_INVALID_PARAMETER;
994 handler->cbs.created.cb = cb;
995 handler->cbs.created.data = cbdata;
999 * Don't go anymore ;)
1005 * It means the current instance is not created,
1006 * so user has to know about this.
1007 * notice it to user using "deleted" event.
1009 cb(handler, ret, cbdata);
1012 dbox_unref(handler, 1);
1015 static int create_real_instance(dynamicbox_h handler, dynamicbox_ret_cb cb, void *data)
1017 struct cb_info *cbinfo;
1018 struct packet *packet;
1019 struct dynamicbox_common *common;
1020 unsigned int cmd = CMD_NEW;
1023 common = handler->common;
1025 packet = packet_create((const char *)&cmd, "dssssdii",
1026 common->timestamp, common->pkgname, common->content,
1027 common->cluster, common->category,
1028 common->dbox.period, common->dbox.width, common->dbox.height);
1030 ErrPrint("Failed to create a new packet\n");
1031 dynamicbox_set_last_status(DBOX_STATUS_ERROR_FAULT);
1032 return DBOX_STATUS_ERROR_FAULT;
1035 cbinfo = dbox_create_cb_info(cb, data);
1037 ErrPrint("Failed to create a cbinfo\n");
1038 packet_destroy(packet);
1039 dynamicbox_set_last_status(DBOX_STATUS_ERROR_OUT_OF_MEMORY);
1040 return DBOX_STATUS_ERROR_OUT_OF_MEMORY;
1045 * master_rpc_async_request will destroy the packet (decrease the refcnt)
1046 * So be aware the packet object after return from master_rpc_async_request.
1048 ret = master_rpc_async_request(handler, packet, 0, new_ret_cb, cbinfo);
1050 ErrPrint("Failed to send a new packet\n");
1051 dbox_destroy_cb_info(cbinfo);
1052 dynamicbox_set_last_status(DBOX_STATUS_ERROR_FAULT);
1053 return DBOX_STATUS_ERROR_FAULT;
1055 handler->common->request.created = 1;
1056 return DBOX_STATUS_ERROR_NONE;
1059 static void create_cb(dynamicbox_h handle, int ret, void *data)
1061 struct cb_info *cbinfo = data;
1064 cbinfo->cb(handle, ret, cbinfo->data);
1067 dbox_destroy_cb_info(cbinfo);
1071 * Forcely generate "updated" event
1073 dbox_invoke_event_handler(handle, DBOX_EVENT_DBOX_UPDATED);
1076 static int create_fake_instance(dynamicbox_h handler, dynamicbox_ret_cb cb, void *data)
1078 struct cb_info *cbinfo;
1080 cbinfo = dbox_create_cb_info(cb, data);
1082 ErrPrint("Failed to create a cbinfo\n");
1083 return DBOX_STATUS_ERROR_OUT_OF_MEMORY;
1086 if (job_add(handler, create_cb, DBOX_STATUS_ERROR_NONE, cbinfo) != DBOX_STATUS_ERROR_NONE) {
1087 dbox_destroy_cb_info(cbinfo);
1090 return DBOX_STATUS_ERROR_NONE;
1093 static void refresh_for_paused_updating_cb(dynamicbox_h handle, int ret, void *data)
1095 if (handle->paused_updating == 0) {
1096 DbgPrint("Paused updates are cleared\n");
1100 DbgPrint("Pending updates are found\n");
1101 dbox_invoke_event_handler(handle, DBOX_EVENT_DBOX_UPDATED);
1104 static int dbox_set_visibility(dynamicbox_h handler, dynamicbox_visible_state_e state)
1106 struct packet *packet;
1107 int need_to_add_job = 0;
1108 unsigned int cmd = CMD_CHANGE_VISIBILITY;
1111 if (handler->common->visible != DBOX_SHOW && state == DBOX_SHOW) {
1112 need_to_add_job = !!handler->paused_updating;
1113 } else if (handler->common->visible == DBOX_SHOW && state != DBOX_SHOW) {
1114 if (!!dbox_find_dbox_in_show(handler->common)) {
1115 return DBOX_STATUS_ERROR_NONE;
1117 } else if (handler->common->visible == DBOX_SHOW && state == DBOX_SHOW && handler->paused_updating) {
1118 if (job_add(handler, refresh_for_paused_updating_cb, DBOX_STATUS_ERROR_NONE, NULL) < 0) {
1119 ErrPrint("Unable to add a new job for refreshing box\n");
1122 return DBOX_STATUS_ERROR_NONE;
1126 * No need to send this to the master
1128 return DBOX_STATUS_ERROR_NONE;
1131 packet = packet_create_noack((const char *)&cmd, "ssi", handler->common->pkgname, handler->common->id, (int)state);
1133 ErrPrint("Failed to create a packet\n");
1134 return DBOX_STATUS_ERROR_FAULT;
1137 ret = master_rpc_request_only(handler, packet);
1138 if (ret == (int)DBOX_STATUS_ERROR_NONE) {
1139 DbgPrint("[%s] visibility is changed 0x[%x]\n", handler->common->pkgname, state);
1140 handler->common->visible = state;
1142 if (need_to_add_job) {
1143 if (job_add(handler, refresh_for_paused_updating_cb, DBOX_STATUS_ERROR_NONE, NULL) < 0) {
1144 ErrPrint("Unable to add a new job for refreshing box\n");
1152 static void dbox_update_visibility(struct dynamicbox_common *old_common)
1156 item = dbox_find_dbox_in_show(old_common);
1158 item = dbox_get_dbox_nth(old_common, 0);
1160 dbox_set_visibility(item, DBOX_HIDE_WITH_PAUSE);
1162 ErrPrint("Unable to get the valid handle from common handler\n");
1165 dbox_set_visibility(item, DBOX_SHOW);
1171 * The second parameter should be the "return value",
1172 * But in this case, we will use it for "type of deleting instance".
1174 static void job_del_cb(dynamicbox_h handle, int type, void *data)
1176 struct cb_info *cbinfo = data;
1177 dynamicbox_ret_cb cb;
1179 if (handle->visible == DBOX_SHOW) {
1180 dbox_update_visibility(handle->common);
1184 data = cbinfo->data;
1185 dbox_destroy_cb_info(cbinfo);
1187 if (handle->common->state != DBOX_STATE_CREATE) {
1188 DbgPrint("[%s] %d\n", handle->common->pkgname, handle->refcnt);
1190 cb(handle, DBOX_STATUS_ERROR_NONE, data);
1196 if (handle->common->refcnt == 1) {
1197 handle->common->delete_type = type;
1198 handle->common->state = DBOX_STATE_DELETE;
1200 if (!handle->common->id) {
1203 * The id is not determined yet.
1204 * It means a user didn't receive created event yet.
1205 * Then just stop to delete procedure from here.
1206 * Because the "created" event handle will release this.
1207 * By the way, if the user adds any callback for getting return status of this,
1211 cb(handle, DBOX_STATUS_ERROR_NONE, data);
1215 DbgPrint("Send delete request\n");
1216 dbox_send_delete(handle, type, cb, data);
1219 cb(handle, DBOX_STATUS_ERROR_NONE, data);
1222 DbgPrint("Before unref: %d\n", handle->common->refcnt);
1223 dbox_unref(handle, 1);
1227 static void resize_job_cb(dynamicbox_h handler, int ret, void *data)
1229 struct cb_info *info = data;
1232 info->cb(handler, ret, info->data);
1239 * Forcely update the box
1241 dbox_invoke_event_handler(handler, DBOX_EVENT_DBOX_UPDATED);
1244 static void turn_off_gbar_destroyed_flag_cb(dynamicbox_h handler, int ret, void *data)
1246 if (handler->common->request.gbar_destroyed) {
1247 dynamicbox_ret_cb cb;
1250 DbgPrint("gbar_destroyed request is canceled\n");
1251 handler->common->request.gbar_destroyed = 0;
1252 cb = handler->cbs.gbar_destroyed.cb;
1253 data = handler->cbs.gbar_destroyed.data;
1254 handler->cbs.gbar_destroyed.cb = NULL;
1255 handler->cbs.gbar_destroyed.data = NULL;
1258 cb(handler, ret, data);
1263 static void turn_off_gbar_created_flag_cb(dynamicbox_h handler, int ret, void *data)
1265 if (handler->common->request.gbar_created) {
1266 dynamicbox_ret_cb cb;
1269 DbgPrint("gbar_created request is canceled\n");
1270 handler->common->request.gbar_created = 0;
1271 cb = handler->cbs.gbar_created.cb;
1272 data = handler->cbs.gbar_created.data;
1273 handler->cbs.gbar_created.cb = NULL;
1274 handler->cbs.gbar_created.data = NULL;
1277 cb(handler, ret, data);
1282 EAPI int dynamicbox_init(void *disp, int prevent_overwrite, double event_filter, int use_thread)
1284 if (s_info.init_count > 0) {
1285 s_info.init_count++;
1286 return DBOX_STATUS_ERROR_NONE;
1291 * Some application doesn't want to use the environment value.
1292 * So set them using arguments.
1294 s_info.prevent_overwrite = prevent_overwrite;
1295 conf_set_event_filter(event_filter);
1297 return initialize_dynamicbox(disp, use_thread);
1300 EAPI int dynamicbox_fini(void)
1302 if (s_info.init_count <= 0) {
1303 ErrPrint("Doesn't initialized\n");
1304 return DBOX_STATUS_ERROR_INVALID_PARAMETER;
1307 s_info.init_count--;
1308 if (s_info.init_count > 0) {
1309 ErrPrint("init count : %d\n", s_info.init_count);
1310 return DBOX_STATUS_ERROR_NONE;
1315 dynamicbox_service_fini();
1316 return DBOX_STATUS_ERROR_NONE;
1319 EAPI dynamicbox_h dynamicbox_add(const char *pkgname, const char *content, const char *cluster, const char *category, double period, dynamicbox_size_type_e type, dynamicbox_ret_cb cb, void *data)
1322 dynamicbox_h handler;
1326 if (!pkgname || !cluster || !category) {
1327 ErrPrint("Invalid arguments: pkgname[%p], cluster[%p], category[%p]\n",
1328 pkgname, cluster, category);
1329 dynamicbox_set_last_status(DBOX_STATUS_ERROR_INVALID_PARAMETER);
1333 dboxid = dbox_pkgname(pkgname);
1335 ErrPrint("Invalid package: %s\n", pkgname);
1336 dynamicbox_set_last_status(DBOX_STATUS_ERROR_INVALID_PARAMETER);
1340 if (dynamicbox_service_is_enabled(dboxid) == 0) {
1341 DbgPrint("Livebox [%s](%s) is disabled package\n", dboxid, pkgname);
1343 dynamicbox_set_last_status(DBOX_STATUS_ERROR_DISABLED);
1347 if (type != DBOX_SIZE_TYPE_UNKNOWN) {
1348 (void)dynamicbox_service_get_size(type, &w, &h);
1351 handler = calloc(1, sizeof(*handler));
1353 ErrPrint("Error: %s\n", strerror(errno));
1355 dynamicbox_set_last_status(DBOX_STATUS_ERROR_OUT_OF_MEMORY);
1360 cb = default_create_cb;
1363 handler->common = dbox_find_sharable_common_handle(dboxid, content, w, h, cluster, category);
1364 if (!handler->common) {
1365 handler->common = dbox_create_common_handle(handler, dboxid, cluster, category);
1367 if (!handler->common) {
1368 ErrPrint("Failed to find common handle\n");
1373 if (!content || !strlen(content)) {
1377 * I know the content should not be modified. use it temporarly without "const"
1379 pc = dynamicbox_service_content(handler->common->pkgname);
1380 dbox_set_content(handler->common, pc);
1383 dbox_set_content(handler->common, content);
1386 dbox_set_period(handler->common, period);
1387 dbox_set_size(handler->common, w, h);
1388 dbox_common_ref(handler->common, handler);
1390 if (create_real_instance(handler, cb, data) < 0) {
1391 if (dbox_common_unref(handler->common, handler) == 0) {
1395 dbox_destroy_common_handle(handler->common);
1396 handler->common = NULL;
1404 dbox_common_ref(handler->common, handler);
1406 if (handler->common->request.created) {
1408 * If a box is in creating, wait its result too
1410 handler->cbs.created.cb = cb;
1411 handler->cbs.created.data = data;
1414 * or fire the fake created_event
1416 if (create_fake_instance(handler, cb, data) < 0) {
1417 if (dbox_common_unref(handler->common, handler) == 0) {
1421 dbox_destroy_common_handle(handler->common);
1429 handler->visible = DBOX_SHOW;
1430 handler->state = DBOX_STATE_CREATE;
1431 handler = dbox_ref(handler);
1433 if (handler->common->visible != DBOX_SHOW) {
1434 dbox_set_visibility(handler, DBOX_SHOW);
1440 EAPI double dynamicbox_period(dynamicbox_h handler)
1442 if (!handler || handler->state != DBOX_STATE_CREATE) {
1443 ErrPrint("Handler is not valid\n");
1444 dynamicbox_set_last_status(DBOX_STATUS_ERROR_INVALID_PARAMETER);
1448 if (!handler->common || handler->common->state != DBOX_STATE_CREATE) {
1449 ErrPrint("Invalid handle\n");
1450 dynamicbox_set_last_status(DBOX_STATUS_ERROR_INVALID_PARAMETER);
1454 if (!handler->common->id) {
1455 ErrPrint("Hnalder is not valid\n");
1456 dynamicbox_set_last_status(DBOX_STATUS_ERROR_INVALID_PARAMETER);
1460 return handler->common->dbox.period;
1463 EAPI int dynamicbox_set_period(dynamicbox_h handler, double period, dynamicbox_ret_cb cb, void *data)
1465 struct packet *packet;
1466 unsigned int cmd = CMD_SET_PERIOD;
1469 if (!handler || handler->state != DBOX_STATE_CREATE) {
1470 ErrPrint("Handler is not valid\n");
1471 return DBOX_STATUS_ERROR_INVALID_PARAMETER;
1474 if (!handler->common || handler->common->state != DBOX_STATE_CREATE) {
1475 ErrPrint("Invalid handle\n");
1476 return DBOX_STATUS_ERROR_INVALID_PARAMETER;
1479 if (!handler->common->id) {
1480 ErrPrint("Handler is not valid\n");
1481 return DBOX_STATUS_ERROR_INVALID_PARAMETER;
1484 if (handler->common->request.period_changed) {
1485 ErrPrint("Previous request for changing period is not finished\n");
1486 return DBOX_STATUS_ERROR_BUSY;
1489 if (!handler->common->is_user) {
1490 ErrPrint("CA Livebox is not able to change the period\n");
1491 return DBOX_STATUS_ERROR_PERMISSION_DENIED;
1494 if (handler->common->dbox.period == period) {
1495 DbgPrint("No changes\n");
1496 return DBOX_STATUS_ERROR_ALREADY;
1499 packet = packet_create((const char *)&cmd, "ssd", handler->common->pkgname, handler->common->id, period);
1501 ErrPrint("Failed to build a packet %s\n", handler->common->pkgname);
1502 return DBOX_STATUS_ERROR_FAULT;
1506 cb = default_period_changed_cb;
1509 ret = master_rpc_async_request(handler, packet, 0, period_ret_cb, NULL);
1510 if (ret == (int)DBOX_STATUS_ERROR_NONE) {
1511 handler->cbs.period_changed.cb = cb;
1512 handler->cbs.period_changed.data = data;
1513 handler->common->request.period_changed = 1;
1519 EAPI int dynamicbox_del(dynamicbox_h handler, dynamicbox_delete_type_e type, dynamicbox_ret_cb cb, void *data)
1521 struct cb_info *cbinfo;
1524 ErrPrint("Handler is NIL\n");
1525 return DBOX_STATUS_ERROR_INVALID_PARAMETER;
1528 if (handler->state != DBOX_STATE_CREATE) {
1529 ErrPrint("Handler is already deleted\n");
1530 return DBOX_STATUS_ERROR_INVALID_PARAMETER;
1533 handler->state = DBOX_STATE_DELETE;
1535 cbinfo = dbox_create_cb_info(cb, data);
1537 ErrPrint("Failed to create a cbinfo\n");
1538 return DBOX_STATUS_ERROR_OUT_OF_MEMORY;
1541 if (job_add(handler, job_del_cb, type, cbinfo) != DBOX_STATUS_ERROR_NONE) {
1542 ErrPrint("Failed to add a new job\n");
1543 dbox_destroy_cb_info(cbinfo);
1544 return DBOX_STATUS_ERROR_FAULT;
1547 return DBOX_STATUS_ERROR_NONE;
1550 EAPI int dynamicbox_add_fault_handler(dynamicbox_fault_handler_cb dbox_cb, void *data)
1553 return DBOX_STATUS_ERROR_INVALID_PARAMETER;
1556 return dbox_add_fault_handler(dbox_cb, data);
1559 EAPI void *dynamicbox_remove_fault_handler(dynamicbox_fault_handler_cb dbox_cb)
1565 return dbox_remove_fault_handler(dbox_cb);
1568 EAPI int dynamicbox_add_event_handler(dynamicbox_event_handler_cb dbox_cb, void *data)
1571 ErrPrint("Invalid argument dbox_cb is nil\n");
1572 return DBOX_STATUS_ERROR_INVALID_PARAMETER;
1575 return dbox_add_event_handler(dbox_cb, data);
1578 EAPI void *dynamicbox_remove_event_handler(dynamicbox_event_handler_cb dbox_cb)
1584 return dbox_remove_event_handler(dbox_cb);
1587 EAPI int dynamicbox_set_update_mode(dynamicbox_h handler, int active_update, dynamicbox_ret_cb cb, void *data)
1589 struct packet *packet;
1590 unsigned int cmd = CMD_UPDATE_MODE;
1593 if (!handler || handler->state != DBOX_STATE_CREATE) {
1594 ErrPrint("Handler is Invalid\n");
1595 return DBOX_STATUS_ERROR_INVALID_PARAMETER;
1598 if (!handler->common || handler->common->state != DBOX_STATE_CREATE) {
1599 ErrPrint("Handler is Invalid\n");
1600 return DBOX_STATUS_ERROR_INVALID_PARAMETER;
1603 if (!handler->common->id) {
1604 ErrPrint("Handler is Invalid\n");
1605 return DBOX_STATUS_ERROR_INVALID_PARAMETER;
1608 if (handler->common->request.update_mode) {
1609 ErrPrint("Previous update_mode cb is not finished yet\n");
1610 return DBOX_STATUS_ERROR_BUSY;
1613 if (handler->common->is_active_update == active_update) {
1614 return DBOX_STATUS_ERROR_ALREADY;
1617 if (!handler->common->is_user) {
1618 return DBOX_STATUS_ERROR_PERMISSION_DENIED;
1621 packet = packet_create((const char *)&cmd, "ssi", handler->common->pkgname, handler->common->id, active_update);
1623 return DBOX_STATUS_ERROR_FAULT;
1627 cb = default_update_mode_cb;
1630 ret = master_rpc_async_request(handler, packet, 0, update_mode_cb, NULL);
1631 if (ret == (int)DBOX_STATUS_ERROR_NONE) {
1632 handler->cbs.update_mode.cb = cb;
1633 handler->cbs.update_mode.data = data;
1634 handler->common->request.update_mode = 1;
1640 EAPI int dynamicbox_is_active_update(dynamicbox_h handler)
1642 if (!handler || handler->state != DBOX_STATE_CREATE) {
1643 ErrPrint("Handler is Invalid\n");
1644 return DBOX_STATUS_ERROR_INVALID_PARAMETER;
1647 if (!handler->common || handler->common->state != DBOX_STATE_CREATE) {
1648 ErrPrint("Handler is Invalid\n");
1649 return DBOX_STATUS_ERROR_INVALID_PARAMETER;
1652 if (!handler->common->id) {
1653 return DBOX_STATUS_ERROR_INVALID_PARAMETER;
1656 return handler->common->is_active_update;
1659 EAPI int dynamicbox_resize(dynamicbox_h handler, dynamicbox_size_type_e type, dynamicbox_ret_cb cb, void *data)
1661 struct dynamicbox_common *common;
1668 * If this handle is host instance or link instance,
1669 * Create a new instance or find another linkable instance.
1672 if (!handler || handler->state != DBOX_STATE_CREATE) {
1673 ErrPrint("Handler is not valid\n");
1674 return DBOX_STATUS_ERROR_INVALID_PARAMETER;
1677 if (!handler->common || handler->common->state != DBOX_STATE_CREATE) {
1678 ErrPrint("Invalid handle\n");
1679 return DBOX_STATUS_ERROR_INVALID_PARAMETER;
1682 if (!handler->common->id) {
1683 ErrPrint("Handler is not valid\n");
1684 return DBOX_STATUS_ERROR_INVALID_PARAMETER;
1689 * resize operation should be separated by each handler.
1690 * If a handler is resizing, the other handler can request resize too.
1691 * So we should not use the common->request.size_changed flag.
1693 if (handler->cbs.size_changed.cb) {
1694 ErrPrint("Previous resize request is not finished yet\n");
1695 return DBOX_STATUS_ERROR_BUSY;
1698 if (dynamicbox_service_get_size(type, &w, &h) != 0) {
1699 ErrPrint("Invalid size type\n");
1700 return DBOX_STATUS_ERROR_INVALID_PARAMETER;
1703 if (handler->common->dbox.width == w && handler->common->dbox.height == h) {
1704 DbgPrint("No changes\n");
1705 return DBOX_STATUS_ERROR_ALREADY;
1708 if (!handler->common->is_user) {
1709 ErrPrint("CA Livebox is not able to be resized\n");
1710 return DBOX_STATUS_ERROR_PERMISSION_DENIED;
1713 if (handler->common->refcnt <= 1) {
1714 struct packet *packet;
1715 unsigned int cmd = CMD_RESIZE;
1717 /* Only 1 instance */
1718 packet = packet_create((const char *)&cmd, "ssii", handler->common->pkgname, handler->common->id, w, h);
1720 ErrPrint("Failed to build param\n");
1721 return DBOX_STATUS_ERROR_FAULT;
1725 cb = default_dbox_size_changed_cb;
1728 ret = master_rpc_async_request(handler, packet, 0, resize_cb, NULL);
1729 if (ret == (int)DBOX_STATUS_ERROR_NONE) {
1730 handler->cbs.size_changed.cb = cb;
1731 handler->cbs.size_changed.data = data;
1732 handler->common->request.size_changed = 1;
1735 common = dbox_find_sharable_common_handle(handler->common->pkgname, handler->common->content, w, h, handler->common->cluster, handler->common->category);
1737 struct dynamicbox_common *old_common;
1740 * If the common handler is in resizing,
1741 * if user tries to resize a hander, then simply create new one even if the requested size is same with this.
1743 if (handler->common->request.size_changed) {
1748 old_common = handler->common;
1750 common = dbox_create_common_handle(handler, old_common->pkgname, old_common->cluster, old_common->category);
1752 ErrPrint("Failed to create common handle\n");
1753 return DBOX_STATUS_ERROR_FAULT;
1756 dbox_set_size(common, w, h);
1757 dbox_set_content(common, old_common->content);
1758 dbox_set_period(common, old_common->dbox.period);
1762 * Disconnecting from old one.
1764 if (dbox_common_unref(old_common, handler) == 0) {
1769 ErrPrint("Common has no associated handler\n");
1772 dbox_common_ref(common, handler);
1775 * Connect to a new one
1777 handler->common = common;
1781 * Need to care, if it fails to create a common handle,
1782 * the resize operation will be failed.
1783 * in that case, we should reuse the old common handle
1785 ret = create_real_instance(handler, cb, data);
1787 dbox_common_unref(common, handler);
1788 dbox_destroy_common_handle(common);
1790 dbox_common_ref(old_common, handler);
1791 handler->common = old_common;
1794 * In this case, we should update visibility of old_common's dynamicboxes
1796 if (handler->visible == DBOX_SHOW) {
1797 dbox_update_visibility(old_common);
1801 struct cb_info *cbinfo;
1803 cbinfo = dbox_create_cb_info(cb, data);
1805 ErrPrint("Failed to create a cbinfo\n");
1806 ret = DBOX_STATUS_ERROR_OUT_OF_MEMORY;
1808 ret = job_add(handler, resize_job_cb, DBOX_STATUS_ERROR_NONE, cbinfo);
1809 if (ret == (int)DBOX_STATUS_ERROR_NONE) {
1810 struct dynamicbox_common *old_common;
1812 old_common = handler->common;
1814 if (dbox_common_unref(handler->common, handler) == 0) {
1815 ErrPrint("Old common has no associated handler\n");
1818 dbox_common_ref(common, handler);
1819 handler->common = common;
1821 if (handler->visible == DBOX_SHOW) {
1822 dbox_update_visibility(old_common); /* To update visibility: Show --> Paused */
1823 dbox_update_visibility(common); /* To update visibility: Paused --> Show */
1826 dbox_destroy_cb_info(cbinfo);
1835 EAPI int dynamicbox_click(dynamicbox_h handler, double x, double y)
1837 struct packet *packet;
1839 unsigned int cmd = CMD_CLICKED;
1842 if (!handler || handler->state != DBOX_STATE_CREATE) {
1843 ErrPrint("Handler is invalid\n");
1844 return DBOX_STATUS_ERROR_INVALID_PARAMETER;
1847 if (!handler->common || handler->common->state != DBOX_STATE_CREATE) {
1848 ErrPrint("Handler is invalid\n");
1849 return DBOX_STATUS_ERROR_INVALID_PARAMETER;
1852 if (!handler->common->id) {
1853 ErrPrint("Handler is not valid\n");
1854 return DBOX_STATUS_ERROR_INVALID_PARAMETER;
1857 if (handler->common->dbox.auto_launch) {
1858 if (s_info.launch.handler) {
1859 ret = s_info.launch.handler(handler, handler->common->dbox.auto_launch, s_info.launch.data);
1861 ErrPrint("launch handler app %s (%d)\n", handler->common->dbox.auto_launch, ret);
1866 timestamp = util_timestamp();
1867 DbgPrint("CLICKED: %lf\n", timestamp);
1869 packet = packet_create_noack((const char *)&cmd, "sssddd", handler->common->pkgname, handler->common->id, "clicked", timestamp, x, y);
1871 ErrPrint("Failed to build param\n");
1872 return DBOX_STATUS_ERROR_FAULT;
1875 ret = master_rpc_request_only(handler, packet);
1879 EAPI int dynamicbox_has_glance_bar(dynamicbox_h handler)
1881 if (!handler || handler->state != DBOX_STATE_CREATE) {
1882 ErrPrint("Handler is invalid\n");
1883 return DBOX_STATUS_ERROR_INVALID_PARAMETER;
1886 if (!handler->common || handler->common->state != DBOX_STATE_CREATE) {
1887 ErrPrint("Handler is invalid\n");
1888 return DBOX_STATUS_ERROR_INVALID_PARAMETER;
1891 if (!handler->common->id) {
1892 ErrPrint("Handler is not valid\n");
1893 return DBOX_STATUS_ERROR_INVALID_PARAMETER;
1896 return !!handler->common->gbar.fb;
1899 EAPI int dynamicbox_glance_bar_is_created(dynamicbox_h handler)
1901 if (!handler || handler->state != DBOX_STATE_CREATE) {
1902 ErrPrint("Handler is invalid\n");
1903 return DBOX_STATUS_ERROR_INVALID_PARAMETER;
1906 if (!handler->common || handler->common->state != DBOX_STATE_CREATE) {
1907 ErrPrint("Handler is invalid\n");
1908 return DBOX_STATUS_ERROR_INVALID_PARAMETER;
1911 if (!handler->common->gbar.fb || !handler->common->id) {
1912 ErrPrint("Handler is not valid\n");
1913 return DBOX_STATUS_ERROR_INVALID_PARAMETER;
1916 return handler->common->is_gbar_created;
1919 EAPI int dynamicbox_create_glance_bar(dynamicbox_h handler, double x, double y, dynamicbox_ret_cb cb, void *data)
1921 struct packet *packet;
1922 unsigned int cmd = CMD_CREATE_GBAR;
1925 if (!handler || handler->state != DBOX_STATE_CREATE) {
1926 ErrPrint("Handler is invalid\n");
1927 return DBOX_STATUS_ERROR_INVALID_PARAMETER;
1930 if (!handler->common || handler->common->state != DBOX_STATE_CREATE) {
1931 ErrPrint("Handler is invalid\n");
1932 return DBOX_STATUS_ERROR_INVALID_PARAMETER;
1935 if (!handler->common->gbar.fb || !handler->common->id) {
1936 ErrPrint("Handler is not valid\n");
1937 return DBOX_STATUS_ERROR_INVALID_PARAMETER;
1942 * Only one handler can have a GBAR
1944 if (handler->common->is_gbar_created) {
1945 DbgPrint("GBAR is already created\n");
1946 return DBOX_STATUS_ERROR_NONE;
1949 if (handler->common->request.gbar_created) {
1950 ErrPrint("Previous request is not completed yet\n");
1951 return DBOX_STATUS_ERROR_BUSY;
1956 * Turn off the gbar_destroyed request flag
1958 if (handler->common->request.gbar_destroyed) {
1959 if (job_add(handler, turn_off_gbar_destroyed_flag_cb, DBOX_STATUS_ERROR_CANCEL, NULL) < 0) {
1960 ErrPrint("Failed to add gbar_destroyed job\n");
1964 packet = packet_create((const char *)&cmd, "ssdd", handler->common->pkgname, handler->common->id, x, y);
1966 ErrPrint("Failed to build param\n");
1967 return DBOX_STATUS_ERROR_FAULT;
1971 cb = default_gbar_created_cb;
1974 DbgPrint("PERF_DBOX\n");
1975 ret = master_rpc_async_request(handler, packet, 0, gbar_create_cb, NULL);
1976 if (ret == (int)DBOX_STATUS_ERROR_NONE) {
1977 handler->cbs.gbar_created.cb = cb;
1978 handler->cbs.gbar_created.data = data;
1979 handler->common->request.gbar_created = 1;
1985 EAPI int dynamicbox_move_glance_bar(dynamicbox_h handler, double x, double y)
1987 struct packet *packet;
1988 unsigned int cmd = CMD_GBAR_MOVE;
1990 if (!handler || handler->state != DBOX_STATE_CREATE) {
1991 ErrPrint("Handler is invalid\n");
1992 return DBOX_STATUS_ERROR_INVALID_PARAMETER;
1995 if (!handler->common || handler->common->state != DBOX_STATE_CREATE) {
1996 ErrPrint("Handler is invalid\n");
1997 return DBOX_STATUS_ERROR_INVALID_PARAMETER;
2000 if (!handler->common->gbar.fb || !handler->common->id) {
2001 ErrPrint("Handler is not valid\n");
2002 return DBOX_STATUS_ERROR_INVALID_PARAMETER;
2005 if (!handler->common->is_gbar_created) {
2006 ErrPrint("GBAR is not created\n");
2007 return DBOX_STATUS_ERROR_INVALID_PARAMETER;
2010 packet = packet_create_noack((const char *)&cmd, "ssdd", handler->common->pkgname, handler->common->id, x, y);
2012 ErrPrint("Failed to build param\n");
2013 return DBOX_STATUS_ERROR_FAULT;
2016 return master_rpc_request_only(handler, packet);
2019 EAPI int dynamicbox_activate(const char *pkgname, dynamicbox_ret_cb cb, void *data)
2021 struct packet *packet;
2022 struct cb_info *cbinfo;
2023 unsigned int cmd = CMD_ACTIVATE_PACKAGE;
2027 return DBOX_STATUS_ERROR_INVALID_PARAMETER;
2030 packet = packet_create((const char *)&cmd, "s", pkgname);
2032 ErrPrint("Failed to build a param\n");
2033 return DBOX_STATUS_ERROR_FAULT;
2036 cbinfo = dbox_create_cb_info(cb, data);
2038 ErrPrint("Unable to create cbinfo\n");
2039 packet_destroy(packet);
2040 return DBOX_STATUS_ERROR_FAULT;
2043 ret = master_rpc_async_request(NULL, packet, 0, activated_cb, cbinfo);
2045 dbox_destroy_cb_info(cbinfo);
2051 EAPI int dynamicbox_destroy_glance_bar(dynamicbox_h handler, dynamicbox_ret_cb cb, void *data)
2053 struct packet *packet;
2054 struct cb_info *cbinfo;
2055 unsigned int cmd = CMD_DESTROY_GBAR;
2058 if (!handler || handler->state != DBOX_STATE_CREATE) {
2059 ErrPrint("Handler is invalid\n");
2060 return DBOX_STATUS_ERROR_INVALID_PARAMETER;
2063 if (!handler->common || handler->common->state != DBOX_STATE_CREATE) {
2064 ErrPrint("Handler is invalid\n");
2065 return DBOX_STATUS_ERROR_INVALID_PARAMETER;
2068 if (!handler->common->gbar.fb || !handler->common->id) {
2069 ErrPrint("Handler is not valid\n");
2070 return DBOX_STATUS_ERROR_INVALID_PARAMETER;
2075 * Replace the callback check code.
2076 * Use the flag instead of callback.
2077 * the flag should be in the ADT "common"
2079 if (!handler->common->is_gbar_created && !handler->common->request.gbar_created) {
2080 ErrPrint("GBAR is not created\n");
2081 return DBOX_STATUS_ERROR_INVALID_PARAMETER;
2084 if (handler->common->request.gbar_destroyed) {
2085 ErrPrint("GBAR destroy request is already sent\n");
2086 return DBOX_STATUS_ERROR_ALREADY;
2091 * Disable the gbar_created request flag
2093 if (handler->common->request.gbar_created) {
2094 if (job_add(handler, turn_off_gbar_created_flag_cb, DBOX_STATUS_ERROR_CANCEL, NULL) < 0) {
2095 ErrPrint("Failed to add a new job\n");
2099 DbgPrint("[%s]\n", handler->common->pkgname);
2101 packet = packet_create((const char *)&cmd, "ss", handler->common->pkgname, handler->common->id);
2103 ErrPrint("Failed to build a param\n");
2104 return DBOX_STATUS_ERROR_FAULT;
2108 cb = default_gbar_destroyed_cb;
2111 cbinfo = dbox_create_cb_info(cb, data);
2113 packet_destroy(packet);
2114 return DBOX_STATUS_ERROR_FAULT;
2117 ret = master_rpc_async_request(handler, packet, 0, gbar_destroy_cb, cbinfo);
2119 dbox_destroy_cb_info(cbinfo);
2121 handler->common->request.gbar_destroyed = 1;
2127 EAPI int dynamicbox_feed_access_event(dynamicbox_h handler, dynamicbox_access_event_type_e type, dynamicbox_access_event_info_t info, dynamicbox_ret_cb cb, void *data)
2132 int ret = 0; /* re-used for sending event type */
2134 if (!handler || handler->state != DBOX_STATE_CREATE) {
2135 ErrPrint("Handler is invalid\n");
2136 return DBOX_STATUS_ERROR_INVALID_PARAMETER;
2139 if (!handler->common || handler->common->state != DBOX_STATE_CREATE) {
2140 ErrPrint("Handler is invalid\n");
2141 return DBOX_STATUS_ERROR_INVALID_PARAMETER;
2144 if (!handler->common->id) {
2145 ErrPrint("Handler is not valid\n");
2146 return DBOX_STATUS_ERROR_INVALID_PARAMETER;
2149 if (handler->common->request.access_event) {
2150 ErrPrint("Previous access event is not yet done\n");
2151 return DBOX_STATUS_ERROR_BUSY;
2154 if (type & DBOX_ACCESS_EVENT_GBAR_MASK) {
2155 if (!handler->common->is_gbar_created) {
2156 ErrPrint("GBAR is not created\n");
2157 return DBOX_STATUS_ERROR_INVALID_PARAMETER;
2160 w = handler->common->gbar.width;
2161 h = handler->common->gbar.height;
2163 switch (type & ~(DBOX_ACCESS_EVENT_GBAR_MASK | DBOX_ACCESS_EVENT_DBOX_MASK)) {
2164 case DBOX_ACCESS_EVENT_HIGHLIGHT:
2165 cmd = CMD_GBAR_ACCESS_HL;
2166 ret = (int)info->type;
2168 case DBOX_ACCESS_EVENT_ACTIVATE:
2169 cmd = CMD_GBAR_ACCESS_ACTIVATE;
2171 case DBOX_ACCESS_EVENT_ACTION:
2172 cmd = CMD_GBAR_ACCESS_ACTION;
2173 ret = (int)info->type;
2175 case DBOX_ACCESS_EVENT_SCROLL:
2176 cmd = CMD_GBAR_ACCESS_SCROLL;
2177 ret = (int)info->type;
2179 case DBOX_ACCESS_EVENT_VALUE_CHANGE:
2180 cmd = CMD_GBAR_ACCESS_VALUE_CHANGE;
2182 case DBOX_ACCESS_EVENT_MOUSE:
2183 cmd = CMD_GBAR_ACCESS_MOUSE;
2184 ret = (int)info->type;
2186 case DBOX_ACCESS_EVENT_BACK:
2187 cmd = CMD_GBAR_ACCESS_BACK;
2189 case DBOX_ACCESS_EVENT_OVER:
2190 cmd = CMD_GBAR_ACCESS_OVER;
2192 case DBOX_ACCESS_EVENT_READ:
2193 cmd = CMD_GBAR_ACCESS_READ;
2195 case DBOX_ACCESS_EVENT_ENABLE:
2196 cmd = CMD_GBAR_ACCESS_ENABLE;
2200 return DBOX_STATUS_ERROR_INVALID_PARAMETER;
2203 } else if (type & DBOX_ACCESS_EVENT_DBOX_MASK) {
2204 w = handler->common->dbox.width;
2205 h = handler->common->dbox.height;
2206 switch (type & ~(DBOX_ACCESS_EVENT_GBAR_MASK | DBOX_ACCESS_EVENT_DBOX_MASK)) {
2207 case DBOX_ACCESS_EVENT_HIGHLIGHT:
2208 cmd = CMD_DBOX_ACCESS_HL;
2209 ret = (int)info->type;
2211 case DBOX_ACCESS_EVENT_ACTIVATE:
2212 cmd = CMD_DBOX_ACCESS_ACTIVATE;
2214 case DBOX_ACCESS_EVENT_ACTION:
2215 cmd = CMD_DBOX_ACCESS_ACTION;
2216 ret = (int)info->type;
2218 case DBOX_ACCESS_EVENT_SCROLL:
2219 cmd = CMD_DBOX_ACCESS_SCROLL;
2220 ret = (int)info->type;
2222 case DBOX_ACCESS_EVENT_VALUE_CHANGE:
2223 cmd = CMD_DBOX_ACCESS_VALUE_CHANGE;
2225 case DBOX_ACCESS_EVENT_MOUSE:
2226 cmd = CMD_DBOX_ACCESS_MOUSE;
2227 ret = (int)info->type;
2229 case DBOX_ACCESS_EVENT_BACK:
2230 cmd = CMD_DBOX_ACCESS_BACK;
2232 case DBOX_ACCESS_EVENT_OVER:
2233 cmd = CMD_DBOX_ACCESS_OVER;
2235 case DBOX_ACCESS_EVENT_READ:
2236 cmd = CMD_DBOX_ACCESS_READ;
2238 case DBOX_ACCESS_EVENT_ENABLE:
2239 cmd = CMD_DBOX_ACCESS_ENABLE;
2243 return DBOX_STATUS_ERROR_INVALID_PARAMETER;
2246 ErrPrint("Invalid event type\n");
2247 return DBOX_STATUS_ERROR_INVALID_PARAMETER;
2251 cb = default_access_event_cb;
2254 ret = send_access_event(handler, (const char *)&cmd, info->x * w, info->y * h, ret);
2255 if (ret == (int)DBOX_STATUS_ERROR_NONE) {
2256 handler->cbs.access_event.cb = cb;
2257 handler->cbs.access_event.data = data;
2258 handler->common->request.access_event = 1;
2264 EAPI int dynamicbox_feed_mouse_event(dynamicbox_h handler, dynamicbox_mouse_event_type_e type, dynamicbox_mouse_event_info_t info)
2270 if (!handler || handler->state != DBOX_STATE_CREATE) {
2271 ErrPrint("Handler is invalid\n");
2272 return DBOX_STATUS_ERROR_INVALID_PARAMETER;
2275 if (!handler->common || handler->common->state != DBOX_STATE_CREATE) {
2276 ErrPrint("Handler is invalid\n");
2277 return DBOX_STATUS_ERROR_INVALID_PARAMETER;
2280 if (!handler->common->id) {
2281 ErrPrint("Handler is not valid\n");
2282 return DBOX_STATUS_ERROR_INVALID_PARAMETER;
2285 if (!(type & DBOX_MOUSE_EVENT_MASK)) {
2286 ErrPrint("Invalid content event is used\n");
2287 return DBOX_STATUS_ERROR_INVALID_PARAMETER;
2290 if (type & DBOX_MOUSE_EVENT_GBAR_MASK) {
2293 if (!handler->common->is_gbar_created) {
2294 ErrPrint("GBAR is not created\n");
2295 return DBOX_STATUS_ERROR_INVALID_PARAMETER;
2298 if (!handler->common->gbar.fb) {
2299 ErrPrint("Handler is not valid\n");
2300 return DBOX_STATUS_ERROR_INVALID_PARAMETER;
2303 if (type & DBOX_MOUSE_EVENT_MOVE) {
2304 if (fabs(info->x - handler->common->gbar.x) < conf_event_filter() && fabs(info->y - handler->common->gbar.y) < conf_event_filter()) {
2305 return DBOX_STATUS_ERROR_BUSY;
2307 } else if (type & DBOX_MOUSE_EVENT_SET) {
2312 handler->common->gbar.x = info->x;
2313 handler->common->gbar.y = info->y;
2314 w = handler->common->gbar.width;
2315 h = handler->common->gbar.height;
2318 switch ((type & ~(DBOX_MOUSE_EVENT_GBAR_MASK | DBOX_MOUSE_EVENT_DBOX_MASK))) {
2319 case DBOX_MOUSE_EVENT_ENTER | DBOX_MOUSE_EVENT_MASK:
2320 cmd = CMD_GBAR_MOUSE_ENTER;
2322 case DBOX_MOUSE_EVENT_LEAVE | DBOX_MOUSE_EVENT_MASK:
2323 cmd = CMD_GBAR_MOUSE_LEAVE;
2325 case DBOX_MOUSE_EVENT_UP | DBOX_MOUSE_EVENT_MASK:
2326 cmd = CMD_GBAR_MOUSE_UP;
2328 case DBOX_MOUSE_EVENT_DOWN | DBOX_MOUSE_EVENT_MASK:
2329 cmd = CMD_GBAR_MOUSE_DOWN;
2331 case DBOX_MOUSE_EVENT_MOVE | DBOX_MOUSE_EVENT_MASK:
2332 cmd = CMD_GBAR_MOUSE_MOVE;
2334 case DBOX_MOUSE_EVENT_SET | DBOX_MOUSE_EVENT_MASK:
2335 cmd = CMD_GBAR_MOUSE_SET;
2337 case DBOX_MOUSE_EVENT_UNSET | DBOX_MOUSE_EVENT_MASK:
2338 cmd = CMD_GBAR_MOUSE_UNSET;
2340 case DBOX_MOUSE_EVENT_ON_SCROLL | DBOX_MOUSE_EVENT_MASK:
2341 cmd = CMD_GBAR_MOUSE_ON_SCROLL;
2343 case DBOX_MOUSE_EVENT_ON_HOLD | DBOX_MOUSE_EVENT_MASK:
2344 cmd = CMD_GBAR_MOUSE_ON_HOLD;
2346 case DBOX_MOUSE_EVENT_OFF_SCROLL | DBOX_MOUSE_EVENT_MASK:
2347 cmd = CMD_GBAR_MOUSE_OFF_SCROLL;
2349 case DBOX_MOUSE_EVENT_OFF_HOLD | DBOX_MOUSE_EVENT_MASK:
2350 cmd = CMD_GBAR_MOUSE_OFF_HOLD;
2353 ErrPrint("Invalid event type\n");
2354 return DBOX_STATUS_ERROR_INVALID_PARAMETER;
2357 } else if (type & DBOX_MOUSE_EVENT_DBOX_MASK) {
2360 if (!handler->common->dbox.fb) {
2361 ErrPrint("Handler is not valid\n");
2362 return DBOX_STATUS_ERROR_INVALID_PARAMETER;
2365 if (type & DBOX_MOUSE_EVENT_MOVE) {
2366 if (fabs(info->x - handler->common->dbox.x) < conf_event_filter() && fabs(info->y - handler->common->dbox.y) < conf_event_filter()) {
2367 return DBOX_STATUS_ERROR_BUSY;
2369 } else if (type & DBOX_MOUSE_EVENT_SET) {
2374 handler->common->dbox.x = info->x;
2375 handler->common->dbox.y = info->y;
2376 w = handler->common->dbox.width;
2377 h = handler->common->dbox.height;
2380 switch ((type & ~(DBOX_MOUSE_EVENT_GBAR_MASK | DBOX_MOUSE_EVENT_DBOX_MASK))) {
2381 case DBOX_MOUSE_EVENT_ENTER | DBOX_MOUSE_EVENT_MASK:
2382 cmd = CMD_DBOX_MOUSE_ENTER;
2384 case DBOX_MOUSE_EVENT_LEAVE | DBOX_MOUSE_EVENT_MASK:
2385 cmd = CMD_DBOX_MOUSE_LEAVE;
2387 case DBOX_MOUSE_EVENT_UP | DBOX_MOUSE_EVENT_MASK:
2388 cmd = CMD_DBOX_MOUSE_UP;
2390 case DBOX_MOUSE_EVENT_DOWN | DBOX_MOUSE_EVENT_MASK:
2391 cmd = CMD_DBOX_MOUSE_DOWN;
2393 case DBOX_MOUSE_EVENT_MOVE | DBOX_MOUSE_EVENT_MASK:
2394 if (!handler->common->dbox.mouse_event) {
2395 return DBOX_STATUS_ERROR_INVALID_PARAMETER;
2397 cmd = CMD_DBOX_MOUSE_MOVE;
2399 case DBOX_MOUSE_EVENT_SET | DBOX_MOUSE_EVENT_MASK:
2400 if (!handler->common->dbox.mouse_event) {
2401 return DBOX_STATUS_ERROR_INVALID_PARAMETER;
2403 cmd = CMD_DBOX_MOUSE_SET;
2405 case DBOX_MOUSE_EVENT_UNSET | DBOX_MOUSE_EVENT_MASK:
2406 if (!handler->common->dbox.mouse_event) {
2407 return DBOX_STATUS_ERROR_INVALID_PARAMETER;
2409 cmd = CMD_DBOX_MOUSE_UNSET;
2411 case DBOX_MOUSE_EVENT_ON_SCROLL | DBOX_MOUSE_EVENT_MASK:
2412 cmd = CMD_DBOX_MOUSE_ON_SCROLL;
2414 case DBOX_MOUSE_EVENT_ON_HOLD | DBOX_MOUSE_EVENT_MASK:
2415 cmd = CMD_DBOX_MOUSE_ON_HOLD;
2417 case DBOX_MOUSE_EVENT_OFF_SCROLL | DBOX_MOUSE_EVENT_MASK:
2418 cmd = CMD_DBOX_MOUSE_OFF_SCROLL;
2420 case DBOX_MOUSE_EVENT_OFF_HOLD | DBOX_MOUSE_EVENT_MASK:
2421 cmd = CMD_DBOX_MOUSE_OFF_HOLD;
2424 ErrPrint("Invalid event type\n");
2425 return DBOX_STATUS_ERROR_INVALID_PARAMETER;
2428 ErrPrint("Invalid event type\n");
2429 return DBOX_STATUS_ERROR_INVALID_PARAMETER;
2432 return send_mouse_event(handler, (const char *)&cmd, info->x * w, info->y * h);
2435 EAPI int dynamicbox_feed_key_event(dynamicbox_h handler, dynamicbox_key_event_type_e type, dynamicbox_key_event_info_t info, dynamicbox_ret_cb cb, void *data)
2440 if (!handler || handler->state != DBOX_STATE_CREATE) {
2441 ErrPrint("Handler is invalid\n");
2442 return DBOX_STATUS_ERROR_INVALID_PARAMETER;
2445 if (!handler->common || handler->common->state != DBOX_STATE_CREATE) {
2446 ErrPrint("Handler is invalid\n");
2447 return DBOX_STATUS_ERROR_INVALID_PARAMETER;
2450 if (!handler->common->id) {
2451 ErrPrint("Handler is not valid\n");
2452 return DBOX_STATUS_ERROR_INVALID_PARAMETER;
2455 if (!(type & DBOX_KEY_EVENT_MASK)) {
2456 ErrPrint("Invalid key event is used\n");
2457 return DBOX_STATUS_ERROR_INVALID_PARAMETER;
2460 if (handler->common->request.key_event) {
2461 ErrPrint("Previous key event is not completed yet\n");
2462 return DBOX_STATUS_ERROR_BUSY;
2465 if (type & DBOX_MOUSE_EVENT_GBAR_MASK) {
2466 if (!handler->common->is_gbar_created) {
2467 ErrPrint("GBAR is not created\n");
2468 return DBOX_STATUS_ERROR_INVALID_PARAMETER;
2471 if (!handler->common->gbar.fb) {
2472 ErrPrint("Handler is not valid\n");
2473 return DBOX_STATUS_ERROR_INVALID_PARAMETER;
2476 if (type & DBOX_KEY_EVENT_DOWN) {
2479 * filtering the reproduced events if it is too fast
2481 } else if (type & DBOX_KEY_EVENT_SET) {
2484 * What can I do for this case?
2489 * Must be short than 29 bytes.
2491 switch ((type & ~(DBOX_MOUSE_EVENT_GBAR_MASK | DBOX_MOUSE_EVENT_DBOX_MASK))) {
2492 case DBOX_KEY_EVENT_FOCUS_IN | DBOX_KEY_EVENT_MASK:
2493 cmd = CMD_GBAR_KEY_FOCUS_IN;
2495 case DBOX_KEY_EVENT_FOCUS_OUT | DBOX_KEY_EVENT_MASK:
2496 cmd = CMD_GBAR_KEY_FOCUS_OUT;
2498 case DBOX_KEY_EVENT_UP | DBOX_KEY_EVENT_MASK:
2499 cmd = CMD_GBAR_KEY_UP;
2501 case DBOX_KEY_EVENT_DOWN | DBOX_KEY_EVENT_MASK:
2502 cmd = CMD_GBAR_KEY_DOWN;
2504 case DBOX_KEY_EVENT_SET | DBOX_KEY_EVENT_MASK:
2505 cmd = CMD_GBAR_KEY_SET;
2507 case DBOX_KEY_EVENT_UNSET | DBOX_KEY_EVENT_MASK:
2508 cmd = CMD_GBAR_KEY_UNSET;
2511 ErrPrint("Invalid event type\n");
2512 return DBOX_STATUS_ERROR_INVALID_PARAMETER;
2515 } else if (type & DBOX_MOUSE_EVENT_DBOX_MASK) {
2516 if (!handler->common->dbox.fb) {
2517 ErrPrint("Handler is not valid\n");
2518 return DBOX_STATUS_ERROR_INVALID_PARAMETER;
2521 if (type & DBOX_KEY_EVENT_DOWN) {
2524 * filtering the reproduced events if it is too fast
2526 } else if (type & DBOX_KEY_EVENT_SET) {
2528 * What can I do for this case?
2532 switch ((type & ~(DBOX_MOUSE_EVENT_GBAR_MASK | DBOX_MOUSE_EVENT_DBOX_MASK))) {
2533 case DBOX_KEY_EVENT_FOCUS_IN | DBOX_KEY_EVENT_MASK:
2534 cmd = CMD_DBOX_KEY_FOCUS_IN;
2536 case DBOX_KEY_EVENT_FOCUS_OUT | DBOX_KEY_EVENT_MASK:
2537 cmd = CMD_DBOX_KEY_FOCUS_OUT;
2539 case DBOX_KEY_EVENT_UP | DBOX_KEY_EVENT_MASK:
2540 cmd = CMD_DBOX_KEY_UP;
2542 case DBOX_KEY_EVENT_DOWN | DBOX_KEY_EVENT_MASK:
2543 cmd = CMD_DBOX_KEY_DOWN;
2545 case DBOX_KEY_EVENT_SET | DBOX_KEY_EVENT_MASK:
2546 cmd = CMD_DBOX_KEY_SET;
2548 case DBOX_KEY_EVENT_UNSET | DBOX_KEY_EVENT_MASK:
2549 cmd = CMD_DBOX_KEY_UNSET;
2552 ErrPrint("Invalid event type\n");
2553 return DBOX_STATUS_ERROR_INVALID_PARAMETER;
2556 ErrPrint("Invalid event type\n");
2557 return DBOX_STATUS_ERROR_INVALID_PARAMETER;
2561 cb = default_key_event_cb;
2564 ret = send_key_event(handler, (const char *)&cmd, info->keycode);
2565 if (ret == (int)DBOX_STATUS_ERROR_NONE) {
2566 handler->cbs.key_event.cb = cb;
2567 handler->cbs.key_event.data = data;
2568 handler->common->request.key_event = 1;
2574 EAPI const char *dynamicbox_filename(dynamicbox_h handler)
2576 if (!handler || handler->state != DBOX_STATE_CREATE) {
2577 ErrPrint("Handler is invalid\n");
2581 if (!handler->common || handler->common->state != DBOX_STATE_CREATE) {
2582 ErrPrint("Handler is invalid\n");
2586 if (!handler->common->id) {
2587 ErrPrint("Handler is not valid\n");
2591 if (handler->common->filename) {
2592 return handler->common->filename;
2596 dynamicbox_set_last_status(DBOX_STATUS_ERROR_NONE);
2597 return util_uri_to_path(handler->common->id);
2600 EAPI int dynamicbox_get_glance_bar_size(dynamicbox_h handler, int *w, int *h)
2605 if (!handler || handler->state != DBOX_STATE_CREATE) {
2606 ErrPrint("Handler is invalid\n");
2607 return DBOX_STATUS_ERROR_INVALID_PARAMETER;
2610 if (!handler->common || handler->common->state != DBOX_STATE_CREATE) {
2611 ErrPrint("Handler is invalid\n");
2612 return DBOX_STATUS_ERROR_INVALID_PARAMETER;
2615 if (!handler->common->id) {
2616 ErrPrint("Handler is not valid\n");
2617 return DBOX_STATUS_ERROR_INVALID_PARAMETER;
2627 if (!handler->common->is_gbar_created) {
2628 *w = handler->common->gbar.default_width;
2629 *h = handler->common->gbar.default_height;
2631 *w = handler->common->gbar.width;
2632 *h = handler->common->gbar.height;
2635 return DBOX_STATUS_ERROR_NONE;
2638 EAPI dynamicbox_size_type_e dynamicbox_size(dynamicbox_h handler)
2643 if (!handler || handler->state != DBOX_STATE_CREATE) {
2644 ErrPrint("Handler is invalid\n");
2645 dynamicbox_set_last_status(DBOX_STATUS_ERROR_INVALID_PARAMETER);
2646 return DBOX_SIZE_TYPE_UNKNOWN;
2649 if (!handler->common || handler->common->state != DBOX_STATE_CREATE) {
2650 ErrPrint("Handler is invalid\n");
2651 dynamicbox_set_last_status(DBOX_STATUS_ERROR_INVALID_PARAMETER);
2652 return DBOX_SIZE_TYPE_UNKNOWN;
2655 if (!handler->common->id) {
2656 ErrPrint("Handler is not valid\n");
2657 dynamicbox_set_last_status(DBOX_STATUS_ERROR_INVALID_PARAMETER);
2658 return DBOX_SIZE_TYPE_UNKNOWN;
2661 w = handler->common->dbox.width;
2662 h = handler->common->dbox.height;
2664 switch (handler->common->dbox.type) {
2665 case DBOX_TYPE_BUFFER:
2666 case DBOX_TYPE_SCRIPT:
2667 if (!fb_is_created(handler->common->dbox.fb)) {
2670 dynamicbox_set_last_status(DBOX_STATUS_ERROR_NOT_EXIST);
2677 return dynamicbox_service_size_type(w, h);
2680 EAPI int dynamicbox_set_group(dynamicbox_h handler, const char *cluster, const char *category, dynamicbox_ret_cb cb, void *data)
2682 struct packet *packet;
2683 unsigned int cmd = CMD_CHANGE_GROUP;
2687 ErrPrint("Handler is NIL\n");
2688 return DBOX_STATUS_ERROR_INVALID_PARAMETER;
2691 if (!cluster || !category || handler->state != DBOX_STATE_CREATE) {
2692 ErrPrint("Invalid argument\n");
2693 return DBOX_STATUS_ERROR_INVALID_PARAMETER;
2696 if (!handler->common || handler->common->state != DBOX_STATE_CREATE) {
2697 ErrPrint("Invalid argument\n");
2698 return DBOX_STATUS_ERROR_INVALID_PARAMETER;
2701 if (!handler->common->id) {
2702 ErrPrint("Invalid argument\n");
2703 return DBOX_STATUS_ERROR_INVALID_PARAMETER;
2706 if (handler->common->request.group_changed) {
2707 ErrPrint("Previous group changing request is not finished yet\n");
2708 return DBOX_STATUS_ERROR_BUSY;
2711 if (!handler->common->is_user) {
2712 ErrPrint("CA Livebox is not able to change the group\n");
2713 return DBOX_STATUS_ERROR_PERMISSION_DENIED;
2716 if (!strcmp(handler->common->cluster, cluster) && !strcmp(handler->common->category, category)) {
2717 DbgPrint("No changes\n");
2718 return DBOX_STATUS_ERROR_ALREADY;
2721 packet = packet_create((const char *)&cmd, "ssss", handler->common->pkgname, handler->common->id, cluster, category);
2723 ErrPrint("Failed to build a param\n");
2724 return DBOX_STATUS_ERROR_FAULT;
2728 cb = default_group_changed_cb;
2731 ret = master_rpc_async_request(handler, packet, 0, set_group_ret_cb, NULL);
2732 if (ret == (int)DBOX_STATUS_ERROR_NONE) {
2733 handler->cbs.group_changed.cb = cb;
2734 handler->cbs.group_changed.data = data;
2735 handler->common->request.group_changed = 1;
2741 EAPI int dynamicbox_get_group(dynamicbox_h handler, const char **cluster, const char **category)
2744 ErrPrint("Handler is NIL\n");
2745 return DBOX_STATUS_ERROR_INVALID_PARAMETER;
2748 if (!cluster || !category || handler->state != DBOX_STATE_CREATE) {
2749 ErrPrint("Invalid argument\n");
2750 return DBOX_STATUS_ERROR_INVALID_PARAMETER;
2753 if (!handler->common || handler->common->state != DBOX_STATE_CREATE) {
2754 ErrPrint("Invalid argument\n");
2755 return DBOX_STATUS_ERROR_INVALID_PARAMETER;
2758 if (!handler->common->id) {
2759 ErrPrint("Invalid argument\n");
2760 return DBOX_STATUS_ERROR_INVALID_PARAMETER;
2763 *cluster = handler->common->cluster;
2764 *category = handler->common->category;
2765 return DBOX_STATUS_ERROR_NONE;
2768 EAPI int dynamicbox_get_supported_sizes(dynamicbox_h handler, int *cnt, dynamicbox_size_type_e *size_list)
2773 if (!handler || !size_list) {
2774 ErrPrint("Invalid argument, handler(%p), size_list(%p)\n", handler, size_list);
2775 return DBOX_STATUS_ERROR_INVALID_PARAMETER;
2778 if (!cnt || handler->state != DBOX_STATE_CREATE) {
2779 ErrPrint("Handler is not valid\n");
2780 return DBOX_STATUS_ERROR_INVALID_PARAMETER;
2783 if (!handler->common || handler->common->state != DBOX_STATE_CREATE) {
2784 ErrPrint("Handler is not valid\n");
2785 return DBOX_STATUS_ERROR_INVALID_PARAMETER;
2788 if (!handler->common->id) {
2789 ErrPrint("Handler is not valid\n");
2790 return DBOX_STATUS_ERROR_INVALID_PARAMETER;
2793 for (j = i = 0; i < DBOX_NR_OF_SIZE_LIST; i++) {
2794 if (handler->common->dbox.size_list & (0x01 << i)) {
2799 size_list[j++] = (dynamicbox_size_type_e)(0x01 << i);
2804 return DBOX_STATUS_ERROR_NONE;
2807 EAPI const char *dynamicbox_pkgname(dynamicbox_h handler)
2810 ErrPrint("Handler is NIL\n");
2811 dynamicbox_set_last_status(DBOX_STATUS_ERROR_INVALID_PARAMETER);
2815 if (handler->state != DBOX_STATE_CREATE) {
2816 ErrPrint("Handler is not valid\n");
2817 dynamicbox_set_last_status(DBOX_STATUS_ERROR_INVALID_PARAMETER);
2821 if (!handler->common || handler->common->state != DBOX_STATE_CREATE) {
2822 ErrPrint("Handler is not valid\n");
2823 dynamicbox_set_last_status(DBOX_STATUS_ERROR_INVALID_PARAMETER);
2827 dynamicbox_set_last_status(DBOX_STATUS_ERROR_NONE);
2828 return handler->common->pkgname;
2831 EAPI double dynamicbox_priority(dynamicbox_h handler)
2833 if (!handler || handler->state != DBOX_STATE_CREATE) {
2834 ErrPrint("Handler is invalid\n");
2835 dynamicbox_set_last_status(DBOX_STATUS_ERROR_INVALID_PARAMETER);
2839 if (!handler->common || handler->common->state != DBOX_STATE_CREATE) {
2840 ErrPrint("Handler is invalid\n");
2841 dynamicbox_set_last_status(DBOX_STATUS_ERROR_INVALID_PARAMETER);
2845 if (!handler->common->id) {
2846 ErrPrint("Handler is not valid (%p)\n", handler);
2847 dynamicbox_set_last_status(DBOX_STATUS_ERROR_INVALID_PARAMETER);
2851 return handler->common->dbox.priority;
2854 EAPI int dynamicbox_delete_cluster(const char *cluster, dynamicbox_ret_cb cb, void *data)
2856 struct packet *packet;
2857 struct cb_info *cbinfo;
2858 unsigned int cmd = CMD_DELETE_CLUSTER;
2861 packet = packet_create((const char *)&cmd, "s", cluster);
2863 ErrPrint("Failed to build a param\n");
2864 return DBOX_STATUS_ERROR_FAULT;
2867 cbinfo = dbox_create_cb_info(cb, data);
2869 packet_destroy(packet);
2870 return DBOX_STATUS_ERROR_FAULT;
2873 ret = master_rpc_async_request(NULL, packet, 0, delete_cluster_cb, cbinfo);
2875 dbox_destroy_cb_info(cbinfo);
2881 EAPI int dynamicbox_delete_category(const char *cluster, const char *category, dynamicbox_ret_cb cb, void *data)
2883 struct packet *packet;
2884 struct cb_info *cbinfo;
2885 unsigned int cmd = CMD_DELETE_CATEGORY;
2888 packet = packet_create((const char *)&cmd, "ss", cluster, category);
2890 ErrPrint("Failed to build a param\n");
2891 return DBOX_STATUS_ERROR_FAULT;
2894 cbinfo = dbox_create_cb_info(cb, data);
2896 packet_destroy(packet);
2897 return DBOX_STATUS_ERROR_FAULT;
2900 ret = master_rpc_async_request(NULL, packet, 0, delete_category_cb, cbinfo);
2902 dbox_destroy_cb_info(cbinfo);
2908 EAPI dynamicbox_type_e dynamicbox_type(dynamicbox_h handler, int gbar)
2910 if (!handler || handler->state != DBOX_STATE_CREATE) {
2911 ErrPrint("Handler is invalid\n");
2912 dynamicbox_set_last_status(DBOX_STATUS_ERROR_INVALID_PARAMETER);
2913 return DBOX_CONTENT_TYPE_INVALID;
2916 if (!handler->common || handler->common->state != DBOX_STATE_CREATE) {
2917 ErrPrint("Handler is invalid\n");
2918 dynamicbox_set_last_status(DBOX_STATUS_ERROR_INVALID_PARAMETER);
2919 return DBOX_CONTENT_TYPE_INVALID;
2922 if (!handler->common->id) {
2923 ErrPrint("Handler is not valid\n");
2924 dynamicbox_set_last_status(DBOX_STATUS_ERROR_INVALID_PARAMETER);
2925 return DBOX_CONTENT_TYPE_INVALID;
2929 switch (handler->common->gbar.type) {
2930 case GBAR_TYPE_TEXT:
2931 return DBOX_CONTENT_TYPE_TEXT;
2932 case GBAR_TYPE_BUFFER:
2933 case GBAR_TYPE_SCRIPT:
2936 id = fb_id(handler->common->gbar.fb);
2937 if (id && !strncasecmp(id, SCHEMA_PIXMAP, strlen(SCHEMA_PIXMAP))) {
2938 return DBOX_CONTENT_TYPE_RESOURCE_ID;
2941 return DBOX_CONTENT_TYPE_BUFFER;
2942 case GBAR_TYPE_UIFW:
2943 return DBOX_CONTENT_TYPE_UIFW;
2948 switch (handler->common->dbox.type) {
2949 case DBOX_TYPE_FILE:
2950 return DBOX_CONTENT_TYPE_IMAGE;
2951 case DBOX_TYPE_BUFFER:
2952 case DBOX_TYPE_SCRIPT:
2955 id = fb_id(handler->common->dbox.fb);
2956 if (id && !strncasecmp(id, SCHEMA_PIXMAP, strlen(SCHEMA_PIXMAP))) {
2957 return DBOX_CONTENT_TYPE_RESOURCE_ID;
2960 return DBOX_CONTENT_TYPE_BUFFER;
2961 case DBOX_TYPE_TEXT:
2962 return DBOX_CONTENT_TYPE_TEXT;
2963 case DBOX_TYPE_UIFW:
2964 return DBOX_CONTENT_TYPE_UIFW;
2970 dynamicbox_set_last_status(DBOX_STATUS_ERROR_INVALID_PARAMETER);
2971 return DBOX_CONTENT_TYPE_INVALID;
2974 EAPI int dynamicbox_set_text_handler(dynamicbox_h handler, int gbar, struct dynamicbox_script_operators *ops)
2977 ErrPrint("Handler is NIL\n");
2978 return DBOX_STATUS_ERROR_INVALID_PARAMETER;
2981 if (handler->state != DBOX_STATE_CREATE) {
2982 ErrPrint("Handler is not valid\n");
2983 return DBOX_STATUS_ERROR_INVALID_PARAMETER;
2987 memcpy(&handler->cbs.gbar_ops, ops, sizeof(*ops));
2989 memcpy(&handler->cbs.dbox_ops, ops, sizeof(*ops));
2992 return DBOX_STATUS_ERROR_NONE;
2995 EAPI int dynamicbox_acquire_extra_resource_id(dynamicbox_h handler, int gbar, int idx, dynamicbox_ret_cb cb, void *data)
2998 return DBOX_STATUS_ERROR_INVALID_PARAMETER;
3001 if (!handler || handler->state != DBOX_STATE_CREATE) {
3002 ErrPrint("Handler is invalid\n");
3003 return DBOX_STATUS_ERROR_INVALID_PARAMETER;
3006 if (!handler->common || handler->common->state != DBOX_STATE_CREATE) {
3007 ErrPrint("Handler is invalid\n");
3008 return DBOX_STATUS_ERROR_INVALID_PARAMETER;
3011 if (!handler->common->id) {
3012 ErrPrint("Invalid handle\n");
3013 return DBOX_STATUS_ERROR_INVALID_PARAMETER;
3018 * This can be called from extra_resource_created event.
3019 * and it can be called before get the created event.
3020 * then we didn't know this handler's buffer type yet
3021 * so we cannot use its type to validate handle
3023 * handler->common.gbar.type == unknown
3025 if (!handler->common->gbar.extra_buffer) {
3026 return DBOX_STATUS_ERROR_NOT_EXIST;
3029 if (idx >= conf_extra_buffer_count()) {
3030 return DBOX_STATUS_ERROR_INVALID_PARAMETER;
3033 return dbox_acquire_gbar_extra_pixmap(handler, idx, cb, data);
3036 * This can be called from extra_resource_created event.
3037 * and it can be called before get the created event.
3038 * then we didn't know this handler's buffer type yet
3039 * so we cannot use its type to validate handle
3041 * handler->common.dbox.type == unknown
3043 if (!handler->common->dbox.extra_buffer) {
3044 ErrPrint("Extra buffer is not prepared\n");
3045 return DBOX_STATUS_ERROR_NOT_EXIST;
3048 if (idx >= conf_extra_buffer_count()) {
3049 ErrPrint("Invalid parameter: %d / %d\n", idx, conf_extra_buffer_count());
3050 return DBOX_STATUS_ERROR_INVALID_PARAMETER;
3053 return dbox_acquire_dbox_extra_pixmap(handler, idx, cb, data);
3057 EAPI int dynamicbox_acquire_resource_id(dynamicbox_h handler, int gbar, dynamicbox_ret_cb cb, void *data)
3059 if (!handler || handler->state != DBOX_STATE_CREATE) {
3060 ErrPrint("Handler is invalid\n");
3061 return DBOX_STATUS_ERROR_INVALID_PARAMETER;
3064 if (!handler->common || handler->common->state != DBOX_STATE_CREATE) {
3065 ErrPrint("Handler is invalid\n");
3066 return DBOX_STATUS_ERROR_INVALID_PARAMETER;
3069 if (!handler->common->id) {
3070 ErrPrint("Invalid handle\n");
3071 return DBOX_STATUS_ERROR_INVALID_PARAMETER;
3075 if (handler->common->gbar.type != GBAR_TYPE_SCRIPT && handler->common->gbar.type != GBAR_TYPE_BUFFER) {
3076 ErrPrint("Handler is not valid type\n");
3077 return DBOX_STATUS_ERROR_INVALID_PARAMETER;
3080 return dbox_acquire_gbar_pixmap(handler, cb, data);
3082 if (handler->common->dbox.type != DBOX_TYPE_SCRIPT && handler->common->dbox.type != DBOX_TYPE_BUFFER) {
3083 ErrPrint("Handler is not valid type\n");
3084 return DBOX_STATUS_ERROR_INVALID_PARAMETER;
3087 return dbox_acquire_dbox_pixmap(handler, cb, data);
3093 * Do not check the state of handler and common-handler.
3094 * If this function is used in the deleted callback,
3095 * the handler and common-handler's state would be DELETE
3096 * if this function check the state of handles,
3097 * user cannot release the pixmap.
3099 EAPI int dynamicbox_release_resource_id(dynamicbox_h handler, int gbar, unsigned int resource_id)
3101 struct packet *packet;
3102 const char *pkgname;
3106 if (resource_id == 0 /* || handler->state != DBOX_STATE_CREATE */) {
3107 ErrPrint("Pixmap is invalid [%d]\n", resource_id);
3108 return DBOX_STATUS_ERROR_INVALID_PARAMETER;
3115 * Even though the handler is NULL, we should send the release request to the master.
3116 * Because the resource_id resource can be released after the handler is destroyed.
3117 * Pixmap resource is used by client. and it cannot be guaranteed to release resource_id.
3118 * In some cases, the resource_id can be released after the handler is deleted.
3120 * Its implementation is up to the viewer app.
3121 * But we cannot force it to use only with valid handler.
3123 DbgPrint("Using NULL handler\n");
3128 * Master will try to find the buffer handler using given resource_id. if the pkgname and id is not valid.
3131 if (!handler->common /* || handler-common->state != DBOX_STATE_CREATE */) {
3132 ErrPrint("Handler is invalid\n");
3133 return DBOX_STATUS_ERROR_INVALID_PARAMETER;
3136 if (!handler->common->id) {
3137 ErrPrint("Invalid handle\n");
3138 return DBOX_STATUS_ERROR_INVALID_PARAMETER;
3142 * This can be called from extra_resource_created event.
3143 * and it can be called before get the created event.
3144 * then we didn't know this handler's buffer type yet
3145 * so we cannot use its type to validate handle
3147 * handler->common.gbar.type == unknown
3150 pkgname = handler->common->pkgname;
3151 id = handler->common->id;
3154 cmd = CMD_GBAR_RELEASE_PIXMAP;
3159 * Even though the handler is NULL, we should send the release request to the master.
3160 * Because the resource_id resource can be released after the handler is destroyed.
3161 * Pixmap resource is used by client. and it cannot be guaranteed to release resource_id.
3162 * In some cases, the resource_id can be released after the handler is deleted.
3164 * Its implementation is up to the viewer app.
3165 * But we cannot force it to use only with valid handler.
3167 DbgPrint("Using NULL handler\n");
3172 * Master will try to find the buffer handler using given resource_id. if the pkgname and id is not valid.
3175 if (!handler->common /* || handler->common->state != DBOX_STATE_CREATE */) {
3176 ErrPrint("Handler is invalid\n");
3177 return DBOX_STATUS_ERROR_INVALID_PARAMETER;
3180 if (!handler->common->id) {
3181 ErrPrint("Invalid handle\n");
3182 return DBOX_STATUS_ERROR_INVALID_PARAMETER;
3186 * This can be called from extra_resource_created event.
3187 * and it can be called before get the created event.
3188 * then we didn't know this handler's buffer type yet
3189 * so we cannot use its type to validate handle
3191 * handler->common.dbox.type == unknown
3194 pkgname = handler->common->pkgname;
3195 id = handler->common->id;
3198 cmd = CMD_DBOX_RELEASE_PIXMAP;
3201 packet = packet_create_noack((const char *)&cmd, "ssi", pkgname, id, resource_id);
3203 ErrPrint("Failed to build a param\n");
3204 return DBOX_STATUS_ERROR_FAULT;
3207 return master_rpc_request_only(handler, packet);
3210 EAPI unsigned int dynamicbox_extra_resource_id(const dynamicbox_h handler, int gbar, int idx)
3213 dynamicbox_set_last_status(DBOX_STATUS_ERROR_INVALID_PARAMETER);
3217 if (!handler || handler->state != DBOX_STATE_CREATE) {
3218 ErrPrint("Handler is invalid\n");
3219 dynamicbox_set_last_status(DBOX_STATUS_ERROR_INVALID_PARAMETER);
3223 if (!handler->common || handler->common->state != DBOX_STATE_CREATE) {
3224 ErrPrint("Handler is invalid\n");
3225 dynamicbox_set_last_status(DBOX_STATUS_ERROR_INVALID_PARAMETER);
3229 if (!handler->common->id) {
3230 ErrPrint("Invalid handler\n");
3231 dynamicbox_set_last_status(DBOX_STATUS_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 handler's buffer type yet
3240 * so we cannot use its type to validate handle
3242 * handler->common.gbar.type == unknown
3245 if (!handler->common->gbar.extra_buffer || handler->common->gbar.last_extra_buffer_idx < 0) {
3246 dynamicbox_set_last_status(DBOX_STATUS_ERROR_NOT_EXIST);
3250 return handler->common->gbar.extra_buffer[handler->common->gbar.last_extra_buffer_idx];
3253 * This can be called from extra_resource_created event.
3254 * and it can be called before get the created event.
3255 * then we didn't know this handler's buffer type yet
3256 * so we cannot use its type to validate handle
3258 * handler->common.dbox.type == unknown
3261 if (!handler->common->dbox.extra_buffer || handler->common->dbox.last_extra_buffer_idx < 0) {
3262 dynamicbox_set_last_status(DBOX_STATUS_ERROR_NOT_EXIST);
3266 return handler->common->dbox.extra_buffer[handler->common->dbox.last_extra_buffer_idx];
3270 EAPI unsigned int dynamicbox_resource_id(const dynamicbox_h handler, int gbar)
3273 unsigned int pixmap = 0u;
3275 if (!handler || handler->state != DBOX_STATE_CREATE) {
3276 ErrPrint("Handler is invalid\n");
3277 dynamicbox_set_last_status(DBOX_STATUS_ERROR_INVALID_PARAMETER);
3281 if (!handler->common || handler->common->state != DBOX_STATE_CREATE) {
3282 ErrPrint("Handler is invalid\n");
3283 dynamicbox_set_last_status(DBOX_STATUS_ERROR_INVALID_PARAMETER);
3287 if (!handler->common->id) {
3288 ErrPrint("Invalid handler\n");
3289 dynamicbox_set_last_status(DBOX_STATUS_ERROR_INVALID_PARAMETER);
3294 if (handler->common->gbar.type != GBAR_TYPE_SCRIPT && handler->common->gbar.type != GBAR_TYPE_BUFFER) {
3295 ErrPrint("Invalid handler\n");
3296 dynamicbox_set_last_status(DBOX_STATUS_ERROR_INVALID_PARAMETER);
3300 id = fb_id(handler->common->gbar.fb);
3301 if (id && sscanf(id, SCHEMA_PIXMAP "%u", &pixmap) != 1) {
3302 ErrPrint("PIXMAP Id is not valid\n");
3303 dynamicbox_set_last_status(DBOX_STATUS_ERROR_INVALID_PARAMETER);
3307 if (handler->common->dbox.type != DBOX_TYPE_SCRIPT && handler->common->dbox.type != DBOX_TYPE_BUFFER) {
3308 ErrPrint("Invalid handler\n");
3309 dynamicbox_set_last_status(DBOX_STATUS_ERROR_INVALID_PARAMETER);
3313 id = fb_id(handler->common->dbox.fb);
3314 if (id && sscanf(id, SCHEMA_PIXMAP "%u", &pixmap) != 1) {
3315 ErrPrint("PIXMAP Id is not valid\n");
3316 dynamicbox_set_last_status(DBOX_STATUS_ERROR_INVALID_PARAMETER);
3324 EAPI void *dynamicbox_acquire_buffer(dynamicbox_h handler, int gbar)
3327 if (!handler || handler->state != DBOX_STATE_CREATE) {
3328 ErrPrint("Handler is invalid\n");
3329 dynamicbox_set_last_status(DBOX_STATUS_ERROR_INVALID_PARAMETER);
3333 if (!handler->common || handler->common->state != DBOX_STATE_CREATE) {
3334 ErrPrint("Handler is invalid\n");
3335 dynamicbox_set_last_status(DBOX_STATUS_ERROR_INVALID_PARAMETER);
3339 if (!handler->common->id) {
3340 ErrPrint("Invalid handler\n");
3341 dynamicbox_set_last_status(DBOX_STATUS_ERROR_INVALID_PARAMETER);
3345 if (handler->common->gbar.type != GBAR_TYPE_SCRIPT && handler->common->gbar.type != GBAR_TYPE_BUFFER) {
3346 ErrPrint("Handler is not valid type\n");
3347 dynamicbox_set_last_status(DBOX_STATUS_ERROR_INVALID_PARAMETER);
3351 return fb_acquire_buffer(handler->common->gbar.fb);
3353 if (!handler || handler->state != DBOX_STATE_CREATE) {
3354 ErrPrint("Handler is invalid\n");
3355 dynamicbox_set_last_status(DBOX_STATUS_ERROR_INVALID_PARAMETER);
3359 if (!handler->common || handler->common->state != DBOX_STATE_CREATE) {
3360 ErrPrint("Handler is invalid\n");
3361 dynamicbox_set_last_status(DBOX_STATUS_ERROR_INVALID_PARAMETER);
3365 if (!handler->common->id) {
3366 ErrPrint("Invalid handle\n");
3367 dynamicbox_set_last_status(DBOX_STATUS_ERROR_INVALID_PARAMETER);
3371 if (handler->common->dbox.type != DBOX_TYPE_SCRIPT && handler->common->dbox.type != DBOX_TYPE_BUFFER) {
3372 ErrPrint("Handler is not valid type\n");
3373 dynamicbox_set_last_status(DBOX_STATUS_ERROR_INVALID_PARAMETER);
3377 return fb_acquire_buffer(handler->common->dbox.fb);
3381 EAPI int dynamicbox_release_buffer(void *buffer)
3383 return fb_release_buffer(buffer);
3386 EAPI int dynamicbox_buffer_refcnt(void *buffer)
3388 return fb_refcnt(buffer);
3391 EAPI int dynamicbox_buffer_size(dynamicbox_h handler, int gbar)
3393 if (!handler || handler->state != DBOX_STATE_CREATE) {
3394 ErrPrint("Handler is invalid\n");
3395 dynamicbox_set_last_status(DBOX_STATUS_ERROR_INVALID_PARAMETER);
3396 return DBOX_STATUS_ERROR_INVALID_PARAMETER;
3399 if (!handler->common || handler->common->state != DBOX_STATE_CREATE) {
3400 ErrPrint("Handler is invalid\n");
3401 dynamicbox_set_last_status(DBOX_STATUS_ERROR_INVALID_PARAMETER);
3402 return DBOX_STATUS_ERROR_INVALID_PARAMETER;
3405 if (!handler->common->id) {
3406 ErrPrint("Invalid handler\n");
3407 dynamicbox_set_last_status(DBOX_STATUS_ERROR_INVALID_PARAMETER);
3408 return DBOX_STATUS_ERROR_INVALID_PARAMETER;
3412 return fb_size(handler->common->gbar.fb);
3414 return fb_size(handler->common->dbox.fb);
3418 EAPI int dynamicbox_is_created_by_user(dynamicbox_h handler)
3420 if (!handler || handler->state != DBOX_STATE_CREATE) {
3421 ErrPrint("Handler is invalid\n");
3422 dynamicbox_set_last_status(DBOX_STATUS_ERROR_INVALID_PARAMETER);
3423 return DBOX_STATUS_ERROR_INVALID_PARAMETER;
3426 if (!handler->common || handler->common->state != DBOX_STATE_CREATE) {
3427 ErrPrint("Handler is invalid\n");
3428 dynamicbox_set_last_status(DBOX_STATUS_ERROR_INVALID_PARAMETER);
3429 return DBOX_STATUS_ERROR_INVALID_PARAMETER;
3432 if (!handler->common->id) {
3433 ErrPrint("Invalid handler\n");
3434 dynamicbox_set_last_status(DBOX_STATUS_ERROR_INVALID_PARAMETER);
3435 return DBOX_STATUS_ERROR_INVALID_PARAMETER;
3438 return handler->common->is_user;
3441 EAPI int dynamicbox_set_pinup(dynamicbox_h handler, int flag, dynamicbox_ret_cb cb, void *data)
3443 struct packet *packet;
3444 unsigned int cmd = CMD_PINUP_CHANGED;
3447 if (!handler || handler->state != DBOX_STATE_CREATE) {
3448 ErrPrint("Handler is invalid\n");
3449 return DBOX_STATUS_ERROR_INVALID_PARAMETER;
3452 if (!handler->common || handler->common->state != DBOX_STATE_CREATE) {
3453 ErrPrint("Handler is invalid\n");
3454 return DBOX_STATUS_ERROR_INVALID_PARAMETER;
3457 if (!handler->common->id) {
3458 ErrPrint("Invalid handler\n");
3459 return DBOX_STATUS_ERROR_INVALID_PARAMETER;
3462 if (handler->common->request.pinup) {
3463 ErrPrint("Previous pinup request is not finished\n");
3464 return DBOX_STATUS_ERROR_BUSY;
3467 if (handler->common->is_pinned_up == flag) {
3468 DbgPrint("No changes\n");
3469 return DBOX_STATUS_ERROR_ALREADY;
3472 packet = packet_create((const char *)&cmd, "ssi", handler->common->pkgname, handler->common->id, flag);
3474 ErrPrint("Failed to build a param\n");
3475 return DBOX_STATUS_ERROR_FAULT;
3479 cb = default_pinup_cb;
3482 ret = master_rpc_async_request(handler, packet, 0, pinup_done_cb, NULL);
3483 if (ret == (int)DBOX_STATUS_ERROR_NONE) {
3484 handler->cbs.pinup.cb = cb;
3485 handler->cbs.pinup.data = data;
3486 handler->common->request.pinup = 1;
3492 EAPI int dynamicbox_is_pinned_up(dynamicbox_h handler)
3494 if (!handler || handler->state != DBOX_STATE_CREATE) {
3495 ErrPrint("Handler is invalid\n");
3496 dynamicbox_set_last_status(DBOX_STATUS_ERROR_INVALID_PARAMETER);
3497 return DBOX_STATUS_ERROR_INVALID_PARAMETER;
3500 if (!handler->common || handler->common->state != DBOX_STATE_CREATE) {
3501 ErrPrint("Handler is invalid\n");
3502 dynamicbox_set_last_status(DBOX_STATUS_ERROR_INVALID_PARAMETER);
3503 return DBOX_STATUS_ERROR_INVALID_PARAMETER;
3506 if (!handler->common->id) {
3507 ErrPrint("Invalid handler\n");
3508 dynamicbox_set_last_status(DBOX_STATUS_ERROR_INVALID_PARAMETER);
3509 return DBOX_STATUS_ERROR_INVALID_PARAMETER;
3512 return handler->common->is_pinned_up;
3515 EAPI int dynamicbox_has_pinup(dynamicbox_h handler)
3517 if (!handler || handler->state != DBOX_STATE_CREATE) {
3518 ErrPrint("Handler is invalid\n");
3519 dynamicbox_set_last_status(DBOX_STATUS_ERROR_INVALID_PARAMETER);
3520 return DBOX_STATUS_ERROR_INVALID_PARAMETER;
3523 if (!handler->common || handler->common->state != DBOX_STATE_CREATE) {
3524 ErrPrint("Handler is invalid\n");
3525 dynamicbox_set_last_status(DBOX_STATUS_ERROR_INVALID_PARAMETER);
3526 return DBOX_STATUS_ERROR_INVALID_PARAMETER;
3529 if (!handler->common->id) {
3530 ErrPrint("Invalid handler\n");
3531 dynamicbox_set_last_status(DBOX_STATUS_ERROR_INVALID_PARAMETER);
3532 return DBOX_STATUS_ERROR_INVALID_PARAMETER;
3535 return handler->common->dbox.pinup_supported;
3538 EAPI int dynamicbox_set_data(dynamicbox_h handler, void *data)
3541 ErrPrint("Handler is NIL\n");
3542 return DBOX_STATUS_ERROR_INVALID_PARAMETER;
3545 if (handler->state != DBOX_STATE_CREATE) {
3546 ErrPrint("Handler is invalid\n");
3547 return DBOX_STATUS_ERROR_INVALID_PARAMETER;
3550 handler->data = data;
3551 return DBOX_STATUS_ERROR_NONE;
3554 EAPI void *dynamicbox_data(dynamicbox_h handler)
3557 ErrPrint("Handler is NIL\n");
3558 dynamicbox_set_last_status(DBOX_STATUS_ERROR_INVALID_PARAMETER);
3562 if (handler->state != DBOX_STATE_CREATE) {
3563 ErrPrint("Handler is invalid\n");
3564 dynamicbox_set_last_status(DBOX_STATUS_ERROR_INVALID_PARAMETER);
3568 return handler->data;
3571 EAPI const char *dynamicbox_content(dynamicbox_h handler)
3573 if (!handler || handler->state != DBOX_STATE_CREATE) {
3574 ErrPrint("Handler is invalid\n");
3575 dynamicbox_set_last_status(DBOX_STATUS_ERROR_INVALID_PARAMETER);
3579 if (!handler->common || handler->common->state != DBOX_STATE_CREATE) {
3580 ErrPrint("Invalid handle\n");
3581 dynamicbox_set_last_status(DBOX_STATUS_ERROR_INVALID_PARAMETER);
3585 dynamicbox_set_last_status(DBOX_STATUS_ERROR_NONE);
3586 return handler->common->content;
3589 EAPI const char *dynamicbox_title(dynamicbox_h handler)
3591 if (!handler || handler->state != DBOX_STATE_CREATE) {
3592 ErrPrint("Handler is invalid\n");
3593 dynamicbox_set_last_status(DBOX_STATUS_ERROR_INVALID_PARAMETER);
3597 if (!handler->common || handler->common->state != DBOX_STATE_CREATE) {
3598 ErrPrint("Invalid handle\n");
3599 dynamicbox_set_last_status(DBOX_STATUS_ERROR_INVALID_PARAMETER);
3603 dynamicbox_set_last_status(DBOX_STATUS_ERROR_NONE);
3604 return handler->common->title;
3607 EAPI int dynamicbox_emit_text_signal(dynamicbox_h handler, dynamicbox_text_event_t event_info, dynamicbox_ret_cb cb, void *data)
3609 struct packet *packet;
3610 struct cb_info *cbinfo;
3611 unsigned int cmd = CMD_TEXT_SIGNAL;
3613 const char *emission;
3616 if (!handler || handler->state != DBOX_STATE_CREATE) {
3617 ErrPrint("Handler is invalid\n");
3618 return DBOX_STATUS_ERROR_INVALID_PARAMETER;
3621 if (!handler->common || handler->common->state != DBOX_STATE_CREATE) {
3622 ErrPrint("Handler is invalid\n");
3623 return DBOX_STATUS_ERROR_INVALID_PARAMETER;
3626 if (handler->common->dbox.type != DBOX_TYPE_TEXT && handler->common->gbar.type != GBAR_TYPE_TEXT) {
3627 DbgPrint("Not a text box, but send signal\n");
3630 if (!handler->common->id) {
3631 ErrPrint("Handler is not valid\n");
3632 return DBOX_STATUS_ERROR_INVALID_PARAMETER;
3636 ErrPrint("Invalid event info\n");
3637 return DBOX_STATUS_ERROR_INVALID_PARAMETER;
3640 emission = event_info->emission;
3645 source = event_info->source;
3650 packet = packet_create((const char *)&cmd, "ssssdddd",
3651 handler->common->pkgname, handler->common->id,
3653 event_info->geometry.sx, event_info->geometry.sy,
3654 event_info->geometry.ex, event_info->geometry.ey);
3656 ErrPrint("Failed to build a param\n");
3657 return DBOX_STATUS_ERROR_FAULT;
3660 cbinfo = dbox_create_cb_info(cb, data);
3662 packet_destroy(packet);
3663 return DBOX_STATUS_ERROR_FAULT;
3666 ret = master_rpc_async_request(handler, packet, 0, text_signal_cb, cbinfo);
3668 dbox_destroy_cb_info(cbinfo);
3674 EAPI int dynamicbox_subscribe_group(const char *cluster, const char *category)
3676 struct packet *packet;
3677 unsigned int cmd = CMD_SUBSCRIBE;
3681 * Validate the group info using DB
3682 * If the group info is not valid, do not send this request
3685 packet = packet_create_noack((const char *)&cmd, "ss", cluster ? cluster : "", category ? category : "");
3687 ErrPrint("Failed to create a packet\n");
3688 return DBOX_STATUS_ERROR_FAULT;
3691 return master_rpc_request_only(NULL, packet);
3694 EAPI int dynamicbox_unsubscribe_group(const char *cluster, const char *category)
3696 struct packet *packet;
3697 unsigned int cmd = CMD_UNSUBSCRIBE;
3701 * Validate the group info using DB
3702 * If the group info is not valid, do not send this request
3703 * AND Check the subscribed or not too
3706 packet = packet_create_noack((const char *)&cmd, "ss", cluster ? cluster : "", category ? category : "");
3708 ErrPrint("Failed to create a packet\n");
3709 return DBOX_STATUS_ERROR_FAULT;
3712 return master_rpc_request_only(NULL, packet);
3715 EAPI int dynamicbox_refresh(dynamicbox_h handler, int force)
3717 struct packet *packet;
3718 unsigned int cmd = CMD_UPDATE;
3720 if (!handler || handler->state != DBOX_STATE_CREATE) {
3721 ErrPrint("Handler is invalid\n");
3722 return DBOX_STATUS_ERROR_INVALID_PARAMETER;
3725 if (!handler->common || handler->common->state != DBOX_STATE_CREATE) {
3726 ErrPrint("Handler is not valid\n");
3727 return DBOX_STATUS_ERROR_INVALID_PARAMETER;
3730 if (!handler->common->id) {
3731 ErrPrint("Handler is not valid\n");
3732 return DBOX_STATUS_ERROR_INVALID_PARAMETER;
3735 packet = packet_create_noack((const char *)&cmd, "ssi", handler->common->pkgname, handler->common->id, force);
3737 ErrPrint("Failed to create a packet\n");
3738 return DBOX_STATUS_ERROR_FAULT;
3741 return master_rpc_request_only(handler, packet);
3744 EAPI int dynamicbox_refresh_group(const char *cluster, const char *category, int force)
3746 struct packet *packet;
3747 unsigned int cmd = CMD_REFRESH_GROUP;
3749 if (!cluster || !category) {
3750 ErrPrint("Invalid argument\n");
3751 return DBOX_STATUS_ERROR_INVALID_PARAMETER;
3754 packet = packet_create_noack((const char *)&cmd, "ssi", cluster, category, force);
3756 ErrPrint("Failed to create a packet\n");
3757 return DBOX_STATUS_ERROR_FAULT;
3760 return master_rpc_request_only(NULL, packet);
3763 EAPI int dynamicbox_set_visibility(dynamicbox_h handler, dynamicbox_visible_state_e state)
3768 if (!handler || handler->state != DBOX_STATE_CREATE) {
3769 ErrPrint("Handler is invalid\n");
3770 return DBOX_STATUS_ERROR_INVALID_PARAMETER;
3773 if (!handler->common || handler->common->state != DBOX_STATE_CREATE) {
3774 ErrPrint("Handler is not valid\n");
3775 return DBOX_STATUS_ERROR_INVALID_PARAMETER;
3778 if (!handler->common->id) {
3779 ErrPrint("Handler is not valid\n");
3780 return DBOX_STATUS_ERROR_INVALID_PARAMETER;
3783 if (!handler->common->is_user) {
3784 /* System cluster dynamicbox cannot be changed its visible states */
3785 if (state == DBOX_HIDE_WITH_PAUSE) {
3786 ErrPrint("CA Livebox is not able to change the visibility\n");
3787 return DBOX_STATUS_ERROR_PERMISSION_DENIED;
3791 if (handler->visible == state) {
3792 DbgPrint("%s has no changes\n", handler->common->pkgname);
3793 return DBOX_STATUS_ERROR_ALREADY;
3796 old_state = handler->visible;
3797 handler->visible = state;
3799 ret = dbox_set_visibility(handler, state);
3801 handler->visible = old_state;
3807 EAPI dynamicbox_visible_state_e dynamicbox_visibility(dynamicbox_h handler)
3809 if (!handler || handler->state != DBOX_STATE_CREATE) {
3810 ErrPrint("Handler is invalid\n");
3811 dynamicbox_set_last_status(DBOX_STATUS_ERROR_INVALID_PARAMETER);
3812 return DBOX_VISIBLE_ERROR;
3815 if (!handler->common || handler->common->state != DBOX_STATE_CREATE) {
3816 ErrPrint("Handler is not valid\n");
3817 dynamicbox_set_last_status(DBOX_STATUS_ERROR_INVALID_PARAMETER);
3818 return DBOX_VISIBLE_ERROR;
3821 if (!handler->common->id) {
3822 ErrPrint("Handler is not valid\n");
3823 dynamicbox_set_last_status(DBOX_STATUS_ERROR_INVALID_PARAMETER);
3824 return DBOX_VISIBLE_ERROR;
3827 return handler->visible;
3830 EAPI int dynamicbox_viewer_set_paused(void)
3832 struct packet *packet;
3833 unsigned int cmd = CMD_CLIENT_PAUSED;
3835 packet = packet_create_noack((const char *)&cmd, "d", util_timestamp());
3837 ErrPrint("Failed to create a pause packet\n");
3838 return DBOX_STATUS_ERROR_FAULT;
3841 return master_rpc_request_only(NULL, packet);
3844 EAPI int dynamicbox_viewer_set_resumed(void)
3846 struct packet *packet;
3847 unsigned int cmd = CMD_CLIENT_RESUMED;
3849 packet = packet_create_noack((const char *)&cmd, "d", util_timestamp());
3851 ErrPrint("Failed to create a resume packet\n");
3852 return DBOX_STATUS_ERROR_FAULT;
3855 return master_rpc_request_only(NULL, packet);
3858 EAPI int dynamicbox_sync_buffer(dynamicbox_h handler, int gbar)
3860 if (!handler || handler->state != DBOX_STATE_CREATE) {
3861 ErrPrint("Invalid handle\n");
3862 return DBOX_STATUS_ERROR_INVALID_PARAMETER;
3865 if (!handler->common || handler->common->state != DBOX_STATE_CREATE) {
3866 ErrPrint("Invalid handle\n");
3867 return DBOX_STATUS_ERROR_INVALID_PARAMETER;
3870 if (!handler->common->id) {
3871 ErrPrint("Invalid handle\n");
3872 return DBOX_STATUS_ERROR_INVALID_PARAMETER;
3876 return dbox_sync_gbar_fb(handler->common);
3878 return dbox_sync_dbox_fb(handler->common);
3882 EAPI const char *dynamicbox_alternative_icon(dynamicbox_h handler)
3884 if (!handler || handler->state != DBOX_STATE_CREATE) {
3885 ErrPrint("Handler is not valid[%p]\n", handler);
3886 dynamicbox_set_last_status(DBOX_STATUS_ERROR_INVALID_PARAMETER);
3890 if (!handler->common || handler->common->state != DBOX_STATE_CREATE) {
3891 ErrPrint("Handler is not valid\n");
3892 dynamicbox_set_last_status(DBOX_STATUS_ERROR_INVALID_PARAMETER);
3896 return handler->common->alt.icon;
3899 EAPI const char *dynamicbox_alternative_name(dynamicbox_h handler)
3901 if (!handler || handler->state != DBOX_STATE_CREATE) {
3902 ErrPrint("Handler is not valid[%p]\n", handler);
3903 dynamicbox_set_last_status(DBOX_STATUS_ERROR_INVALID_PARAMETER);
3907 if (!handler->common || handler->common->state != DBOX_STATE_CREATE) {
3908 ErrPrint("Handler is not valid\n");
3909 dynamicbox_set_last_status(DBOX_STATUS_ERROR_INVALID_PARAMETER);
3913 return handler->common->alt.name;
3916 EAPI int dynamicbox_acquire_buffer_lock(dynamicbox_h handler, int is_gbar)
3918 int ret = DBOX_STATUS_ERROR_NONE;
3920 if (!handler || handler->state != DBOX_STATE_CREATE) {
3921 ErrPrint("Handler is not valid[%p]\n", handler);
3922 return DBOX_STATUS_ERROR_INVALID_PARAMETER;
3925 if (!handler->common || handler->common->state != DBOX_STATE_CREATE) {
3926 ErrPrint("Handler is not valid\n");
3927 return DBOX_STATUS_ERROR_INVALID_PARAMETER;
3930 if (!handler->common->id) {
3931 ErrPrint("Handler is not valid[%p]\n", handler);
3932 return DBOX_STATUS_ERROR_INVALID_PARAMETER;
3936 ret = dynamicbox_service_acquire_lock(handler->common->gbar.lock);
3938 ret = dynamicbox_service_acquire_lock(handler->common->dbox.lock);
3941 return ret == 0 ? DBOX_STATUS_ERROR_NONE : DBOX_STATUS_ERROR_FAULT;
3944 EAPI int dynamicbox_release_buffer_lock(dynamicbox_h handler, int is_gbar)
3946 int ret = DBOX_STATUS_ERROR_NONE;
3948 if (!handler || handler->state != DBOX_STATE_CREATE) {
3949 ErrPrint("Invalid handle\n");
3950 return DBOX_STATUS_ERROR_INVALID_PARAMETER;
3953 if (!handler->common || handler->common->state != DBOX_STATE_CREATE) {
3954 ErrPrint("Invalid handle\n");
3955 return DBOX_STATUS_ERROR_INVALID_PARAMETER;
3958 if (!handler->common->id) {
3959 ErrPrint("Handler is not valid[%p]\n", handler);
3960 return DBOX_STATUS_ERROR_INVALID_PARAMETER;
3964 ret = dynamicbox_service_release_lock(handler->common->gbar.lock);
3966 ret = dynamicbox_service_release_lock(handler->common->dbox.lock);
3969 return ret == 0 ? DBOX_STATUS_ERROR_NONE : DBOX_STATUS_ERROR_FAULT;
3972 EAPI int dynamicbox_set_option(dynamicbox_option_type_e option, int state)
3974 int ret = DBOX_STATUS_ERROR_NONE;
3977 case DBOX_OPTION_MANUAL_SYNC:
3978 conf_set_manual_sync(state);
3980 case DBOX_OPTION_FRAME_DROP_FOR_RESIZE:
3981 conf_set_frame_drop_for_resizing(state);
3983 case DBOX_OPTION_SHARED_CONTENT:
3984 conf_set_shared_content(state);
3986 case DBOX_OPTION_DIRECT_UPDATE:
3987 if (s_info.init_count) {
3988 DbgPrint("Already intialized, this option is not applied\n");
3990 conf_set_direct_update(state);
3992 case DBOX_OPTION_EXTRA_BUFFER_CNT:
3993 ErrPrint("Permission denied\n");
3994 ret = DBOX_STATUS_ERROR_PERMISSION_DENIED;
3997 ret = DBOX_STATUS_ERROR_INVALID_PARAMETER;
4004 EAPI int dynamicbox_option(dynamicbox_option_type_e option)
4008 dynamicbox_set_last_status(DBOX_STATUS_ERROR_NONE);
4010 case DBOX_OPTION_MANUAL_SYNC:
4011 ret = conf_manual_sync();
4013 case DBOX_OPTION_FRAME_DROP_FOR_RESIZE:
4014 ret = conf_frame_drop_for_resizing();
4016 case DBOX_OPTION_SHARED_CONTENT:
4017 ret = conf_shared_content();
4019 case DBOX_OPTION_DIRECT_UPDATE:
4020 ret = conf_direct_update();
4022 case DBOX_OPTION_EXTRA_BUFFER_CNT:
4023 ret = conf_extra_buffer_count();
4026 ret = DBOX_STATUS_ERROR_INVALID_PARAMETER;
4027 dynamicbox_set_last_status(DBOX_STATUS_ERROR_INVALID_PARAMETER);
4034 EAPI int dynamicbox_set_auto_launch_handler(dynamicbox_auto_launch_handler_cb dbox_launch_handler, void *data)
4036 s_info.launch.handler = dbox_launch_handler;
4037 s_info.launch.data = data;
4039 return DBOX_STATUS_ERROR_NONE;
4042 EAPI int dynamicbox_damage_region_get(dynamicbox_h handler, int gbar, const dynamicbox_damage_region_t *region)
4044 if (!handler || handler->state != DBOX_STATE_CREATE) {
4045 ErrPrint("Invalid handle\n");
4046 return DBOX_STATUS_ERROR_INVALID_PARAMETER;
4049 if (!handler->common || handler->common->state != DBOX_STATE_CREATE) {
4050 ErrPrint("Invalid handle\n");
4051 return DBOX_STATUS_ERROR_INVALID_PARAMETER;
4054 if (!handler->common->id) {
4055 ErrPrint("Handler is not valid[%p]\n", handler);
4056 return DBOX_STATUS_ERROR_INVALID_PARAMETER;
4060 region = &handler->common->dbox.last_damage;
4062 region = &handler->common->gbar.last_damage;
4065 return DBOX_STATUS_ERROR_NONE;
4068 EAPI int dynamicbox_get_affected_extra_buffer(dynamicbox_h handler, int gbar, int *idx, unsigned int *resource_id)
4071 unsigned int _resource_id;
4073 if (!handler || handler->state != DBOX_STATE_CREATE) {
4074 ErrPrint("Invalid handle\n");
4075 return DBOX_STATUS_ERROR_INVALID_PARAMETER;
4078 if (!handler->common || handler->common->state != DBOX_STATE_CREATE) {
4079 ErrPrint("Invalid handle\n");
4080 return DBOX_STATUS_ERROR_INVALID_PARAMETER;
4083 if (!handler->common->id) {
4084 ErrPrint("Handler is not valid[%p]\n", handler);
4085 return DBOX_STATUS_ERROR_INVALID_PARAMETER;
4093 resource_id = &_resource_id;
4097 if (!handler->common->gbar.extra_buffer || handler->common->gbar.last_extra_buffer_idx < 0) {
4098 return DBOX_STATUS_ERROR_NOT_EXIST;
4101 *idx = handler->common->gbar.last_extra_buffer_idx;
4102 *resource_id = handler->common->gbar.extra_buffer[*idx];
4104 if (!handler->common->dbox.extra_buffer || handler->common->dbox.last_extra_buffer_idx < 0) {
4105 return DBOX_STATUS_ERROR_NOT_EXIST;
4108 *idx = handler->common->dbox.last_extra_buffer_idx;
4109 *resource_id = handler->common->dbox.extra_buffer[*idx];
4112 return DBOX_STATUS_ERROR_NONE;