2 * Copyright 2013 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 */
27 #include <com-core_packet.h>
29 #include <livebox-service.h>
30 #include <livebox-errno.h>
35 #include "livebox_internal.h"
38 #include "master_rpc.h"
40 #include "critical_log.h"
43 #define EAPI __attribute__((visibility("default")))
44 #define MINIMUM_EVENT s_info.event_filter
51 struct dlist *livebox_list;
52 struct dlist *event_list;
53 struct dlist *fault_list;
55 int prevent_overwrite;
62 .prevent_overwrite = 0,
63 .event_filter = 0.01f,
72 int (*handler)(struct livebox *handler, enum livebox_event_type event, void *data);
77 int (*handler)(enum livebox_fault_type event, const char *pkgname, const char *filename, const char *func, void *data);
81 static inline void default_create_cb(struct livebox *handler, int ret, void *data)
83 DbgPrint("Default created event handler: %d\n", ret);
86 static inline void default_delete_cb(struct livebox *handler, int ret, void *data)
88 DbgPrint("Default deleted event handler: %d\n", ret);
91 static inline void default_pinup_cb(struct livebox *handler, int ret, void *data)
93 DbgPrint("Default pinup event handler: %d\n", ret);
96 static inline void default_group_changed_cb(struct livebox *handler, int ret, void *data)
98 DbgPrint("Default group changed event handler: %d\n", ret);
101 static inline void default_period_changed_cb(struct livebox *handler, int ret, void *data)
103 DbgPrint("Default period changed event handler: %d\n", ret);
106 static inline void default_pd_created_cb(struct livebox *handler, int ret, void *data)
108 DbgPrint("Default PD created event handler: %d\n", ret);
111 static inline void default_pd_destroyed_cb(struct livebox *handler, int ret, void *data)
113 DbgPrint("Default PD destroyed event handler: %d\n", ret);
116 static inline void default_lb_size_changed_cb(struct livebox *handler, int ret, void *data)
118 DbgPrint("Default LB size changed event handler: %d\n", ret);
121 static inline void default_update_mode_cb(struct livebox *handler, int ret, void *data)
123 DbgPrint("Default update mode set event handler: %d\n", ret);
126 static inline void default_access_event_cb(struct livebox *handler, int ret, void *data)
128 DbgPrint("Default access event handler: %d\n", ret);
131 static inline __attribute__((always_inline)) struct cb_info *create_cb_info(ret_cb_t cb, void *data)
133 struct cb_info *info;
135 info = malloc(sizeof(*info));
137 CRITICAL_LOG("Heap: %s\n", strerror(errno));
146 static inline void destroy_cb_info(struct cb_info *info)
151 static void update_mode_cb(struct livebox *handler, const struct packet *result, void *data)
156 ret = LB_STATUS_ERROR_FAULT;
158 } else if (packet_get(result, "i", &ret) != 1) {
159 ErrPrint("Invalid argument\n");
160 ret = LB_STATUS_ERROR_INVALID;
165 ErrPrint("Resize request is failed: %d\n", ret);
172 handler->update_mode_cb(handler, ret, handler->update_mode_cbdata);
173 handler->update_mode_cb = NULL;
174 handler->update_mode_cbdata = NULL;
178 static void resize_cb(struct livebox *handler, const struct packet *result, void *data)
183 ret = LB_STATUS_ERROR_FAULT;
185 } else if (packet_get(result, "i", &ret) != 1) {
186 ErrPrint("Invalid argument\n");
187 ret = LB_STATUS_ERROR_INVALID;
193 * In case of resize request,
194 * The livebox handler will not have resized value right after this callback,
195 * It can only get the new size when it makes updates.
197 * So the user can only get the resized value(result) from the first update event
198 * after this request.
201 ErrPrint("Resize request is failed: %d\n", ret);
208 handler->size_changed_cb(handler, ret, handler->size_cbdata);
209 handler->size_changed_cb = NULL;
210 handler->size_cbdata = NULL;
213 static void text_signal_cb(struct livebox *handler, const struct packet *result, void *data)
217 struct cb_info *info = data;
222 destroy_cb_info(info);
225 ret = LB_STATUS_ERROR_FAULT;
226 } else if (packet_get(result, "i", &ret) != 1) {
227 ErrPrint("Invalid argument\n");
228 ret = LB_STATUS_ERROR_INVALID;
232 cb(handler, ret, cbdata);
237 static void set_group_ret_cb(struct livebox *handler, const struct packet *result, void *data)
242 ret = LB_STATUS_ERROR_FAULT;
244 } else if (packet_get(result, "i", &ret) != 1) {
245 ErrPrint("Invalid argument\n");
246 ret = LB_STATUS_ERROR_INVALID;
257 handler->group_changed_cb(handler, ret, handler->group_cbdata);
258 handler->group_changed_cb = NULL;
259 handler->group_cbdata = NULL;
262 static void period_ret_cb(struct livebox *handler, const struct packet *result, void *data)
267 ret = LB_STATUS_ERROR_FAULT;
269 } else if (packet_get(result, "i", &ret) != 1) {
270 ErrPrint("Invalid argument\n");
271 ret = LB_STATUS_ERROR_INVALID;
282 handler->period_changed_cb(handler, ret, handler->period_cbdata);
283 handler->period_changed_cb = NULL;
284 handler->period_cbdata = NULL;
287 static void del_ret_cb(struct livebox *handler, const struct packet *result, void *data)
289 struct cb_info *info = data;
296 destroy_cb_info(info);
299 ErrPrint("Connection lost?\n");
300 ret = LB_STATUS_ERROR_FAULT;
301 } else if (packet_get(result, "i", &ret) != 1) {
302 ErrPrint("Invalid argument\n");
303 ret = LB_STATUS_ERROR_INVALID;
307 handler->deleted_cb = cb;
308 handler->deleted_cbdata = cbdata;
310 cb(handler, ret, cbdata);
315 * Do not call the deleted callback from here.
316 * master will send the "deleted" event.
317 * Then invoke this callback.
319 * if (handler->deleted_cb)
320 * handler->deleted_cb(handler, ret, handler->deleted_cbdata);
324 static void new_ret_cb(struct livebox *handler, const struct packet *result, void *data)
327 struct cb_info *info = data;
333 destroy_cb_info(info);
336 ret = LB_STATUS_ERROR_FAULT;
337 } else if (packet_get(result, "i", &ret) != 1) {
338 ret = LB_STATUS_ERROR_INVALID;
342 handler->created_cb = cb;
343 handler->created_cbdata = cbdata;
347 * Don't go anymore ;)
353 * It means the current instance is not created,
354 * so user has to know about this.
355 * notice it to user using "deleted" event.
357 cb(handler, ret, cbdata);
363 static void pd_create_cb(struct livebox *handler, const struct packet *result, void *data)
368 ret = LB_STATUS_ERROR_FAULT;
370 } else if (packet_get(result, "i", &ret) != 1) {
371 ret = LB_STATUS_ERROR_INVALID;
376 ErrPrint("Failed to create a PD[%d]\n", ret);
383 handler->pd_created_cb(handler, ret, handler->pd_created_cbdata);
384 handler->pd_created_cb = NULL;
385 handler->pd_created_cbdata = NULL;
388 static void activated_cb(struct livebox *handler, const struct packet *result, void *data)
391 struct cb_info *info = data;
394 const char *pkgname = "";
398 destroy_cb_info(info);
401 ret = LB_STATUS_ERROR_FAULT;
402 } else if (packet_get(result, "is", &ret, &pkgname) != 2) {
403 ret = LB_STATUS_ERROR_INVALID;
407 cb(handler, ret, cbdata);
411 static void pd_destroy_cb(struct livebox *handler, const struct packet *result, void *data)
416 struct cb_info *info = data;
420 destroy_cb_info(info);
423 ErrPrint("Result is NIL (may connection lost)\n");
424 ret = LB_STATUS_ERROR_FAULT;
425 } else if (packet_get(result, "i", &ret) != 1) {
426 ErrPrint("Invalid parameter\n");
427 ret = LB_STATUS_ERROR_INVALID;
431 handler->pd_destroyed_cb = cb;
432 handler->pd_destroyed_cbdata = cbdata;
434 handler->is_pd_created = 0;
435 cb(handler, ret, cbdata);
439 static void delete_cluster_cb(struct livebox *handler, const struct packet *result, void *data)
441 struct cb_info *info = data;
448 destroy_cb_info(info);
451 ret = LB_STATUS_ERROR_FAULT;
452 } else if (packet_get(result, "i", &ret) != 1) {
453 ret = LB_STATUS_ERROR_INVALID;
457 cb(handler, ret, cbdata);
461 static void delete_category_cb(struct livebox *handler, const struct packet *result, void *data)
463 struct cb_info *info = data;
470 destroy_cb_info(info);
473 ret = LB_STATUS_ERROR_FAULT;
474 } else if (packet_get(result, "i", &ret) != 1) {
475 ret = LB_STATUS_ERROR_INVALID;
479 cb(handler, ret, cbdata);
483 static void lb_pixmap_acquired_cb(struct livebox *handler, const struct packet *result, void *data)
486 int ret = LB_STATUS_ERROR_INVALID;
489 struct cb_info *info = data;
493 destroy_cb_info(info);
496 pixmap = 0; /* PIXMAP 0 means error */
497 } else if (packet_get(result, "ii", &pixmap, &ret) != 2) {
501 if (ret == LB_STATUS_ERROR_BUSY) {
502 ret = livebox_acquire_lb_pixmap(handler, cb, cbdata);
503 DbgPrint("Busy, Try again: %d\n", ret);
507 cb(handler, pixmap, cbdata);
512 static void pd_pixmap_acquired_cb(struct livebox *handler, const struct packet *result, void *data)
518 struct cb_info *info = data;
522 destroy_cb_info(info);
525 pixmap = 0; /* PIXMAP 0 means error */
526 ret = LB_STATUS_ERROR_FAULT;
527 } else if (packet_get(result, "ii", &pixmap, &ret) != 2) {
529 ret = LB_STATUS_ERROR_INVALID;
532 if (ret == LB_STATUS_ERROR_BUSY) {
533 ret = livebox_acquire_pd_pixmap(handler, cb, cbdata);
534 DbgPrint("Busy, Try again: %d\n", ret);
538 DbgPrint("ret: %d, pixmap: %d\n", ret, pixmap);
539 cb(handler, pixmap, cbdata);
544 static void pinup_done_cb(struct livebox *handler, const struct packet *result, void *data)
549 ret = LB_STATUS_ERROR_FAULT;
551 } else if (packet_get(result, "i", &ret) != 1) {
562 handler->pinup_cb(handler, ret, handler->pinup_cbdata);
563 handler->pinup_cb = NULL;
564 handler->pinup_cbdata = NULL;
567 static void access_ret_cb(struct livebox *handler, const struct packet *result, void *data)
572 ret = LB_STATUS_ERROR_FAULT;
576 if (packet_get(result, "i", &ret) != 1) {
577 ret = LB_STATUS_ERROR_INVALID;
581 if (ret != LB_STATUS_SUCCESS) {
588 handler->access_event_cb(handler, ret, handler->access_event_cbdata);
589 handler->access_event_cb = NULL;
590 handler->access_event_cbdata = NULL;
594 static int send_access_event(struct livebox *handler, const char *event, int x, int y)
596 struct packet *packet;
599 timestamp = util_timestamp();
601 packet = packet_create(event, "ssdii", handler->pkgname, handler->id, timestamp, x, y);
603 ErrPrint("Failed to build packet\n");
604 return LB_STATUS_ERROR_FAULT;
607 return master_rpc_async_request(handler, packet, 0, access_ret_cb, NULL);
610 static int send_mouse_event(struct livebox *handler, const char *event, int x, int y)
612 struct packet *packet;
615 timestamp = util_timestamp();
616 packet = packet_create_noack(event, "ssdii", handler->pkgname, handler->id, timestamp, x, y);
618 ErrPrint("Failed to build param\n");
619 return LB_STATUS_ERROR_FAULT;
622 return master_rpc_request_only(handler, packet);
625 static void initialize_livebox(void *disp)
628 char filename[BUFSIZ];
629 snprintf(filename, sizeof(filename), "/tmp/%d.box.log", getpid());
630 __file_log_fp = fopen(filename, "w+t");
631 if (!__file_log_fp) {
632 __file_log_fp = fdopen(1, "w+t");
635 critical_log_init("viewer");
636 livebox_service_init();
644 EAPI int livebox_init_with_options(void *disp, int prevent_overwrite, double event_filter)
646 if (s_info.init_count > 0) {
648 return LB_STATUS_SUCCESS;
653 * Some application doesn't want to use the environment value.
654 * So set them using arguments.
656 s_info.prevent_overwrite = prevent_overwrite;
657 MINIMUM_EVENT = event_filter;
659 initialize_livebox(disp);
660 return LB_STATUS_SUCCESS;
663 EAPI int livebox_init(void *disp)
667 if (s_info.init_count > 0) {
669 return LB_STATUS_SUCCESS;
672 env = getenv("PROVIDER_DISABLE_PREVENT_OVERWRITE");
673 if (env && !strcasecmp(env, "true")) {
674 s_info.prevent_overwrite = 1;
677 env = getenv("PROVIDER_EVENT_FILTER");
679 sscanf(env, "%lf", &MINIMUM_EVENT);
682 initialize_livebox(disp);
683 return LB_STATUS_SUCCESS;
686 EAPI int livebox_fini(void)
688 if (s_info.init_count <= 0) {
689 ErrPrint("Doesn't initialized\n");
690 return LB_STATUS_ERROR_INVALID;
694 if (s_info.init_count > 0) {
695 ErrPrint("init count : %d\n", s_info.init_count);
696 return LB_STATUS_SUCCESS;
701 livebox_service_fini();
703 return LB_STATUS_SUCCESS;
706 static inline char *lb_pkgname(const char *pkgname)
710 lb = livebox_service_pkgname(pkgname);
712 if (util_validate_livebox_package(pkgname) == 0) {
713 return strdup(pkgname);
721 * Just wrapping the livebox_add_with_size function.
723 EAPI struct livebox *livebox_add(const char *pkgname, const char *content, const char *cluster, const char *category, double period, ret_cb_t cb, void *data)
725 return livebox_add_with_size(pkgname, content, cluster, category, period, LB_SIZE_TYPE_UNKNOWN, cb, data);
728 EAPI struct livebox *livebox_add_with_size(const char *pkgname, const char *content, const char *cluster, const char *category, double period, int type, ret_cb_t cb, void *data)
730 struct livebox *handler;
731 struct packet *packet;
735 struct cb_info *cbinfo;
737 if (!pkgname || !cluster || !category) {
738 ErrPrint("Invalid arguments: pkgname[%p], cluster[%p], category[%p]\n",
739 pkgname, cluster, category);
743 if (type != LB_SIZE_TYPE_UNKNOWN) {
744 livebox_service_get_size(type, &width, &height);
747 handler = calloc(1, sizeof(*handler));
749 ErrPrint("Error: %s\n", strerror(errno));
753 handler->pkgname = lb_pkgname(pkgname);
754 if (!handler->pkgname) {
759 if (livebox_service_is_enabled(handler->pkgname) == 0) {
760 DbgPrint("Livebox [%s](%s) is disabled package\n", handler->pkgname, pkgname);
761 free(handler->pkgname);
766 if (content && strlen(content)) {
767 handler->content = strdup(content);
768 if (!handler->content) {
769 ErrPrint("Error: %s\n", strerror(errno));
770 free(handler->pkgname);
775 handler->content = livebox_service_content(handler->pkgname);
778 handler->cluster = strdup(cluster);
779 if (!handler->cluster) {
780 ErrPrint("Error: %s\n", strerror(errno));
781 free(handler->content);
782 free(handler->pkgname);
787 handler->category = strdup(category);
788 if (!handler->category) {
789 ErrPrint("Error: %s\n", strerror(errno));
790 free(handler->cluster);
791 free(handler->content);
792 free(handler->pkgname);
798 cb = default_create_cb;
801 /* Data provider will set this */
802 handler->lb.type = _LB_TYPE_FILE;
803 handler->pd.type = _PD_TYPE_SCRIPT;
804 handler->lb.period = period;
806 /* Used for handling the mouse event on a box */
807 handler->lb.mouse_event = livebox_service_mouse_event(handler->pkgname);
809 /* Cluster infomration is not determined yet */
810 handler->nr_of_sizes = 0x01;
812 handler->timestamp = util_timestamp();
813 handler->is_user = 1;
814 handler->visible = LB_SHOW;
816 s_info.livebox_list = dlist_append(s_info.livebox_list, handler);
818 packet = packet_create("new", "dssssdii", handler->timestamp, handler->pkgname, handler->content, cluster, category, period, width, height);
820 ErrPrint("Failed to create a new packet\n");
821 free(handler->category);
822 free(handler->cluster);
823 free(handler->content);
824 free(handler->pkgname);
829 cbinfo = create_cb_info(cb, data);
831 ErrPrint("Failed to create a cbinfo\n");
832 packet_destroy(packet);
833 free(handler->category);
834 free(handler->cluster);
835 free(handler->content);
836 free(handler->pkgname);
841 ret = master_rpc_async_request(handler, packet, 0, new_ret_cb, cbinfo);
843 ErrPrint("Failed to send a new packet\n");
844 destroy_cb_info(cbinfo);
845 free(handler->category);
846 free(handler->cluster);
847 free(handler->content);
848 free(handler->pkgname);
853 handler->state = CREATE;
854 return lb_ref(handler);
857 EAPI double livebox_period(struct livebox *handler)
859 if (!handler || handler->state != CREATE || !handler->id) {
860 ErrPrint("Handler is not valid\n");
864 return handler->lb.period;
867 EAPI int livebox_set_period(struct livebox *handler, double period, ret_cb_t cb, void *data)
869 struct packet *packet;
872 if (!handler || handler->state != CREATE || !handler->id) {
873 ErrPrint("Handler is not valid\n");
874 return LB_STATUS_ERROR_INVALID;
877 if (handler->period_changed_cb) {
878 ErrPrint("Previous request for changing period is not finished\n");
879 return LB_STATUS_ERROR_BUSY;
882 if (!handler->is_user) {
883 ErrPrint("CA Livebox is not able to change the period\n");
884 return LB_STATUS_ERROR_PERMISSION;
887 if (handler->lb.period == period) {
888 DbgPrint("No changes\n");
889 return LB_STATUS_ERROR_ALREADY;
892 packet = packet_create("set_period", "ssd", handler->pkgname, handler->id, period);
894 ErrPrint("Failed to build a packet %s\n", handler->pkgname);
895 return LB_STATUS_ERROR_FAULT;
899 cb = default_period_changed_cb;
902 ret = master_rpc_async_request(handler, packet, 0, period_ret_cb, NULL);
903 if (ret == LB_STATUS_SUCCESS) {
904 handler->period_changed_cb = cb;
905 handler->period_cbdata = data;
911 EAPI int livebox_del(struct livebox *handler, ret_cb_t cb, void *data)
914 ErrPrint("Handler is NIL\n");
915 return LB_STATUS_ERROR_INVALID;
918 if (handler->state != CREATE) {
919 ErrPrint("Handler is already deleted\n");
920 return LB_STATUS_ERROR_INVALID;
923 handler->state = DELETE;
928 * The id is not determined yet.
929 * It means a user didn't receive created event yet.
930 * Then just stop to delete procedure from here.
931 * Because the "created" event handler will release this.
932 * By the way, if the user adds any callback for getting return status of this,
936 cb(handler, 0, data);
938 return LB_STATUS_SUCCESS;
942 cb = default_delete_cb;
945 return lb_send_delete(handler, cb, data);
948 EAPI int livebox_set_fault_handler(int (*cb)(enum livebox_fault_type, const char *, const char *, const char *, void *), void *data)
950 struct fault_info *info;
953 return LB_STATUS_ERROR_INVALID;
956 info = malloc(sizeof(*info));
958 CRITICAL_LOG("Heap: %s\n", strerror(errno));
959 return LB_STATUS_ERROR_MEMORY;
963 info->user_data = data;
965 s_info.fault_list = dlist_append(s_info.fault_list, info);
966 return LB_STATUS_SUCCESS;
969 EAPI void *livebox_unset_fault_handler(int (*cb)(enum livebox_fault_type, const char *, const char *, const char *, void *))
971 struct fault_info *info;
974 dlist_foreach(s_info.fault_list, l, info) {
975 if (info->handler == cb) {
978 s_info.fault_list = dlist_remove(s_info.fault_list, l);
979 data = info->user_data;
989 EAPI int livebox_set_event_handler(int (*cb)(struct livebox *, enum livebox_event_type, void *), void *data)
991 struct event_info *info;
994 ErrPrint("Invalid argument cb is nil\n");
995 return LB_STATUS_ERROR_INVALID;
998 info = malloc(sizeof(*info));
1000 CRITICAL_LOG("Heap: %s\n", strerror(errno));
1001 return LB_STATUS_ERROR_MEMORY;
1005 info->user_data = data;
1007 s_info.event_list = dlist_append(s_info.event_list, info);
1008 return LB_STATUS_SUCCESS;
1011 EAPI void *livebox_unset_event_handler(int (*cb)(struct livebox *, enum livebox_event_type, void *))
1013 struct event_info *info;
1016 dlist_foreach(s_info.event_list, l, info) {
1017 if (info->handler == cb) {
1020 s_info.event_list = dlist_remove(s_info.event_list, l);
1021 data = info->user_data;
1031 EAPI int livebox_set_update_mode(struct livebox *handler, int active_update, ret_cb_t cb, void *data)
1033 struct packet *packet;
1037 ErrPrint("Handler is NIL\n");
1038 return LB_STATUS_ERROR_INVALID;
1041 if (handler->state != CREATE || !handler->id) {
1042 return LB_STATUS_ERROR_INVALID;
1045 if (handler->update_mode_cb) {
1046 ErrPrint("Previous update_mode cb is not finished yet\n");
1047 return LB_STATUS_ERROR_BUSY;
1050 if (handler->is_active_update == active_update) {
1051 return LB_STATUS_ERROR_ALREADY;
1054 if (!handler->is_user) {
1055 return LB_STATUS_ERROR_PERMISSION;
1058 packet = packet_create("update_mode", "ssi", handler->pkgname, handler->id, active_update);
1060 return LB_STATUS_ERROR_FAULT;
1064 cb = default_update_mode_cb;
1067 ret = master_rpc_async_request(handler, packet, 0, update_mode_cb, NULL);
1068 if (ret == LB_STATUS_SUCCESS) {
1069 handler->update_mode_cb = cb;
1070 handler->update_mode_cbdata = data;
1076 EAPI int livebox_is_active_update(struct livebox *handler)
1079 ErrPrint("Handler is NIL\n");
1080 return LB_STATUS_ERROR_INVALID;
1083 if (handler->state != CREATE || !handler->id) {
1084 return LB_STATUS_ERROR_INVALID;
1087 return handler->is_active_update;
1090 EAPI int livebox_resize(struct livebox *handler, int type, ret_cb_t cb, void *data)
1092 struct packet *packet;
1098 ErrPrint("Handler is NIL\n");
1099 return LB_STATUS_ERROR_INVALID;
1102 if (handler->state != CREATE || !handler->id) {
1103 ErrPrint("Handler is not valid\n");
1104 return LB_STATUS_ERROR_INVALID;
1107 if (handler->size_changed_cb) {
1108 ErrPrint("Previous resize request is not finished yet\n");
1109 return LB_STATUS_ERROR_BUSY;
1112 if (!handler->is_user) {
1113 ErrPrint("CA Livebox is not able to be resized\n");
1114 return LB_STATUS_ERROR_PERMISSION;
1117 if (livebox_service_get_size(type, &w, &h) != 0) {
1118 ErrPrint("Invalid size type\n");
1119 return LB_STATUS_ERROR_INVALID;
1122 if (handler->lb.width == w && handler->lb.height == h) {
1123 DbgPrint("No changes\n");
1124 return LB_STATUS_ERROR_ALREADY;
1127 packet = packet_create("resize", "ssii", handler->pkgname, handler->id, w, h);
1129 ErrPrint("Failed to build param\n");
1130 return LB_STATUS_ERROR_FAULT;
1134 cb = default_lb_size_changed_cb;
1137 ret = master_rpc_async_request(handler, packet, 0, resize_cb, NULL);
1138 if (ret == LB_STATUS_SUCCESS) {
1139 handler->size_changed_cb = cb;
1140 handler->size_cbdata = data;
1146 EAPI int livebox_click(struct livebox *handler, double x, double y)
1148 struct packet *packet;
1152 timestamp = util_timestamp();
1155 ErrPrint("Handler is NIL\n");
1156 return LB_STATUS_ERROR_INVALID;
1159 if (handler->state != CREATE || !handler->id) {
1160 ErrPrint("Handler is not valid\n");
1161 return LB_STATUS_ERROR_INVALID;
1164 if (handler->lb.auto_launch) {
1165 DbgPrint("AUTO_LAUNCH [%s]\n", handler->lb.auto_launch);
1166 if (aul_launch_app(handler->lb.auto_launch, NULL) < 0) {
1167 ErrPrint("Failed to launch app %s\n", handler->lb.auto_launch);
1171 packet = packet_create_noack("clicked", "sssddd", handler->pkgname, handler->id, "clicked", timestamp, x, y);
1173 ErrPrint("Failed to build param\n");
1174 return LB_STATUS_ERROR_FAULT;
1177 DbgPrint("CLICKED: %lf\n", timestamp);
1178 ret = master_rpc_request_only(handler, packet);
1180 if (!handler->lb.mouse_event && (handler->lb.type == _LB_TYPE_BUFFER || handler->lb.type == _LB_TYPE_SCRIPT)) {
1181 int ret; /* Shadow variable */
1182 ret = send_mouse_event(handler, "lb_mouse_down", x * handler->lb.width, y * handler->lb.height);
1184 ErrPrint("Failed to send Down: %d\n", ret);
1187 ret = send_mouse_event(handler, "lb_mouse_move", x * handler->lb.width, y * handler->lb.height);
1189 ErrPrint("Failed to send Move: %d\n", ret);
1192 ret = send_mouse_event(handler, "lb_mouse_up", x * handler->lb.width, y * handler->lb.height);
1194 ErrPrint("Failed to send Up: %d\n", ret);
1201 EAPI int livebox_has_pd(struct livebox *handler)
1204 ErrPrint("Handler is NIL\n");
1205 return LB_STATUS_ERROR_INVALID;
1208 if (handler->state != CREATE || !handler->id) {
1209 ErrPrint("Handler is not valid\n");
1210 return LB_STATUS_ERROR_INVALID;
1213 return !!handler->pd.data.fb;
1216 EAPI int livebox_pd_is_created(struct livebox *handler)
1219 ErrPrint("Handler is NIL\n");
1220 return LB_STATUS_ERROR_INVALID;
1223 if (!handler->pd.data.fb || handler->state != CREATE || !handler->id) {
1224 ErrPrint("Handler is not valid\n");
1225 return LB_STATUS_ERROR_INVALID;
1228 return handler->is_pd_created;
1231 EAPI int livebox_create_pd(struct livebox *handler, ret_cb_t cb, void *data)
1233 return livebox_create_pd_with_position(handler, -1.0, -1.0, cb, data);
1236 EAPI int livebox_create_pd_with_position(struct livebox *handler, double x, double y, ret_cb_t cb, void *data)
1238 struct packet *packet;
1242 ErrPrint("Handler is NIL\n");
1243 return LB_STATUS_ERROR_INVALID;
1246 if (!handler->pd.data.fb || handler->state != CREATE || !handler->id) {
1247 ErrPrint("Handler is not valid\n");
1248 return LB_STATUS_ERROR_INVALID;
1251 if (handler->is_pd_created == 1) {
1252 DbgPrint("PD already created\n");
1253 return LB_STATUS_SUCCESS;
1256 if (handler->pd_created_cb) {
1257 ErrPrint("Previous request is not completed yet\n");
1258 return LB_STATUS_ERROR_BUSY;
1261 packet = packet_create("create_pd", "ssdd", handler->pkgname, handler->id, x, y);
1263 ErrPrint("Failed to build param\n");
1264 return LB_STATUS_ERROR_FAULT;
1268 cb = default_pd_created_cb;
1271 DbgPrint("PERF_DBOX\n");
1272 ret = master_rpc_async_request(handler, packet, 0, pd_create_cb, NULL);
1273 if (ret == LB_STATUS_SUCCESS) {
1274 handler->pd_created_cb = cb;
1275 handler->pd_created_cbdata = data;
1281 EAPI int livebox_move_pd(struct livebox *handler, double x, double y)
1283 struct packet *packet;
1286 ErrPrint("Handler is NIL\n");
1287 return LB_STATUS_ERROR_INVALID;
1290 if (!handler->pd.data.fb || handler->state != CREATE || !handler->id) {
1291 ErrPrint("Handler is not valid\n");
1292 return LB_STATUS_ERROR_INVALID;
1295 if (!handler->is_pd_created) {
1296 ErrPrint("PD is not created\n");
1297 return LB_STATUS_ERROR_INVALID;
1300 packet = packet_create_noack("pd_move", "ssdd", handler->pkgname, handler->id, x, y);
1302 ErrPrint("Failed to build param\n");
1303 return LB_STATUS_ERROR_FAULT;
1306 return master_rpc_request_only(handler, packet);
1309 EAPI int livebox_activate(const char *pkgname, ret_cb_t cb, void *data)
1311 struct packet *packet;
1312 struct cb_info *cbinfo;
1316 return LB_STATUS_ERROR_INVALID;
1319 packet = packet_create("activate_package", "s", pkgname);
1321 ErrPrint("Failed to build a param\n");
1322 return LB_STATUS_ERROR_FAULT;
1325 cbinfo = create_cb_info(cb, data);
1327 ErrPrint("Unable to create cbinfo\n");
1328 packet_destroy(packet);
1329 return LB_STATUS_ERROR_FAULT;
1332 ret = master_rpc_async_request(NULL, packet, 0, activated_cb, cbinfo);
1334 destroy_cb_info(cbinfo);
1340 EAPI int livebox_destroy_pd(struct livebox *handler, ret_cb_t cb, void *data)
1342 struct packet *packet;
1343 struct cb_info *cbinfo;
1347 ErrPrint("Handler is NIL\n");
1348 return LB_STATUS_ERROR_INVALID;
1351 if (!handler->pd.data.fb || handler->state != CREATE || !handler->id) {
1352 ErrPrint("Handler is not valid\n");
1353 return LB_STATUS_ERROR_INVALID;
1356 if (!handler->is_pd_created && !handler->pd_created_cb) {
1357 ErrPrint("PD is not created\n");
1358 return LB_STATUS_ERROR_INVALID;
1361 packet = packet_create("destroy_pd", "ss", handler->pkgname, handler->id);
1363 ErrPrint("Failed to build a param\n");
1364 return LB_STATUS_ERROR_FAULT;
1368 cb = default_pd_destroyed_cb;
1371 cbinfo = create_cb_info(cb, data);
1373 packet_destroy(packet);
1374 return LB_STATUS_ERROR_FAULT;
1377 ret = master_rpc_async_request(handler, packet, 0, pd_destroy_cb, cbinfo);
1379 destroy_cb_info(cbinfo);
1385 EAPI int livebox_access_event(struct livebox *handler, enum access_event_type type, double x, double y, ret_cb_t cb, void *data)
1389 char cmd[32] = { '\0', };
1394 ErrPrint("Handler is NIL\n");
1395 return LB_STATUS_ERROR_INVALID;
1398 if (handler->state != CREATE || !handler->id) {
1399 ErrPrint("Handler is not valid\n");
1400 return LB_STATUS_ERROR_INVALID;
1403 if (handler->access_event_cb) {
1404 ErrPrint("Previous access event is not yet done\n");
1405 return LB_STATUS_ERROR_BUSY;
1408 if (type & ACCESS_EVENT_PD_MASK) {
1409 if (!handler->is_pd_created) {
1410 ErrPrint("PD is not created\n");
1411 return LB_STATUS_ERROR_INVALID;
1415 w = handler->pd.width;
1416 h = handler->pd.height;
1417 } else if (type & ACCESS_EVENT_LB_MASK) {
1420 w = handler->lb.width;
1421 h = handler->lb.height;
1423 ErrPrint("Invalid event type\n");
1424 return LB_STATUS_ERROR_INVALID;
1427 switch (type & ~ACCESS_EVENT_PD_MASK) {
1428 case ACCESS_EVENT_HIGHLIGHT:
1429 strcpy(ptr, "_access_hl");
1431 case ACCESS_EVENT_HIGHLIGHT_NEXT:
1432 strcpy(ptr, "_access_hl_next");
1434 case ACCESS_EVENT_HIGHLIGHT_PREV:
1435 strcpy(ptr, "_access_hl_prev");
1437 case ACCESS_EVENT_ACTIVATE:
1438 strcpy(ptr, "_access_activate");
1440 case ACCESS_EVENT_ACTION_DOWN:
1441 strcpy(ptr, "_access_action_down");
1443 case ACCESS_EVENT_ACTION_UP:
1444 strcpy(ptr, "_access_action_up");
1446 case ACCESS_EVENT_UNHIGHLIGHT:
1447 strcpy(ptr, "_access_unhighlight");
1449 case ACCESS_EVENT_SCROLL_DOWN:
1450 strcpy(ptr, "_access_scroll_down");
1452 case ACCESS_EVENT_SCROLL_MOVE:
1453 strcpy(ptr, "_access_scroll_move");
1455 case ACCESS_EVENT_SCROLL_UP:
1456 strcpy(ptr, "_access_scroll_up");
1459 return LB_STATUS_ERROR_INVALID;
1463 cb = default_access_event_cb;
1466 ret = send_access_event(handler, cmd, x * w, y * h);
1467 if (ret == LB_STATUS_SUCCESS) {
1468 handler->access_event_cb = cb;
1469 handler->access_event_cbdata = data;
1475 EAPI int livebox_content_event(struct livebox *handler, enum content_event_type type, double x, double y)
1479 char cmd[32] = { '\0', };
1483 ErrPrint("Handler is NIL\n");
1484 return LB_STATUS_ERROR_INVALID;
1487 if (handler->state != CREATE || !handler->id) {
1488 ErrPrint("Handler is not valid\n");
1489 return LB_STATUS_ERROR_INVALID;
1492 if (type & CONTENT_EVENT_PD_MASK) {
1495 if (!handler->is_pd_created) {
1496 ErrPrint("PD is not created\n");
1497 return LB_STATUS_ERROR_INVALID;
1500 if (type & CONTENT_EVENT_MOUSE_MASK) {
1501 if (!handler->pd.data.fb) {
1502 ErrPrint("Handler is not valid\n");
1503 return LB_STATUS_ERROR_INVALID;
1506 if (type & CONTENT_EVENT_MOUSE_MOVE) {
1507 if (fabs(x - handler->pd.x) < MINIMUM_EVENT && fabs(y - handler->pd.y) < MINIMUM_EVENT) {
1508 return LB_STATUS_ERROR_BUSY;
1510 } else if (type & CONTENT_EVENT_MOUSE_SET) {
1516 w = handler->pd.width;
1517 h = handler->pd.height;
1523 } else if (type & CONTENT_EVENT_LB_MASK) {
1526 if (type & CONTENT_EVENT_MOUSE_MASK) {
1527 if (!handler->lb.mouse_event) {
1528 return LB_STATUS_ERROR_INVALID;
1531 if (!handler->lb.data.fb) {
1532 ErrPrint("Handler is not valid\n");
1533 return LB_STATUS_ERROR_INVALID;
1536 if (type & CONTENT_EVENT_MOUSE_MOVE) {
1537 if (fabs(x - handler->lb.x) < MINIMUM_EVENT && fabs(y - handler->lb.y) < MINIMUM_EVENT) {
1538 return LB_STATUS_ERROR_BUSY;
1540 } else if (type & CONTENT_EVENT_MOUSE_SET) {
1546 w = handler->lb.width;
1547 h = handler->lb.height;
1554 ErrPrint("Invalid event type\n");
1555 return LB_STATUS_ERROR_INVALID;
1559 * Must be short than 29 bytes.
1561 switch ((type & ~(CONTENT_EVENT_PD_MASK | CONTENT_EVENT_LB_MASK))) {
1562 case CONTENT_EVENT_MOUSE_ENTER | CONTENT_EVENT_MOUSE_MASK:
1563 strcpy(ptr, "_mouse_enter");
1565 case CONTENT_EVENT_MOUSE_LEAVE | CONTENT_EVENT_MOUSE_MASK:
1566 strcpy(ptr, "_mouse_leave");
1568 case CONTENT_EVENT_MOUSE_UP | CONTENT_EVENT_MOUSE_MASK:
1569 strcpy(ptr, "_mouse_up");
1571 case CONTENT_EVENT_MOUSE_DOWN | CONTENT_EVENT_MOUSE_MASK:
1572 strcpy(ptr, "_mouse_down");
1574 case CONTENT_EVENT_MOUSE_MOVE | CONTENT_EVENT_MOUSE_MASK:
1575 strcpy(ptr, "_mouse_move");
1577 case CONTENT_EVENT_MOUSE_SET | CONTENT_EVENT_MOUSE_MASK:
1578 strcpy(ptr, "_mouse_set");
1580 case CONTENT_EVENT_MOUSE_UNSET | CONTENT_EVENT_MOUSE_MASK:
1581 strcpy(ptr, "_mouse_unset");
1583 case CONTENT_EVENT_KEY_DOWN | CONTENT_EVENT_KEY_MASK:
1584 strcpy(ptr, "_key_down");
1586 case CONTENT_EVENT_KEY_UP | CONTENT_EVENT_KEY_MASK:
1587 strcpy(ptr, "_key_up");
1590 ErrPrint("Invalid event type\n");
1591 return LB_STATUS_ERROR_INVALID;
1594 return send_mouse_event(handler, cmd, x * w, y * h);
1597 EAPI const char *livebox_filename(struct livebox *handler)
1600 ErrPrint("Handler is NIL\n");
1604 if (handler->state != CREATE || !handler->id) {
1605 ErrPrint("Handler is not valid\n");
1609 if (handler->filename) {
1610 return handler->filename;
1614 return util_uri_to_path(handler->id);
1617 EAPI int livebox_get_pdsize(struct livebox *handler, int *w, int *h)
1623 ErrPrint("Handler is NIL\n");
1624 return LB_STATUS_ERROR_INVALID;
1627 if (handler->state != CREATE || !handler->id) {
1628 ErrPrint("Handler is not valid\n");
1629 return LB_STATUS_ERROR_INVALID;
1639 if (!handler->is_pd_created) {
1640 *w = handler->pd.default_width;
1641 *h = handler->pd.default_height;
1643 *w = handler->pd.width;
1644 *h = handler->pd.height;
1647 return LB_STATUS_SUCCESS;
1650 EAPI int livebox_size(struct livebox *handler)
1656 ErrPrint("Handler is NIL\n");
1657 return LB_STATUS_ERROR_INVALID;
1660 if (handler->state != CREATE || !handler->id) {
1661 ErrPrint("Handler is not valid\n");
1662 return LB_STATUS_ERROR_INVALID;
1665 w = handler->lb.width;
1666 h = handler->lb.height;
1668 switch (handler->lb.type) {
1669 case _LB_TYPE_BUFFER:
1670 case _LB_TYPE_SCRIPT:
1671 if (!fb_is_created(handler->lb.data.fb)) {
1680 return livebox_service_size_type(w, h);
1683 EAPI int livebox_set_group(struct livebox *handler, const char *cluster, const char *category, ret_cb_t cb, void *data)
1685 struct packet *packet;
1689 ErrPrint("Handler is NIL\n");
1690 return LB_STATUS_ERROR_INVALID;
1693 if (!cluster || !category || handler->state != CREATE || !handler->id) {
1694 ErrPrint("Invalid argument\n");
1695 return LB_STATUS_ERROR_INVALID;
1698 if (handler->group_changed_cb) {
1699 ErrPrint("Previous group changing request is not finished yet\n");
1700 return LB_STATUS_ERROR_BUSY;
1703 if (!handler->is_user) {
1704 ErrPrint("CA Livebox is not able to change the group\n");
1705 return LB_STATUS_ERROR_PERMISSION;
1708 if (!strcmp(handler->cluster, cluster) && !strcmp(handler->category, category)) {
1709 DbgPrint("No changes\n");
1710 return LB_STATUS_ERROR_ALREADY;
1713 packet = packet_create("change_group", "ssss", handler->pkgname, handler->id, cluster, category);
1715 ErrPrint("Failed to build a param\n");
1716 return LB_STATUS_ERROR_FAULT;
1720 cb = default_group_changed_cb;
1723 ret = master_rpc_async_request(handler, packet, 0, set_group_ret_cb, NULL);
1724 if (ret == LB_STATUS_SUCCESS) {
1725 handler->group_changed_cb = cb;
1726 handler->group_cbdata = data;
1732 EAPI int livebox_get_group(struct livebox *handler, char ** const cluster, char ** const category)
1735 ErrPrint("Handler is NIL\n");
1736 return LB_STATUS_ERROR_INVALID;
1739 if (!cluster || !category || handler->state != CREATE || !handler->id) {
1740 ErrPrint("Invalid argument\n");
1741 return LB_STATUS_ERROR_INVALID;
1744 *cluster = handler->cluster;
1745 *category = handler->category;
1746 return LB_STATUS_SUCCESS;
1749 EAPI int livebox_get_supported_sizes(struct livebox *handler, int *cnt, int *size_list)
1754 if (!handler || !size_list) {
1755 ErrPrint("Invalid argument, handler(%p), size_list(%p)\n", handler, size_list);
1756 return LB_STATUS_ERROR_INVALID;
1759 if (!cnt || handler->state != CREATE || !handler->id) {
1760 ErrPrint("Handler is not valid\n");
1761 return LB_STATUS_ERROR_INVALID;
1764 for (j = i = 0; i < NR_OF_SIZE_LIST; i++) {
1765 if (handler->lb.size_list & (0x01 << i)) {
1770 size_list[j++] = (0x01 << i);
1775 return LB_STATUS_SUCCESS;
1778 EAPI const char *livebox_pkgname(struct livebox *handler)
1781 ErrPrint("Handler is NIL\n");
1785 if (handler->state != CREATE) {
1786 ErrPrint("Handler is not valid\n");
1790 return handler->pkgname;
1793 EAPI double livebox_priority(struct livebox *handler)
1796 ErrPrint("Handler is NIL\n");
1800 if (handler->state != CREATE || !handler->id) {
1801 ErrPrint("Handler is not valid (%p)\n", handler);
1805 return handler->lb.priority;
1808 EAPI int livebox_delete_cluster(const char *cluster, ret_cb_t cb, void *data)
1810 struct packet *packet;
1811 struct cb_info *cbinfo;
1814 packet = packet_create("delete_cluster", "s", cluster);
1816 ErrPrint("Failed to build a param\n");
1817 return LB_STATUS_ERROR_FAULT;
1820 cbinfo = create_cb_info(cb, data);
1822 packet_destroy(packet);
1823 return LB_STATUS_ERROR_FAULT;
1826 ret = master_rpc_async_request(NULL, packet, 0, delete_cluster_cb, cbinfo);
1828 destroy_cb_info(cbinfo);
1834 EAPI int livebox_delete_category(const char *cluster, const char *category, ret_cb_t cb, void *data)
1836 struct packet *packet;
1837 struct cb_info *cbinfo;
1840 packet = packet_create("delete_category", "ss", cluster, category);
1842 ErrPrint("Failed to build a param\n");
1843 return LB_STATUS_ERROR_FAULT;
1846 cbinfo = create_cb_info(cb, data);
1848 packet_destroy(packet);
1849 return LB_STATUS_ERROR_FAULT;
1852 ret = master_rpc_async_request(NULL, packet, 0, delete_category_cb, cbinfo);
1854 destroy_cb_info(cbinfo);
1860 EAPI enum livebox_lb_type livebox_lb_type(struct livebox *handler)
1863 ErrPrint("Handler is NIL\n");
1864 return LB_TYPE_INVALID;
1867 if (handler->state != CREATE || !handler->id) {
1868 ErrPrint("Handler is not valid\n");
1869 return LB_TYPE_INVALID;
1872 switch (handler->lb.type) {
1874 return LB_TYPE_IMAGE;
1875 case _LB_TYPE_BUFFER:
1876 case _LB_TYPE_SCRIPT:
1879 id = fb_id(handler->lb.data.fb);
1880 if (id && !strncasecmp(id, SCHEMA_PIXMAP, strlen(SCHEMA_PIXMAP))) {
1881 return LB_TYPE_PIXMAP;
1884 return LB_TYPE_BUFFER;
1886 return LB_TYPE_TEXT;
1891 return LB_TYPE_INVALID;
1894 EAPI enum livebox_pd_type livebox_pd_type(struct livebox *handler)
1897 ErrPrint("Handler is NIL\n");
1898 return PD_TYPE_INVALID;
1901 if (handler->state != CREATE || !handler->id) {
1902 ErrPrint("Handler is not valid\n");
1903 return PD_TYPE_INVALID;
1906 switch (handler->pd.type) {
1908 return PD_TYPE_TEXT;
1909 case _PD_TYPE_BUFFER:
1910 case _PD_TYPE_SCRIPT:
1913 id = fb_id(handler->pd.data.fb);
1914 if (id && !strncasecmp(id, SCHEMA_PIXMAP, strlen(SCHEMA_PIXMAP))) {
1915 return PD_TYPE_PIXMAP;
1918 return PD_TYPE_BUFFER;
1923 return PD_TYPE_INVALID;
1926 EAPI int livebox_set_pd_text_handler(struct livebox *handler, struct livebox_script_operators *ops)
1929 ErrPrint("Handler is NIL\n");
1930 return LB_STATUS_ERROR_INVALID;
1933 if (handler->state != CREATE) {
1934 ErrPrint("Handler is not valid\n");
1935 return LB_STATUS_ERROR_INVALID;
1938 memcpy(&handler->pd.data.ops, ops, sizeof(*ops));
1939 return LB_STATUS_SUCCESS;
1942 EAPI int livebox_set_text_handler(struct livebox *handler, struct livebox_script_operators *ops)
1945 ErrPrint("Handler is NIL\n");
1946 return LB_STATUS_ERROR_INVALID;
1949 if (handler->state != CREATE) {
1950 ErrPrint("Handler is not valid\n");
1951 return LB_STATUS_ERROR_INVALID;
1954 memcpy(&handler->lb.data.ops, ops, sizeof(*ops));
1955 return LB_STATUS_SUCCESS;
1958 EAPI int livebox_acquire_lb_pixmap(struct livebox *handler, ret_cb_t cb, void *data)
1960 struct packet *packet;
1961 struct cb_info *cbinfo;
1966 ErrPrint("Handler is NIL\n");
1967 return LB_STATUS_ERROR_INVALID;
1970 if (handler->state != CREATE || !handler->id) {
1971 ErrPrint("Invalid handle\n");
1972 return LB_STATUS_ERROR_INVALID;
1975 if (handler->lb.type != _LB_TYPE_SCRIPT && handler->lb.type != _LB_TYPE_BUFFER) {
1976 ErrPrint("Handler is not valid type\n");
1977 return LB_STATUS_ERROR_INVALID;
1980 id = fb_id(handler->lb.data.fb);
1981 if (!id || strncasecmp(id, SCHEMA_PIXMAP, strlen(SCHEMA_PIXMAP))) {
1982 return LB_STATUS_ERROR_INVALID;
1985 packet = packet_create("lb_acquire_pixmap", "ss", handler->pkgname, handler->id);
1987 ErrPrint("Failed to build a param\n");
1988 return LB_STATUS_ERROR_FAULT;
1991 cbinfo = create_cb_info(cb, data);
1993 packet_destroy(packet);
1994 return LB_STATUS_ERROR_FAULT;
1997 ret = master_rpc_async_request(handler, packet, 0, lb_pixmap_acquired_cb, cbinfo);
1999 destroy_cb_info(cbinfo);
2005 EAPI int livebox_release_lb_pixmap(struct livebox *handler, int pixmap)
2007 struct packet *packet;
2009 if (!handler || pixmap == 0) {
2010 ErrPrint("Handler is NIL [%d]\n", pixmap);
2011 return LB_STATUS_ERROR_INVALID;
2014 if (handler->state != CREATE || !handler->id) {
2015 ErrPrint("Invalid handle\n");
2016 return LB_STATUS_ERROR_INVALID;
2019 if (handler->lb.type != _LB_TYPE_SCRIPT && handler->lb.type != _LB_TYPE_BUFFER) {
2020 ErrPrint("Handler is not valid type\n");
2021 return LB_STATUS_ERROR_INVALID;
2024 packet = packet_create_noack("lb_release_pixmap", "ssi", handler->pkgname, handler->id, pixmap);
2026 ErrPrint("Failed to build a param\n");
2027 return LB_STATUS_ERROR_INVALID;
2030 return master_rpc_request_only(handler, packet);
2033 EAPI int livebox_acquire_pd_pixmap(struct livebox *handler, ret_cb_t cb, void *data)
2035 struct packet *packet;
2036 struct cb_info *cbinfo;
2041 ErrPrint("Handler is NIL\n");
2042 return LB_STATUS_ERROR_INVALID;
2045 if (handler->state != CREATE || !handler->id) {
2046 ErrPrint("Invalid handle\n");
2047 return LB_STATUS_ERROR_INVALID;
2050 if (handler->pd.type != _PD_TYPE_SCRIPT && handler->pd.type != _PD_TYPE_BUFFER) {
2051 ErrPrint("Handler is not valid type\n");
2052 return LB_STATUS_ERROR_INVALID;
2055 id = fb_id(handler->pd.data.fb);
2056 if (!id || strncasecmp(id, SCHEMA_PIXMAP, strlen(SCHEMA_PIXMAP))) {
2057 return LB_STATUS_ERROR_INVALID;
2060 packet = packet_create("pd_acquire_pixmap", "ss", handler->pkgname, handler->id);
2062 ErrPrint("Failed to build a param\n");
2063 return LB_STATUS_ERROR_FAULT;
2066 cbinfo = create_cb_info(cb, data);
2068 packet_destroy(packet);
2069 return LB_STATUS_ERROR_FAULT;
2072 ret = master_rpc_async_request(handler, packet, 0, pd_pixmap_acquired_cb, cbinfo);
2074 destroy_cb_info(cbinfo);
2080 EAPI int livebox_pd_pixmap(const struct livebox *handler)
2086 ErrPrint("Handler is NIL\n");
2090 if (handler->state != CREATE || !handler->id) {
2091 ErrPrint("Invalid handler\n");
2095 if (handler->pd.type != _PD_TYPE_SCRIPT && handler->pd.type != _PD_TYPE_BUFFER) {
2096 ErrPrint("Invalid handler\n");
2100 id = fb_id(handler->pd.data.fb);
2101 if (id && sscanf(id, SCHEMA_PIXMAP "%d", &pixmap) != 1) {
2102 ErrPrint("PIXMAP Id is not valid\n");
2109 EAPI int livebox_lb_pixmap(const struct livebox *handler)
2115 ErrPrint("Handler is NIL\n");
2119 if (handler->state != CREATE || !handler->id) {
2120 ErrPrint("Invalid handler\n");
2124 if (handler->lb.type != _LB_TYPE_SCRIPT && handler->lb.type != _LB_TYPE_BUFFER) {
2125 ErrPrint("Invalid handler\n");
2129 id = fb_id(handler->lb.data.fb);
2130 if (id && sscanf(id, SCHEMA_PIXMAP "%d", &pixmap) != 1) {
2131 ErrPrint("PIXMAP Id is not valid\n");
2138 EAPI int livebox_release_pd_pixmap(struct livebox *handler, int pixmap)
2140 struct packet *packet;
2142 if (!handler || pixmap == 0) {
2143 ErrPrint("Handler is NIL [%d]\n", pixmap);
2144 return LB_STATUS_ERROR_INVALID;
2147 if (handler->state != CREATE || !handler->id) {
2148 ErrPrint("Invalid handle\n");
2149 return LB_STATUS_ERROR_INVALID;
2152 if (handler->pd.type != _PD_TYPE_SCRIPT && handler->pd.type != _PD_TYPE_BUFFER) {
2153 ErrPrint("Handler is not valid type\n");
2154 return LB_STATUS_ERROR_INVALID;
2157 packet = packet_create_noack("pd_release_pixmap", "ssi", handler->pkgname, handler->id, pixmap);
2159 ErrPrint("Failed to build a param\n");
2160 return LB_STATUS_ERROR_FAULT;
2163 return master_rpc_request_only(handler, packet);
2166 EAPI void *livebox_acquire_fb(struct livebox *handler)
2169 ErrPrint("Handler is NIL\n");
2173 if (handler->state != CREATE || !handler->id) {
2174 ErrPrint("Invalid handle\n");
2178 if (handler->lb.type != _LB_TYPE_SCRIPT && handler->lb.type != _LB_TYPE_BUFFER) {
2179 ErrPrint("Handler is not valid type\n");
2183 return fb_acquire_buffer(handler->lb.data.fb);
2186 EAPI int livebox_release_fb(void *buffer)
2188 return fb_release_buffer(buffer);
2191 EAPI int livebox_fb_refcnt(void *buffer)
2193 return fb_refcnt(buffer);
2196 EAPI void *livebox_acquire_pdfb(struct livebox *handler)
2199 ErrPrint("Handler is NIL\n");
2203 if (handler->state != CREATE || !handler->id) {
2204 ErrPrint("Invalid handler\n");
2208 if (handler->pd.type != _PD_TYPE_SCRIPT && handler->pd.type != _PD_TYPE_BUFFER) {
2209 ErrPrint("Handler is not valid type\n");
2213 return fb_acquire_buffer(handler->pd.data.fb);
2216 EAPI int livebox_release_pdfb(void *buffer)
2218 return fb_release_buffer(buffer);
2221 EAPI int livebox_pdfb_refcnt(void *buffer)
2223 return fb_refcnt(buffer);
2226 EAPI int livebox_pdfb_bufsz(struct livebox *handler)
2229 ErrPrint("Handler is NIL\n");
2230 return LB_STATUS_ERROR_INVALID;
2233 if (handler->state != CREATE || !handler->id) {
2234 ErrPrint("Handler is not valid\n");
2235 return LB_STATUS_ERROR_INVALID;
2238 return fb_size(handler->pd.data.fb);
2241 EAPI int livebox_lbfb_bufsz(struct livebox *handler)
2244 ErrPrint("Handler is NIL\n");
2245 return LB_STATUS_ERROR_INVALID;
2248 if (handler->state != CREATE || !handler->id) {
2249 ErrPrint("Handler is not valid\n");
2250 return LB_STATUS_ERROR_INVALID;
2253 return fb_size(handler->lb.data.fb);
2256 EAPI int livebox_is_user(struct livebox *handler)
2259 ErrPrint("Handler is NIL\n");
2260 return LB_STATUS_ERROR_INVALID;
2263 if (handler->state != CREATE) {
2264 ErrPrint("Handler is invalid\n");
2265 return LB_STATUS_ERROR_INVALID;
2268 return handler->is_user;
2271 EAPI int livebox_set_pinup(struct livebox *handler, int flag, ret_cb_t cb, void *data)
2273 struct packet *packet;
2277 ErrPrint("Handler is NIL\n");
2278 return LB_STATUS_ERROR_INVALID;
2281 if (handler->state != CREATE || !handler->id) {
2282 ErrPrint("Handler is not valid\n");
2283 return LB_STATUS_ERROR_INVALID;
2286 if (handler->pinup_cb) {
2287 ErrPrint("Previous pinup request is not finished\n");
2288 return LB_STATUS_ERROR_BUSY;
2291 if (handler->is_pinned_up == flag) {
2292 DbgPrint("No changes\n");
2293 return LB_STATUS_ERROR_ALREADY;
2296 packet = packet_create("pinup_changed", "ssi", handler->pkgname, handler->id, flag);
2298 ErrPrint("Failed to build a param\n");
2299 return LB_STATUS_ERROR_FAULT;
2303 cb = default_pinup_cb;
2306 ret = master_rpc_async_request(handler, packet, 0, pinup_done_cb, NULL);
2307 if (ret == LB_STATUS_SUCCESS) {
2308 handler->pinup_cb = cb;
2309 handler->pinup_cbdata = data;
2315 EAPI int livebox_is_pinned_up(struct livebox *handler)
2318 ErrPrint("Handler is NIL\n");
2319 return LB_STATUS_ERROR_INVALID;
2322 if (handler->state != CREATE || !handler->id) {
2323 return LB_STATUS_ERROR_INVALID;
2326 return handler->is_pinned_up;
2329 EAPI int livebox_has_pinup(struct livebox *handler)
2332 ErrPrint("Handler is NIL\n");
2333 return LB_STATUS_ERROR_INVALID;
2336 if (handler->state != CREATE || !handler->id) {
2337 return LB_STATUS_ERROR_INVALID;
2340 return handler->lb.pinup_supported;
2343 EAPI int livebox_set_data(struct livebox *handler, void *data)
2346 ErrPrint("Handler is NIL\n");
2347 return LB_STATUS_ERROR_INVALID;
2350 if (handler->state != CREATE) {
2351 return LB_STATUS_ERROR_INVALID;
2354 handler->data = data;
2355 return LB_STATUS_SUCCESS;
2358 EAPI void *livebox_get_data(struct livebox *handler)
2361 ErrPrint("Handler is NIL\n");
2365 if (handler->state != CREATE) {
2369 return handler->data;
2372 EAPI int livebox_is_exists(const char *pkgname)
2376 lb = lb_pkgname(pkgname);
2385 EAPI const char *livebox_content(struct livebox *handler)
2388 ErrPrint("Handler is NIL\n");
2392 if (handler->state != CREATE) {
2396 return handler->content;
2399 EAPI const char *livebox_category_title(struct livebox *handler)
2402 ErrPrint("Handler is NIL\n");
2406 if (handler->state != CREATE) {
2410 return handler->title;
2413 EAPI int livebox_emit_text_signal(struct livebox *handler, const char *emission, const char *source, double sx, double sy, double ex, double ey, ret_cb_t cb, void *data)
2415 struct packet *packet;
2416 struct cb_info *cbinfo;
2420 ErrPrint("Handler is NIL\n");
2421 return LB_STATUS_ERROR_INVALID;
2424 if ((handler->lb.type != _LB_TYPE_TEXT && handler->pd.type != _PD_TYPE_TEXT) || handler->state != CREATE || !handler->id) {
2425 ErrPrint("Handler is not valid\n");
2426 return LB_STATUS_ERROR_INVALID;
2437 packet = packet_create("text_signal", "ssssdddd",
2438 handler->pkgname, handler->id, emission, source, sx, sy, ex, ey);
2440 ErrPrint("Failed to build a param\n");
2441 return LB_STATUS_ERROR_FAULT;
2444 cbinfo = create_cb_info(cb, data);
2446 packet_destroy(packet);
2447 return LB_STATUS_ERROR_FAULT;
2450 ret = master_rpc_async_request(handler, packet, 0, text_signal_cb, cbinfo);
2452 destroy_cb_info(cbinfo);
2458 EAPI int livebox_subscribe_group(const char *cluster, const char *category)
2460 struct packet *packet;
2464 * Validate the group info using DB
2465 * If the group info is not valid, do not send this request
2468 packet = packet_create_noack("subscribe", "ss", cluster ? cluster : "", category ? category : "");
2470 ErrPrint("Failed to create a packet\n");
2471 return LB_STATUS_ERROR_FAULT;
2474 return master_rpc_request_only(NULL, packet);
2477 EAPI int livebox_unsubscribe_group(const char *cluster, const char *category)
2479 struct packet *packet;
2483 * Validate the group info using DB
2484 * If the group info is not valid, do not send this request
2485 * AND Check the subscribed or not too
2488 packet = packet_create_noack("unsubscribe", "ss", cluster ? cluster : "", category ? category : "");
2490 ErrPrint("Failed to create a packet\n");
2491 return LB_STATUS_ERROR_FAULT;
2494 return master_rpc_request_only(NULL, packet);
2497 EAPI int livebox_refresh(struct livebox *handler)
2499 struct packet *packet;
2502 ErrPrint("Hnalder is NIL\n");
2503 return LB_STATUS_ERROR_INVALID;
2506 if (handler->state != CREATE || !handler->id) {
2507 return LB_STATUS_ERROR_INVALID;
2510 packet = packet_create_noack("update", "ss", handler->pkgname, handler->id);
2512 ErrPrint("Failed to create a packet\n");
2513 return LB_STATUS_ERROR_FAULT;
2516 return master_rpc_request_only(handler, packet);
2519 EAPI int livebox_refresh_group(const char *cluster, const char *category)
2521 struct packet *packet;
2523 if (!cluster || !category) {
2524 ErrPrint("Invalid argument\n");
2525 return LB_STATUS_ERROR_INVALID;
2528 packet = packet_create_noack("refresh_group", "ss", cluster, category);
2530 ErrPrint("Failed to create a packet\n");
2531 return LB_STATUS_ERROR_FAULT;
2534 return master_rpc_request_only(NULL, packet);
2537 EAPI int livebox_set_visibility(struct livebox *handler, enum livebox_visible_state state)
2539 struct packet *packet;
2543 ErrPrint("Handler is NIL\n");
2544 return LB_STATUS_ERROR_INVALID;
2547 if (handler->state != CREATE || !handler->id) {
2548 return LB_STATUS_ERROR_INVALID;
2551 if (!handler->is_user) {
2552 /* System cluster livebox cannot be changed its visible states */
2553 if (state == LB_HIDE_WITH_PAUSE) {
2554 ErrPrint("CA Livebox is not able to change the visibility\n");
2555 return LB_STATUS_ERROR_PERMISSION;
2559 if (handler->visible == state) {
2560 return LB_STATUS_ERROR_ALREADY;
2563 packet = packet_create_noack("change,visibility", "ssi", handler->pkgname, handler->id, (int)state);
2565 ErrPrint("Failed to create a packet\n");
2566 return LB_STATUS_ERROR_FAULT;
2569 ret = master_rpc_request_only(handler, packet);
2571 handler->visible = state;
2577 EAPI enum livebox_visible_state livebox_visibility(struct livebox *handler)
2580 ErrPrint("Handler is NIL\n");
2581 return LB_VISIBLE_ERROR;
2584 if (handler->state != CREATE || !handler->id) {
2585 return LB_VISIBLE_ERROR;
2588 return handler->visible;
2591 int lb_set_group(struct livebox *handler, const char *cluster, const char *category)
2597 pc = strdup(cluster);
2599 CRITICAL_LOG("Heap: %s (cluster: %s)\n", strerror(errno), cluster);
2600 return LB_STATUS_ERROR_MEMORY;
2605 ps = strdup(category);
2607 CRITICAL_LOG("Heap: %s (category: %s)\n", strerror(errno), category);
2609 return LB_STATUS_ERROR_MEMORY;
2613 if (handler->cluster) {
2614 free(handler->cluster);
2617 if (handler->category) {
2618 free(handler->category);
2621 handler->cluster = pc;
2622 handler->category = ps;
2624 return LB_STATUS_SUCCESS;
2627 void lb_set_size(struct livebox *handler, int w, int h)
2629 handler->lb.width = w;
2630 handler->lb.height = h;
2633 void lb_set_update_mode(struct livebox *handle, int active_mode)
2635 handle->is_active_update = active_mode;
2638 void lb_set_pdsize(struct livebox *handler, int w, int h)
2640 handler->pd.width = w;
2641 handler->pd.height = h;
2644 void lb_set_default_pdsize(struct livebox *handler, int w, int h)
2646 handler->pd.default_width = w;
2647 handler->pd.default_height = h;
2650 void lb_invoke_fault_handler(enum livebox_fault_type event, const char *pkgname, const char *file, const char *func)
2654 struct fault_info *info;
2656 dlist_foreach_safe(s_info.fault_list, l, n, info) {
2657 if (info->handler(event, pkgname, file, func, info->user_data) == EXIT_FAILURE) {
2658 s_info.fault_list = dlist_remove(s_info.fault_list, l);
2663 void lb_invoke_event_handler(struct livebox *handler, enum livebox_event_type event)
2667 struct event_info *info;
2669 dlist_foreach_safe(s_info.event_list, l, n, info) {
2670 if (info->handler(handler, event, info->user_data) == EXIT_FAILURE) {
2671 s_info.event_list = dlist_remove(s_info.event_list, l);
2676 struct livebox *lb_find_livebox(const char *pkgname, const char *id)
2679 struct livebox *handler;
2681 dlist_foreach(s_info.livebox_list, l, handler) {
2686 if (!strcmp(handler->pkgname, pkgname) && !strcmp(handler->id, id)) {
2694 struct livebox *lb_find_livebox_by_timestamp(double timestamp)
2697 struct livebox *handler;
2699 dlist_foreach(s_info.livebox_list, l, handler) {
2700 if (handler->timestamp == timestamp) {
2708 struct livebox *lb_new_livebox(const char *pkgname, const char *id, double timestamp)
2710 struct livebox *handler;
2712 handler = calloc(1, sizeof(*handler));
2714 ErrPrint("Failed to create a new livebox\n");
2718 handler->pkgname = strdup(pkgname);
2719 if (!handler->pkgname) {
2720 ErrPrint("%s\n", strerror(errno));
2725 handler->id = strdup(id);
2727 ErrPrint("%s\n", strerror(errno));
2728 free(handler->pkgname);
2733 handler->timestamp = timestamp;
2734 handler->lb.type = _LB_TYPE_FILE;
2735 handler->pd.type = _PD_TYPE_SCRIPT;
2736 handler->state = CREATE;
2737 handler->visible = LB_SHOW;
2739 s_info.livebox_list = dlist_append(s_info.livebox_list, handler);
2744 int lb_delete_all(void)
2748 struct livebox *handler;
2750 dlist_foreach_safe(s_info.livebox_list, l, n, handler) {
2751 lb_invoke_event_handler(handler, LB_EVENT_DELETED);
2755 return LB_STATUS_SUCCESS;
2758 int lb_set_content(struct livebox *handler, const char *content)
2760 if (handler->content) {
2761 free(handler->content);
2762 handler->content = NULL;
2766 handler->content = strdup(content);
2767 if (!handler->content) {
2768 CRITICAL_LOG("Heap: %s (content: %s)\n", strerror(errno), content);
2769 return LB_STATUS_ERROR_MEMORY;
2773 return LB_STATUS_SUCCESS;
2776 int lb_set_title(struct livebox *handler, const char *title)
2778 if (handler->title) {
2779 free(handler->title);
2780 handler->title = NULL;
2784 handler->title = strdup(title);
2785 if (!handler->title) {
2786 CRITICAL_LOG("Heap: %s (title: %s)\n", strerror(errno), title);
2787 return LB_STATUS_ERROR_MEMORY;
2791 return LB_STATUS_SUCCESS;
2794 void lb_set_size_list(struct livebox *handler, int size_list)
2796 handler->lb.size_list = size_list;
2799 void lb_set_auto_launch(struct livebox *handler, const char *auto_launch)
2801 if (!strlen(auto_launch)) {
2805 handler->lb.auto_launch = strdup(auto_launch);
2806 if (!handler->lb.auto_launch) {
2807 ErrPrint("Heap: %s\n", strerror(errno));
2811 void lb_set_priority(struct livebox *handler, double priority)
2813 handler->lb.priority = priority;
2816 void lb_set_id(struct livebox *handler, const char *id)
2822 handler->id = strdup(id);
2824 ErrPrint("Error: %s\n", strerror(errno));
2828 void lb_set_filename(struct livebox *handler, const char *filename)
2830 if (handler->filename) {
2831 if (handler->filename[0] && unlink(handler->filename) < 0) {
2832 ErrPrint("unlink: %s (%s)\n", strerror(errno), handler->filename);
2835 free(handler->filename);
2838 handler->filename = strdup(filename);
2839 if (!handler->filename) {
2840 ErrPrint("Heap: %s (%s)\n", strerror(errno), handler->filename);
2845 int lb_set_lb_fb(struct livebox *handler, const char *filename)
2850 return LB_STATUS_ERROR_INVALID;
2853 fb = handler->lb.data.fb;
2854 if (fb && !strcmp(fb_id(fb), filename)) { /*!< BUFFER is not changed, */
2855 return LB_STATUS_SUCCESS;
2858 handler->lb.data.fb = NULL;
2860 if (!filename || filename[0] == '\0') {
2864 return LB_STATUS_SUCCESS;
2867 handler->lb.data.fb = fb_create(filename, handler->lb.width, handler->lb.height);
2868 if (!handler->lb.data.fb) {
2869 ErrPrint("Faield to create a FB\n");
2873 return LB_STATUS_ERROR_FAULT;
2880 return LB_STATUS_SUCCESS;
2883 int lb_set_pd_fb(struct livebox *handler, const char *filename)
2888 return LB_STATUS_ERROR_INVALID;
2891 fb = handler->pd.data.fb;
2892 if (fb && !strcmp(fb_id(fb), filename)) {
2893 /* BUFFER is not changed, just update the content */
2894 return LB_STATUS_ERROR_EXIST;
2896 handler->pd.data.fb = NULL;
2898 if (!filename || filename[0] == '\0') {
2902 return LB_STATUS_SUCCESS;
2905 handler->pd.data.fb = fb_create(filename, handler->pd.width, handler->pd.height);
2906 if (!handler->pd.data.fb) {
2907 ErrPrint("Failed to create a FB\n");
2911 return LB_STATUS_ERROR_FAULT;
2917 return LB_STATUS_SUCCESS;
2920 struct fb_info *lb_get_lb_fb(struct livebox *handler)
2922 return handler->lb.data.fb;
2925 struct fb_info *lb_get_pd_fb(struct livebox *handler)
2927 return handler->pd.data.fb;
2930 void lb_set_user(struct livebox *handler, int user)
2932 handler->is_user = user;
2935 void lb_set_pinup(struct livebox *handler, int pinup_supported)
2937 handler->lb.pinup_supported = pinup_supported;
2940 void lb_set_text_lb(struct livebox *handler)
2942 handler->lb.type = _LB_TYPE_TEXT;
2945 void lb_set_text_pd(struct livebox *handler)
2947 handler->pd.type = _PD_TYPE_TEXT;
2950 int lb_text_lb(struct livebox *handler)
2952 return handler->lb.type == _LB_TYPE_TEXT;
2955 int lb_text_pd(struct livebox *handler)
2957 return handler->pd.type == _PD_TYPE_TEXT;
2960 void lb_set_period(struct livebox *handler, double period)
2962 handler->lb.period = period;
2965 struct livebox *lb_ref(struct livebox *handler)
2975 struct livebox *lb_unref(struct livebox *handler)
2982 if (handler->refcnt > 0) {
2986 if (handler->created_cb) {
2987 handler->created_cb(handler, LB_STATUS_ERROR_FAULT, handler->created_cbdata);
2988 handler->created_cb = NULL;
2989 handler->created_cbdata = NULL;
2992 if (handler->deleted_cb) {
2993 handler->deleted_cb(handler, LB_STATUS_ERROR_FAULT, handler->deleted_cbdata);
2994 handler->deleted_cb = NULL;
2995 handler->deleted_cbdata = NULL;
2998 if (handler->pinup_cb) {
2999 handler->pinup_cb(handler, LB_STATUS_ERROR_FAULT, handler->pinup_cbdata);
3000 handler->pinup_cb = NULL;
3001 handler->pinup_cbdata = NULL;
3004 if (handler->group_changed_cb) {
3005 handler->group_changed_cb(handler, LB_STATUS_ERROR_FAULT, handler->group_cbdata);
3006 handler->group_changed_cb = NULL;
3007 handler->group_cbdata = NULL;
3010 if (handler->period_changed_cb) {
3011 handler->period_changed_cb(handler, LB_STATUS_ERROR_FAULT, handler->period_cbdata);
3012 handler->period_changed_cb = NULL;
3013 handler->period_cbdata = NULL;
3016 if (handler->size_changed_cb) {
3017 handler->size_changed_cb(handler, LB_STATUS_ERROR_FAULT, handler->size_cbdata);
3018 handler->size_changed_cb = NULL;
3019 handler->size_cbdata = NULL;
3022 if (handler->pd_created_cb) {
3023 handler->pd_created_cb(handler, LB_STATUS_ERROR_FAULT, handler->pd_created_cbdata);
3024 handler->pd_created_cb = NULL;
3025 handler->pd_created_cbdata = NULL;
3028 if (handler->pd_destroyed_cb) {
3029 handler->pd_destroyed_cb(handler, LB_STATUS_ERROR_FAULT, handler->pd_destroyed_cbdata);
3030 handler->pd_destroyed_cb = NULL;
3031 handler->pd_destroyed_cbdata = NULL;
3034 if (handler->update_mode_cb) {
3035 handler->update_mode_cb(handler, LB_STATUS_ERROR_FAULT, handler->update_mode_cbdata);
3036 handler->update_mode_cb = NULL;
3037 handler->update_mode_cbdata = NULL;
3040 if (handler->access_event_cb) {
3041 handler->access_event_cb(handler, LB_ACCESS_STATUS_ERROR, handler->access_event_cbdata);
3042 handler->access_event_cb = NULL;
3043 handler->access_event_cbdata = NULL;
3046 if (handler->filename) {
3047 (void)util_unlink(handler->filename);
3050 dlist_remove_data(s_info.livebox_list, handler);
3052 handler->state = DESTROYED;
3053 free(handler->cluster);
3054 free(handler->category);
3056 free(handler->pkgname);
3057 free(handler->filename);
3058 free(handler->lb.auto_launch);
3060 if (handler->lb.data.fb) {
3061 fb_destroy(handler->lb.data.fb);
3062 handler->lb.data.fb = NULL;
3065 if (handler->pd.data.fb) {
3066 fb_destroy(handler->pd.data.fb);
3067 handler->pd.data.fb = NULL;
3074 int lb_send_delete(struct livebox *handler, ret_cb_t cb, void *data)
3076 struct packet *packet;
3077 struct cb_info *cbinfo;
3080 if (!cb && !!data) {
3081 ErrPrint("Invalid argument\n");
3082 return LB_STATUS_ERROR_INVALID;
3085 if (handler->deleted_cb) {
3086 ErrPrint("Already in-progress\n");
3087 return LB_STATUS_ERROR_BUSY;
3090 packet = packet_create("delete", "ss", handler->pkgname, handler->id);
3092 ErrPrint("Failed to build a param\n");
3094 cb(handler, LB_STATUS_ERROR_FAULT, data);
3097 return LB_STATUS_ERROR_FAULT;
3101 cb = default_delete_cb;
3104 cbinfo = create_cb_info(cb, data);
3106 packet_destroy(packet);
3107 return LB_STATUS_ERROR_FAULT;
3110 ret = master_rpc_async_request(handler, packet, 0, del_ret_cb, cbinfo);
3112 destroy_cb_info(cbinfo);
3118 EAPI int livebox_client_paused(void)
3120 struct packet *packet;
3122 packet = packet_create_noack("client_paused", "d", util_timestamp());
3124 ErrPrint("Failed to create a pause packet\n");
3125 return LB_STATUS_ERROR_FAULT;
3128 return master_rpc_request_only(NULL, packet);
3131 EAPI int livebox_client_resumed(void)
3133 struct packet *packet;
3135 packet = packet_create_noack("client_resumed", "d", util_timestamp());
3137 ErrPrint("Failed to create a resume packet\n");
3138 return LB_STATUS_ERROR_FAULT;
3141 return master_rpc_request_only(NULL, packet);
3144 EAPI void livebox_set_manual_sync(int flag)
3146 conf_set_manual_sync(flag);
3149 EAPI int livebox_manual_sync(void)
3151 return conf_manual_sync();
3154 EAPI void livebox_set_frame_drop_for_resizing(int flag)
3156 conf_set_frame_drop_for_resizing(flag);
3159 EAPI int livebox_frame_drop_for_resizing(void)
3161 return conf_frame_drop_for_resizing();
3164 EAPI int livebox_sync_lb_fb(struct livebox *handler)
3166 return fb_sync(lb_get_lb_fb(handler));
3169 EAPI int livebox_sync_pd_fb(struct livebox *handler)
3171 return fb_sync(lb_get_pd_fb(handler));