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"
42 #define EAPI __attribute__((visibility("default")))
43 #define MINIMUM_EVENT s_info.event_filter
50 struct dlist *livebox_list;
51 struct dlist *event_list;
52 struct dlist *fault_list;
54 int prevent_overwrite;
61 .prevent_overwrite = 0,
62 .event_filter = 0.01f,
71 int (*handler)(struct livebox *handler, enum livebox_event_type event, void *data);
76 int (*handler)(enum livebox_fault_type event, const char *pkgname, const char *filename, const char *func, void *data);
80 static inline void default_create_cb(struct livebox *handler, int ret, void *data)
82 DbgPrint("Default created event handler: %d\n", ret);
85 static inline void default_delete_cb(struct livebox *handler, int ret, void *data)
87 DbgPrint("Default deleted event handler: %d\n", ret);
90 static inline void default_pinup_cb(struct livebox *handler, int ret, void *data)
92 DbgPrint("Default pinup event handler: %d\n", ret);
95 static inline void default_group_changed_cb(struct livebox *handler, int ret, void *data)
97 DbgPrint("Default group changed event handler: %d\n", ret);
100 static inline void default_period_changed_cb(struct livebox *handler, int ret, void *data)
102 DbgPrint("Default period changed event handler: %d\n", ret);
105 static inline void default_pd_created_cb(struct livebox *handler, int ret, void *data)
107 DbgPrint("Default PD created event handler: %d\n", ret);
110 static inline void default_pd_destroyed_cb(struct livebox *handler, int ret, void *data)
112 DbgPrint("Default PD destroyed event handler: %d\n", ret);
115 static inline void default_lb_size_changed_cb(struct livebox *handler, int ret, void *data)
117 DbgPrint("Default LB size changed event handler: %d\n", ret);
120 static inline void default_update_mode_cb(struct livebox *handler, int ret, void *data)
122 DbgPrint("Default update mode set event handler: %d\n", ret);
125 static inline void default_access_event_cb(struct livebox *handler, int ret, void *data)
127 DbgPrint("Default access event handler: %d\n", ret);
130 static inline __attribute__((always_inline)) struct cb_info *create_cb_info(ret_cb_t cb, void *data)
132 struct cb_info *info;
134 info = malloc(sizeof(*info));
136 CRITICAL_LOG("Heap: %s\n", strerror(errno));
145 static inline void destroy_cb_info(struct cb_info *info)
150 static void update_mode_cb(struct livebox *handler, const struct packet *result, void *data)
155 ret = LB_STATUS_ERROR_FAULT;
157 } else if (packet_get(result, "i", &ret) != 1) {
158 ErrPrint("Invalid argument\n");
159 ret = LB_STATUS_ERROR_INVALID;
164 ErrPrint("Resize request is failed: %d\n", ret);
171 handler->update_mode_cb(handler, ret, handler->update_mode_cbdata);
172 handler->update_mode_cb = NULL;
173 handler->update_mode_cbdata = NULL;
177 static void resize_cb(struct livebox *handler, const struct packet *result, void *data)
182 ret = LB_STATUS_ERROR_FAULT;
184 } else if (packet_get(result, "i", &ret) != 1) {
185 ErrPrint("Invalid argument\n");
186 ret = LB_STATUS_ERROR_INVALID;
192 * In case of resize request,
193 * The livebox handler will not have resized value right after this callback,
194 * It can only get the new size when it makes updates.
196 * So the user can only get the resized value(result) from the first update event
197 * after this request.
200 ErrPrint("Resize request is failed: %d\n", ret);
207 handler->size_changed_cb(handler, ret, handler->size_cbdata);
208 handler->size_changed_cb = NULL;
209 handler->size_cbdata = NULL;
212 static void text_signal_cb(struct livebox *handler, const struct packet *result, void *data)
216 struct cb_info *info = data;
221 destroy_cb_info(info);
224 ret = LB_STATUS_ERROR_FAULT;
225 } else if (packet_get(result, "i", &ret) != 1) {
226 ErrPrint("Invalid argument\n");
227 ret = LB_STATUS_ERROR_INVALID;
231 cb(handler, ret, cbdata);
236 static void set_group_ret_cb(struct livebox *handler, const struct packet *result, void *data)
241 ret = LB_STATUS_ERROR_FAULT;
243 } else if (packet_get(result, "i", &ret) != 1) {
244 ErrPrint("Invalid argument\n");
245 ret = LB_STATUS_ERROR_INVALID;
256 handler->group_changed_cb(handler, ret, handler->group_cbdata);
257 handler->group_changed_cb = NULL;
258 handler->group_cbdata = NULL;
261 static void period_ret_cb(struct livebox *handler, const struct packet *result, void *data)
266 ret = LB_STATUS_ERROR_FAULT;
268 } else if (packet_get(result, "i", &ret) != 1) {
269 ErrPrint("Invalid argument\n");
270 ret = LB_STATUS_ERROR_INVALID;
281 handler->period_changed_cb(handler, ret, handler->period_cbdata);
282 handler->period_changed_cb = NULL;
283 handler->period_cbdata = NULL;
286 static void del_ret_cb(struct livebox *handler, const struct packet *result, void *data)
288 struct cb_info *info = data;
295 destroy_cb_info(info);
298 ErrPrint("Connection lost?\n");
299 ret = LB_STATUS_ERROR_FAULT;
300 } else if (packet_get(result, "i", &ret) != 1) {
301 ErrPrint("Invalid argument\n");
302 ret = LB_STATUS_ERROR_INVALID;
306 handler->deleted_cb = cb;
307 handler->deleted_cbdata = cbdata;
309 cb(handler, ret, cbdata);
314 * Do not call the deleted callback from here.
315 * master will send the "deleted" event.
316 * Then invoke this callback.
318 * if (handler->deleted_cb)
319 * handler->deleted_cb(handler, ret, handler->deleted_cbdata);
323 static void new_ret_cb(struct livebox *handler, const struct packet *result, void *data)
326 struct cb_info *info = data;
332 destroy_cb_info(info);
335 ret = LB_STATUS_ERROR_FAULT;
336 } else if (packet_get(result, "i", &ret) != 1) {
337 ret = LB_STATUS_ERROR_INVALID;
341 handler->created_cb = cb;
342 handler->created_cbdata = cbdata;
346 * Don't go anymore ;)
352 * It means the current instance is not created,
353 * so user has to know about this.
354 * notice it to user using "deleted" event.
356 cb(handler, ret, cbdata);
362 static void pd_create_cb(struct livebox *handler, const struct packet *result, void *data)
367 ret = LB_STATUS_ERROR_FAULT;
369 } else if (packet_get(result, "i", &ret) != 1) {
370 ret = LB_STATUS_ERROR_INVALID;
375 ErrPrint("Failed to create a PD[%d]\n", ret);
382 handler->pd_created_cb(handler, ret, handler->pd_created_cbdata);
383 handler->pd_created_cb = NULL;
384 handler->pd_created_cbdata = NULL;
387 static void activated_cb(struct livebox *handler, const struct packet *result, void *data)
390 struct cb_info *info = data;
393 const char *pkgname = "";
397 destroy_cb_info(info);
400 ret = LB_STATUS_ERROR_FAULT;
401 } else if (packet_get(result, "is", &ret, &pkgname) != 2) {
402 ret = LB_STATUS_ERROR_INVALID;
406 cb(handler, ret, cbdata);
410 static void pd_destroy_cb(struct livebox *handler, const struct packet *result, void *data)
415 struct cb_info *info = data;
419 destroy_cb_info(info);
422 ErrPrint("Result is NIL (may connection lost)\n");
423 ret = LB_STATUS_ERROR_FAULT;
424 } else if (packet_get(result, "i", &ret) != 1) {
425 ErrPrint("Invalid parameter\n");
426 ret = LB_STATUS_ERROR_INVALID;
430 handler->pd_destroyed_cb = cb;
431 handler->pd_destroyed_cbdata = cbdata;
433 handler->is_pd_created = 0;
434 cb(handler, ret, cbdata);
438 static void delete_cluster_cb(struct livebox *handler, const struct packet *result, void *data)
440 struct cb_info *info = data;
447 destroy_cb_info(info);
450 ret = LB_STATUS_ERROR_FAULT;
451 } else if (packet_get(result, "i", &ret) != 1) {
452 ret = LB_STATUS_ERROR_INVALID;
456 cb(handler, ret, cbdata);
460 static void delete_category_cb(struct livebox *handler, const struct packet *result, void *data)
462 struct cb_info *info = data;
469 destroy_cb_info(info);
472 ret = LB_STATUS_ERROR_FAULT;
473 } else if (packet_get(result, "i", &ret) != 1) {
474 ret = LB_STATUS_ERROR_INVALID;
478 cb(handler, ret, cbdata);
482 static void lb_pixmap_acquired_cb(struct livebox *handler, const struct packet *result, void *data)
485 int ret = LB_STATUS_ERROR_INVALID;
488 struct cb_info *info = data;
492 destroy_cb_info(info);
495 pixmap = 0; /* PIXMAP 0 means error */
496 } else if (packet_get(result, "ii", &pixmap, &ret) != 2) {
500 if (ret == LB_STATUS_ERROR_BUSY) {
501 ret = livebox_acquire_lb_pixmap(handler, cb, cbdata);
502 DbgPrint("Busy, Try again: %d\n", ret);
506 cb(handler, pixmap, cbdata);
511 static void pd_pixmap_acquired_cb(struct livebox *handler, const struct packet *result, void *data)
517 struct cb_info *info = data;
521 destroy_cb_info(info);
524 pixmap = 0; /* PIXMAP 0 means error */
525 ret = LB_STATUS_ERROR_FAULT;
526 } else if (packet_get(result, "ii", &pixmap, &ret) != 2) {
528 ret = LB_STATUS_ERROR_INVALID;
531 if (ret == LB_STATUS_ERROR_BUSY) {
532 ret = livebox_acquire_pd_pixmap(handler, cb, cbdata);
533 DbgPrint("Busy, Try again: %d\n", ret);
537 DbgPrint("ret: %d, pixmap: %d\n", ret, pixmap);
538 cb(handler, pixmap, cbdata);
543 static void pinup_done_cb(struct livebox *handler, const struct packet *result, void *data)
548 ret = LB_STATUS_ERROR_FAULT;
550 } else if (packet_get(result, "i", &ret) != 1) {
561 handler->pinup_cb(handler, ret, handler->pinup_cbdata);
562 handler->pinup_cb = NULL;
563 handler->pinup_cbdata = NULL;
566 static void access_ret_cb(struct livebox *handler, const struct packet *result, void *data)
571 ret = LB_STATUS_ERROR_FAULT;
575 if (packet_get(result, "i", &ret) != 1) {
576 ret = LB_STATUS_ERROR_INVALID;
580 if (ret != LB_STATUS_SUCCESS) {
587 handler->access_event_cb(handler, ret, handler->access_event_cbdata);
588 handler->access_event_cb = NULL;
589 handler->access_event_cbdata = NULL;
593 static int send_access_event(struct livebox *handler, const char *event, int x, int y)
595 struct packet *packet;
598 timestamp = util_timestamp();
600 packet = packet_create(event, "ssdii", handler->pkgname, handler->id, timestamp, x, y);
602 ErrPrint("Failed to build packet\n");
603 return LB_STATUS_ERROR_FAULT;
606 return master_rpc_async_request(handler, packet, 0, access_ret_cb, NULL);
609 static int send_mouse_event(struct livebox *handler, const char *event, int x, int y)
611 struct packet *packet;
614 timestamp = util_timestamp();
615 packet = packet_create_noack(event, "ssdii", handler->pkgname, handler->id, timestamp, x, y);
617 ErrPrint("Failed to build param\n");
618 return LB_STATUS_ERROR_FAULT;
621 return master_rpc_request_only(handler, packet);
624 static void initialize_livebox(void *disp)
627 char filename[BUFSIZ];
628 snprintf(filename, sizeof(filename), "/tmp/%d.box.log", getpid());
629 __file_log_fp = fopen(filename, "w+t");
630 if (!__file_log_fp) {
631 __file_log_fp = fdopen(1, "w+t");
634 critical_log_init("viewer");
635 livebox_service_init();
643 EAPI int livebox_init_with_options(void *disp, int prevent_overwrite, double event_filter)
645 if (s_info.init_count > 0) {
647 return LB_STATUS_SUCCESS;
652 * Some application doesn't want to use the environment value.
653 * So set them using arguments.
655 s_info.prevent_overwrite = prevent_overwrite;
656 MINIMUM_EVENT = event_filter;
658 initialize_livebox(disp);
659 return LB_STATUS_SUCCESS;
662 EAPI int livebox_init(void *disp)
666 if (s_info.init_count > 0) {
668 return LB_STATUS_SUCCESS;
671 env = getenv("PROVIDER_DISABLE_PREVENT_OVERWRITE");
672 if (env && !strcasecmp(env, "true")) {
673 s_info.prevent_overwrite = 1;
676 env = getenv("PROVIDER_EVENT_FILTER");
678 sscanf(env, "%lf", &MINIMUM_EVENT);
681 initialize_livebox(disp);
682 return LB_STATUS_SUCCESS;
685 EAPI int livebox_fini(void)
687 if (s_info.init_count <= 0) {
688 ErrPrint("Doesn't initialized\n");
689 return LB_STATUS_ERROR_INVALID;
693 if (s_info.init_count > 0) {
694 ErrPrint("init count : %d\n", s_info.init_count);
695 return LB_STATUS_SUCCESS;
700 livebox_service_fini();
702 return LB_STATUS_SUCCESS;
705 static inline char *lb_pkgname(const char *pkgname)
709 lb = livebox_service_pkgname(pkgname);
711 if (util_validate_livebox_package(pkgname) == 0) {
712 return strdup(pkgname);
720 * Just wrapping the livebox_add_with_size function.
722 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)
724 return livebox_add_with_size(pkgname, content, cluster, category, period, LB_SIZE_TYPE_UNKNOWN, cb, data);
727 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)
729 struct livebox *handler;
730 struct packet *packet;
734 struct cb_info *cbinfo;
736 if (!pkgname || !cluster || !category) {
737 ErrPrint("Invalid arguments: pkgname[%p], cluster[%p], category[%p]\n",
738 pkgname, cluster, category);
742 if (type != LB_SIZE_TYPE_UNKNOWN) {
743 livebox_service_get_size(type, &width, &height);
746 handler = calloc(1, sizeof(*handler));
748 ErrPrint("Error: %s\n", strerror(errno));
752 handler->pkgname = lb_pkgname(pkgname);
753 if (!handler->pkgname) {
758 if (livebox_service_is_enabled(handler->pkgname) == 0) {
759 DbgPrint("Livebox [%s](%s) is disabled package\n", handler->pkgname, pkgname);
760 free(handler->pkgname);
765 if (content && strlen(content)) {
766 handler->content = strdup(content);
767 if (!handler->content) {
768 ErrPrint("Error: %s\n", strerror(errno));
769 free(handler->pkgname);
774 handler->content = livebox_service_content(handler->pkgname);
777 handler->cluster = strdup(cluster);
778 if (!handler->cluster) {
779 ErrPrint("Error: %s\n", strerror(errno));
780 free(handler->content);
781 free(handler->pkgname);
786 handler->category = strdup(category);
787 if (!handler->category) {
788 ErrPrint("Error: %s\n", strerror(errno));
789 free(handler->cluster);
790 free(handler->content);
791 free(handler->pkgname);
797 cb = default_create_cb;
800 /* Data provider will set this */
801 handler->lb.type = _LB_TYPE_FILE;
802 handler->pd.type = _PD_TYPE_SCRIPT;
803 handler->lb.period = period;
805 /* Used for handling the mouse event on a box */
806 handler->lb.mouse_event = livebox_service_mouse_event(handler->pkgname);
808 /* Cluster infomration is not determined yet */
809 handler->nr_of_sizes = 0x01;
811 handler->timestamp = util_timestamp();
812 handler->is_user = 1;
813 handler->visible = LB_SHOW;
815 s_info.livebox_list = dlist_append(s_info.livebox_list, handler);
817 packet = packet_create("new", "dssssdii", handler->timestamp, handler->pkgname, handler->content, cluster, category, period, width, height);
819 ErrPrint("Failed to create a new packet\n");
820 free(handler->category);
821 free(handler->cluster);
822 free(handler->content);
823 free(handler->pkgname);
828 cbinfo = create_cb_info(cb, data);
830 ErrPrint("Failed to create a cbinfo\n");
831 packet_destroy(packet);
832 free(handler->category);
833 free(handler->cluster);
834 free(handler->content);
835 free(handler->pkgname);
840 ret = master_rpc_async_request(handler, packet, 0, new_ret_cb, cbinfo);
842 ErrPrint("Failed to send a new packet\n");
843 destroy_cb_info(cbinfo);
844 free(handler->category);
845 free(handler->cluster);
846 free(handler->content);
847 free(handler->pkgname);
852 handler->state = CREATE;
853 return lb_ref(handler);
856 EAPI double livebox_period(struct livebox *handler)
858 if (!handler || handler->state != CREATE || !handler->id) {
859 ErrPrint("Handler is not valid\n");
863 return handler->lb.period;
866 EAPI int livebox_set_period(struct livebox *handler, double period, ret_cb_t cb, void *data)
868 struct packet *packet;
871 if (!handler || handler->state != CREATE || !handler->id) {
872 ErrPrint("Handler is not valid\n");
873 return LB_STATUS_ERROR_INVALID;
876 if (handler->period_changed_cb) {
877 ErrPrint("Previous request for changing period is not finished\n");
878 return LB_STATUS_ERROR_BUSY;
881 if (!handler->is_user) {
882 ErrPrint("CA Livebox is not able to change the period\n");
883 return LB_STATUS_ERROR_PERMISSION;
886 if (handler->lb.period == period) {
887 DbgPrint("No changes\n");
888 return LB_STATUS_ERROR_ALREADY;
891 packet = packet_create("set_period", "ssd", handler->pkgname, handler->id, period);
893 ErrPrint("Failed to build a packet %s\n", handler->pkgname);
894 return LB_STATUS_ERROR_FAULT;
898 cb = default_period_changed_cb;
901 ret = master_rpc_async_request(handler, packet, 0, period_ret_cb, NULL);
902 if (ret == LB_STATUS_SUCCESS) {
903 handler->period_changed_cb = cb;
904 handler->period_cbdata = data;
910 EAPI int livebox_del(struct livebox *handler, ret_cb_t cb, void *data)
913 ErrPrint("Handler is NIL\n");
914 return LB_STATUS_ERROR_INVALID;
917 if (handler->state != CREATE) {
918 ErrPrint("Handler is already deleted\n");
919 return LB_STATUS_ERROR_INVALID;
922 handler->state = DELETE;
927 * The id is not determined yet.
928 * It means a user didn't receive created event yet.
929 * Then just stop to delete procedure from here.
930 * Because the "created" event handler will release this.
931 * By the way, if the user adds any callback for getting return status of this,
935 cb(handler, 0, data);
937 return LB_STATUS_SUCCESS;
941 cb = default_delete_cb;
944 return lb_send_delete(handler, cb, data);
947 EAPI int livebox_set_fault_handler(int (*cb)(enum livebox_fault_type, const char *, const char *, const char *, void *), void *data)
949 struct fault_info *info;
952 return LB_STATUS_ERROR_INVALID;
955 info = malloc(sizeof(*info));
957 CRITICAL_LOG("Heap: %s\n", strerror(errno));
958 return LB_STATUS_ERROR_MEMORY;
962 info->user_data = data;
964 s_info.fault_list = dlist_append(s_info.fault_list, info);
965 return LB_STATUS_SUCCESS;
968 EAPI void *livebox_unset_fault_handler(int (*cb)(enum livebox_fault_type, const char *, const char *, const char *, void *))
970 struct fault_info *info;
973 dlist_foreach(s_info.fault_list, l, info) {
974 if (info->handler == cb) {
977 s_info.fault_list = dlist_remove(s_info.fault_list, l);
978 data = info->user_data;
988 EAPI int livebox_set_event_handler(int (*cb)(struct livebox *, enum livebox_event_type, void *), void *data)
990 struct event_info *info;
993 ErrPrint("Invalid argument cb is nil\n");
994 return LB_STATUS_ERROR_INVALID;
997 info = malloc(sizeof(*info));
999 CRITICAL_LOG("Heap: %s\n", strerror(errno));
1000 return LB_STATUS_ERROR_MEMORY;
1004 info->user_data = data;
1006 s_info.event_list = dlist_append(s_info.event_list, info);
1007 return LB_STATUS_SUCCESS;
1010 EAPI void *livebox_unset_event_handler(int (*cb)(struct livebox *, enum livebox_event_type, void *))
1012 struct event_info *info;
1015 dlist_foreach(s_info.event_list, l, info) {
1016 if (info->handler == cb) {
1019 s_info.event_list = dlist_remove(s_info.event_list, l);
1020 data = info->user_data;
1030 EAPI int livebox_set_update_mode(struct livebox *handler, int active_update, ret_cb_t cb, void *data)
1032 struct packet *packet;
1036 ErrPrint("Handler is NIL\n");
1037 return LB_STATUS_ERROR_INVALID;
1040 if (handler->state != CREATE || !handler->id) {
1041 return LB_STATUS_ERROR_INVALID;
1044 if (handler->update_mode_cb) {
1045 ErrPrint("Previous update_mode cb is not finished yet\n");
1046 return LB_STATUS_ERROR_BUSY;
1049 if (handler->is_active_update == active_update) {
1050 return LB_STATUS_ERROR_ALREADY;
1053 if (!handler->is_user) {
1054 return LB_STATUS_ERROR_PERMISSION;
1057 packet = packet_create("update_mode", "ssi", handler->pkgname, handler->id, active_update);
1059 return LB_STATUS_ERROR_FAULT;
1063 cb = default_update_mode_cb;
1066 ret = master_rpc_async_request(handler, packet, 0, update_mode_cb, NULL);
1067 if (ret == LB_STATUS_SUCCESS) {
1068 handler->update_mode_cb = cb;
1069 handler->update_mode_cbdata = data;
1075 EAPI int livebox_is_active_update(struct livebox *handler)
1078 ErrPrint("Handler is NIL\n");
1079 return LB_STATUS_ERROR_INVALID;
1082 if (handler->state != CREATE || !handler->id) {
1083 return LB_STATUS_ERROR_INVALID;
1086 return handler->is_active_update;
1089 EAPI int livebox_resize(struct livebox *handler, int type, ret_cb_t cb, void *data)
1091 struct packet *packet;
1097 ErrPrint("Handler is NIL\n");
1098 return LB_STATUS_ERROR_INVALID;
1101 if (handler->state != CREATE || !handler->id) {
1102 ErrPrint("Handler is not valid\n");
1103 return LB_STATUS_ERROR_INVALID;
1106 if (handler->size_changed_cb) {
1107 ErrPrint("Previous resize request is not finished yet\n");
1108 return LB_STATUS_ERROR_BUSY;
1111 if (!handler->is_user) {
1112 ErrPrint("CA Livebox is not able to be resized\n");
1113 return LB_STATUS_ERROR_PERMISSION;
1116 if (livebox_service_get_size(type, &w, &h) != 0) {
1117 ErrPrint("Invalid size type\n");
1118 return LB_STATUS_ERROR_INVALID;
1121 if (handler->lb.width == w && handler->lb.height == h) {
1122 DbgPrint("No changes\n");
1123 return LB_STATUS_ERROR_ALREADY;
1126 packet = packet_create("resize", "ssii", handler->pkgname, handler->id, w, h);
1128 ErrPrint("Failed to build param\n");
1129 return LB_STATUS_ERROR_FAULT;
1133 cb = default_lb_size_changed_cb;
1136 ret = master_rpc_async_request(handler, packet, 0, resize_cb, NULL);
1137 if (ret == LB_STATUS_SUCCESS) {
1138 handler->size_changed_cb = cb;
1139 handler->size_cbdata = data;
1145 EAPI int livebox_click(struct livebox *handler, double x, double y)
1147 struct packet *packet;
1151 timestamp = util_timestamp();
1154 ErrPrint("Handler is NIL\n");
1155 return LB_STATUS_ERROR_INVALID;
1158 if (handler->state != CREATE || !handler->id) {
1159 ErrPrint("Handler is not valid\n");
1160 return LB_STATUS_ERROR_INVALID;
1163 if (handler->lb.auto_launch) {
1164 DbgPrint("AUTO_LAUNCH [%s]\n", handler->lb.auto_launch);
1165 if (aul_launch_app(handler->lb.auto_launch, NULL) < 0) {
1166 ErrPrint("Failed to launch app %s\n", handler->lb.auto_launch);
1170 packet = packet_create_noack("clicked", "sssddd", handler->pkgname, handler->id, "clicked", timestamp, x, y);
1172 ErrPrint("Failed to build param\n");
1173 return LB_STATUS_ERROR_FAULT;
1176 DbgPrint("CLICKED: %lf\n", timestamp);
1177 ret = master_rpc_request_only(handler, packet);
1179 if (!handler->lb.mouse_event && (handler->lb.type == _LB_TYPE_BUFFER || handler->lb.type == _LB_TYPE_SCRIPT)) {
1180 int ret; /* Shadow variable */
1181 ret = send_mouse_event(handler, "lb_mouse_down", x * handler->lb.width, y * handler->lb.height);
1183 ErrPrint("Failed to send Down: %d\n", ret);
1186 ret = send_mouse_event(handler, "lb_mouse_move", x * handler->lb.width, y * handler->lb.height);
1188 ErrPrint("Failed to send Move: %d\n", ret);
1191 ret = send_mouse_event(handler, "lb_mouse_up", x * handler->lb.width, y * handler->lb.height);
1193 ErrPrint("Failed to send Up: %d\n", ret);
1200 EAPI int livebox_has_pd(struct livebox *handler)
1203 ErrPrint("Handler is NIL\n");
1204 return LB_STATUS_ERROR_INVALID;
1207 if (handler->state != CREATE || !handler->id) {
1208 ErrPrint("Handler is not valid\n");
1209 return LB_STATUS_ERROR_INVALID;
1212 return !!handler->pd.data.fb;
1215 EAPI int livebox_pd_is_created(struct livebox *handler)
1218 ErrPrint("Handler is NIL\n");
1219 return LB_STATUS_ERROR_INVALID;
1222 if (!handler->pd.data.fb || handler->state != CREATE || !handler->id) {
1223 ErrPrint("Handler is not valid\n");
1224 return LB_STATUS_ERROR_INVALID;
1227 return handler->is_pd_created;
1230 EAPI int livebox_create_pd(struct livebox *handler, ret_cb_t cb, void *data)
1232 return livebox_create_pd_with_position(handler, -1.0, -1.0, cb, data);
1235 EAPI int livebox_create_pd_with_position(struct livebox *handler, double x, double y, ret_cb_t cb, void *data)
1237 struct packet *packet;
1241 ErrPrint("Handler is NIL\n");
1242 return LB_STATUS_ERROR_INVALID;
1245 if (!handler->pd.data.fb || handler->state != CREATE || !handler->id) {
1246 ErrPrint("Handler is not valid\n");
1247 return LB_STATUS_ERROR_INVALID;
1250 if (handler->is_pd_created == 1) {
1251 DbgPrint("PD already created\n");
1252 return LB_STATUS_SUCCESS;
1255 if (handler->pd_created_cb) {
1256 ErrPrint("Previous request is not completed yet\n");
1257 return LB_STATUS_ERROR_BUSY;
1260 packet = packet_create("create_pd", "ssdd", handler->pkgname, handler->id, x, y);
1262 ErrPrint("Failed to build param\n");
1263 return LB_STATUS_ERROR_FAULT;
1267 cb = default_pd_created_cb;
1270 DbgPrint("PERF_DBOX\n");
1271 ret = master_rpc_async_request(handler, packet, 0, pd_create_cb, NULL);
1272 if (ret == LB_STATUS_SUCCESS) {
1273 handler->pd_created_cb = cb;
1274 handler->pd_created_cbdata = data;
1280 EAPI int livebox_move_pd(struct livebox *handler, double x, double y)
1282 struct packet *packet;
1285 ErrPrint("Handler is NIL\n");
1286 return LB_STATUS_ERROR_INVALID;
1289 if (!handler->pd.data.fb || handler->state != CREATE || !handler->id) {
1290 ErrPrint("Handler is not valid\n");
1291 return LB_STATUS_ERROR_INVALID;
1294 if (!handler->is_pd_created) {
1295 ErrPrint("PD is not created\n");
1296 return LB_STATUS_ERROR_INVALID;
1299 packet = packet_create_noack("pd_move", "ssdd", handler->pkgname, handler->id, x, y);
1301 ErrPrint("Failed to build param\n");
1302 return LB_STATUS_ERROR_FAULT;
1305 return master_rpc_request_only(handler, packet);
1308 EAPI int livebox_activate(const char *pkgname, ret_cb_t cb, void *data)
1310 struct packet *packet;
1311 struct cb_info *cbinfo;
1315 return LB_STATUS_ERROR_INVALID;
1318 packet = packet_create("activate_package", "s", pkgname);
1320 ErrPrint("Failed to build a param\n");
1321 return LB_STATUS_ERROR_FAULT;
1324 cbinfo = create_cb_info(cb, data);
1326 ErrPrint("Unable to create cbinfo\n");
1327 packet_destroy(packet);
1328 return LB_STATUS_ERROR_FAULT;
1331 ret = master_rpc_async_request(NULL, packet, 0, activated_cb, cbinfo);
1333 destroy_cb_info(cbinfo);
1339 EAPI int livebox_destroy_pd(struct livebox *handler, ret_cb_t cb, void *data)
1341 struct packet *packet;
1342 struct cb_info *cbinfo;
1346 ErrPrint("Handler is NIL\n");
1347 return LB_STATUS_ERROR_INVALID;
1350 if (!handler->pd.data.fb || handler->state != CREATE || !handler->id) {
1351 ErrPrint("Handler is not valid\n");
1352 return LB_STATUS_ERROR_INVALID;
1355 if (!handler->is_pd_created && !handler->pd_created_cb) {
1356 ErrPrint("PD is not created\n");
1357 return LB_STATUS_ERROR_INVALID;
1360 packet = packet_create("destroy_pd", "ss", handler->pkgname, handler->id);
1362 ErrPrint("Failed to build a param\n");
1363 return LB_STATUS_ERROR_FAULT;
1367 cb = default_pd_destroyed_cb;
1370 cbinfo = create_cb_info(cb, data);
1372 packet_destroy(packet);
1373 return LB_STATUS_ERROR_FAULT;
1376 ret = master_rpc_async_request(handler, packet, 0, pd_destroy_cb, cbinfo);
1378 destroy_cb_info(cbinfo);
1384 EAPI int livebox_access_event(struct livebox *handler, enum access_event_type type, double x, double y, ret_cb_t cb, void *data)
1388 char cmd[32] = { '\0', };
1393 ErrPrint("Handler is NIL\n");
1394 return LB_STATUS_ERROR_INVALID;
1397 if (handler->state != CREATE || !handler->id) {
1398 ErrPrint("Handler is not valid\n");
1399 return LB_STATUS_ERROR_INVALID;
1402 if (handler->access_event_cb) {
1403 ErrPrint("Previous access event is not yet done\n");
1404 return LB_STATUS_ERROR_BUSY;
1407 if (type & ACCESS_EVENT_PD_MASK) {
1408 if (!handler->is_pd_created) {
1409 ErrPrint("PD is not created\n");
1410 return LB_STATUS_ERROR_INVALID;
1414 w = handler->pd.width;
1415 h = handler->pd.height;
1416 } else if (type & ACCESS_EVENT_LB_MASK) {
1419 w = handler->lb.width;
1420 h = handler->lb.height;
1422 ErrPrint("Invalid event type\n");
1423 return LB_STATUS_ERROR_INVALID;
1426 switch (type & ~ACCESS_EVENT_PD_MASK) {
1427 case ACCESS_EVENT_HIGHLIGHT:
1428 strcpy(ptr, "_access_hl");
1430 case ACCESS_EVENT_HIGHLIGHT_NEXT:
1431 strcpy(ptr, "_access_hl_next");
1433 case ACCESS_EVENT_HIGHLIGHT_PREV:
1434 strcpy(ptr, "_access_hl_prev");
1436 case ACCESS_EVENT_ACTIVATE:
1437 strcpy(ptr, "_access_activate");
1439 case ACCESS_EVENT_ACTION_DOWN:
1440 strcpy(ptr, "_access_action_down");
1442 case ACCESS_EVENT_ACTION_UP:
1443 strcpy(ptr, "_access_action_up");
1445 case ACCESS_EVENT_UNHIGHLIGHT:
1446 strcpy(ptr, "_access_unhighlight");
1448 case ACCESS_EVENT_SCROLL_DOWN:
1449 strcpy(ptr, "_access_scroll_down");
1451 case ACCESS_EVENT_SCROLL_MOVE:
1452 strcpy(ptr, "_access_scroll_move");
1454 case ACCESS_EVENT_SCROLL_UP:
1455 strcpy(ptr, "_access_scroll_up");
1458 return LB_STATUS_ERROR_INVALID;
1462 cb = default_access_event_cb;
1465 ret = send_access_event(handler, cmd, x * w, y * h);
1466 if (ret == LB_STATUS_SUCCESS) {
1467 handler->access_event_cb = cb;
1468 handler->access_event_cbdata = data;
1474 EAPI int livebox_content_event(struct livebox *handler, enum content_event_type type, double x, double y)
1478 char cmd[32] = { '\0', };
1482 ErrPrint("Handler is NIL\n");
1483 return LB_STATUS_ERROR_INVALID;
1486 if (handler->state != CREATE || !handler->id) {
1487 ErrPrint("Handler is not valid\n");
1488 return LB_STATUS_ERROR_INVALID;
1491 if (type & CONTENT_EVENT_PD_MASK) {
1494 if (!handler->is_pd_created) {
1495 ErrPrint("PD is not created\n");
1496 return LB_STATUS_ERROR_INVALID;
1499 if (type & CONTENT_EVENT_MOUSE_MASK) {
1500 if (!handler->pd.data.fb) {
1501 ErrPrint("Handler is not valid\n");
1502 return LB_STATUS_ERROR_INVALID;
1505 if (type & CONTENT_EVENT_MOUSE_MOVE) {
1506 if (fabs(x - handler->pd.x) < MINIMUM_EVENT && fabs(y - handler->pd.y) < MINIMUM_EVENT) {
1507 return LB_STATUS_ERROR_BUSY;
1509 } else if (type & CONTENT_EVENT_MOUSE_SET) {
1515 w = handler->pd.width;
1516 h = handler->pd.height;
1522 } else if (type & CONTENT_EVENT_LB_MASK) {
1525 if (type & CONTENT_EVENT_MOUSE_MASK) {
1526 if (!handler->lb.mouse_event) {
1527 return LB_STATUS_ERROR_INVALID;
1530 if (!handler->lb.data.fb) {
1531 ErrPrint("Handler is not valid\n");
1532 return LB_STATUS_ERROR_INVALID;
1535 if (type & CONTENT_EVENT_MOUSE_MOVE) {
1536 if (fabs(x - handler->lb.x) < MINIMUM_EVENT && fabs(y - handler->lb.y) < MINIMUM_EVENT) {
1537 return LB_STATUS_ERROR_BUSY;
1539 } else if (type & CONTENT_EVENT_MOUSE_SET) {
1545 w = handler->lb.width;
1546 h = handler->lb.height;
1553 ErrPrint("Invalid event type\n");
1554 return LB_STATUS_ERROR_INVALID;
1558 * Must be short than 29 bytes.
1560 switch ((type & ~(CONTENT_EVENT_PD_MASK | CONTENT_EVENT_LB_MASK))) {
1561 case CONTENT_EVENT_MOUSE_ENTER | CONTENT_EVENT_MOUSE_MASK:
1562 strcpy(ptr, "_mouse_enter");
1564 case CONTENT_EVENT_MOUSE_LEAVE | CONTENT_EVENT_MOUSE_MASK:
1565 strcpy(ptr, "_mouse_leave");
1567 case CONTENT_EVENT_MOUSE_UP | CONTENT_EVENT_MOUSE_MASK:
1568 strcpy(ptr, "_mouse_up");
1570 case CONTENT_EVENT_MOUSE_DOWN | CONTENT_EVENT_MOUSE_MASK:
1571 strcpy(ptr, "_mouse_down");
1573 case CONTENT_EVENT_MOUSE_MOVE | CONTENT_EVENT_MOUSE_MASK:
1574 strcpy(ptr, "_mouse_move");
1576 case CONTENT_EVENT_MOUSE_SET | CONTENT_EVENT_MOUSE_MASK:
1577 strcpy(ptr, "_mouse_set");
1579 case CONTENT_EVENT_MOUSE_UNSET | CONTENT_EVENT_MOUSE_MASK:
1580 strcpy(ptr, "_mouse_unset");
1582 case CONTENT_EVENT_KEY_DOWN | CONTENT_EVENT_KEY_MASK:
1583 strcpy(ptr, "_key_down");
1585 case CONTENT_EVENT_KEY_UP | CONTENT_EVENT_KEY_MASK:
1586 strcpy(ptr, "_key_up");
1589 ErrPrint("Invalid event type\n");
1590 return LB_STATUS_ERROR_INVALID;
1593 return send_mouse_event(handler, cmd, x * w, y * h);
1596 EAPI const char *livebox_filename(struct livebox *handler)
1599 ErrPrint("Handler is NIL\n");
1603 if (handler->state != CREATE || !handler->id) {
1604 ErrPrint("Handler is not valid\n");
1608 if (handler->filename) {
1609 return handler->filename;
1613 return util_uri_to_path(handler->id);
1616 EAPI int livebox_get_pdsize(struct livebox *handler, int *w, int *h)
1622 ErrPrint("Handler is NIL\n");
1623 return LB_STATUS_ERROR_INVALID;
1626 if (handler->state != CREATE || !handler->id) {
1627 ErrPrint("Handler is not valid\n");
1628 return LB_STATUS_ERROR_INVALID;
1638 if (!handler->is_pd_created) {
1639 *w = handler->pd.default_width;
1640 *h = handler->pd.default_height;
1642 *w = handler->pd.width;
1643 *h = handler->pd.height;
1646 return LB_STATUS_SUCCESS;
1649 EAPI int livebox_size(struct livebox *handler)
1655 ErrPrint("Handler is NIL\n");
1656 return LB_STATUS_ERROR_INVALID;
1659 if (handler->state != CREATE || !handler->id) {
1660 ErrPrint("Handler is not valid\n");
1661 return LB_STATUS_ERROR_INVALID;
1664 w = handler->lb.width;
1665 h = handler->lb.height;
1667 switch (handler->lb.type) {
1668 case _LB_TYPE_BUFFER:
1669 case _LB_TYPE_SCRIPT:
1670 if (!fb_is_created(handler->lb.data.fb)) {
1679 return livebox_service_size_type(w, h);
1682 EAPI int livebox_set_group(struct livebox *handler, const char *cluster, const char *category, ret_cb_t cb, void *data)
1684 struct packet *packet;
1688 ErrPrint("Handler is NIL\n");
1689 return LB_STATUS_ERROR_INVALID;
1692 if (!cluster || !category || handler->state != CREATE || !handler->id) {
1693 ErrPrint("Invalid argument\n");
1694 return LB_STATUS_ERROR_INVALID;
1697 if (handler->group_changed_cb) {
1698 ErrPrint("Previous group changing request is not finished yet\n");
1699 return LB_STATUS_ERROR_BUSY;
1702 if (!handler->is_user) {
1703 ErrPrint("CA Livebox is not able to change the group\n");
1704 return LB_STATUS_ERROR_PERMISSION;
1707 if (!strcmp(handler->cluster, cluster) && !strcmp(handler->category, category)) {
1708 DbgPrint("No changes\n");
1709 return LB_STATUS_ERROR_ALREADY;
1712 packet = packet_create("change_group", "ssss", handler->pkgname, handler->id, cluster, category);
1714 ErrPrint("Failed to build a param\n");
1715 return LB_STATUS_ERROR_FAULT;
1719 cb = default_group_changed_cb;
1722 ret = master_rpc_async_request(handler, packet, 0, set_group_ret_cb, NULL);
1723 if (ret == LB_STATUS_SUCCESS) {
1724 handler->group_changed_cb = cb;
1725 handler->group_cbdata = data;
1731 EAPI int livebox_get_group(struct livebox *handler, char ** const cluster, char ** const category)
1734 ErrPrint("Handler is NIL\n");
1735 return LB_STATUS_ERROR_INVALID;
1738 if (!cluster || !category || handler->state != CREATE || !handler->id) {
1739 ErrPrint("Invalid argument\n");
1740 return LB_STATUS_ERROR_INVALID;
1743 *cluster = handler->cluster;
1744 *category = handler->category;
1745 return LB_STATUS_SUCCESS;
1748 EAPI int livebox_get_supported_sizes(struct livebox *handler, int *cnt, int *size_list)
1753 if (!handler || !size_list) {
1754 ErrPrint("Invalid argument, handler(%p), size_list(%p)\n", handler, size_list);
1755 return LB_STATUS_ERROR_INVALID;
1758 if (!cnt || handler->state != CREATE || !handler->id) {
1759 ErrPrint("Handler is not valid\n");
1760 return LB_STATUS_ERROR_INVALID;
1763 for (j = i = 0; i < NR_OF_SIZE_LIST; i++) {
1764 if (handler->lb.size_list & (0x01 << i)) {
1769 size_list[j++] = (0x01 << i);
1774 return LB_STATUS_SUCCESS;
1777 EAPI const char *livebox_pkgname(struct livebox *handler)
1780 ErrPrint("Handler is NIL\n");
1784 if (handler->state != CREATE) {
1785 ErrPrint("Handler is not valid\n");
1789 return handler->pkgname;
1792 EAPI double livebox_priority(struct livebox *handler)
1795 ErrPrint("Handler is NIL\n");
1799 if (handler->state != CREATE || !handler->id) {
1800 ErrPrint("Handler is not valid (%p)\n", handler);
1804 return handler->lb.priority;
1807 EAPI int livebox_delete_cluster(const char *cluster, ret_cb_t cb, void *data)
1809 struct packet *packet;
1810 struct cb_info *cbinfo;
1813 packet = packet_create("delete_cluster", "s", cluster);
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_cluster_cb, cbinfo);
1827 destroy_cb_info(cbinfo);
1833 EAPI int livebox_delete_category(const char *cluster, const char *category, ret_cb_t cb, void *data)
1835 struct packet *packet;
1836 struct cb_info *cbinfo;
1839 packet = packet_create("delete_category", "ss", cluster, category);
1841 ErrPrint("Failed to build a param\n");
1842 return LB_STATUS_ERROR_FAULT;
1845 cbinfo = create_cb_info(cb, data);
1847 packet_destroy(packet);
1848 return LB_STATUS_ERROR_FAULT;
1851 ret = master_rpc_async_request(NULL, packet, 0, delete_category_cb, cbinfo);
1853 destroy_cb_info(cbinfo);
1859 EAPI enum livebox_lb_type livebox_lb_type(struct livebox *handler)
1862 ErrPrint("Handler is NIL\n");
1863 return LB_TYPE_INVALID;
1866 if (handler->state != CREATE || !handler->id) {
1867 ErrPrint("Handler is not valid\n");
1868 return LB_TYPE_INVALID;
1871 switch (handler->lb.type) {
1873 return LB_TYPE_IMAGE;
1874 case _LB_TYPE_BUFFER:
1875 case _LB_TYPE_SCRIPT:
1878 id = fb_id(handler->lb.data.fb);
1879 if (id && !strncasecmp(id, SCHEMA_PIXMAP, strlen(SCHEMA_PIXMAP))) {
1880 return LB_TYPE_PIXMAP;
1883 return LB_TYPE_BUFFER;
1885 return LB_TYPE_TEXT;
1890 return LB_TYPE_INVALID;
1893 EAPI enum livebox_pd_type livebox_pd_type(struct livebox *handler)
1896 ErrPrint("Handler is NIL\n");
1897 return PD_TYPE_INVALID;
1900 if (handler->state != CREATE || !handler->id) {
1901 ErrPrint("Handler is not valid\n");
1902 return PD_TYPE_INVALID;
1905 switch (handler->pd.type) {
1907 return PD_TYPE_TEXT;
1908 case _PD_TYPE_BUFFER:
1909 case _PD_TYPE_SCRIPT:
1912 id = fb_id(handler->pd.data.fb);
1913 if (id && !strncasecmp(id, SCHEMA_PIXMAP, strlen(SCHEMA_PIXMAP))) {
1914 return PD_TYPE_PIXMAP;
1917 return PD_TYPE_BUFFER;
1922 return PD_TYPE_INVALID;
1925 EAPI int livebox_set_pd_text_handler(struct livebox *handler, struct livebox_script_operators *ops)
1928 ErrPrint("Handler is NIL\n");
1929 return LB_STATUS_ERROR_INVALID;
1932 if (handler->state != CREATE) {
1933 ErrPrint("Handler is not valid\n");
1934 return LB_STATUS_ERROR_INVALID;
1937 memcpy(&handler->pd.data.ops, ops, sizeof(*ops));
1938 return LB_STATUS_SUCCESS;
1941 EAPI int livebox_set_text_handler(struct livebox *handler, struct livebox_script_operators *ops)
1944 ErrPrint("Handler is NIL\n");
1945 return LB_STATUS_ERROR_INVALID;
1948 if (handler->state != CREATE) {
1949 ErrPrint("Handler is not valid\n");
1950 return LB_STATUS_ERROR_INVALID;
1953 memcpy(&handler->lb.data.ops, ops, sizeof(*ops));
1954 return LB_STATUS_SUCCESS;
1957 EAPI int livebox_acquire_lb_pixmap(struct livebox *handler, ret_cb_t cb, void *data)
1959 struct packet *packet;
1960 struct cb_info *cbinfo;
1965 ErrPrint("Handler is NIL\n");
1966 return LB_STATUS_ERROR_INVALID;
1969 if (handler->state != CREATE || !handler->id) {
1970 ErrPrint("Invalid handle\n");
1971 return LB_STATUS_ERROR_INVALID;
1974 if (handler->lb.type != _LB_TYPE_SCRIPT && handler->lb.type != _LB_TYPE_BUFFER) {
1975 ErrPrint("Handler is not valid type\n");
1976 return LB_STATUS_ERROR_INVALID;
1979 id = fb_id(handler->lb.data.fb);
1980 if (!id || strncasecmp(id, SCHEMA_PIXMAP, strlen(SCHEMA_PIXMAP))) {
1981 return LB_STATUS_ERROR_INVALID;
1984 packet = packet_create("lb_acquire_pixmap", "ss", handler->pkgname, handler->id);
1986 ErrPrint("Failed to build a param\n");
1987 return LB_STATUS_ERROR_FAULT;
1990 cbinfo = create_cb_info(cb, data);
1992 packet_destroy(packet);
1993 return LB_STATUS_ERROR_FAULT;
1996 ret = master_rpc_async_request(handler, packet, 0, lb_pixmap_acquired_cb, cbinfo);
1998 destroy_cb_info(cbinfo);
2004 EAPI int livebox_release_lb_pixmap(struct livebox *handler, int pixmap)
2006 struct packet *packet;
2008 if (!handler || pixmap == 0) {
2009 ErrPrint("Handler is NIL [%d]\n", pixmap);
2010 return LB_STATUS_ERROR_INVALID;
2013 if (handler->state != CREATE || !handler->id) {
2014 ErrPrint("Invalid handle\n");
2015 return LB_STATUS_ERROR_INVALID;
2018 if (handler->lb.type != _LB_TYPE_SCRIPT && handler->lb.type != _LB_TYPE_BUFFER) {
2019 ErrPrint("Handler is not valid type\n");
2020 return LB_STATUS_ERROR_INVALID;
2023 packet = packet_create_noack("lb_release_pixmap", "ssi", handler->pkgname, handler->id, pixmap);
2025 ErrPrint("Failed to build a param\n");
2026 return LB_STATUS_ERROR_INVALID;
2029 return master_rpc_request_only(handler, packet);
2032 EAPI int livebox_acquire_pd_pixmap(struct livebox *handler, ret_cb_t cb, void *data)
2034 struct packet *packet;
2035 struct cb_info *cbinfo;
2040 ErrPrint("Handler is NIL\n");
2041 return LB_STATUS_ERROR_INVALID;
2044 if (handler->state != CREATE || !handler->id) {
2045 ErrPrint("Invalid handle\n");
2046 return LB_STATUS_ERROR_INVALID;
2049 if (handler->pd.type != _PD_TYPE_SCRIPT && handler->pd.type != _PD_TYPE_BUFFER) {
2050 ErrPrint("Handler is not valid type\n");
2051 return LB_STATUS_ERROR_INVALID;
2054 id = fb_id(handler->pd.data.fb);
2055 if (!id || strncasecmp(id, SCHEMA_PIXMAP, strlen(SCHEMA_PIXMAP))) {
2056 return LB_STATUS_ERROR_INVALID;
2059 packet = packet_create("pd_acquire_pixmap", "ss", handler->pkgname, handler->id);
2061 ErrPrint("Failed to build a param\n");
2062 return LB_STATUS_ERROR_FAULT;
2065 cbinfo = create_cb_info(cb, data);
2067 packet_destroy(packet);
2068 return LB_STATUS_ERROR_FAULT;
2071 ret = master_rpc_async_request(handler, packet, 0, pd_pixmap_acquired_cb, cbinfo);
2073 destroy_cb_info(cbinfo);
2079 EAPI int livebox_pd_pixmap(const struct livebox *handler)
2085 ErrPrint("Handler is NIL\n");
2089 if (handler->state != CREATE || !handler->id) {
2090 ErrPrint("Invalid handler\n");
2094 if (handler->pd.type != _PD_TYPE_SCRIPT && handler->pd.type != _PD_TYPE_BUFFER) {
2095 ErrPrint("Invalid handler\n");
2099 id = fb_id(handler->pd.data.fb);
2100 if (id && sscanf(id, SCHEMA_PIXMAP "%d", &pixmap) != 1) {
2101 ErrPrint("PIXMAP Id is not valid\n");
2108 EAPI int livebox_lb_pixmap(const struct livebox *handler)
2114 ErrPrint("Handler is NIL\n");
2118 if (handler->state != CREATE || !handler->id) {
2119 ErrPrint("Invalid handler\n");
2123 if (handler->lb.type != _LB_TYPE_SCRIPT && handler->lb.type != _LB_TYPE_BUFFER) {
2124 ErrPrint("Invalid handler\n");
2128 id = fb_id(handler->lb.data.fb);
2129 if (id && sscanf(id, SCHEMA_PIXMAP "%d", &pixmap) != 1) {
2130 ErrPrint("PIXMAP Id is not valid\n");
2137 EAPI int livebox_release_pd_pixmap(struct livebox *handler, int pixmap)
2139 struct packet *packet;
2141 if (!handler || pixmap == 0) {
2142 ErrPrint("Handler is NIL [%d]\n", pixmap);
2143 return LB_STATUS_ERROR_INVALID;
2146 if (handler->state != CREATE || !handler->id) {
2147 ErrPrint("Invalid handle\n");
2148 return LB_STATUS_ERROR_INVALID;
2151 if (handler->pd.type != _PD_TYPE_SCRIPT && handler->pd.type != _PD_TYPE_BUFFER) {
2152 ErrPrint("Handler is not valid type\n");
2153 return LB_STATUS_ERROR_INVALID;
2156 packet = packet_create_noack("pd_release_pixmap", "ssi", handler->pkgname, handler->id, pixmap);
2158 ErrPrint("Failed to build a param\n");
2159 return LB_STATUS_ERROR_FAULT;
2162 return master_rpc_request_only(handler, packet);
2165 EAPI void *livebox_acquire_fb(struct livebox *handler)
2168 ErrPrint("Handler is NIL\n");
2172 if (handler->state != CREATE || !handler->id) {
2173 ErrPrint("Invalid handle\n");
2177 if (handler->lb.type != _LB_TYPE_SCRIPT && handler->lb.type != _LB_TYPE_BUFFER) {
2178 ErrPrint("Handler is not valid type\n");
2182 return fb_acquire_buffer(handler->lb.data.fb);
2185 EAPI int livebox_release_fb(void *buffer)
2187 return fb_release_buffer(buffer);
2190 EAPI int livebox_fb_refcnt(void *buffer)
2192 return fb_refcnt(buffer);
2195 EAPI void *livebox_acquire_pdfb(struct livebox *handler)
2198 ErrPrint("Handler is NIL\n");
2202 if (handler->state != CREATE || !handler->id) {
2203 ErrPrint("Invalid handler\n");
2207 if (handler->pd.type != _PD_TYPE_SCRIPT && handler->pd.type != _PD_TYPE_BUFFER) {
2208 ErrPrint("Handler is not valid type\n");
2212 return fb_acquire_buffer(handler->pd.data.fb);
2215 EAPI int livebox_release_pdfb(void *buffer)
2217 return fb_release_buffer(buffer);
2220 EAPI int livebox_pdfb_refcnt(void *buffer)
2222 return fb_refcnt(buffer);
2225 EAPI int livebox_pdfb_bufsz(struct livebox *handler)
2228 ErrPrint("Handler is NIL\n");
2229 return LB_STATUS_ERROR_INVALID;
2232 if (handler->state != CREATE || !handler->id) {
2233 ErrPrint("Handler is not valid\n");
2234 return LB_STATUS_ERROR_INVALID;
2237 return fb_size(handler->pd.data.fb);
2240 EAPI int livebox_lbfb_bufsz(struct livebox *handler)
2243 ErrPrint("Handler is NIL\n");
2244 return LB_STATUS_ERROR_INVALID;
2247 if (handler->state != CREATE || !handler->id) {
2248 ErrPrint("Handler is not valid\n");
2249 return LB_STATUS_ERROR_INVALID;
2252 return fb_size(handler->lb.data.fb);
2255 EAPI int livebox_is_user(struct livebox *handler)
2258 ErrPrint("Handler is NIL\n");
2259 return LB_STATUS_ERROR_INVALID;
2262 if (handler->state != CREATE) {
2263 ErrPrint("Handler is invalid\n");
2264 return LB_STATUS_ERROR_INVALID;
2267 return handler->is_user;
2270 EAPI int livebox_set_pinup(struct livebox *handler, int flag, ret_cb_t cb, void *data)
2272 struct packet *packet;
2276 ErrPrint("Handler is NIL\n");
2277 return LB_STATUS_ERROR_INVALID;
2280 if (handler->state != CREATE || !handler->id) {
2281 ErrPrint("Handler is not valid\n");
2282 return LB_STATUS_ERROR_INVALID;
2285 if (handler->pinup_cb) {
2286 ErrPrint("Previous pinup request is not finished\n");
2287 return LB_STATUS_ERROR_BUSY;
2290 if (handler->is_pinned_up == flag) {
2291 DbgPrint("No changes\n");
2292 return LB_STATUS_ERROR_ALREADY;
2295 packet = packet_create("pinup_changed", "ssi", handler->pkgname, handler->id, flag);
2297 ErrPrint("Failed to build a param\n");
2298 return LB_STATUS_ERROR_FAULT;
2302 cb = default_pinup_cb;
2305 ret = master_rpc_async_request(handler, packet, 0, pinup_done_cb, NULL);
2306 if (ret == LB_STATUS_SUCCESS) {
2307 handler->pinup_cb = cb;
2308 handler->pinup_cbdata = data;
2314 EAPI int livebox_is_pinned_up(struct livebox *handler)
2317 ErrPrint("Handler is NIL\n");
2318 return LB_STATUS_ERROR_INVALID;
2321 if (handler->state != CREATE || !handler->id) {
2322 return LB_STATUS_ERROR_INVALID;
2325 return handler->is_pinned_up;
2328 EAPI int livebox_has_pinup(struct livebox *handler)
2331 ErrPrint("Handler is NIL\n");
2332 return LB_STATUS_ERROR_INVALID;
2335 if (handler->state != CREATE || !handler->id) {
2336 return LB_STATUS_ERROR_INVALID;
2339 return handler->lb.pinup_supported;
2342 EAPI int livebox_set_data(struct livebox *handler, void *data)
2345 ErrPrint("Handler is NIL\n");
2346 return LB_STATUS_ERROR_INVALID;
2349 if (handler->state != CREATE) {
2350 return LB_STATUS_ERROR_INVALID;
2353 handler->data = data;
2354 return LB_STATUS_SUCCESS;
2357 EAPI void *livebox_get_data(struct livebox *handler)
2360 ErrPrint("Handler is NIL\n");
2364 if (handler->state != CREATE) {
2368 return handler->data;
2371 EAPI int livebox_is_exists(const char *pkgname)
2375 lb = lb_pkgname(pkgname);
2384 EAPI const char *livebox_content(struct livebox *handler)
2387 ErrPrint("Handler is NIL\n");
2391 if (handler->state != CREATE) {
2395 return handler->content;
2398 EAPI const char *livebox_category_title(struct livebox *handler)
2401 ErrPrint("Handler is NIL\n");
2405 if (handler->state != CREATE) {
2409 return handler->title;
2412 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)
2414 struct packet *packet;
2415 struct cb_info *cbinfo;
2419 ErrPrint("Handler is NIL\n");
2420 return LB_STATUS_ERROR_INVALID;
2423 if ((handler->lb.type != _LB_TYPE_TEXT && handler->pd.type != _PD_TYPE_TEXT) || handler->state != CREATE || !handler->id) {
2424 ErrPrint("Handler is not valid\n");
2425 return LB_STATUS_ERROR_INVALID;
2436 packet = packet_create("text_signal", "ssssdddd",
2437 handler->pkgname, handler->id, emission, source, sx, sy, ex, ey);
2439 ErrPrint("Failed to build a param\n");
2440 return LB_STATUS_ERROR_FAULT;
2443 cbinfo = create_cb_info(cb, data);
2445 packet_destroy(packet);
2446 return LB_STATUS_ERROR_FAULT;
2449 ret = master_rpc_async_request(handler, packet, 0, text_signal_cb, cbinfo);
2451 destroy_cb_info(cbinfo);
2457 EAPI int livebox_subscribe_group(const char *cluster, const char *category)
2459 struct packet *packet;
2463 * Validate the group info using DB
2464 * If the group info is not valid, do not send this request
2467 packet = packet_create_noack("subscribe", "ss", cluster ? cluster : "", category ? category : "");
2469 ErrPrint("Failed to create a packet\n");
2470 return LB_STATUS_ERROR_FAULT;
2473 return master_rpc_request_only(NULL, packet);
2476 EAPI int livebox_unsubscribe_group(const char *cluster, const char *category)
2478 struct packet *packet;
2482 * Validate the group info using DB
2483 * If the group info is not valid, do not send this request
2484 * AND Check the subscribed or not too
2487 packet = packet_create_noack("unsubscribe", "ss", cluster ? cluster : "", category ? category : "");
2489 ErrPrint("Failed to create a packet\n");
2490 return LB_STATUS_ERROR_FAULT;
2493 return master_rpc_request_only(NULL, packet);
2496 EAPI int livebox_refresh(struct livebox *handler)
2498 struct packet *packet;
2501 ErrPrint("Hnalder is NIL\n");
2502 return LB_STATUS_ERROR_INVALID;
2505 if (handler->state != CREATE || !handler->id) {
2506 return LB_STATUS_ERROR_INVALID;
2509 packet = packet_create_noack("update", "ss", handler->pkgname, handler->id);
2511 ErrPrint("Failed to create a packet\n");
2512 return LB_STATUS_ERROR_FAULT;
2515 return master_rpc_request_only(handler, packet);
2518 EAPI int livebox_refresh_group(const char *cluster, const char *category)
2520 struct packet *packet;
2522 if (!cluster || !category) {
2523 ErrPrint("Invalid argument\n");
2524 return LB_STATUS_ERROR_INVALID;
2527 packet = packet_create_noack("refresh_group", "ss", cluster, category);
2529 ErrPrint("Failed to create a packet\n");
2530 return LB_STATUS_ERROR_FAULT;
2533 return master_rpc_request_only(NULL, packet);
2536 EAPI int livebox_set_visibility(struct livebox *handler, enum livebox_visible_state state)
2538 struct packet *packet;
2542 ErrPrint("Handler is NIL\n");
2543 return LB_STATUS_ERROR_INVALID;
2546 if (handler->state != CREATE || !handler->id) {
2547 return LB_STATUS_ERROR_INVALID;
2550 if (!handler->is_user) {
2551 /* System cluster livebox cannot be changed its visible states */
2552 if (state == LB_HIDE_WITH_PAUSE) {
2553 ErrPrint("CA Livebox is not able to change the visibility\n");
2554 return LB_STATUS_ERROR_PERMISSION;
2558 if (handler->visible == state) {
2559 return LB_STATUS_ERROR_ALREADY;
2562 packet = packet_create_noack("change,visibility", "ssi", handler->pkgname, handler->id, (int)state);
2564 ErrPrint("Failed to create a packet\n");
2565 return LB_STATUS_ERROR_FAULT;
2568 ret = master_rpc_request_only(handler, packet);
2570 handler->visible = state;
2576 EAPI enum livebox_visible_state livebox_visibility(struct livebox *handler)
2579 ErrPrint("Handler is NIL\n");
2580 return LB_VISIBLE_ERROR;
2583 if (handler->state != CREATE || !handler->id) {
2584 return LB_VISIBLE_ERROR;
2587 return handler->visible;
2590 int lb_set_group(struct livebox *handler, const char *cluster, const char *category)
2596 pc = strdup(cluster);
2598 CRITICAL_LOG("Heap: %s (cluster: %s)\n", strerror(errno), cluster);
2599 return LB_STATUS_ERROR_MEMORY;
2604 ps = strdup(category);
2606 CRITICAL_LOG("Heap: %s (category: %s)\n", strerror(errno), category);
2608 return LB_STATUS_ERROR_MEMORY;
2612 if (handler->cluster) {
2613 free(handler->cluster);
2616 if (handler->category) {
2617 free(handler->category);
2620 handler->cluster = pc;
2621 handler->category = ps;
2623 return LB_STATUS_SUCCESS;
2626 void lb_set_size(struct livebox *handler, int w, int h)
2628 handler->lb.width = w;
2629 handler->lb.height = h;
2632 void lb_set_update_mode(struct livebox *handle, int active_mode)
2634 handle->is_active_update = active_mode;
2637 void lb_set_pdsize(struct livebox *handler, int w, int h)
2639 handler->pd.width = w;
2640 handler->pd.height = h;
2643 void lb_set_default_pdsize(struct livebox *handler, int w, int h)
2645 handler->pd.default_width = w;
2646 handler->pd.default_height = h;
2649 void lb_invoke_fault_handler(enum livebox_fault_type event, const char *pkgname, const char *file, const char *func)
2653 struct fault_info *info;
2655 dlist_foreach_safe(s_info.fault_list, l, n, info) {
2656 if (info->handler(event, pkgname, file, func, info->user_data) == EXIT_FAILURE) {
2657 s_info.fault_list = dlist_remove(s_info.fault_list, l);
2662 void lb_invoke_event_handler(struct livebox *handler, enum livebox_event_type event)
2666 struct event_info *info;
2668 dlist_foreach_safe(s_info.event_list, l, n, info) {
2669 if (info->handler(handler, event, info->user_data) == EXIT_FAILURE) {
2670 s_info.event_list = dlist_remove(s_info.event_list, l);
2675 struct livebox *lb_find_livebox(const char *pkgname, const char *id)
2678 struct livebox *handler;
2680 dlist_foreach(s_info.livebox_list, l, handler) {
2685 if (!strcmp(handler->pkgname, pkgname) && !strcmp(handler->id, id)) {
2693 struct livebox *lb_find_livebox_by_timestamp(double timestamp)
2696 struct livebox *handler;
2698 dlist_foreach(s_info.livebox_list, l, handler) {
2699 if (handler->timestamp == timestamp) {
2707 struct livebox *lb_new_livebox(const char *pkgname, const char *id, double timestamp)
2709 struct livebox *handler;
2711 handler = calloc(1, sizeof(*handler));
2713 ErrPrint("Failed to create a new livebox\n");
2717 handler->pkgname = strdup(pkgname);
2718 if (!handler->pkgname) {
2719 ErrPrint("%s\n", strerror(errno));
2724 handler->id = strdup(id);
2726 ErrPrint("%s\n", strerror(errno));
2727 free(handler->pkgname);
2732 handler->timestamp = timestamp;
2733 handler->lb.type = _LB_TYPE_FILE;
2734 handler->pd.type = _PD_TYPE_SCRIPT;
2735 handler->state = CREATE;
2736 handler->visible = LB_SHOW;
2738 s_info.livebox_list = dlist_append(s_info.livebox_list, handler);
2743 int lb_delete_all(void)
2747 struct livebox *handler;
2749 dlist_foreach_safe(s_info.livebox_list, l, n, handler) {
2750 lb_invoke_event_handler(handler, LB_EVENT_DELETED);
2754 return LB_STATUS_SUCCESS;
2757 int lb_set_content(struct livebox *handler, const char *content)
2759 if (handler->content) {
2760 free(handler->content);
2761 handler->content = NULL;
2765 handler->content = strdup(content);
2766 if (!handler->content) {
2767 CRITICAL_LOG("Heap: %s (content: %s)\n", strerror(errno), content);
2768 return LB_STATUS_ERROR_MEMORY;
2772 return LB_STATUS_SUCCESS;
2775 int lb_set_title(struct livebox *handler, const char *title)
2777 if (handler->title) {
2778 free(handler->title);
2779 handler->title = NULL;
2783 handler->title = strdup(title);
2784 if (!handler->title) {
2785 CRITICAL_LOG("Heap: %s (title: %s)\n", strerror(errno), title);
2786 return LB_STATUS_ERROR_MEMORY;
2790 return LB_STATUS_SUCCESS;
2793 void lb_set_size_list(struct livebox *handler, int size_list)
2795 handler->lb.size_list = size_list;
2798 void lb_set_auto_launch(struct livebox *handler, const char *auto_launch)
2800 if (!strlen(auto_launch)) {
2804 handler->lb.auto_launch = strdup(auto_launch);
2805 if (!handler->lb.auto_launch) {
2806 ErrPrint("Heap: %s\n", strerror(errno));
2810 void lb_set_priority(struct livebox *handler, double priority)
2812 handler->lb.priority = priority;
2815 void lb_set_id(struct livebox *handler, const char *id)
2821 handler->id = strdup(id);
2823 ErrPrint("Error: %s\n", strerror(errno));
2827 void lb_set_filename(struct livebox *handler, const char *filename)
2829 if (handler->filename) {
2830 if (unlink(handler->filename) < 0) {
2831 ErrPrint("unlink: %s\n", strerror(errno));
2834 free(handler->filename);
2837 handler->filename = strdup(filename);
2838 if (!handler->filename) {
2839 ErrPrint("Heap: %s\n", strerror(errno));
2844 int lb_set_lb_fb(struct livebox *handler, const char *filename)
2849 return LB_STATUS_ERROR_INVALID;
2852 fb = handler->lb.data.fb;
2853 if (fb && !strcmp(fb_id(fb), filename)) { /*!< BUFFER is not changed, */
2854 return LB_STATUS_SUCCESS;
2857 handler->lb.data.fb = NULL;
2859 if (!filename || filename[0] == '\0') {
2863 return LB_STATUS_SUCCESS;
2866 handler->lb.data.fb = fb_create(filename, handler->lb.width, handler->lb.height);
2867 if (!handler->lb.data.fb) {
2868 ErrPrint("Faield to create a FB\n");
2872 return LB_STATUS_ERROR_FAULT;
2879 return LB_STATUS_SUCCESS;
2882 int lb_set_pd_fb(struct livebox *handler, const char *filename)
2887 return LB_STATUS_ERROR_INVALID;
2890 fb = handler->pd.data.fb;
2891 if (fb && !strcmp(fb_id(fb), filename)) {
2892 /* BUFFER is not changed, just update the content */
2893 return LB_STATUS_ERROR_EXIST;
2895 handler->pd.data.fb = NULL;
2897 if (!filename || filename[0] == '\0') {
2901 return LB_STATUS_SUCCESS;
2904 handler->pd.data.fb = fb_create(filename, handler->pd.width, handler->pd.height);
2905 if (!handler->pd.data.fb) {
2906 ErrPrint("Failed to create a FB\n");
2910 return LB_STATUS_ERROR_FAULT;
2916 return LB_STATUS_SUCCESS;
2919 struct fb_info *lb_get_lb_fb(struct livebox *handler)
2921 return handler->lb.data.fb;
2924 struct fb_info *lb_get_pd_fb(struct livebox *handler)
2926 return handler->pd.data.fb;
2929 void lb_set_user(struct livebox *handler, int user)
2931 handler->is_user = user;
2934 void lb_set_pinup(struct livebox *handler, int pinup_supported)
2936 handler->lb.pinup_supported = pinup_supported;
2939 void lb_set_text_lb(struct livebox *handler)
2941 handler->lb.type = _LB_TYPE_TEXT;
2944 void lb_set_text_pd(struct livebox *handler)
2946 handler->pd.type = _PD_TYPE_TEXT;
2949 int lb_text_lb(struct livebox *handler)
2951 return handler->lb.type == _LB_TYPE_TEXT;
2954 int lb_text_pd(struct livebox *handler)
2956 return handler->pd.type == _PD_TYPE_TEXT;
2959 void lb_set_period(struct livebox *handler, double period)
2961 handler->lb.period = period;
2964 struct livebox *lb_ref(struct livebox *handler)
2974 struct livebox *lb_unref(struct livebox *handler)
2981 if (handler->refcnt > 0) {
2985 if (handler->created_cb) {
2986 handler->created_cb(handler, LB_STATUS_ERROR_FAULT, handler->created_cbdata);
2987 handler->created_cb = NULL;
2988 handler->created_cbdata = NULL;
2991 if (handler->deleted_cb) {
2992 handler->deleted_cb(handler, LB_STATUS_ERROR_FAULT, handler->deleted_cbdata);
2993 handler->deleted_cb = NULL;
2994 handler->deleted_cbdata = NULL;
2997 if (handler->pinup_cb) {
2998 handler->pinup_cb(handler, LB_STATUS_ERROR_FAULT, handler->pinup_cbdata);
2999 handler->pinup_cb = NULL;
3000 handler->pinup_cbdata = NULL;
3003 if (handler->group_changed_cb) {
3004 handler->group_changed_cb(handler, LB_STATUS_ERROR_FAULT, handler->group_cbdata);
3005 handler->group_changed_cb = NULL;
3006 handler->group_cbdata = NULL;
3009 if (handler->period_changed_cb) {
3010 handler->period_changed_cb(handler, LB_STATUS_ERROR_FAULT, handler->period_cbdata);
3011 handler->period_changed_cb = NULL;
3012 handler->period_cbdata = NULL;
3015 if (handler->size_changed_cb) {
3016 handler->size_changed_cb(handler, LB_STATUS_ERROR_FAULT, handler->size_cbdata);
3017 handler->size_changed_cb = NULL;
3018 handler->size_cbdata = NULL;
3021 if (handler->pd_created_cb) {
3022 handler->pd_created_cb(handler, LB_STATUS_ERROR_FAULT, handler->pd_created_cbdata);
3023 handler->pd_created_cb = NULL;
3024 handler->pd_created_cbdata = NULL;
3027 if (handler->pd_destroyed_cb) {
3028 handler->pd_destroyed_cb(handler, LB_STATUS_ERROR_FAULT, handler->pd_destroyed_cbdata);
3029 handler->pd_destroyed_cb = NULL;
3030 handler->pd_destroyed_cbdata = NULL;
3033 if (handler->update_mode_cb) {
3034 handler->update_mode_cb(handler, LB_STATUS_ERROR_FAULT, handler->update_mode_cbdata);
3035 handler->update_mode_cb = NULL;
3036 handler->update_mode_cbdata = NULL;
3039 if (handler->access_event_cb) {
3040 handler->access_event_cb(handler, LB_ACCESS_STATUS_ERROR, handler->access_event_cbdata);
3041 handler->access_event_cb = NULL;
3042 handler->access_event_cbdata = NULL;
3045 if (handler->filename) {
3046 (void)util_unlink(handler->filename);
3049 dlist_remove_data(s_info.livebox_list, handler);
3051 handler->state = DESTROYED;
3052 free(handler->cluster);
3053 free(handler->category);
3055 free(handler->pkgname);
3056 free(handler->filename);
3057 free(handler->lb.auto_launch);
3059 if (handler->lb.data.fb) {
3060 fb_destroy(handler->lb.data.fb);
3061 handler->lb.data.fb = NULL;
3064 if (handler->pd.data.fb) {
3065 fb_destroy(handler->pd.data.fb);
3066 handler->pd.data.fb = NULL;
3073 int lb_send_delete(struct livebox *handler, ret_cb_t cb, void *data)
3075 struct packet *packet;
3076 struct cb_info *cbinfo;
3079 if (!cb && !!data) {
3080 ErrPrint("Invalid argument\n");
3081 return LB_STATUS_ERROR_INVALID;
3084 if (handler->deleted_cb) {
3085 ErrPrint("Already in-progress\n");
3086 return LB_STATUS_ERROR_BUSY;
3089 packet = packet_create("delete", "ss", handler->pkgname, handler->id);
3091 ErrPrint("Failed to build a param\n");
3093 cb(handler, LB_STATUS_ERROR_FAULT, data);
3096 return LB_STATUS_ERROR_FAULT;
3100 cb = default_delete_cb;
3103 cbinfo = create_cb_info(cb, data);
3105 packet_destroy(packet);
3106 return LB_STATUS_ERROR_FAULT;
3109 ret = master_rpc_async_request(handler, packet, 0, del_ret_cb, cbinfo);
3111 destroy_cb_info(cbinfo);
3117 EAPI int livebox_client_paused(void)
3119 struct packet *packet;
3121 packet = packet_create_noack("client_paused", "d", util_timestamp());
3123 ErrPrint("Failed to create a pause packet\n");
3124 return LB_STATUS_ERROR_FAULT;
3127 return master_rpc_request_only(NULL, packet);
3130 EAPI int livebox_client_resumed(void)
3132 struct packet *packet;
3134 packet = packet_create_noack("client_resumed", "d", util_timestamp());
3136 ErrPrint("Failed to create a resume packet\n");
3137 return LB_STATUS_ERROR_FAULT;
3140 return master_rpc_request_only(NULL, packet);