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 */
26 #include <com-core_packet.h>
28 #include <livebox-service.h>
29 #include <livebox-errno.h>
34 #include "livebox_internal.h"
37 #include "master_rpc.h"
39 #include "critical_log.h"
41 #define EAPI __attribute__((visibility("default")))
42 #define MINIMUM_EVENT s_info.event_filter
49 struct dlist *livebox_list;
50 struct dlist *event_list;
51 struct dlist *fault_list;
53 int prevent_overwrite;
60 .prevent_overwrite = 0,
61 .event_filter = 0.01f,
70 int (*handler)(struct livebox *handler, enum livebox_event_type event, void *data);
75 int (*handler)(enum livebox_fault_type event, const char *pkgname, const char *filename, const char *func, void *data);
79 static inline void default_create_cb(struct livebox *handler, int ret, void *data)
81 DbgPrint("Default created event handler: %d\n", ret);
84 static inline void default_delete_cb(struct livebox *handler, int ret, void *data)
86 DbgPrint("Default deleted event handler: %d\n", ret);
89 static inline void default_pinup_cb(struct livebox *handler, int ret, void *data)
91 DbgPrint("Default pinup event handler: %d\n", ret);
94 static inline void default_group_changed_cb(struct livebox *handler, int ret, void *data)
96 DbgPrint("Default group changed event handler: %d\n", ret);
99 static inline void default_period_changed_cb(struct livebox *handler, int ret, void *data)
101 DbgPrint("Default period changed event handler: %d\n", ret);
104 static inline void default_pd_created_cb(struct livebox *handler, int ret, void *data)
106 DbgPrint("Default PD created event handler: %d\n", ret);
109 static inline void default_pd_destroyed_cb(struct livebox *handler, int ret, void *data)
111 DbgPrint("Default PD destroyed event handler: %d\n", ret);
114 static inline void default_lb_size_changed_cb(struct livebox *handler, int ret, void *data)
116 DbgPrint("Default LB size changed event handler: %d\n", ret);
119 static inline void default_update_mode_cb(struct livebox *handler, int ret, void *data)
121 DbgPrint("Default update mode set event handler: %d\n", ret);
124 static inline void default_access_event_cb(struct livebox *handler, int ret, void *data)
126 DbgPrint("Default access event handler: %d\n", ret);
129 static inline __attribute__((always_inline)) struct cb_info *create_cb_info(ret_cb_t cb, void *data)
131 struct cb_info *info;
133 info = malloc(sizeof(*info));
135 CRITICAL_LOG("Heap: %s\n", strerror(errno));
144 static inline void destroy_cb_info(struct cb_info *info)
149 static void update_mode_cb(struct livebox *handler, const struct packet *result, void *data)
154 ret = LB_STATUS_ERROR_FAULT;
156 } else if (packet_get(result, "i", &ret) != 1) {
157 ErrPrint("Invalid argument\n");
158 ret = LB_STATUS_ERROR_INVALID;
163 ErrPrint("Resize request is failed: %d\n", ret);
170 handler->update_mode_cb(handler, ret, handler->update_mode_cbdata);
171 handler->update_mode_cb = NULL;
172 handler->update_mode_cbdata = NULL;
176 static void resize_cb(struct livebox *handler, const struct packet *result, void *data)
181 ret = LB_STATUS_ERROR_FAULT;
183 } else if (packet_get(result, "i", &ret) != 1) {
184 ErrPrint("Invalid argument\n");
185 ret = LB_STATUS_ERROR_INVALID;
191 * In case of resize request,
192 * The livebox handler will not have resized value right after this callback,
193 * It can only get the new size when it makes updates.
195 * So the user can only get the resized value(result) from the first update event
196 * after this request.
199 ErrPrint("Resize request is failed: %d\n", ret);
206 handler->size_changed_cb(handler, ret, handler->size_cbdata);
207 handler->size_changed_cb = NULL;
208 handler->size_cbdata = NULL;
211 static void text_signal_cb(struct livebox *handler, const struct packet *result, void *data)
215 struct cb_info *info = data;
220 destroy_cb_info(info);
223 ret = LB_STATUS_ERROR_FAULT;
224 } else if (packet_get(result, "i", &ret) != 1) {
225 ErrPrint("Invalid argument\n");
226 ret = LB_STATUS_ERROR_INVALID;
230 cb(handler, ret, cbdata);
235 static void set_group_ret_cb(struct livebox *handler, const struct packet *result, void *data)
240 ret = LB_STATUS_ERROR_FAULT;
242 } else if (packet_get(result, "i", &ret) != 1) {
243 ErrPrint("Invalid argument\n");
244 ret = LB_STATUS_ERROR_INVALID;
255 handler->group_changed_cb(handler, ret, handler->group_cbdata);
256 handler->group_changed_cb = NULL;
257 handler->group_cbdata = NULL;
260 static void period_ret_cb(struct livebox *handler, const struct packet *result, void *data)
265 ret = LB_STATUS_ERROR_FAULT;
267 } else if (packet_get(result, "i", &ret) != 1) {
268 ErrPrint("Invalid argument\n");
269 ret = LB_STATUS_ERROR_INVALID;
280 handler->period_changed_cb(handler, ret, handler->period_cbdata);
281 handler->period_changed_cb = NULL;
282 handler->period_cbdata = NULL;
285 static void del_ret_cb(struct livebox *handler, const struct packet *result, void *data)
287 struct cb_info *info = data;
294 destroy_cb_info(info);
297 ErrPrint("Connection lost?\n");
298 ret = LB_STATUS_ERROR_FAULT;
299 } else if (packet_get(result, "i", &ret) != 1) {
300 ErrPrint("Invalid argument\n");
301 ret = LB_STATUS_ERROR_INVALID;
305 handler->deleted_cb = cb;
306 handler->deleted_cbdata = cbdata;
308 cb(handler, ret, cbdata);
313 * Do not call the deleted callback from here.
314 * master will send the "deleted" event.
315 * Then invoke this callback.
317 * if (handler->deleted_cb)
318 * handler->deleted_cb(handler, ret, handler->deleted_cbdata);
322 static void new_ret_cb(struct livebox *handler, const struct packet *result, void *data)
325 struct cb_info *info = data;
331 destroy_cb_info(info);
334 ret = LB_STATUS_ERROR_FAULT;
335 } else if (packet_get(result, "i", &ret) != 1) {
336 ret = LB_STATUS_ERROR_INVALID;
340 handler->created_cb = cb;
341 handler->created_cbdata = cbdata;
345 * Don't go anymore ;)
351 * It means the current instance is not created,
352 * so user has to know about this.
353 * notice it to user using "deleted" event.
355 cb(handler, ret, cbdata);
361 static void pd_create_cb(struct livebox *handler, const struct packet *result, void *data)
366 ret = LB_STATUS_ERROR_FAULT;
368 } else if (packet_get(result, "i", &ret) != 1) {
369 ret = LB_STATUS_ERROR_INVALID;
374 ErrPrint("Failed to create a PD[%d]\n", ret);
381 handler->pd_created_cb(handler, ret, handler->pd_created_cbdata);
382 handler->pd_created_cb = NULL;
383 handler->pd_created_cbdata = NULL;
386 static void activated_cb(struct livebox *handler, const struct packet *result, void *data)
389 struct cb_info *info = data;
392 const char *pkgname = "";
396 destroy_cb_info(info);
399 ret = LB_STATUS_ERROR_FAULT;
400 } else if (packet_get(result, "is", &ret, &pkgname) != 2) {
401 ret = LB_STATUS_ERROR_INVALID;
405 cb(handler, ret, cbdata);
409 static void pd_destroy_cb(struct livebox *handler, const struct packet *result, void *data)
414 struct cb_info *info = data;
418 destroy_cb_info(info);
421 ErrPrint("Result is NIL (may connection lost)\n");
422 ret = LB_STATUS_ERROR_FAULT;
423 } else if (packet_get(result, "i", &ret) != 1) {
424 ErrPrint("Invalid parameter\n");
425 ret = LB_STATUS_ERROR_INVALID;
429 handler->pd_destroyed_cb = cb;
430 handler->pd_destroyed_cbdata = cbdata;
432 handler->is_pd_created = 0;
433 cb(handler, ret, cbdata);
437 static void delete_cluster_cb(struct livebox *handler, const struct packet *result, void *data)
439 struct cb_info *info = data;
446 destroy_cb_info(info);
449 ret = LB_STATUS_ERROR_FAULT;
450 } else if (packet_get(result, "i", &ret) != 1) {
451 ret = LB_STATUS_ERROR_INVALID;
455 cb(handler, ret, cbdata);
459 static void delete_category_cb(struct livebox *handler, const struct packet *result, void *data)
461 struct cb_info *info = data;
468 destroy_cb_info(info);
471 ret = LB_STATUS_ERROR_FAULT;
472 } else if (packet_get(result, "i", &ret) != 1) {
473 ret = LB_STATUS_ERROR_INVALID;
477 cb(handler, ret, cbdata);
481 static void lb_pixmap_acquired_cb(struct livebox *handler, const struct packet *result, void *data)
487 struct cb_info *info = data;
491 destroy_cb_info(info);
494 pixmap = 0; /* PIXMAP 0 means error */
495 } else if (packet_get(result, "ii", &pixmap, &ret) != 2) {
499 if (ret == LB_STATUS_ERROR_BUSY) {
500 ret = livebox_acquire_lb_pixmap(handler, cb, cbdata);
501 DbgPrint("Busy, Try again: %d\n", ret);
505 cb(handler, pixmap, cbdata);
510 static void pd_pixmap_acquired_cb(struct livebox *handler, const struct packet *result, void *data)
516 struct cb_info *info = data;
520 destroy_cb_info(info);
523 pixmap = 0; /* PIXMAP 0 means error */
524 ret = LB_STATUS_ERROR_FAULT;
525 } else if (packet_get(result, "ii", &pixmap, &ret) != 2) {
527 ret = LB_STATUS_ERROR_INVALID;
530 if (ret == LB_STATUS_ERROR_BUSY) {
531 ret = livebox_acquire_pd_pixmap(handler, cb, cbdata);
532 DbgPrint("Busy, Try again: %d\n", ret);
536 DbgPrint("ret: %d, pixmap: %d\n", ret, pixmap);
537 cb(handler, pixmap, cbdata);
542 static void pinup_done_cb(struct livebox *handler, const struct packet *result, void *data)
547 ret = LB_STATUS_ERROR_FAULT;
549 } else if (packet_get(result, "i", &ret) != 1) {
560 handler->pinup_cb(handler, ret, handler->pinup_cbdata);
561 handler->pinup_cb = NULL;
562 handler->pinup_cbdata = NULL;
565 static void access_ret_cb(struct livebox *handler, const struct packet *result, void *data)
570 ret = LB_STATUS_ERROR_FAULT;
574 if (packet_get(result, "i", &ret) != 1) {
575 ret = LB_STATUS_ERROR_INVALID;
579 if (ret != LB_STATUS_SUCCESS) {
586 handler->access_event_cb(handler, ret, handler->access_event_cbdata);
587 handler->access_event_cb = NULL;
588 handler->access_event_cbdata = NULL;
592 static int send_access_event(struct livebox *handler, const char *event, int x, int y)
594 struct packet *packet;
597 timestamp = util_timestamp();
599 packet = packet_create(event, "ssdii", handler->pkgname, handler->id, timestamp, x, y);
601 ErrPrint("Failed to build packet\n");
602 return LB_STATUS_ERROR_FAULT;
605 return master_rpc_async_request(handler, packet, 0, access_ret_cb, NULL);
608 static int send_mouse_event(struct livebox *handler, const char *event, int x, int y)
610 struct packet *packet;
613 timestamp = util_timestamp();
614 packet = packet_create_noack(event, "ssdii", handler->pkgname, handler->id, timestamp, x, y);
616 ErrPrint("Failed to build param\n");
617 return LB_STATUS_ERROR_FAULT;
620 return master_rpc_request_only(handler, packet);
623 EAPI int livebox_init(void *disp)
627 if (s_info.init_count > 0) {
629 return LB_STATUS_SUCCESS;
631 env = getenv("PROVIDER_DISABLE_PREVENT_OVERWRITE");
632 if (env && !strcasecmp(env, "true")) {
633 s_info.prevent_overwrite = 1;
636 env = getenv("PROVIDER_EVENT_FILTER");
638 sscanf(env, "%lf", &MINIMUM_EVENT);
642 char filename[BUFSIZ];
643 snprintf(filename, sizeof(filename), "/tmp/%d.box.log", getpid());
644 __file_log_fp = fopen(filename, "w+t");
645 if (!__file_log_fp) {
646 __file_log_fp = fdopen(1, "w+t");
649 critical_log_init("viewer");
650 livebox_service_init();
656 return LB_STATUS_SUCCESS;
659 EAPI int livebox_fini(void)
661 if (s_info.init_count <= 0) {
662 ErrPrint("Doesn't initialized\n");
663 return LB_STATUS_ERROR_INVALID;
667 if (s_info.init_count > 0) {
668 ErrPrint("init count : %d\n", s_info.init_count);
669 return LB_STATUS_SUCCESS;
674 livebox_service_fini();
676 return LB_STATUS_SUCCESS;
679 static inline char *lb_pkgname(const char *pkgname)
683 lb = livebox_service_pkgname(pkgname);
685 if (util_validate_livebox_package(pkgname) == 0) {
686 return strdup(pkgname);
694 * Just wrapping the livebox_add_with_size function.
696 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)
698 return livebox_add_with_size(pkgname, content, cluster, category, period, LB_SIZE_TYPE_UNKNOWN, cb, data);
701 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)
703 struct livebox *handler;
704 struct packet *packet;
708 struct cb_info *cbinfo;
710 if (!pkgname || !cluster || !category) {
711 ErrPrint("Invalid arguments: pkgname[%p], cluster[%p], category[%p]\n",
712 pkgname, cluster, category);
716 if (type != LB_SIZE_TYPE_UNKNOWN) {
717 livebox_service_get_size(type, &width, &height);
720 handler = calloc(1, sizeof(*handler));
722 ErrPrint("Error: %s\n", strerror(errno));
726 handler->pkgname = lb_pkgname(pkgname);
727 if (!handler->pkgname) {
732 if (livebox_service_is_enabled(handler->pkgname) == 0) {
733 DbgPrint("Livebox [%s](%s) is disabled package\n", handler->pkgname, pkgname);
734 free(handler->pkgname);
740 handler->content = strdup(content);
741 if (!handler->content) {
742 ErrPrint("Error: %s\n", strerror(errno));
743 free(handler->pkgname);
748 handler->content = livebox_service_content(handler->pkgname);
751 handler->cluster = strdup(cluster);
752 if (!handler->cluster) {
753 ErrPrint("Error: %s\n", strerror(errno));
754 free(handler->content);
755 free(handler->pkgname);
760 handler->category = strdup(category);
761 if (!handler->category) {
762 ErrPrint("Error: %s\n", strerror(errno));
763 free(handler->cluster);
764 free(handler->content);
765 free(handler->pkgname);
771 cb = default_create_cb;
774 /* Data provider will set this */
775 handler->lb.type = _LB_TYPE_FILE;
776 handler->pd.type = _PD_TYPE_SCRIPT;
777 handler->lb.period = period;
779 /* Used for handling the mouse event on a box */
780 handler->lb.mouse_event = livebox_service_mouse_event(handler->pkgname);
782 /* Cluster infomration is not determined yet */
783 handler->nr_of_sizes = 0x01;
785 handler->timestamp = util_timestamp();
786 handler->is_user = 1;
787 handler->visible = LB_SHOW;
789 s_info.livebox_list = dlist_append(s_info.livebox_list, handler);
791 packet = packet_create("new", "dssssdii", handler->timestamp, handler->pkgname, handler->content, cluster, category, period, width, height);
793 ErrPrint("Failed to create a new packet\n");
794 free(handler->category);
795 free(handler->cluster);
796 free(handler->content);
797 free(handler->pkgname);
802 cbinfo = create_cb_info(cb, data);
804 ErrPrint("Failed to create a cbinfo\n");
805 packet_destroy(packet);
806 free(handler->category);
807 free(handler->cluster);
808 free(handler->content);
809 free(handler->pkgname);
814 ret = master_rpc_async_request(handler, packet, 0, new_ret_cb, cbinfo);
816 ErrPrint("Failed to send a new packet\n");
817 destroy_cb_info(cbinfo);
818 free(handler->category);
819 free(handler->cluster);
820 free(handler->content);
821 free(handler->pkgname);
826 handler->state = CREATE;
827 return lb_ref(handler);
830 EAPI double livebox_period(struct livebox *handler)
832 if (!handler || handler->state != CREATE || !handler->id) {
833 ErrPrint("Handler is not valid\n");
837 return handler->lb.period;
840 EAPI int livebox_set_period(struct livebox *handler, double period, ret_cb_t cb, void *data)
842 struct packet *packet;
845 if (!handler || handler->state != CREATE || !handler->id) {
846 ErrPrint("Handler is not valid\n");
847 return LB_STATUS_ERROR_INVALID;
850 if (handler->period_changed_cb) {
851 ErrPrint("Previous request for changing period is not finished\n");
852 return LB_STATUS_ERROR_BUSY;
855 if (!handler->is_user) {
856 ErrPrint("CA Livebox is not able to change the period\n");
857 return LB_STATUS_ERROR_PERMISSION;
860 if (handler->lb.period == period) {
861 DbgPrint("No changes\n");
862 return LB_STATUS_ERROR_ALREADY;
865 packet = packet_create("set_period", "ssd", handler->pkgname, handler->id, period);
867 ErrPrint("Failed to build a packet %s\n", handler->pkgname);
868 return LB_STATUS_ERROR_FAULT;
872 cb = default_period_changed_cb;
875 ret = master_rpc_async_request(handler, packet, 0, period_ret_cb, NULL);
876 if (ret == LB_STATUS_SUCCESS) {
877 handler->period_changed_cb = cb;
878 handler->period_cbdata = data;
884 EAPI int livebox_del(struct livebox *handler, ret_cb_t cb, void *data)
887 ErrPrint("Handler is NIL\n");
888 return LB_STATUS_ERROR_INVALID;
891 if (handler->state != CREATE) {
892 ErrPrint("Handler is already deleted\n");
893 return LB_STATUS_ERROR_INVALID;
896 handler->state = DELETE;
901 * The id is not determined yet.
902 * It means a user didn't receive created event yet.
903 * Then just stop to delete procedure from here.
904 * Because the "created" event handler will release this.
905 * By the way, if the user adds any callback for getting return status of this,
909 cb(handler, 0, data);
911 return LB_STATUS_SUCCESS;
915 cb = default_delete_cb;
918 return lb_send_delete(handler, cb, data);
921 EAPI int livebox_set_fault_handler(int (*cb)(enum livebox_fault_type, const char *, const char *, const char *, void *), void *data)
923 struct fault_info *info;
926 return LB_STATUS_ERROR_INVALID;
929 info = malloc(sizeof(*info));
931 CRITICAL_LOG("Heap: %s\n", strerror(errno));
932 return LB_STATUS_ERROR_MEMORY;
936 info->user_data = data;
938 s_info.fault_list = dlist_append(s_info.fault_list, info);
939 return LB_STATUS_SUCCESS;
942 EAPI void *livebox_unset_fault_handler(int (*cb)(enum livebox_fault_type, const char *, const char *, const char *, void *))
944 struct fault_info *info;
947 dlist_foreach(s_info.fault_list, l, info) {
948 if (info->handler == cb) {
951 s_info.fault_list = dlist_remove(s_info.fault_list, l);
952 data = info->user_data;
962 EAPI int livebox_set_event_handler(int (*cb)(struct livebox *, enum livebox_event_type, void *), void *data)
964 struct event_info *info;
967 ErrPrint("Invalid argument cb is nil\n");
968 return LB_STATUS_ERROR_INVALID;
971 info = malloc(sizeof(*info));
973 CRITICAL_LOG("Heap: %s\n", strerror(errno));
974 return LB_STATUS_ERROR_MEMORY;
978 info->user_data = data;
980 s_info.event_list = dlist_append(s_info.event_list, info);
981 return LB_STATUS_SUCCESS;
984 EAPI void *livebox_unset_event_handler(int (*cb)(struct livebox *, enum livebox_event_type, void *))
986 struct event_info *info;
989 dlist_foreach(s_info.event_list, l, info) {
990 if (info->handler == cb) {
993 s_info.event_list = dlist_remove(s_info.event_list, l);
994 data = info->user_data;
1004 EAPI int livebox_set_update_mode(struct livebox *handler, int active_update, ret_cb_t cb, void *data)
1006 struct packet *packet;
1010 ErrPrint("Handler is NIL\n");
1011 return LB_STATUS_ERROR_INVALID;
1014 if (handler->state != CREATE || !handler->id) {
1015 return LB_STATUS_ERROR_INVALID;
1018 if (handler->update_mode_cb) {
1019 ErrPrint("Previous update_mode cb is not finished yet\n");
1020 return LB_STATUS_ERROR_BUSY;
1023 if (handler->is_active_update == active_update) {
1024 return LB_STATUS_ERROR_ALREADY;
1027 if (!handler->is_user) {
1028 return LB_STATUS_ERROR_PERMISSION;
1031 packet = packet_create("update_mode", "ssi", handler->pkgname, handler->id, active_update);
1033 return LB_STATUS_ERROR_FAULT;
1037 cb = default_update_mode_cb;
1040 ret = master_rpc_async_request(handler, packet, 0, update_mode_cb, NULL);
1041 if (ret == LB_STATUS_SUCCESS) {
1042 handler->update_mode_cb = cb;
1043 handler->update_mode_cbdata = data;
1049 EAPI int livebox_is_active_update(struct livebox *handler)
1052 ErrPrint("Handler is NIL\n");
1053 return LB_STATUS_ERROR_INVALID;
1056 if (handler->state != CREATE || !handler->id) {
1057 return LB_STATUS_ERROR_INVALID;
1060 return handler->is_active_update;
1063 EAPI int livebox_resize(struct livebox *handler, int type, ret_cb_t cb, void *data)
1065 struct packet *packet;
1071 ErrPrint("Handler is NIL\n");
1072 return LB_STATUS_ERROR_INVALID;
1075 if (handler->state != CREATE || !handler->id) {
1076 ErrPrint("Handler is not valid\n");
1077 return LB_STATUS_ERROR_INVALID;
1080 if (handler->size_changed_cb) {
1081 ErrPrint("Previous resize request is not finished yet\n");
1082 return LB_STATUS_ERROR_BUSY;
1085 if (!handler->is_user) {
1086 ErrPrint("CA Livebox is not able to be resized\n");
1087 return LB_STATUS_ERROR_PERMISSION;
1090 if (livebox_service_get_size(type, &w, &h) != 0) {
1091 ErrPrint("Invalid size type\n");
1092 return LB_STATUS_ERROR_INVALID;
1095 if (handler->lb.width == w && handler->lb.height == h) {
1096 DbgPrint("No changes\n");
1097 return LB_STATUS_ERROR_ALREADY;;
1100 packet = packet_create("resize", "ssii", handler->pkgname, handler->id, w, h);
1102 ErrPrint("Failed to build param\n");
1103 return LB_STATUS_ERROR_FAULT;
1107 cb = default_lb_size_changed_cb;
1110 ret = master_rpc_async_request(handler, packet, 0, resize_cb, NULL);
1111 if (ret == LB_STATUS_SUCCESS) {
1112 handler->size_changed_cb = cb;
1113 handler->size_cbdata = data;
1119 EAPI int livebox_click(struct livebox *handler, double x, double y)
1121 struct packet *packet;
1125 timestamp = util_timestamp();
1128 ErrPrint("Handler is NIL\n");
1129 return LB_STATUS_ERROR_INVALID;
1132 if (handler->state != CREATE || !handler->id) {
1133 ErrPrint("Handler is not valid\n");
1134 return LB_STATUS_ERROR_INVALID;
1137 if (handler->lb.auto_launch) {
1138 DbgPrint("AUTO_LAUNCH [%s]\n", handler->lb.auto_launch);
1139 if (aul_launch_app(handler->lb.auto_launch, NULL) < 0) {
1140 ErrPrint("Failed to launch app %s\n", handler->lb.auto_launch);
1144 packet = packet_create_noack("clicked", "sssddd", handler->pkgname, handler->id, "clicked", timestamp, x, y);
1146 ErrPrint("Failed to build param\n");
1147 return LB_STATUS_ERROR_FAULT;
1150 DbgPrint("CLICKED: %lf\n", timestamp);
1151 ret = master_rpc_request_only(handler, packet);
1153 if (!handler->lb.mouse_event && (handler->lb.type == _LB_TYPE_BUFFER || handler->lb.type == _LB_TYPE_SCRIPT)) {
1154 int ret; /* Shadow variable */
1155 ret = send_mouse_event(handler, "lb_mouse_down", x * handler->lb.width, y * handler->lb.height);
1157 ErrPrint("Failed to send Down: %d\n", ret);
1160 ret = send_mouse_event(handler, "lb_mouse_move", x * handler->lb.width, y * handler->lb.height);
1162 ErrPrint("Failed to send Move: %d\n", ret);
1165 ret = send_mouse_event(handler, "lb_mouse_up", x * handler->lb.width, y * handler->lb.height);
1167 ErrPrint("Failed to send Up: %d\n", ret);
1174 EAPI int livebox_has_pd(struct livebox *handler)
1177 ErrPrint("Handler is NIL\n");
1178 return LB_STATUS_ERROR_INVALID;
1181 if (handler->state != CREATE || !handler->id) {
1182 ErrPrint("Handler is not valid\n");
1183 return LB_STATUS_ERROR_INVALID;
1186 return !!handler->pd.data.fb;
1189 EAPI int livebox_pd_is_created(struct livebox *handler)
1192 ErrPrint("Handler is NIL\n");
1193 return LB_STATUS_ERROR_INVALID;
1196 if (!handler->pd.data.fb || handler->state != CREATE || !handler->id) {
1197 ErrPrint("Handler is not valid\n");
1198 return LB_STATUS_ERROR_INVALID;
1201 return handler->is_pd_created;
1204 EAPI int livebox_create_pd(struct livebox *handler, ret_cb_t cb, void *data)
1206 return livebox_create_pd_with_position(handler, -1.0, -1.0, cb, data);
1209 EAPI int livebox_create_pd_with_position(struct livebox *handler, double x, double y, ret_cb_t cb, void *data)
1211 struct packet *packet;
1215 ErrPrint("Handler is NIL\n");
1216 return LB_STATUS_ERROR_INVALID;
1219 if (!handler->pd.data.fb || handler->state != CREATE || !handler->id) {
1220 ErrPrint("Handler is not valid\n");
1221 return LB_STATUS_ERROR_INVALID;
1224 if (handler->is_pd_created == 1) {
1225 DbgPrint("PD already created\n");
1226 return LB_STATUS_SUCCESS;
1229 if (handler->pd_created_cb) {
1230 ErrPrint("Previous request is not completed yet\n");
1231 return LB_STATUS_ERROR_BUSY;
1234 packet = packet_create("create_pd", "ssdd", handler->pkgname, handler->id, x, y);
1236 ErrPrint("Failed to build param\n");
1237 return LB_STATUS_ERROR_FAULT;
1241 cb = default_pd_created_cb;
1244 DbgPrint("PERF_DBOX\n");
1245 ret = master_rpc_async_request(handler, packet, 0, pd_create_cb, NULL);
1246 if (ret == LB_STATUS_SUCCESS) {
1247 handler->pd_created_cb = cb;
1248 handler->pd_created_cbdata = data;
1254 EAPI int livebox_move_pd(struct livebox *handler, double x, double y)
1256 struct packet *packet;
1259 ErrPrint("Handler is NIL\n");
1260 return LB_STATUS_ERROR_INVALID;
1263 if (!handler->pd.data.fb || handler->state != CREATE || !handler->id) {
1264 ErrPrint("Handler is not valid\n");
1265 return LB_STATUS_ERROR_INVALID;
1268 if (!handler->is_pd_created) {
1269 ErrPrint("PD is not created\n");
1270 return LB_STATUS_ERROR_INVALID;
1273 packet = packet_create_noack("pd_move", "ssdd", handler->pkgname, handler->id, x, y);
1275 ErrPrint("Failed to build param\n");
1276 return LB_STATUS_ERROR_FAULT;
1279 return master_rpc_request_only(handler, packet);
1282 EAPI int livebox_activate(const char *pkgname, ret_cb_t cb, void *data)
1284 struct packet *packet;
1285 struct cb_info *cbinfo;
1289 return LB_STATUS_ERROR_INVALID;
1292 packet = packet_create("activate_package", "s", pkgname);
1294 ErrPrint("Failed to build a param\n");
1295 return LB_STATUS_ERROR_FAULT;
1298 cbinfo = create_cb_info(cb, data);
1300 ErrPrint("Unable to create cbinfo\n");
1301 packet_destroy(packet);
1302 return LB_STATUS_ERROR_FAULT;
1305 ret = master_rpc_async_request(NULL, packet, 0, activated_cb, cbinfo);
1307 destroy_cb_info(cbinfo);
1313 EAPI int livebox_destroy_pd(struct livebox *handler, ret_cb_t cb, void *data)
1315 struct packet *packet;
1316 struct cb_info *cbinfo;
1320 ErrPrint("Handler is NIL\n");
1321 return LB_STATUS_ERROR_INVALID;
1324 if (!handler->pd.data.fb || handler->state != CREATE || !handler->id) {
1325 ErrPrint("Handler is not valid\n");
1326 return LB_STATUS_ERROR_INVALID;
1329 if (!handler->is_pd_created && !handler->pd_created_cb) {
1330 ErrPrint("PD is not created\n");
1331 return LB_STATUS_ERROR_INVALID;
1334 packet = packet_create("destroy_pd", "ss", handler->pkgname, handler->id);
1336 ErrPrint("Failed to build a param\n");
1337 return LB_STATUS_ERROR_FAULT;
1341 cb = default_pd_destroyed_cb;
1344 cbinfo = create_cb_info(cb, data);
1346 packet_destroy(packet);
1347 return LB_STATUS_ERROR_FAULT;
1350 ret = master_rpc_async_request(handler, packet, 0, pd_destroy_cb, cbinfo);
1352 destroy_cb_info(cbinfo);
1358 EAPI int livebox_access_event(struct livebox *handler, enum access_event_type type, double x, double y, ret_cb_t cb, void *data)
1362 char cmd[32] = { '\0', };
1367 ErrPrint("Handler is NIL\n");
1368 return LB_STATUS_ERROR_INVALID;
1371 if (handler->state != CREATE || !handler->id) {
1372 ErrPrint("Handler is not valid\n");
1373 return LB_STATUS_ERROR_INVALID;
1376 if (handler->access_event_cb) {
1377 ErrPrint("Previous access event is not yet done\n");
1378 return LB_STATUS_ERROR_BUSY;
1381 if (type & ACCESS_EVENT_PD_MASK) {
1382 if (!handler->is_pd_created) {
1383 ErrPrint("PD is not created\n");
1384 return LB_STATUS_ERROR_INVALID;
1388 w = handler->pd.width;
1389 h = handler->pd.height;
1390 } else if (type & ACCESS_EVENT_LB_MASK) {
1393 w = handler->lb.width;
1394 h = handler->lb.height;
1396 ErrPrint("Invalid event type\n");
1397 return LB_STATUS_ERROR_INVALID;
1400 switch (type & ~ACCESS_EVENT_PD_MASK) {
1401 case ACCESS_EVENT_HIGHLIGHT:
1402 strcpy(ptr, "_access_hl");
1404 case ACCESS_EVENT_HIGHLIGHT_NEXT:
1405 strcpy(ptr, "_access_hl_next");
1407 case ACCESS_EVENT_HIGHLIGHT_PREV:
1408 strcpy(ptr, "_access_hl_prev");
1410 case ACCESS_EVENT_ACTIVATE:
1411 strcpy(ptr, "_access_activate");
1413 case ACCESS_EVENT_ACTION_DOWN:
1414 strcpy(ptr, "_access_action_down");
1416 case ACCESS_EVENT_ACTION_UP:
1417 strcpy(ptr, "_access_action_up");
1419 case ACCESS_EVENT_UNHIGHLIGHT:
1420 strcpy(ptr, "_access_unhighlight");
1422 case ACCESS_EVENT_SCROLL_DOWN:
1423 strcpy(ptr, "_access_scroll_down");
1425 case ACCESS_EVENT_SCROLL_MOVE:
1426 strcpy(ptr, "_access_scroll_move");
1428 case ACCESS_EVENT_SCROLL_UP:
1429 strcpy(ptr, "_access_scroll_up");
1432 return LB_STATUS_ERROR_INVALID;
1436 cb = default_access_event_cb;
1439 ret = send_access_event(handler, cmd, x * w, y * h);
1440 if (ret == LB_STATUS_SUCCESS) {
1441 handler->access_event_cb = cb;
1442 handler->access_event_cbdata = data;
1448 EAPI int livebox_content_event(struct livebox *handler, enum content_event_type type, double x, double y)
1452 char cmd[32] = { '\0', };
1456 ErrPrint("Handler is NIL\n");
1457 return LB_STATUS_ERROR_INVALID;
1460 if (handler->state != CREATE || !handler->id) {
1461 ErrPrint("Handler is not valid\n");
1462 return LB_STATUS_ERROR_INVALID;
1465 if (type & CONTENT_EVENT_PD_MASK) {
1468 if (!handler->is_pd_created) {
1469 ErrPrint("PD is not created\n");
1470 return LB_STATUS_ERROR_INVALID;
1473 if (type & CONTENT_EVENT_MOUSE_MASK) {
1474 if (!handler->pd.data.fb) {
1475 ErrPrint("Handler is not valid\n");
1476 return LB_STATUS_ERROR_INVALID;
1479 if (type & CONTENT_EVENT_MOUSE_MOVE) {
1480 if (fabs(x - handler->pd.x) < MINIMUM_EVENT && fabs(y - handler->pd.y) < MINIMUM_EVENT) {
1481 return LB_STATUS_ERROR_BUSY;
1483 } else if (type & CONTENT_EVENT_MOUSE_SET) {
1489 w = handler->pd.width;
1490 h = handler->pd.height;
1496 } else if (type & CONTENT_EVENT_LB_MASK) {
1499 if (type & CONTENT_EVENT_MOUSE_MASK) {
1500 if (!handler->lb.mouse_event) {
1501 return LB_STATUS_ERROR_INVALID;
1504 if (!handler->lb.data.fb) {
1505 ErrPrint("Handler is not valid\n");
1506 return LB_STATUS_ERROR_INVALID;
1509 if (type & CONTENT_EVENT_MOUSE_MOVE) {
1510 if (fabs(x - handler->lb.x) < MINIMUM_EVENT && fabs(y - handler->lb.y) < MINIMUM_EVENT) {
1511 return LB_STATUS_ERROR_BUSY;
1513 } else if (type & CONTENT_EVENT_MOUSE_SET) {
1519 w = handler->lb.width;
1520 h = handler->lb.height;
1527 ErrPrint("Invalid event type\n");
1528 return LB_STATUS_ERROR_INVALID;
1532 * Must be short than 29 bytes.
1534 switch ((type & ~(CONTENT_EVENT_PD_MASK | CONTENT_EVENT_LB_MASK))) {
1535 case CONTENT_EVENT_MOUSE_ENTER | CONTENT_EVENT_MOUSE_MASK:
1536 strcpy(ptr, "_mouse_enter");
1538 case CONTENT_EVENT_MOUSE_LEAVE | CONTENT_EVENT_MOUSE_MASK:
1539 strcpy(ptr, "_mouse_leave");
1541 case CONTENT_EVENT_MOUSE_UP | CONTENT_EVENT_MOUSE_MASK:
1542 strcpy(ptr, "_mouse_up");
1544 case CONTENT_EVENT_MOUSE_DOWN | CONTENT_EVENT_MOUSE_MASK:
1545 strcpy(ptr, "_mouse_down");
1547 case CONTENT_EVENT_MOUSE_MOVE | CONTENT_EVENT_MOUSE_MASK:
1548 strcpy(ptr, "_mouse_move");
1550 case CONTENT_EVENT_MOUSE_SET | CONTENT_EVENT_MOUSE_MASK:
1551 strcpy(ptr, "_mouse_set");
1553 case CONTENT_EVENT_MOUSE_UNSET | CONTENT_EVENT_MOUSE_MASK:
1554 strcpy(ptr, "_mouse_unset");
1556 case CONTENT_EVENT_KEY_DOWN | CONTENT_EVENT_KEY_MASK:
1557 strcpy(ptr, "_key_down");
1559 case CONTENT_EVENT_KEY_UP | CONTENT_EVENT_KEY_MASK:
1560 strcpy(ptr, "_key_up");
1563 ErrPrint("Invalid event type\n");
1564 return LB_STATUS_ERROR_INVALID;
1567 return send_mouse_event(handler, cmd, x * w, y * h);
1570 EAPI const char *livebox_filename(struct livebox *handler)
1573 ErrPrint("Handler is NIL\n");
1577 if (handler->state != CREATE || !handler->id) {
1578 ErrPrint("Handler is not valid\n");
1582 if (handler->filename) {
1583 return handler->filename;
1587 return util_uri_to_path(handler->id);
1590 EAPI int livebox_get_pdsize(struct livebox *handler, int *w, int *h)
1596 ErrPrint("Handler is NIL\n");
1597 return LB_STATUS_ERROR_INVALID;
1600 if (handler->state != CREATE || !handler->id) {
1601 ErrPrint("Handler is not valid\n");
1602 return LB_STATUS_ERROR_INVALID;
1612 if (!handler->is_pd_created) {
1613 *w = handler->pd.default_width;
1614 *h = handler->pd.default_height;
1616 *w = handler->pd.width;
1617 *h = handler->pd.height;
1620 return LB_STATUS_SUCCESS;
1623 EAPI int livebox_size(struct livebox *handler)
1629 ErrPrint("Handler is NIL\n");
1630 return LB_STATUS_ERROR_INVALID;
1633 if (handler->state != CREATE || !handler->id) {
1634 ErrPrint("Handler is not valid\n");
1635 return LB_STATUS_ERROR_INVALID;
1638 w = handler->lb.width;
1639 h = handler->lb.height;
1641 switch (handler->lb.type) {
1642 case _LB_TYPE_BUFFER:
1643 case _LB_TYPE_SCRIPT:
1644 if (!fb_is_created(handler->lb.data.fb)) {
1653 return livebox_service_size_type(w, h);
1656 EAPI int livebox_set_group(struct livebox *handler, const char *cluster, const char *category, ret_cb_t cb, void *data)
1658 struct packet *packet;
1662 ErrPrint("Handler is NIL\n");
1663 return LB_STATUS_ERROR_INVALID;
1666 if (!cluster || !category || handler->state != CREATE || !handler->id) {
1667 ErrPrint("Invalid argument\n");
1668 return LB_STATUS_ERROR_INVALID;
1671 if (handler->group_changed_cb) {
1672 ErrPrint("Previous group changing request is not finished yet\n");
1673 return LB_STATUS_ERROR_BUSY;
1676 if (!handler->is_user) {
1677 ErrPrint("CA Livebox is not able to change the group\n");
1678 return LB_STATUS_ERROR_PERMISSION;
1681 if (!strcmp(handler->cluster, cluster) && !strcmp(handler->category, category)) {
1682 DbgPrint("No changes\n");
1683 return LB_STATUS_ERROR_ALREADY;
1686 packet = packet_create("change_group", "ssss", handler->pkgname, handler->id, cluster, category);
1688 ErrPrint("Failed to build a param\n");
1689 return LB_STATUS_ERROR_FAULT;
1693 cb = default_group_changed_cb;
1696 ret = master_rpc_async_request(handler, packet, 0, set_group_ret_cb, NULL);
1697 if (ret == LB_STATUS_SUCCESS) {
1698 handler->group_changed_cb = cb;
1699 handler->group_cbdata = data;
1705 EAPI int livebox_get_group(struct livebox *handler, char ** const cluster, char ** const category)
1708 ErrPrint("Handler is NIL\n");
1709 return LB_STATUS_ERROR_INVALID;
1712 if (!cluster || !category || handler->state != CREATE || !handler->id) {
1713 ErrPrint("Invalid argument\n");
1714 return LB_STATUS_ERROR_INVALID;
1717 *cluster = handler->cluster;
1718 *category = handler->category;
1719 return LB_STATUS_SUCCESS;
1722 EAPI int livebox_get_supported_sizes(struct livebox *handler, int *cnt, int *size_list)
1727 if (!handler || !size_list) {
1728 ErrPrint("Invalid argument, handler(%p), size_list(%p)\n", handler, size_list);
1729 return LB_STATUS_ERROR_INVALID;
1732 if (!cnt || handler->state != CREATE || !handler->id) {
1733 ErrPrint("Handler is not valid\n");
1734 return LB_STATUS_ERROR_INVALID;
1737 for (j = i = 0; i < NR_OF_SIZE_LIST; i++) {
1738 if (handler->lb.size_list & (0x01 << i)) {
1743 size_list[j++] = (0x01 << i);
1748 return LB_STATUS_SUCCESS;
1751 EAPI const char *livebox_pkgname(struct livebox *handler)
1754 ErrPrint("Handler is NIL\n");
1758 if (handler->state != CREATE) {
1759 ErrPrint("Handler is not valid\n");
1763 return handler->pkgname;
1766 EAPI double livebox_priority(struct livebox *handler)
1769 ErrPrint("Handler is NIL\n");
1773 if (handler->state != CREATE || !handler->id) {
1774 ErrPrint("Handler is not valid (%p)\n", handler);
1778 return handler->lb.priority;
1781 EAPI int livebox_delete_cluster(const char *cluster, ret_cb_t cb, void *data)
1783 struct packet *packet;
1784 struct cb_info *cbinfo;
1787 packet = packet_create("delete_cluster", "s", cluster);
1789 ErrPrint("Failed to build a param\n");
1790 return LB_STATUS_ERROR_FAULT;
1793 cbinfo = create_cb_info(cb, data);
1795 packet_destroy(packet);
1796 return LB_STATUS_ERROR_FAULT;
1799 ret = master_rpc_async_request(NULL, packet, 0, delete_cluster_cb, cbinfo);
1801 destroy_cb_info(cbinfo);
1807 EAPI int livebox_delete_category(const char *cluster, const char *category, ret_cb_t cb, void *data)
1809 struct packet *packet;
1810 struct cb_info *cbinfo;
1813 packet = packet_create("delete_category", "ss", cluster, category);
1815 ErrPrint("Failed to build a param\n");
1816 return LB_STATUS_ERROR_FAULT;
1819 cbinfo = create_cb_info(cb, data);
1821 packet_destroy(packet);
1822 return LB_STATUS_ERROR_FAULT;
1825 ret = master_rpc_async_request(NULL, packet, 0, delete_category_cb, cbinfo);
1827 destroy_cb_info(cbinfo);
1833 EAPI enum livebox_lb_type livebox_lb_type(struct livebox *handler)
1836 ErrPrint("Handler is NIL\n");
1837 return LB_TYPE_INVALID;
1840 if (handler->state != CREATE || !handler->id) {
1841 ErrPrint("Handler is not valid\n");
1842 return LB_TYPE_INVALID;
1845 switch (handler->lb.type) {
1847 return LB_TYPE_IMAGE;
1848 case _LB_TYPE_BUFFER:
1849 case _LB_TYPE_SCRIPT:
1852 id = fb_id(handler->lb.data.fb);
1853 if (id && !strncasecmp(id, SCHEMA_PIXMAP, strlen(SCHEMA_PIXMAP))) {
1854 return LB_TYPE_PIXMAP;
1857 return LB_TYPE_BUFFER;
1859 return LB_TYPE_TEXT;
1864 return LB_TYPE_INVALID;
1867 EAPI enum livebox_pd_type livebox_pd_type(struct livebox *handler)
1870 ErrPrint("Handler is NIL\n");
1871 return PD_TYPE_INVALID;
1874 if (handler->state != CREATE || !handler->id) {
1875 ErrPrint("Handler is not valid\n");
1876 return PD_TYPE_INVALID;
1879 switch (handler->pd.type) {
1881 return PD_TYPE_TEXT;
1882 case _PD_TYPE_BUFFER:
1883 case _PD_TYPE_SCRIPT:
1886 id = fb_id(handler->pd.data.fb);
1887 if (id && !strncasecmp(id, SCHEMA_PIXMAP, strlen(SCHEMA_PIXMAP))) {
1888 return PD_TYPE_PIXMAP;
1891 return PD_TYPE_BUFFER;
1896 return PD_TYPE_INVALID;
1899 EAPI int livebox_set_pd_text_handler(struct livebox *handler, struct livebox_script_operators *ops)
1902 ErrPrint("Handler is NIL\n");
1903 return LB_STATUS_ERROR_INVALID;
1906 if (handler->state != CREATE) {
1907 ErrPrint("Handler is not valid\n");
1908 return LB_STATUS_ERROR_INVALID;
1911 memcpy(&handler->pd.data.ops, ops, sizeof(*ops));
1912 return LB_STATUS_SUCCESS;
1915 EAPI int livebox_set_text_handler(struct livebox *handler, struct livebox_script_operators *ops)
1918 ErrPrint("Handler is NIL\n");
1919 return LB_STATUS_ERROR_INVALID;
1922 if (handler->state != CREATE) {
1923 ErrPrint("Handler is not valid\n");
1924 return LB_STATUS_ERROR_INVALID;
1927 memcpy(&handler->lb.data.ops, ops, sizeof(*ops));
1928 return LB_STATUS_SUCCESS;
1931 EAPI int livebox_acquire_lb_pixmap(struct livebox *handler, ret_cb_t cb, void *data)
1933 struct packet *packet;
1934 struct cb_info *cbinfo;
1939 ErrPrint("Handler is NIL\n");
1940 return LB_STATUS_ERROR_INVALID;
1943 if (handler->state != CREATE || !handler->id) {
1944 ErrPrint("Invalid handle\n");
1945 return LB_STATUS_ERROR_INVALID;
1948 if (handler->lb.type != _LB_TYPE_SCRIPT && handler->lb.type != _LB_TYPE_BUFFER) {
1949 ErrPrint("Handler is not valid type\n");
1950 return LB_STATUS_ERROR_INVALID;
1953 id = fb_id(handler->lb.data.fb);
1954 if (!id || strncasecmp(id, SCHEMA_PIXMAP, strlen(SCHEMA_PIXMAP))) {
1955 return LB_STATUS_ERROR_INVALID;
1958 packet = packet_create("lb_acquire_pixmap", "ss", handler->pkgname, handler->id);
1960 ErrPrint("Failed to build a param\n");
1961 return LB_STATUS_ERROR_FAULT;
1964 cbinfo = create_cb_info(cb, data);
1966 packet_destroy(packet);
1967 return LB_STATUS_ERROR_FAULT;
1970 ret = master_rpc_async_request(handler, packet, 0, lb_pixmap_acquired_cb, cbinfo);
1972 destroy_cb_info(cbinfo);
1978 EAPI int livebox_release_lb_pixmap(struct livebox *handler, int pixmap)
1980 struct packet *packet;
1982 if (!handler || pixmap == 0) {
1983 ErrPrint("Handler is NIL [%d]\n", pixmap);
1984 return LB_STATUS_ERROR_INVALID;
1987 if (handler->state != CREATE || !handler->id) {
1988 ErrPrint("Invalid handle\n");
1989 return LB_STATUS_ERROR_INVALID;
1992 if (handler->lb.type != _LB_TYPE_SCRIPT && handler->lb.type != _LB_TYPE_BUFFER) {
1993 ErrPrint("Handler is not valid type\n");
1994 return LB_STATUS_ERROR_INVALID;
1997 packet = packet_create_noack("lb_release_pixmap", "ssi", handler->pkgname, handler->id, pixmap);
1999 ErrPrint("Failed to build a param\n");
2000 return LB_STATUS_ERROR_INVALID;
2003 return master_rpc_request_only(handler, packet);
2006 EAPI int livebox_acquire_pd_pixmap(struct livebox *handler, ret_cb_t cb, void *data)
2008 struct packet *packet;
2009 struct cb_info *cbinfo;
2014 ErrPrint("Handler is NIL\n");
2015 return LB_STATUS_ERROR_INVALID;
2018 if (handler->state != CREATE || !handler->id) {
2019 ErrPrint("Invalid handle\n");
2020 return LB_STATUS_ERROR_INVALID;
2023 if (handler->pd.type != _PD_TYPE_SCRIPT && handler->pd.type != _PD_TYPE_BUFFER) {
2024 ErrPrint("Handler is not valid type\n");
2025 return LB_STATUS_ERROR_INVALID;
2028 id = fb_id(handler->pd.data.fb);
2029 if (!id || strncasecmp(id, SCHEMA_PIXMAP, strlen(SCHEMA_PIXMAP))) {
2030 return LB_STATUS_ERROR_INVALID;
2033 packet = packet_create("pd_acquire_pixmap", "ss", handler->pkgname, handler->id);
2035 ErrPrint("Failed to build a param\n");
2036 return LB_STATUS_ERROR_FAULT;
2039 cbinfo = create_cb_info(cb, data);
2041 packet_destroy(packet);
2042 return LB_STATUS_ERROR_FAULT;
2045 ret = master_rpc_async_request(handler, packet, 0, pd_pixmap_acquired_cb, cbinfo);
2047 destroy_cb_info(cbinfo);
2053 EAPI int livebox_pd_pixmap(const struct livebox *handler)
2059 ErrPrint("Handler is NIL\n");
2063 if (handler->state != CREATE || !handler->id) {
2064 ErrPrint("Invalid handler\n");
2068 if (handler->pd.type != _PD_TYPE_SCRIPT && handler->pd.type != _PD_TYPE_BUFFER) {
2069 ErrPrint("Invalid handler\n");
2073 id = fb_id(handler->pd.data.fb);
2074 if (id && sscanf(id, SCHEMA_PIXMAP "%d", &pixmap) != 1) {
2075 ErrPrint("PIXMAP Id is not valid\n");
2082 EAPI int livebox_lb_pixmap(const struct livebox *handler)
2088 ErrPrint("Handler is NIL\n");
2092 if (handler->state != CREATE || !handler->id) {
2093 ErrPrint("Invalid handler\n");
2097 if (handler->lb.type != _LB_TYPE_SCRIPT && handler->lb.type != _LB_TYPE_BUFFER) {
2098 ErrPrint("Invalid handler\n");
2102 id = fb_id(handler->lb.data.fb);
2103 if (id && sscanf(id, SCHEMA_PIXMAP "%d", &pixmap) != 1) {
2104 ErrPrint("PIXMAP Id is not valid\n");
2111 EAPI int livebox_release_pd_pixmap(struct livebox *handler, int pixmap)
2113 struct packet *packet;
2115 if (!handler || pixmap == 0) {
2116 ErrPrint("Handler is NIL [%d]\n", pixmap);
2117 return LB_STATUS_ERROR_INVALID;
2120 if (handler->state != CREATE || !handler->id) {
2121 ErrPrint("Invalid handle\n");
2122 return LB_STATUS_ERROR_INVALID;
2125 if (handler->pd.type != _PD_TYPE_SCRIPT && handler->pd.type != _PD_TYPE_BUFFER) {
2126 ErrPrint("Handler is not valid type\n");
2127 return LB_STATUS_ERROR_INVALID;
2130 packet = packet_create_noack("pd_release_pixmap", "ssi", handler->pkgname, handler->id, pixmap);
2132 ErrPrint("Failed to build a param\n");
2133 return LB_STATUS_ERROR_FAULT;
2136 return master_rpc_request_only(handler, packet);
2139 EAPI void *livebox_acquire_fb(struct livebox *handler)
2142 ErrPrint("Handler is NIL\n");
2146 if (handler->state != CREATE || !handler->id) {
2147 ErrPrint("Invalid handle\n");
2151 if (handler->lb.type != _LB_TYPE_SCRIPT && handler->lb.type != _LB_TYPE_BUFFER) {
2152 ErrPrint("Handler is not valid type\n");
2156 return fb_acquire_buffer(handler->lb.data.fb);
2159 EAPI int livebox_release_fb(void *buffer)
2161 return fb_release_buffer(buffer);
2164 EAPI int livebox_fb_refcnt(void *buffer)
2166 return fb_refcnt(buffer);
2169 EAPI void *livebox_acquire_pdfb(struct livebox *handler)
2172 ErrPrint("Handler is NIL\n");
2176 if (handler->state != CREATE || !handler->id) {
2177 ErrPrint("Invalid handler\n");
2181 if (handler->pd.type != _PD_TYPE_SCRIPT && handler->pd.type != _PD_TYPE_BUFFER) {
2182 ErrPrint("Handler is not valid type\n");
2186 return fb_acquire_buffer(handler->pd.data.fb);
2189 EAPI int livebox_release_pdfb(void *buffer)
2191 return fb_release_buffer(buffer);
2194 EAPI int livebox_pdfb_refcnt(void *buffer)
2196 return fb_refcnt(buffer);
2199 EAPI int livebox_pdfb_bufsz(struct livebox *handler)
2202 ErrPrint("Handler is NIL\n");
2203 return LB_STATUS_ERROR_INVALID;
2206 if (handler->state != CREATE || !handler->id) {
2207 ErrPrint("Handler is not valid\n");
2208 return LB_STATUS_ERROR_INVALID;
2211 return fb_size(handler->pd.data.fb);
2214 EAPI int livebox_lbfb_bufsz(struct livebox *handler)
2217 ErrPrint("Handler is NIL\n");
2218 return LB_STATUS_ERROR_INVALID;
2221 if (handler->state != CREATE || !handler->id) {
2222 ErrPrint("Handler is not valid\n");
2223 return LB_STATUS_ERROR_INVALID;
2226 return fb_size(handler->lb.data.fb);
2229 EAPI int livebox_is_user(struct livebox *handler)
2232 ErrPrint("Handler is NIL\n");
2233 return LB_STATUS_ERROR_INVALID;
2236 if (handler->state != CREATE) {
2237 ErrPrint("Handler is invalid\n");
2238 return LB_STATUS_ERROR_INVALID;
2241 return handler->is_user;
2244 EAPI int livebox_set_pinup(struct livebox *handler, int flag, ret_cb_t cb, void *data)
2246 struct packet *packet;
2250 ErrPrint("Handler is NIL\n");
2251 return LB_STATUS_ERROR_INVALID;
2254 if (handler->state != CREATE || !handler->id) {
2255 ErrPrint("Handler is not valid\n");
2256 return LB_STATUS_ERROR_INVALID;
2259 if (handler->pinup_cb) {
2260 ErrPrint("Previous pinup request is not finished\n");
2261 return LB_STATUS_ERROR_BUSY;
2264 if (handler->is_pinned_up == flag) {
2265 DbgPrint("No changes\n");
2266 return LB_STATUS_ERROR_ALREADY;
2269 packet = packet_create("pinup_changed", "ssi", handler->pkgname, handler->id, flag);
2271 ErrPrint("Failed to build a param\n");
2272 return LB_STATUS_ERROR_FAULT;
2276 cb = default_pinup_cb;
2279 ret = master_rpc_async_request(handler, packet, 0, pinup_done_cb, NULL);
2280 if (ret == LB_STATUS_SUCCESS) {
2281 handler->pinup_cb = cb;
2282 handler->pinup_cbdata = data;
2288 EAPI int livebox_is_pinned_up(struct livebox *handler)
2291 ErrPrint("Handler is NIL\n");
2292 return LB_STATUS_ERROR_INVALID;
2295 if (handler->state != CREATE || !handler->id) {
2296 return LB_STATUS_ERROR_INVALID;
2299 return handler->is_pinned_up;
2302 EAPI int livebox_has_pinup(struct livebox *handler)
2305 ErrPrint("Handler is NIL\n");
2306 return LB_STATUS_ERROR_INVALID;
2309 if (handler->state != CREATE || !handler->id) {
2310 return LB_STATUS_ERROR_INVALID;
2313 return handler->lb.pinup_supported;
2316 EAPI int livebox_set_data(struct livebox *handler, void *data)
2319 ErrPrint("Handler is NIL\n");
2320 return LB_STATUS_ERROR_INVALID;
2323 if (handler->state != CREATE) {
2324 return LB_STATUS_ERROR_INVALID;
2327 handler->data = data;
2328 return LB_STATUS_SUCCESS;
2331 EAPI void *livebox_get_data(struct livebox *handler)
2334 ErrPrint("Handler is NIL\n");
2338 if (handler->state != CREATE) {
2342 return handler->data;
2345 EAPI int livebox_is_exists(const char *pkgname)
2349 lb = lb_pkgname(pkgname);
2358 EAPI const char *livebox_content(struct livebox *handler)
2361 ErrPrint("Handler is NIL\n");
2365 if (handler->state != CREATE) {
2369 return handler->content;
2372 EAPI const char *livebox_category_title(struct livebox *handler)
2375 ErrPrint("Handler is NIL\n");
2379 if (handler->state != CREATE) {
2383 return handler->title;
2386 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)
2388 struct packet *packet;
2389 struct cb_info *cbinfo;
2393 ErrPrint("Handler is NIL\n");
2394 return LB_STATUS_ERROR_INVALID;
2397 if ((handler->lb.type != _LB_TYPE_TEXT && handler->pd.type != _PD_TYPE_TEXT) || handler->state != CREATE || !handler->id) {
2398 ErrPrint("Handler is not valid\n");
2399 return LB_STATUS_ERROR_INVALID;
2410 packet = packet_create("text_signal", "ssssdddd",
2411 handler->pkgname, handler->id, emission, source, sx, sy, ex, ey);
2413 ErrPrint("Failed to build a param\n");
2414 return LB_STATUS_ERROR_FAULT;
2417 cbinfo = create_cb_info(cb, data);
2419 packet_destroy(packet);
2420 return LB_STATUS_ERROR_FAULT;
2423 ret = master_rpc_async_request(handler, packet, 0, text_signal_cb, cbinfo);
2425 destroy_cb_info(cbinfo);
2428 return LB_STATUS_ERROR_FAULT;
2431 EAPI int livebox_subscribe_group(const char *cluster, const char *category)
2433 struct packet *packet;
2437 * Validate the group info using DB
2438 * If the group info is not valid, do not send this request
2441 packet = packet_create_noack("subscribe", "ss", cluster ? cluster : "", category ? category : "");
2443 ErrPrint("Failed to create a packet\n");
2444 return LB_STATUS_ERROR_FAULT;
2447 return master_rpc_request_only(NULL, packet);
2450 EAPI int livebox_unsubscribe_group(const char *cluster, const char *category)
2452 struct packet *packet;
2456 * Validate the group info using DB
2457 * If the group info is not valid, do not send this request
2458 * AND Check the subscribed or not too
2461 packet = packet_create_noack("unsubscribe", "ss", cluster ? cluster : "", category ? category : "");
2463 ErrPrint("Failed to create a packet\n");
2464 return LB_STATUS_ERROR_FAULT;
2467 return master_rpc_request_only(NULL, packet);
2470 EAPI int livebox_refresh(struct livebox *handler)
2472 struct packet *packet;
2475 ErrPrint("Hnalder is NIL\n");
2476 return LB_STATUS_ERROR_INVALID;
2479 if (handler->state != CREATE || !handler->id) {
2480 return LB_STATUS_ERROR_INVALID;
2483 packet = packet_create_noack("update", "ss", handler->pkgname, handler->id);
2485 ErrPrint("Failed to create a packet\n");
2486 return LB_STATUS_ERROR_FAULT;
2489 return master_rpc_request_only(handler, packet);
2492 EAPI int livebox_refresh_group(const char *cluster, const char *category)
2494 struct packet *packet;
2496 if (!cluster || !category) {
2497 ErrPrint("Invalid argument\n");
2498 return LB_STATUS_ERROR_INVALID;
2501 packet = packet_create_noack("refresh_group", "ss", cluster, category);
2503 ErrPrint("Failed to create a packet\n");
2504 return LB_STATUS_ERROR_FAULT;
2507 return master_rpc_request_only(NULL, packet);
2510 EAPI int livebox_set_visibility(struct livebox *handler, enum livebox_visible_state state)
2512 struct packet *packet;
2516 ErrPrint("Handler is NIL\n");
2517 return LB_STATUS_ERROR_INVALID;
2520 if (handler->state != CREATE || !handler->id) {
2521 return LB_STATUS_ERROR_INVALID;
2524 if (!handler->is_user) {
2525 /* System cluster livebox cannot be changed its visible states */
2526 if (state == LB_HIDE_WITH_PAUSE) {
2527 ErrPrint("CA Livebox is not able to change the visibility\n");
2528 return LB_STATUS_ERROR_PERMISSION;
2532 if (handler->visible == state) {
2533 return LB_STATUS_ERROR_ALREADY;
2536 packet = packet_create_noack("change,visibility", "ssi", handler->pkgname, handler->id, (int)state);
2538 ErrPrint("Failed to create a packet\n");
2539 return LB_STATUS_ERROR_FAULT;
2542 ret = master_rpc_request_only(handler, packet);
2544 handler->visible = state;
2550 EAPI enum livebox_visible_state livebox_visibility(struct livebox *handler)
2553 ErrPrint("Handler is NIL\n");
2554 return LB_VISIBLE_ERROR;
2557 if (handler->state != CREATE || !handler->id) {
2558 return LB_VISIBLE_ERROR;
2561 return handler->visible;
2564 int lb_set_group(struct livebox *handler, const char *cluster, const char *category)
2570 pc = strdup(cluster);
2572 CRITICAL_LOG("Heap: %s (cluster: %s)\n", strerror(errno), cluster);
2573 return LB_STATUS_ERROR_MEMORY;
2578 ps = strdup(category);
2580 CRITICAL_LOG("Heap: %s (category: %s)\n", strerror(errno), category);
2582 return LB_STATUS_ERROR_MEMORY;
2586 if (handler->cluster) {
2587 free(handler->cluster);
2590 if (handler->category) {
2591 free(handler->category);
2594 handler->cluster = pc;
2595 handler->category = ps;
2597 return LB_STATUS_SUCCESS;
2600 void lb_set_size(struct livebox *handler, int w, int h)
2602 handler->lb.width = w;
2603 handler->lb.height = h;
2606 void lb_set_update_mode(struct livebox *handle, int active_mode)
2608 handle->is_active_update = active_mode;
2611 void lb_set_pdsize(struct livebox *handler, int w, int h)
2613 handler->pd.width = w;
2614 handler->pd.height = h;
2617 void lb_set_default_pdsize(struct livebox *handler, int w, int h)
2619 handler->pd.default_width = w;
2620 handler->pd.default_height = h;
2623 void lb_invoke_fault_handler(enum livebox_fault_type event, const char *pkgname, const char *file, const char *func)
2627 struct fault_info *info;
2629 dlist_foreach_safe(s_info.fault_list, l, n, info) {
2630 if (info->handler(event, pkgname, file, func, info->user_data) == EXIT_FAILURE) {
2631 s_info.fault_list = dlist_remove(s_info.fault_list, l);
2636 void lb_invoke_event_handler(struct livebox *handler, enum livebox_event_type event)
2640 struct event_info *info;
2642 dlist_foreach_safe(s_info.event_list, l, n, info) {
2643 if (info->handler(handler, event, info->user_data) == EXIT_FAILURE) {
2644 s_info.event_list = dlist_remove(s_info.event_list, l);
2649 struct livebox *lb_find_livebox(const char *pkgname, const char *id)
2652 struct livebox *handler;
2654 dlist_foreach(s_info.livebox_list, l, handler) {
2659 if (!strcmp(handler->pkgname, pkgname) && !strcmp(handler->id, id)) {
2667 struct livebox *lb_find_livebox_by_timestamp(double timestamp)
2670 struct livebox *handler;
2672 dlist_foreach(s_info.livebox_list, l, handler) {
2673 if (handler->timestamp == timestamp) {
2681 static inline char *get_file_kept_in_safe(const char *id)
2688 path = util_uri_to_path(id);
2690 ErrPrint("Invalid URI(%s)\n", id);
2697 if (s_info.prevent_overwrite) {
2698 new_path = strdup(path);
2700 ErrPrint("Heap: %s\n", strerror(errno));
2710 while (base_idx > 0 && path[base_idx] != '/') base_idx--;
2711 base_idx += (path[base_idx] == '/');
2713 new_path = malloc(len + 10);
2715 ErrPrint("Heap: %s\n", strerror(errno));
2719 strncpy(new_path, path, base_idx);
2720 snprintf(new_path + base_idx, len + 10 - base_idx, "reader/%s", path + base_idx);
2724 struct livebox *lb_new_livebox(const char *pkgname, const char *id, double timestamp)
2726 struct livebox *handler;
2728 handler = calloc(1, sizeof(*handler));
2730 ErrPrint("Failed to create a new livebox\n");
2734 handler->pkgname = strdup(pkgname);
2735 if (!handler->pkgname) {
2736 ErrPrint("%s\n", strerror(errno));
2741 handler->id = strdup(id);
2743 ErrPrint("%s\n", strerror(errno));
2744 free(handler->pkgname);
2749 handler->filename = get_file_kept_in_safe(id);
2750 if (!handler->filename) {
2751 handler->filename = strdup(util_uri_to_path(id));
2752 if (!handler->filename) {
2753 ErrPrint("Error: %s\n", strerror(errno));
2757 handler->timestamp = timestamp;
2758 handler->lb.type = _LB_TYPE_FILE;
2759 handler->pd.type = _PD_TYPE_SCRIPT;
2760 handler->state = CREATE;
2761 handler->visible = LB_SHOW;
2763 s_info.livebox_list = dlist_append(s_info.livebox_list, handler);
2768 int lb_delete_all(void)
2772 struct livebox *handler;
2774 dlist_foreach_safe(s_info.livebox_list, l, n, handler) {
2775 lb_invoke_event_handler(handler, LB_EVENT_DELETED);
2779 return LB_STATUS_SUCCESS;
2782 int lb_set_content(struct livebox *handler, const char *content)
2784 if (handler->content) {
2785 free(handler->content);
2786 handler->content = NULL;
2790 handler->content = strdup(content);
2791 if (!handler->content) {
2792 CRITICAL_LOG("Heap: %s (content: %s)\n", strerror(errno), content);
2793 return LB_STATUS_ERROR_MEMORY;
2797 return LB_STATUS_SUCCESS;
2800 int lb_set_title(struct livebox *handler, const char *title)
2802 if (handler->title) {
2803 free(handler->title);
2804 handler->title = NULL;
2808 handler->title = strdup(title);
2809 if (!handler->title) {
2810 CRITICAL_LOG("Heap: %s (title: %s)\n", strerror(errno), title);
2811 return LB_STATUS_ERROR_MEMORY;
2815 return LB_STATUS_SUCCESS;
2818 void lb_set_size_list(struct livebox *handler, int size_list)
2820 handler->lb.size_list = size_list;
2823 void lb_set_auto_launch(struct livebox *handler, const char *auto_launch)
2825 if (!strlen(auto_launch)) {
2829 handler->lb.auto_launch = strdup(auto_launch);
2830 if (!handler->lb.auto_launch) {
2831 ErrPrint("Heap: %s\n", strerror(errno));
2835 void lb_set_priority(struct livebox *handler, double priority)
2837 handler->lb.priority = priority;
2840 void lb_set_id(struct livebox *handler, const char *id)
2846 handler->id = strdup(id);
2848 ErrPrint("Error: %s\n", strerror(errno));
2851 if (handler->filename) {
2852 free(handler->filename);
2855 handler->filename = get_file_kept_in_safe(id);
2856 if (!handler->filename) {
2857 handler->filename = strdup(util_uri_to_path(id));
2858 if (!handler->filename) {
2859 ErrPrint("Error: %s\n", strerror(errno));
2864 int lb_set_lb_fb(struct livebox *handler, const char *filename)
2869 return LB_STATUS_ERROR_INVALID;
2872 fb = handler->lb.data.fb;
2873 if (fb && !strcmp(fb_id(fb), filename)) { /*!< BUFFER is not changed, */
2874 return LB_STATUS_SUCCESS;
2877 handler->lb.data.fb = NULL;
2879 if (!filename || filename[0] == '\0') {
2883 return LB_STATUS_SUCCESS;
2886 handler->lb.data.fb = fb_create(filename, handler->lb.width, handler->lb.height);
2887 if (!handler->lb.data.fb) {
2888 ErrPrint("Faield to create a FB\n");
2892 return LB_STATUS_ERROR_FAULT;
2899 return LB_STATUS_SUCCESS;
2902 int lb_set_pd_fb(struct livebox *handler, const char *filename)
2907 return LB_STATUS_ERROR_INVALID;
2910 fb = handler->pd.data.fb;
2911 if (fb && !strcmp(fb_id(fb), filename)) {
2912 /* BUFFER is not changed, just update the content */
2913 return LB_STATUS_ERROR_EXIST;
2915 handler->pd.data.fb = NULL;
2917 if (!filename || filename[0] == '\0') {
2921 return LB_STATUS_SUCCESS;
2924 handler->pd.data.fb = fb_create(filename, handler->pd.width, handler->pd.height);
2925 if (!handler->pd.data.fb) {
2926 ErrPrint("Failed to create a FB\n");
2930 return LB_STATUS_ERROR_FAULT;
2936 return LB_STATUS_SUCCESS;
2939 struct fb_info *lb_get_lb_fb(struct livebox *handler)
2941 return handler->lb.data.fb;
2944 struct fb_info *lb_get_pd_fb(struct livebox *handler)
2946 return handler->pd.data.fb;
2949 void lb_set_user(struct livebox *handler, int user)
2951 handler->is_user = user;
2954 void lb_set_pinup(struct livebox *handler, int pinup_supported)
2956 handler->lb.pinup_supported = pinup_supported;
2959 void lb_set_text_lb(struct livebox *handler)
2961 handler->lb.type = _LB_TYPE_TEXT;
2964 void lb_set_text_pd(struct livebox *handler)
2966 handler->pd.type = _PD_TYPE_TEXT;
2969 int lb_text_lb(struct livebox *handler)
2971 return handler->lb.type == _LB_TYPE_TEXT;
2974 int lb_text_pd(struct livebox *handler)
2976 return handler->pd.type == _PD_TYPE_TEXT;
2979 void lb_set_period(struct livebox *handler, double period)
2981 handler->lb.period = period;
2984 struct livebox *lb_ref(struct livebox *handler)
2994 struct livebox *lb_unref(struct livebox *handler)
3001 if (handler->refcnt > 0) {
3005 if (handler->created_cb) {
3006 handler->created_cb(handler, LB_STATUS_ERROR_FAULT, handler->created_cbdata);
3007 handler->created_cb = NULL;
3008 handler->created_cbdata = NULL;
3011 if (handler->deleted_cb) {
3012 handler->deleted_cb(handler, LB_STATUS_ERROR_FAULT, handler->deleted_cbdata);
3013 handler->deleted_cb = NULL;
3014 handler->deleted_cbdata = NULL;
3017 if (handler->pinup_cb) {
3018 handler->pinup_cb(handler, LB_STATUS_ERROR_FAULT, handler->pinup_cbdata);
3019 handler->pinup_cb = NULL;
3020 handler->pinup_cbdata = NULL;
3023 if (handler->group_changed_cb) {
3024 handler->group_changed_cb(handler, LB_STATUS_ERROR_FAULT, handler->group_cbdata);
3025 handler->group_changed_cb = NULL;
3026 handler->group_cbdata = NULL;
3029 if (handler->period_changed_cb) {
3030 handler->period_changed_cb(handler, LB_STATUS_ERROR_FAULT, handler->period_cbdata);
3031 handler->period_changed_cb = NULL;
3032 handler->period_cbdata = NULL;
3035 if (handler->size_changed_cb) {
3036 handler->size_changed_cb(handler, LB_STATUS_ERROR_FAULT, handler->size_cbdata);
3037 handler->size_changed_cb = NULL;
3038 handler->size_cbdata = NULL;
3041 if (handler->pd_created_cb) {
3042 handler->pd_created_cb(handler, LB_STATUS_ERROR_FAULT, handler->pd_created_cbdata);
3043 handler->pd_created_cb = NULL;
3044 handler->pd_created_cbdata = NULL;
3047 if (handler->pd_destroyed_cb) {
3048 handler->pd_destroyed_cb(handler, LB_STATUS_ERROR_FAULT, handler->pd_destroyed_cbdata);
3049 handler->pd_destroyed_cb = NULL;
3050 handler->pd_destroyed_cbdata = NULL;
3053 if (handler->update_mode_cb) {
3054 handler->update_mode_cb(handler, LB_STATUS_ERROR_FAULT, handler->update_mode_cbdata);
3055 handler->update_mode_cb = NULL;
3056 handler->update_mode_cbdata = NULL;
3059 if (handler->access_event_cb) {
3060 handler->access_event_cb(handler, LB_ACCESS_STATUS_ERROR, handler->access_event_cbdata);
3061 handler->access_event_cb = NULL;
3062 handler->access_event_cbdata = NULL;
3065 if (handler->filename) {
3066 util_unlink(handler->filename);
3069 dlist_remove_data(s_info.livebox_list, handler);
3071 handler->state = DESTROYED;
3072 free(handler->cluster);
3073 free(handler->category);
3075 free(handler->pkgname);
3076 free(handler->filename);
3077 free(handler->lb.auto_launch);
3079 if (handler->lb.data.fb) {
3080 fb_destroy(handler->lb.data.fb);
3081 handler->lb.data.fb = NULL;
3084 if (handler->pd.data.fb) {
3085 fb_destroy(handler->pd.data.fb);
3086 handler->pd.data.fb = NULL;
3093 int lb_send_delete(struct livebox *handler, ret_cb_t cb, void *data)
3095 struct packet *packet;
3096 struct cb_info *cbinfo;
3099 if (!cb && !!data) {
3100 ErrPrint("Invalid argument\n");
3101 return LB_STATUS_ERROR_INVALID;
3104 if (handler->deleted_cb) {
3105 ErrPrint("Already in-progress\n");
3106 return LB_STATUS_ERROR_BUSY;
3109 packet = packet_create("delete", "ss", handler->pkgname, handler->id);
3111 ErrPrint("Failed to build a param\n");
3113 cb(handler, LB_STATUS_ERROR_FAULT, data);
3116 return LB_STATUS_ERROR_FAULT;
3120 cb = default_delete_cb;
3123 cbinfo = create_cb_info(cb, data);
3125 packet_destroy(packet);
3126 return LB_STATUS_ERROR_FAULT;
3129 ret = master_rpc_async_request(handler, packet, 0, del_ret_cb, cbinfo);
3131 destroy_cb_info(cbinfo);
3137 EAPI int livebox_client_paused(void)
3139 struct packet *packet;
3141 packet = packet_create_noack("client_paused", "d", util_timestamp());
3143 ErrPrint("Failed to create a pause packet\n");
3144 return LB_STATUS_ERROR_FAULT;
3147 return master_rpc_request_only(NULL, packet);
3150 EAPI int livebox_client_resumed(void)
3152 struct packet *packet;
3154 packet = packet_create_noack("client_resumed", "d", util_timestamp());
3156 ErrPrint("Failed to create a resume packet\n");
3157 return LB_STATUS_ERROR_FAULT;
3160 return master_rpc_request_only(NULL, packet);