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 DbgPrint("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 DbgPrint("Resize request is failed: %d\n", ret);
203 DbgPrint("Resize request is successfully sent\n");
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);
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;
254 handler->group_changed_cb(handler, ret, handler->group_cbdata);
255 handler->group_changed_cb = NULL;
256 handler->group_cbdata = NULL;
259 static void period_ret_cb(struct livebox *handler, const struct packet *result, void *data)
264 ret = LB_STATUS_ERROR_FAULT;
266 } else if (packet_get(result, "i", &ret) != 1) {
267 ErrPrint("Invalid argument\n");
268 ret = LB_STATUS_ERROR_INVALID;
275 DbgPrint("Succeed to send period change request, waiting result\n");
279 handler->period_changed_cb(handler, ret, handler->period_cbdata);
280 handler->period_changed_cb = NULL;
281 handler->period_cbdata = NULL;
284 static void del_ret_cb(struct livebox *handler, const struct packet *result, void *data)
286 struct cb_info *info = data;
293 destroy_cb_info(info);
296 ErrPrint("Connection lost?\n");
297 ret = LB_STATUS_ERROR_FAULT;
298 } else if (packet_get(result, "i", &ret) != 1) {
299 ErrPrint("Invalid argument\n");
300 ret = LB_STATUS_ERROR_INVALID;
304 DbgPrint("Returns %d (waiting deleted event)\n", ret);
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 DbgPrint("new request is sent, just waiting the created event\n");
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 DbgPrint("Failed to create a PD\n");
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);
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 DbgPrint("Result is NIL (may connection lost)\n");
422 ret = LB_STATUS_ERROR_FAULT;
423 } else if (packet_get(result, "i", &ret) != 1) {
424 DbgPrint("Invalid parameter\n");
425 ret = LB_STATUS_ERROR_INVALID;
429 DbgPrint("PD Destroyed callback prepared\n");
430 handler->pd_destroyed_cb = cb;
431 handler->pd_destroyed_cbdata = cbdata;
433 DbgPrint("PD is not desroyed (forcely reset, pd flag)\n");
434 handler->is_pd_created = 0;
435 cb(handler, ret, cbdata);
439 static void delete_cluster_cb(struct livebox *handler, const struct packet *result, void *data)
441 struct cb_info *info = data;
448 destroy_cb_info(info);
451 ret = LB_STATUS_ERROR_FAULT;
452 } else if (packet_get(result, "i", &ret) != 1) {
453 ret = LB_STATUS_ERROR_INVALID;
456 DbgPrint("Delete category returns: %d\n", ret);
459 cb(handler, ret, cbdata);
462 static void delete_category_cb(struct livebox *handler, const struct packet *result, void *data)
464 struct cb_info *info = data;
471 destroy_cb_info(info);
474 ret = LB_STATUS_ERROR_FAULT;
475 else if (packet_get(result, "i", &ret) != 1)
476 ret = LB_STATUS_ERROR_INVALID;
478 DbgPrint("Delete category returns: %d\n", ret);
481 cb(handler, ret, cbdata);
484 static void pixmap_acquired_cb(struct livebox *handler, const struct packet *result, void *data)
489 struct cb_info *info = data;
493 destroy_cb_info(info);
496 ret = 0; /* PIXMAP 0 means error */
497 else if (packet_get(result, "i", &ret) != 1)
501 cb(handler, ret, cbdata);
504 static void pinup_done_cb(struct livebox *handler, const struct packet *result, void *data)
509 ret = LB_STATUS_ERROR_FAULT;
511 } else if (packet_get(result, "i", &ret) != 1) {
521 handler->pinup_cb(handler, ret, handler->pinup_cbdata);
522 handler->pinup_cb = NULL;
523 handler->pinup_cbdata = NULL;
526 static void access_ret_cb(struct livebox *handler, const struct packet *result, void *data)
531 ret = LB_STATUS_ERROR_FAULT;
535 if (packet_get(result, "i", &ret) != 1) {
536 ret = LB_STATUS_ERROR_INVALID;
540 if (ret != LB_STATUS_SUCCESS) {
544 DbgPrint("Access event is successfully sent. waiting result\n");
548 handler->access_event_cb(handler, ret, handler->access_event_cbdata);
549 handler->access_event_cb = NULL;
550 handler->access_event_cbdata = NULL;
554 static int send_access_event(struct livebox *handler, const char *event, int x, int y)
556 struct packet *packet;
559 timestamp = util_timestamp();
561 packet = packet_create(event, "ssdii", handler->pkgname, handler->id, timestamp, x, y);
563 ErrPrint("Failed to build packet\n");
564 return LB_STATUS_ERROR_FAULT;
567 DbgPrint("Send: %dx%d\n", x, y);
569 return master_rpc_async_request(handler, packet, 0, access_ret_cb, NULL);
572 static int send_mouse_event(struct livebox *handler, const char *event, int x, int y)
574 struct packet *packet;
577 timestamp = util_timestamp();
578 packet = packet_create_noack(event, "ssdii", handler->pkgname, handler->id, timestamp, x, y);
580 ErrPrint("Failed to build param\n");
581 return LB_STATUS_ERROR_FAULT;
584 DbgPrint("Send: %dx%d\n", x, y);
586 return master_rpc_request_only(handler, packet);
589 EAPI int livebox_init(void *disp)
593 if (s_info.init_count > 0) {
595 return LB_STATUS_SUCCESS;
597 env = getenv("PROVIDER_DISABLE_PREVENT_OVERWRITE");
598 if (env && !strcasecmp(env, "true"))
599 s_info.prevent_overwrite = 1;
601 env = getenv("PROVIDER_EVENT_FILTER");
603 sscanf(env, "%lf", &MINIMUM_EVENT);
606 char filename[BUFSIZ];
607 snprintf(filename, sizeof(filename), "/tmp/%d.box.log", getpid());
608 __file_log_fp = fopen(filename, "w+t");
610 __file_log_fp = fdopen(1, "w+t");
612 critical_log_init("viewer");
613 livebox_service_init();
619 return LB_STATUS_SUCCESS;
622 EAPI int livebox_fini(void)
624 if (s_info.init_count <= 0) {
625 DbgPrint("Didn't initialized\n");
626 return LB_STATUS_ERROR_INVALID;
630 if (s_info.init_count > 0) {
631 DbgPrint("init count : %d\n", s_info.init_count);
632 return LB_STATUS_SUCCESS;
637 livebox_service_fini();
639 return LB_STATUS_SUCCESS;
642 static inline char *lb_pkgname(const char *pkgname)
646 lb = livebox_service_pkgname(pkgname);
648 if (util_validate_livebox_package(pkgname) == 0)
649 return strdup(pkgname);
656 * Just wrapping the livebox_add_with_size function.
658 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)
660 return livebox_add_with_size(pkgname, content, cluster, category, period, LB_SIZE_TYPE_UNKNOWN, cb, data);
663 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)
665 struct livebox *handler;
666 struct packet *packet;
670 struct cb_info *cbinfo;
672 if (!pkgname || !cluster || !category) {
673 ErrPrint("Invalid arguments: pkgname[%p], cluster[%p], category[%p]\n",
674 pkgname, cluster, category);
678 if (type != LB_SIZE_TYPE_UNKNOWN)
679 livebox_service_get_size(type, &width, &height);
681 handler = calloc(1, sizeof(*handler));
683 ErrPrint("Error: %s\n", strerror(errno));
687 handler->pkgname = lb_pkgname(pkgname);
688 if (!handler->pkgname) {
693 if (livebox_service_is_enabled(handler->pkgname) == 0) {
694 DbgPrint("Livebox [%s](%s) is disabled package\n", handler->pkgname, pkgname);
695 free(handler->pkgname);
701 handler->content = strdup(content);
702 if (!handler->content) {
703 ErrPrint("Error: %s\n", strerror(errno));
704 free(handler->pkgname);
709 handler->content = livebox_service_content(handler->pkgname);
712 handler->cluster = strdup(cluster);
713 if (!handler->cluster) {
714 ErrPrint("Error: %s\n", strerror(errno));
715 free(handler->content);
716 free(handler->pkgname);
721 handler->category = strdup(category);
722 if (!handler->category) {
723 ErrPrint("Error: %s\n", strerror(errno));
724 free(handler->cluster);
725 free(handler->content);
726 free(handler->pkgname);
732 cb = default_create_cb;
734 /* Data provider will set this */
735 handler->lb.type = _LB_TYPE_FILE;
736 handler->pd.type = _PD_TYPE_SCRIPT;
737 handler->lb.period = period;
739 /* Used for handling the mouse event on a box */
740 handler->lb.mouse_event = livebox_service_mouse_event(handler->pkgname);
742 /* Cluster infomration is not determined yet */
743 handler->nr_of_sizes = 0x01;
745 handler->timestamp = util_timestamp();
746 handler->is_user = 1;
747 handler->visible = LB_SHOW;
749 s_info.livebox_list = dlist_append(s_info.livebox_list, handler);
751 packet = packet_create("new", "dssssdii", handler->timestamp, handler->pkgname, handler->content, cluster, category, period, width, height);
753 ErrPrint("Failed to create a new packet\n");
754 free(handler->category);
755 free(handler->cluster);
756 free(handler->content);
757 free(handler->pkgname);
762 cbinfo = create_cb_info(cb, data);
764 ErrPrint("Failed to create a cbinfo\n");
765 packet_destroy(packet);
766 free(handler->category);
767 free(handler->cluster);
768 free(handler->content);
769 free(handler->pkgname);
774 ret = master_rpc_async_request(handler, packet, 0, new_ret_cb, cbinfo);
776 ErrPrint("Failed to send a new packet\n");
777 destroy_cb_info(cbinfo);
778 free(handler->category);
779 free(handler->cluster);
780 free(handler->content);
781 free(handler->pkgname);
786 DbgPrint("Successfully sent a new request ([%lf] %s)\n", handler->timestamp, handler->pkgname);
787 handler->state = CREATE;
788 return lb_ref(handler);
791 EAPI double livebox_period(struct livebox *handler)
793 if (!handler || handler->state != CREATE || !handler->id) {
794 ErrPrint("Handler is not valid\n");
798 return handler->lb.period;
801 EAPI int livebox_set_period(struct livebox *handler, double period, ret_cb_t cb, void *data)
803 struct packet *packet;
806 if (!handler || handler->state != CREATE || !handler->id) {
807 ErrPrint("Handler is not valid\n");
808 return LB_STATUS_ERROR_INVALID;
811 if (handler->period_changed_cb) {
812 ErrPrint("Previous request for changing period is not finished\n");
813 return LB_STATUS_ERROR_BUSY;
816 if (!handler->is_user) {
817 ErrPrint("CA Livebox is not able to change the period\n");
818 return LB_STATUS_ERROR_PERMISSION;
821 if (handler->lb.period == period) {
822 DbgPrint("No changes\n");
823 return LB_STATUS_ERROR_ALREADY;
826 packet = packet_create("set_period", "ssd", handler->pkgname, handler->id, period);
828 ErrPrint("Failed to build a packet %s\n", handler->pkgname);
829 return LB_STATUS_ERROR_FAULT;
833 cb = default_period_changed_cb;
835 handler->period_changed_cb = cb;
836 handler->period_cbdata = data;
838 ret = master_rpc_async_request(handler, packet, 0, period_ret_cb, NULL);
840 handler->period_changed_cb = NULL;
841 handler->period_cbdata = NULL;
847 EAPI int livebox_del(struct livebox *handler, ret_cb_t cb, void *data)
850 ErrPrint("Handler is NIL\n");
851 return LB_STATUS_ERROR_INVALID;
854 if (handler->state != CREATE) {
855 ErrPrint("Handler is already deleted\n");
856 return LB_STATUS_ERROR_INVALID;
859 handler->state = DELETE;
864 * The id is not determined yet.
865 * It means a user didn't receive created event yet.
866 * Then just stop to delete procedure from here.
867 * Because the "created" event handler will release this.
868 * By the way, if the user adds any callback for getting return status of this,
872 cb(handler, 0, data);
873 return LB_STATUS_SUCCESS;
877 cb = default_delete_cb;
879 return lb_send_delete(handler, cb, data);
882 EAPI int livebox_set_fault_handler(int (*cb)(enum livebox_fault_type, const char *, const char *, const char *, void *), void *data)
884 struct fault_info *info;
887 return LB_STATUS_ERROR_INVALID;
889 info = malloc(sizeof(*info));
891 CRITICAL_LOG("Heap: %s\n", strerror(errno));
892 return LB_STATUS_ERROR_MEMORY;
896 info->user_data = data;
898 s_info.fault_list = dlist_append(s_info.fault_list, info);
899 return LB_STATUS_SUCCESS;
902 EAPI void *livebox_unset_fault_handler(int (*cb)(enum livebox_fault_type, const char *, const char *, const char *, void *))
904 struct fault_info *info;
907 dlist_foreach(s_info.fault_list, l, info) {
908 if (info->handler == cb) {
910 s_info.fault_list = dlist_remove(s_info.fault_list, l);
911 data = info->user_data;
921 EAPI int livebox_set_event_handler(int (*cb)(struct livebox *, enum livebox_event_type, void *), void *data)
923 struct event_info *info;
926 ErrPrint("Invalid argument cb is nil\n");
927 return LB_STATUS_ERROR_INVALID;
930 info = malloc(sizeof(*info));
932 CRITICAL_LOG("Heap: %s\n", strerror(errno));
933 return LB_STATUS_ERROR_MEMORY;
937 info->user_data = data;
939 s_info.event_list = dlist_append(s_info.event_list, info);
940 return LB_STATUS_SUCCESS;
943 EAPI void *livebox_unset_event_handler(int (*cb)(struct livebox *, enum livebox_event_type, void *))
945 struct event_info *info;
948 dlist_foreach(s_info.event_list, l, info) {
949 if (info->handler == cb) {
952 s_info.event_list = dlist_remove(s_info.event_list, l);
953 data = info->user_data;
963 EAPI int livebox_set_update_mode(struct livebox *handler, int active_update, ret_cb_t cb, void *data)
965 struct packet *packet;
969 ErrPrint("Handler is NIL\n");
970 return LB_STATUS_ERROR_INVALID;
973 if (handler->state != CREATE || !handler->id)
974 return LB_STATUS_ERROR_INVALID;
976 if (handler->update_mode_cb) {
977 ErrPrint("Previous update_mode cb is not finished yet\n");
978 return LB_STATUS_ERROR_BUSY;
981 if (handler->is_active_update == active_update)
982 return LB_STATUS_ERROR_ALREADY;
984 if (!handler->is_user)
985 return LB_STATUS_ERROR_PERMISSION;
987 packet = packet_create("update_mode", "ssi", handler->pkgname, handler->id, active_update);
989 return LB_STATUS_ERROR_FAULT;
992 cb = default_update_mode_cb;
994 handler->update_mode_cb = cb;
995 handler->update_mode_cbdata = data;
997 ret = master_rpc_async_request(handler, packet, 0, update_mode_cb, NULL);
999 handler->update_mode_cb = NULL;
1000 handler->update_mode_cbdata = NULL;
1006 EAPI int livebox_is_active_update(struct livebox *handler)
1009 ErrPrint("Handler is NIL\n");
1010 return LB_STATUS_ERROR_INVALID;
1013 if (handler->state != CREATE || !handler->id)
1014 return LB_STATUS_ERROR_INVALID;
1016 return handler->is_active_update;
1019 EAPI int livebox_resize(struct livebox *handler, int type, ret_cb_t cb, void *data)
1021 struct packet *packet;
1027 ErrPrint("Handler is NIL\n");
1028 return LB_STATUS_ERROR_INVALID;
1031 if (handler->state != CREATE || !handler->id) {
1032 ErrPrint("Handler is not valid\n");
1033 return LB_STATUS_ERROR_INVALID;
1036 if (handler->size_changed_cb) {
1037 ErrPrint("Previous resize request is not finished yet\n");
1038 return LB_STATUS_ERROR_BUSY;
1041 if (!handler->is_user) {
1042 ErrPrint("CA Livebox is not able to be resized\n");
1043 return LB_STATUS_ERROR_PERMISSION;
1046 if (livebox_service_get_size(type, &w, &h) != 0) {
1047 ErrPrint("Invalid size type\n");
1048 return LB_STATUS_ERROR_INVALID;
1051 if (handler->lb.width == w && handler->lb.height == h) {
1052 DbgPrint("No changes\n");
1053 return LB_STATUS_ERROR_ALREADY;;
1056 packet = packet_create("resize", "ssii", handler->pkgname, handler->id, w, h);
1058 ErrPrint("Failed to build param\n");
1059 return LB_STATUS_ERROR_FAULT;
1063 cb = default_lb_size_changed_cb;
1065 handler->size_changed_cb = cb;
1066 handler->size_cbdata = data;
1068 ret = master_rpc_async_request(handler, packet, 0, resize_cb, NULL);
1070 handler->size_changed_cb = NULL;
1071 handler->size_cbdata = NULL;
1077 EAPI int livebox_click(struct livebox *handler, double x, double y)
1079 struct packet *packet;
1083 timestamp = util_timestamp();
1084 DbgPrint("CLICKED: %lf\n", timestamp);
1087 ErrPrint("Handler is NIL\n");
1088 return LB_STATUS_ERROR_INVALID;
1091 if (handler->state != CREATE || !handler->id) {
1092 ErrPrint("Handler is not valid\n");
1093 return LB_STATUS_ERROR_INVALID;
1096 if (handler->lb.auto_launch) {
1097 DbgPrint("Auto-launch enabled: %s\n", handler->lb.auto_launch);
1098 if (aul_launch_app(handler->lb.auto_launch, NULL) < 0)
1099 ErrPrint("Failed to launch app %s\n", handler->lb.auto_launch);
1102 packet = packet_create_noack("clicked", "sssddd", handler->pkgname, handler->id, "clicked", timestamp, x, y);
1104 ErrPrint("Failed to build param\n");
1105 return LB_STATUS_ERROR_FAULT;
1108 ret = master_rpc_request_only(handler, packet);
1109 DbgPrint("Click request: %d\n", ret);
1111 if (!handler->lb.mouse_event && (handler->lb.type == _LB_TYPE_BUFFER || handler->lb.type == _LB_TYPE_SCRIPT)) {
1112 int ret; /* Shadow variable */
1113 ret = send_mouse_event(handler, "lb_mouse_down", x * handler->lb.width, y * handler->lb.height);
1115 DbgPrint("Failed to send Down: %d\n", ret);
1117 ret = send_mouse_event(handler, "lb_mouse_move", x * handler->lb.width, y * handler->lb.height);
1119 DbgPrint("Failed to send Move: %d\n", ret);
1121 ret = send_mouse_event(handler, "lb_mouse_up", x * handler->lb.width, y * handler->lb.height);
1123 DbgPrint("Failed to send Up: %d\n", ret);
1129 EAPI int livebox_has_pd(struct livebox *handler)
1132 ErrPrint("Handler is NIL\n");
1133 return LB_STATUS_ERROR_INVALID;
1136 if (handler->state != CREATE || !handler->id) {
1137 ErrPrint("Handler is not valid\n");
1138 return LB_STATUS_ERROR_INVALID;
1141 return !!handler->pd.data.fb;
1144 EAPI int livebox_pd_is_created(struct livebox *handler)
1147 ErrPrint("Handler is NIL\n");
1148 return LB_STATUS_ERROR_INVALID;
1151 if (!handler->pd.data.fb || handler->state != CREATE || !handler->id) {
1152 ErrPrint("Handler is not valid\n");
1153 return LB_STATUS_ERROR_INVALID;
1156 return handler->is_pd_created;
1159 EAPI int livebox_create_pd(struct livebox *handler, ret_cb_t cb, void *data)
1161 return livebox_create_pd_with_position(handler, -1.0, -1.0, cb, data);
1164 EAPI int livebox_create_pd_with_position(struct livebox *handler, double x, double y, ret_cb_t cb, void *data)
1166 struct packet *packet;
1170 ErrPrint("Handler is NIL\n");
1171 return LB_STATUS_ERROR_INVALID;
1174 if (!handler->pd.data.fb || handler->state != CREATE || !handler->id) {
1175 ErrPrint("Handler is not valid\n");
1176 return LB_STATUS_ERROR_INVALID;
1179 if (handler->is_pd_created == 1) {
1180 DbgPrint("PD already created\n");
1181 return LB_STATUS_SUCCESS;
1184 if (handler->pd_created_cb) {
1185 ErrPrint("Previous request is not completed yet\n");
1186 return LB_STATUS_ERROR_BUSY;
1189 packet = packet_create("create_pd", "ssdd", handler->pkgname, handler->id, x, y);
1191 ErrPrint("Failed to build param\n");
1192 return LB_STATUS_ERROR_FAULT;
1196 cb = default_pd_created_cb;
1198 handler->pd_created_cb = cb;
1199 handler->pd_created_cbdata = data;
1201 ret = master_rpc_async_request(handler, packet, 0, pd_create_cb, NULL);
1203 handler->pd_created_cb = NULL;
1204 handler->pd_created_cbdata = NULL;
1210 EAPI int livebox_move_pd(struct livebox *handler, double x, double y)
1212 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) {
1225 DbgPrint("PD is not created\n");
1226 return LB_STATUS_ERROR_INVALID;
1229 packet = packet_create_noack("pd_move", "ssdd", handler->pkgname, handler->id, x, y);
1231 ErrPrint("Failed to build param\n");
1232 return LB_STATUS_ERROR_FAULT;
1235 return master_rpc_request_only(handler, packet);
1238 EAPI int livebox_activate(const char *pkgname, ret_cb_t cb, void *data)
1240 struct packet *packet;
1241 struct cb_info *cbinfo;
1245 return LB_STATUS_ERROR_INVALID;
1247 packet = packet_create("activate_package", "s", pkgname);
1249 ErrPrint("Failed to build a param\n");
1250 return LB_STATUS_ERROR_FAULT;
1253 cbinfo = create_cb_info(cb, data);
1255 ErrPrint("Unable to create cbinfo\n");
1256 packet_destroy(packet);
1257 return LB_STATUS_ERROR_FAULT;
1260 ret = master_rpc_async_request(NULL, packet, 0, activated_cb, cbinfo);
1262 destroy_cb_info(cbinfo);
1267 EAPI int livebox_destroy_pd(struct livebox *handler, ret_cb_t cb, void *data)
1269 struct packet *packet;
1270 struct cb_info *cbinfo;
1274 ErrPrint("Handler is NIL\n");
1275 return LB_STATUS_ERROR_INVALID;
1278 if (!handler->pd.data.fb || handler->state != CREATE || !handler->id) {
1279 ErrPrint("Handler is not valid\n");
1280 return LB_STATUS_ERROR_INVALID;
1283 if (!handler->is_pd_created && !handler->pd_created_cb) {
1284 ErrPrint("PD is not created\n");
1285 return LB_STATUS_ERROR_INVALID;
1288 packet = packet_create("destroy_pd", "ss", handler->pkgname, handler->id);
1290 ErrPrint("Failed to build a param\n");
1291 return LB_STATUS_ERROR_FAULT;
1295 cb = default_pd_destroyed_cb;
1297 cbinfo = create_cb_info(cb, data);
1299 packet_destroy(packet);
1300 return LB_STATUS_ERROR_FAULT;
1303 ret = master_rpc_async_request(handler, packet, 0, pd_destroy_cb, cbinfo);
1305 destroy_cb_info(cbinfo);
1310 EAPI int livebox_access_event(struct livebox *handler, enum access_event_type type, double x, double y, ret_cb_t cb, void *data)
1314 char cmd[32] = { '\0', };
1319 ErrPrint("Handler is NIL\n");
1320 return LB_STATUS_ERROR_INVALID;
1323 if (handler->state != CREATE || !handler->id) {
1324 ErrPrint("Handler is not valid\n");
1325 return LB_STATUS_ERROR_INVALID;
1328 if (handler->access_event_cb) {
1329 ErrPrint("Previous access event is not yet done\n");
1330 return LB_STATUS_ERROR_BUSY;
1333 if (type & ACCESS_EVENT_PD_MASK) {
1334 if (!handler->is_pd_created) {
1335 ErrPrint("PD is not created\n");
1336 return LB_STATUS_ERROR_INVALID;
1340 w = handler->pd.width;
1341 h = handler->pd.height;
1342 } else if (type & ACCESS_EVENT_LB_MASK) {
1345 w = handler->lb.width;
1346 h = handler->lb.height;
1348 ErrPrint("Invalid event type\n");
1349 return LB_STATUS_ERROR_INVALID;
1352 switch (type & ~ACCESS_EVENT_PD_MASK) {
1353 case ACCESS_EVENT_HIGHLIGHT:
1354 strcpy(ptr, "_access_hl");
1356 case ACCESS_EVENT_HIGHLIGHT_NEXT:
1357 strcpy(ptr, "_access_hl_next");
1359 case ACCESS_EVENT_HIGHLIGHT_PREV:
1360 strcpy(ptr, "_access_hl_prev");
1362 case ACCESS_EVENT_ACTIVATE:
1363 strcpy(ptr, "_access_activate");
1365 case ACCESS_EVENT_ACTION_DOWN:
1366 strcpy(ptr, "_access_action_down");
1368 case ACCESS_EVENT_ACTION_UP:
1369 strcpy(ptr, "_access_action_up");
1371 case ACCESS_EVENT_UNHIGHLIGHT:
1372 strcpy(ptr, "_access_unhighlight");
1374 case ACCESS_EVENT_SCROLL_DOWN:
1375 strcpy(ptr, "_access_scroll_down");
1377 case ACCESS_EVENT_SCROLL_MOVE:
1378 strcpy(ptr, "_access_scroll_move");
1380 case ACCESS_EVENT_SCROLL_UP:
1381 strcpy(ptr, "_access_scroll_up");
1384 return LB_STATUS_ERROR_INVALID;
1388 cb = default_access_event_cb;
1390 handler->access_event_cb = cb;
1391 handler->access_event_cbdata = data;
1393 ret = send_access_event(handler, cmd, x * w, y * h);
1395 handler->access_event_cb = NULL;
1396 handler->access_event_cbdata = NULL;
1402 EAPI int livebox_content_event(struct livebox *handler, enum content_event_type type, double x, double y)
1406 char cmd[32] = { '\0', };
1410 ErrPrint("Handler is NIL\n");
1411 return LB_STATUS_ERROR_INVALID;
1414 if (handler->state != CREATE || !handler->id) {
1415 ErrPrint("Handler is not valid\n");
1416 return LB_STATUS_ERROR_INVALID;
1419 if (type & CONTENT_EVENT_PD_MASK) {
1422 if (!handler->is_pd_created) {
1423 ErrPrint("PD is not created\n");
1424 return LB_STATUS_ERROR_INVALID;
1427 if (type & CONTENT_EVENT_MOUSE_MASK) {
1428 if (!handler->pd.data.fb) {
1429 ErrPrint("Handler is not valid\n");
1430 return LB_STATUS_ERROR_INVALID;
1433 if (type & CONTENT_EVENT_MOUSE_MOVE) {
1434 if (fabs(x - handler->pd.x) < MINIMUM_EVENT && fabs(y - handler->pd.y) < MINIMUM_EVENT)
1435 return LB_STATUS_ERROR_BUSY;
1436 } else if (type & CONTENT_EVENT_MOUSE_SET) {
1442 w = handler->pd.width;
1443 h = handler->pd.height;
1449 } else if (type & CONTENT_EVENT_LB_MASK) {
1452 if (type & CONTENT_EVENT_MOUSE_MASK) {
1453 if (!handler->lb.mouse_event) {
1454 ErrPrint("Box is not support the mouse event\n");
1455 return LB_STATUS_ERROR_INVALID;
1458 if (!handler->lb.data.fb) {
1459 ErrPrint("Handler is not valid\n");
1460 return LB_STATUS_ERROR_INVALID;
1463 if (type & CONTENT_EVENT_MOUSE_MOVE) {
1464 if (fabs(x - handler->lb.x) < MINIMUM_EVENT && fabs(y - handler->lb.y) < MINIMUM_EVENT)
1465 return LB_STATUS_ERROR_BUSY;
1466 } else if (type & CONTENT_EVENT_MOUSE_SET) {
1472 w = handler->lb.width;
1473 h = handler->lb.height;
1480 ErrPrint("Invalid event type\n");
1481 return LB_STATUS_ERROR_INVALID;
1485 * Must be short than 29 bytes.
1487 switch ((type & ~(CONTENT_EVENT_PD_MASK | CONTENT_EVENT_LB_MASK))) {
1488 case CONTENT_EVENT_MOUSE_ENTER | CONTENT_EVENT_MOUSE_MASK:
1489 strcpy(ptr, "_mouse_enter");
1491 case CONTENT_EVENT_MOUSE_LEAVE | CONTENT_EVENT_MOUSE_MASK:
1492 strcpy(ptr, "_mouse_leave");
1494 case CONTENT_EVENT_MOUSE_UP | CONTENT_EVENT_MOUSE_MASK:
1495 strcpy(ptr, "_mouse_up");
1497 case CONTENT_EVENT_MOUSE_DOWN | CONTENT_EVENT_MOUSE_MASK:
1498 strcpy(ptr, "_mouse_down");
1500 case CONTENT_EVENT_MOUSE_MOVE | CONTENT_EVENT_MOUSE_MASK:
1501 strcpy(ptr, "_mouse_move");
1503 case CONTENT_EVENT_MOUSE_SET | CONTENT_EVENT_MOUSE_MASK:
1504 strcpy(ptr, "_mouse_set");
1506 case CONTENT_EVENT_MOUSE_UNSET | CONTENT_EVENT_MOUSE_MASK:
1507 strcpy(ptr, "_mouse_unset");
1509 case CONTENT_EVENT_KEY_DOWN | CONTENT_EVENT_KEY_MASK:
1510 strcpy(ptr, "_key_down");
1512 case CONTENT_EVENT_KEY_UP | CONTENT_EVENT_KEY_MASK:
1513 strcpy(ptr, "_key_up");
1516 ErrPrint("Invalid event type\n");
1517 return LB_STATUS_ERROR_INVALID;
1520 return send_mouse_event(handler, cmd, x * w, y * h);
1523 EAPI const char *livebox_filename(struct livebox *handler)
1526 ErrPrint("Handler is NIL\n");
1530 if (handler->state != CREATE || !handler->id) {
1531 ErrPrint("Handler is not valid\n");
1535 if (handler->filename)
1536 return handler->filename;
1539 return util_uri_to_path(handler->id);
1542 EAPI int livebox_get_pdsize(struct livebox *handler, int *w, int *h)
1548 ErrPrint("Handler is NIL\n");
1549 return LB_STATUS_ERROR_INVALID;
1552 if (handler->state != CREATE || !handler->id) {
1553 ErrPrint("Handler is not valid\n");
1554 return LB_STATUS_ERROR_INVALID;
1562 if (!handler->is_pd_created) {
1563 DbgPrint("Buffer is not created yet [%dx%d]\n", *w, *h);
1564 *w = handler->pd.default_width;
1565 *h = handler->pd.default_height;
1567 *w = handler->pd.width;
1568 *h = handler->pd.height;
1571 return LB_STATUS_SUCCESS;
1574 EAPI int livebox_size(struct livebox *handler)
1580 ErrPrint("Handler is NIL\n");
1581 return LB_STATUS_ERROR_INVALID;
1584 if (handler->state != CREATE || !handler->id) {
1585 ErrPrint("Handler is not valid\n");
1586 return LB_STATUS_ERROR_INVALID;
1589 w = handler->lb.width;
1590 h = handler->lb.height;
1592 switch (handler->lb.type) {
1593 case _LB_TYPE_BUFFER:
1594 case _LB_TYPE_SCRIPT:
1595 if (!fb_is_created(handler->lb.data.fb)) {
1596 DbgPrint("Buffer is not created yet - reset size\n");
1605 return livebox_service_size_type(w, h);
1608 EAPI int livebox_set_group(struct livebox *handler, const char *cluster, const char *category, ret_cb_t cb, void *data)
1610 struct packet *packet;
1614 ErrPrint("Handler is NIL\n");
1615 return LB_STATUS_ERROR_INVALID;
1618 if (!cluster || !category || handler->state != CREATE || !handler->id) {
1619 ErrPrint("Invalid argument\n");
1620 return LB_STATUS_ERROR_INVALID;
1623 if (handler->group_changed_cb) {
1624 ErrPrint("Previous group changing request is not finished yet\n");
1625 return LB_STATUS_ERROR_BUSY;
1628 if (!handler->is_user) {
1629 ErrPrint("CA Livebox is not able to change the group\n");
1630 return LB_STATUS_ERROR_PERMISSION;
1633 if (!strcmp(handler->cluster, cluster) && !strcmp(handler->category, category)) {
1634 DbgPrint("No changes\n");
1635 return LB_STATUS_ERROR_ALREADY;
1638 packet = packet_create("change_group", "ssss", handler->pkgname, handler->id, cluster, category);
1640 ErrPrint("Failed to build a param\n");
1641 return LB_STATUS_ERROR_FAULT;
1645 cb = default_group_changed_cb;
1647 handler->group_changed_cb = cb;
1648 handler->group_cbdata = data;
1650 ret = master_rpc_async_request(handler, packet, 0, set_group_ret_cb, NULL);
1652 handler->group_changed_cb = NULL;
1653 handler->group_cbdata = NULL;
1659 EAPI int livebox_get_group(struct livebox *handler, char ** const cluster, char ** const category)
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 *cluster = handler->cluster;
1672 *category = handler->category;
1673 return LB_STATUS_SUCCESS;
1676 EAPI int livebox_get_supported_sizes(struct livebox *handler, int *cnt, int *size_list)
1681 if (!handler || !size_list) {
1682 ErrPrint("Invalid argument, handler(%p), size_list(%p)\n", handler, size_list);
1683 return LB_STATUS_ERROR_INVALID;
1686 if (!cnt || handler->state != CREATE || !handler->id) {
1687 ErrPrint("Handler is not valid\n");
1688 return LB_STATUS_ERROR_INVALID;
1691 for (j = i = 0; i < NR_OF_SIZE_LIST; i++) {
1692 if (handler->lb.size_list & (0x01 << i)) {
1696 size_list[j++] = (0x01 << i);
1701 return LB_STATUS_SUCCESS;
1704 EAPI const char *livebox_pkgname(struct livebox *handler)
1707 ErrPrint("Handler is NIL\n");
1711 if (handler->state != CREATE) {
1712 ErrPrint("Handler is not valid\n");
1716 return handler->pkgname;
1719 EAPI double livebox_priority(struct livebox *handler)
1722 ErrPrint("Handler is NIL\n");
1726 if (handler->state != CREATE || !handler->id) {
1727 ErrPrint("Handler is not valid (%p)\n", handler);
1731 return handler->lb.priority;
1734 EAPI int livebox_delete_cluster(const char *cluster, ret_cb_t cb, void *data)
1736 struct packet *packet;
1737 struct cb_info *cbinfo;
1740 packet = packet_create("delete_cluster", "s", cluster);
1742 ErrPrint("Failed to build a param\n");
1743 return LB_STATUS_ERROR_FAULT;
1746 cbinfo = create_cb_info(cb, data);
1748 packet_destroy(packet);
1749 return LB_STATUS_ERROR_FAULT;
1752 ret = master_rpc_async_request(NULL, packet, 0, delete_cluster_cb, cbinfo);
1754 destroy_cb_info(cbinfo);
1759 EAPI int livebox_delete_category(const char *cluster, const char *category, ret_cb_t cb, void *data)
1761 struct packet *packet;
1762 struct cb_info *cbinfo;
1765 packet = packet_create("delete_category", "ss", cluster, category);
1767 ErrPrint("Failed to build a param\n");
1768 return LB_STATUS_ERROR_FAULT;
1771 cbinfo = create_cb_info(cb, data);
1773 packet_destroy(packet);
1774 return LB_STATUS_ERROR_FAULT;
1777 ret = master_rpc_async_request(NULL, packet, 0, delete_category_cb, cbinfo);
1779 destroy_cb_info(cbinfo);
1784 EAPI enum livebox_lb_type livebox_lb_type(struct livebox *handler)
1787 ErrPrint("Handler is NIL\n");
1788 return LB_TYPE_INVALID;
1791 if (handler->state != CREATE || !handler->id) {
1792 ErrPrint("Handler is not valid\n");
1793 return LB_TYPE_INVALID;
1796 switch (handler->lb.type) {
1798 return LB_TYPE_IMAGE;
1799 case _LB_TYPE_BUFFER:
1800 case _LB_TYPE_SCRIPT:
1803 id = fb_id(handler->lb.data.fb);
1804 if (id && !strncasecmp(id, SCHEMA_PIXMAP, strlen(SCHEMA_PIXMAP)))
1805 return LB_TYPE_PIXMAP;
1807 return LB_TYPE_BUFFER;
1809 return LB_TYPE_TEXT;
1814 return LB_TYPE_INVALID;
1817 EAPI enum livebox_pd_type livebox_pd_type(struct livebox *handler)
1820 ErrPrint("Handler is NIL\n");
1821 return PD_TYPE_INVALID;
1824 if (handler->state != CREATE || !handler->id) {
1825 ErrPrint("Handler is not valid\n");
1826 return PD_TYPE_INVALID;
1829 switch (handler->pd.type) {
1831 return PD_TYPE_TEXT;
1832 case _PD_TYPE_BUFFER:
1833 case _PD_TYPE_SCRIPT:
1836 id = fb_id(handler->pd.data.fb);
1837 if (id && !strncasecmp(id, SCHEMA_PIXMAP, strlen(SCHEMA_PIXMAP)))
1838 return PD_TYPE_PIXMAP;
1840 return PD_TYPE_BUFFER;
1845 return PD_TYPE_INVALID;
1848 EAPI int livebox_set_pd_text_handler(struct livebox *handler, struct livebox_script_operators *ops)
1851 ErrPrint("Handler is NIL\n");
1852 return LB_STATUS_ERROR_INVALID;
1855 if (handler->state != CREATE) {
1856 ErrPrint("Handler is not valid\n");
1857 return LB_STATUS_ERROR_INVALID;
1860 memcpy(&handler->pd.data.ops, ops, sizeof(*ops));
1861 return LB_STATUS_SUCCESS;
1864 EAPI int livebox_set_text_handler(struct livebox *handler, struct livebox_script_operators *ops)
1867 ErrPrint("Handler is NIL\n");
1868 return LB_STATUS_ERROR_INVALID;
1871 if (handler->state != CREATE) {
1872 ErrPrint("Handler is not valid\n");
1873 return LB_STATUS_ERROR_INVALID;
1876 memcpy(&handler->lb.data.ops, ops, sizeof(*ops));
1877 return LB_STATUS_SUCCESS;
1880 EAPI int livebox_acquire_lb_pixmap(struct livebox *handler, ret_cb_t cb, void *data)
1882 struct packet *packet;
1883 struct cb_info *cbinfo;
1888 ErrPrint("Handler is NIL\n");
1889 return LB_STATUS_ERROR_INVALID;
1892 if (handler->state != CREATE || !handler->id) {
1893 ErrPrint("Invalid handle\n");
1894 return LB_STATUS_ERROR_INVALID;
1897 if (handler->lb.type != _LB_TYPE_SCRIPT && handler->lb.type != _LB_TYPE_BUFFER) {
1898 ErrPrint("Handler is not valid type\n");
1899 return LB_STATUS_ERROR_INVALID;
1902 id = fb_id(handler->lb.data.fb);
1903 if (!id || strncasecmp(id, SCHEMA_PIXMAP, strlen(SCHEMA_PIXMAP)))
1904 return LB_STATUS_ERROR_INVALID;
1906 packet = packet_create("lb_acquire_pixmap", "ss", handler->pkgname, handler->id);
1908 ErrPrint("Failed to build a param\n");
1909 return LB_STATUS_ERROR_FAULT;
1912 cbinfo = create_cb_info(cb, data);
1914 packet_destroy(packet);
1915 return LB_STATUS_ERROR_FAULT;
1918 ret = master_rpc_async_request(handler, packet, 0, pixmap_acquired_cb, cbinfo);
1920 destroy_cb_info(cbinfo);
1925 EAPI int livebox_release_lb_pixmap(struct livebox *handler, int pixmap)
1927 struct packet *packet;
1930 ErrPrint("Handler is NIL\n");
1931 return LB_STATUS_ERROR_INVALID;
1934 if (handler->state != CREATE || !handler->id) {
1935 ErrPrint("Invalid handle\n");
1936 return LB_STATUS_ERROR_INVALID;
1939 if (handler->lb.type != _LB_TYPE_SCRIPT && handler->lb.type != _LB_TYPE_BUFFER) {
1940 ErrPrint("Handler is not valid type\n");
1941 return LB_STATUS_ERROR_INVALID;
1944 packet = packet_create_noack("lb_release_pixmap", "ssi", handler->pkgname, handler->id, pixmap);
1946 ErrPrint("Failed to build a param\n");
1947 return LB_STATUS_ERROR_INVALID;
1950 return master_rpc_request_only(handler, packet);
1953 EAPI int livebox_acquire_pd_pixmap(struct livebox *handler, ret_cb_t cb, void *data)
1955 struct packet *packet;
1956 struct cb_info *cbinfo;
1961 ErrPrint("Handler is NIL\n");
1962 return LB_STATUS_ERROR_INVALID;
1965 if (handler->state != CREATE || !handler->id) {
1966 ErrPrint("Invalid handle\n");
1967 return LB_STATUS_ERROR_INVALID;
1970 if (handler->pd.type != _PD_TYPE_SCRIPT && handler->pd.type != _PD_TYPE_BUFFER) {
1971 ErrPrint("Handler is not valid type\n");
1972 return LB_STATUS_ERROR_INVALID;
1975 id = fb_id(handler->pd.data.fb);
1976 if (!id || strncasecmp(id, SCHEMA_PIXMAP, strlen(SCHEMA_PIXMAP)))
1977 return LB_STATUS_ERROR_INVALID;
1979 packet = packet_create("pd_acquire_pixmap", "ss", handler->pkgname, handler->id);
1981 ErrPrint("Failed to build a param\n");
1982 return LB_STATUS_ERROR_FAULT;
1985 cbinfo = create_cb_info(cb, data);
1987 packet_destroy(packet);
1988 return LB_STATUS_ERROR_FAULT;
1991 ret = master_rpc_async_request(handler, packet, 0, pixmap_acquired_cb, cbinfo);
1993 destroy_cb_info(cbinfo);
1998 EAPI int livebox_pd_pixmap(const struct livebox *handler)
2004 ErrPrint("Handler is NIL\n");
2008 if (handler->state != CREATE || !handler->id) {
2009 ErrPrint("Invalid handler\n");
2013 if (handler->pd.type != _PD_TYPE_SCRIPT && handler->pd.type != _PD_TYPE_BUFFER) {
2014 ErrPrint("Invalid handler\n");
2018 id = fb_id(handler->pd.data.fb);
2019 if (id && sscanf(id, SCHEMA_PIXMAP "%d", &pixmap) != 1) {
2020 ErrPrint("PIXMAP Id is not valid\n");
2027 EAPI int livebox_lb_pixmap(const struct livebox *handler)
2033 ErrPrint("Handler is NIL\n");
2037 if (handler->state != CREATE || !handler->id) {
2038 ErrPrint("Invalid handler\n");
2042 if (handler->lb.type != _LB_TYPE_SCRIPT && handler->lb.type != _LB_TYPE_BUFFER) {
2043 ErrPrint("Invalid handler\n");
2047 id = fb_id(handler->lb.data.fb);
2048 if (id && sscanf(id, SCHEMA_PIXMAP "%d", &pixmap) != 1) {
2049 ErrPrint("PIXMAP Id is not valid\n");
2056 EAPI int livebox_release_pd_pixmap(struct livebox *handler, int pixmap)
2058 struct packet *packet;
2061 ErrPrint("Handler is NIL\n");
2062 return LB_STATUS_ERROR_INVALID;
2065 if (handler->state != CREATE || !handler->id) {
2066 ErrPrint("Invalid handle\n");
2067 return LB_STATUS_ERROR_INVALID;
2070 if (handler->pd.type != _PD_TYPE_SCRIPT && handler->pd.type != _PD_TYPE_BUFFER) {
2071 ErrPrint("Handler is not valid type\n");
2072 return LB_STATUS_ERROR_INVALID;
2075 packet = packet_create_noack("pd_release_pixmap", "ssi", handler->pkgname, handler->id, pixmap);
2077 ErrPrint("Failed to build a param\n");
2078 return LB_STATUS_ERROR_FAULT;
2081 return master_rpc_request_only(handler, packet);
2084 EAPI void *livebox_acquire_fb(struct livebox *handler)
2087 ErrPrint("Handler is NIL\n");
2091 if (handler->state != CREATE || !handler->id) {
2092 ErrPrint("Invalid handle\n");
2096 if (handler->lb.type != _LB_TYPE_SCRIPT && handler->lb.type != _LB_TYPE_BUFFER) {
2097 ErrPrint("Handler is not valid type\n");
2101 return fb_acquire_buffer(handler->lb.data.fb);
2104 EAPI int livebox_release_fb(void *buffer)
2106 return fb_release_buffer(buffer);
2109 EAPI int livebox_fb_refcnt(void *buffer)
2111 return fb_refcnt(buffer);
2114 EAPI void *livebox_acquire_pdfb(struct livebox *handler)
2117 ErrPrint("Handler is NIL\n");
2121 if (handler->state != CREATE || !handler->id) {
2122 ErrPrint("Invalid handler\n");
2126 if (handler->pd.type != _PD_TYPE_SCRIPT && handler->pd.type != _PD_TYPE_BUFFER) {
2127 ErrPrint("Handler is not valid type\n");
2131 return fb_acquire_buffer(handler->pd.data.fb);
2134 EAPI int livebox_release_pdfb(void *buffer)
2136 return fb_release_buffer(buffer);
2139 EAPI int livebox_pdfb_refcnt(void *buffer)
2141 return fb_refcnt(buffer);
2144 EAPI int livebox_pdfb_bufsz(struct livebox *handler)
2147 ErrPrint("Handler is NIL\n");
2148 return LB_STATUS_ERROR_INVALID;
2151 if (handler->state != CREATE || !handler->id) {
2152 ErrPrint("Handler is not valid\n");
2153 return LB_STATUS_ERROR_INVALID;
2156 return fb_size(handler->pd.data.fb);
2159 EAPI int livebox_lbfb_bufsz(struct livebox *handler)
2162 ErrPrint("Handler is NIL\n");
2163 return LB_STATUS_ERROR_INVALID;
2166 if (handler->state != CREATE || !handler->id) {
2167 ErrPrint("Handler is not valid\n");
2168 return LB_STATUS_ERROR_INVALID;
2171 return fb_size(handler->lb.data.fb);
2174 EAPI int livebox_is_user(struct livebox *handler)
2177 ErrPrint("Handler is NIL\n");
2178 return LB_STATUS_ERROR_INVALID;
2181 if (handler->state != CREATE) {
2182 ErrPrint("Handler is invalid\n");
2183 return LB_STATUS_ERROR_INVALID;
2186 return handler->is_user;
2189 EAPI int livebox_set_pinup(struct livebox *handler, int flag, ret_cb_t cb, void *data)
2191 struct packet *packet;
2195 ErrPrint("Handler is NIL\n");
2196 return LB_STATUS_ERROR_INVALID;
2199 if (handler->state != CREATE || !handler->id) {
2200 ErrPrint("Handler is not valid\n");
2201 return LB_STATUS_ERROR_INVALID;
2204 if (handler->pinup_cb) {
2205 ErrPrint("Previous pinup request is not finished\n");
2206 return LB_STATUS_ERROR_BUSY;
2209 if (handler->is_pinned_up == flag) {
2210 DbgPrint("No changes\n");
2211 return LB_STATUS_ERROR_ALREADY;
2214 packet = packet_create("pinup_changed", "ssi", handler->pkgname, handler->id, flag);
2216 ErrPrint("Failed to build a param\n");
2217 return LB_STATUS_ERROR_FAULT;
2221 cb = default_pinup_cb;
2223 handler->pinup_cb = cb;
2224 handler->pinup_cbdata = data;
2226 ret = master_rpc_async_request(handler, packet, 0, pinup_done_cb, NULL);
2228 handler->pinup_cb = NULL;
2229 handler->pinup_cbdata = NULL;
2235 EAPI int livebox_is_pinned_up(struct livebox *handler)
2238 ErrPrint("Handler is NIL\n");
2239 return LB_STATUS_ERROR_INVALID;
2242 if (handler->state != CREATE || !handler->id)
2243 return LB_STATUS_ERROR_INVALID;
2245 return handler->is_pinned_up;
2248 EAPI int livebox_has_pinup(struct livebox *handler)
2251 ErrPrint("Handler is NIL\n");
2252 return LB_STATUS_ERROR_INVALID;
2255 if (handler->state != CREATE || !handler->id)
2256 return LB_STATUS_ERROR_INVALID;
2258 return handler->lb.pinup_supported;
2261 EAPI int livebox_set_data(struct livebox *handler, void *data)
2264 ErrPrint("Handler is NIL\n");
2265 return LB_STATUS_ERROR_INVALID;
2268 if (handler->state != CREATE)
2269 return LB_STATUS_ERROR_INVALID;
2271 handler->data = data;
2272 return LB_STATUS_SUCCESS;
2275 EAPI void *livebox_get_data(struct livebox *handler)
2278 ErrPrint("Handler is NIL\n");
2282 if (handler->state != CREATE)
2285 return handler->data;
2288 EAPI int livebox_is_exists(const char *pkgname)
2292 lb = lb_pkgname(pkgname);
2301 EAPI const char *livebox_content(struct livebox *handler)
2304 ErrPrint("Handler is NIL\n");
2308 if (handler->state != CREATE)
2311 return handler->content;
2314 EAPI const char *livebox_category_title(struct livebox *handler)
2317 ErrPrint("Handler is NIL\n");
2321 if (handler->state != CREATE)
2324 return handler->title;
2327 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)
2329 struct packet *packet;
2330 struct cb_info *cbinfo;
2334 ErrPrint("Handler is NIL\n");
2335 return LB_STATUS_ERROR_INVALID;
2338 if ((handler->lb.type != _LB_TYPE_TEXT && handler->pd.type != _PD_TYPE_TEXT) || handler->state != CREATE || !handler->id) {
2339 ErrPrint("Handler is not valid\n");
2340 return LB_STATUS_ERROR_INVALID;
2349 packet = packet_create("text_signal", "ssssdddd",
2350 handler->pkgname, handler->id, emission, source, sx, sy, ex, ey);
2352 ErrPrint("Failed to build a param\n");
2353 return LB_STATUS_ERROR_FAULT;
2356 cbinfo = create_cb_info(cb, data);
2358 packet_destroy(packet);
2359 return LB_STATUS_ERROR_FAULT;
2362 ret = master_rpc_async_request(handler, packet, 0, text_signal_cb, cbinfo);
2364 destroy_cb_info(cbinfo);
2366 return LB_STATUS_ERROR_FAULT;
2369 EAPI int livebox_subscribe_group(const char *cluster, const char *category)
2371 struct packet *packet;
2375 * Validate the group info using DB
2376 * If the group info is not valid, do not send this request
2379 packet = packet_create_noack("subscribe", "ss", cluster ? cluster : "", category ? category : "");
2381 ErrPrint("Failed to create a packet\n");
2382 return LB_STATUS_ERROR_FAULT;
2385 return master_rpc_request_only(NULL, packet);
2388 EAPI int livebox_unsubscribe_group(const char *cluster, const char *category)
2390 struct packet *packet;
2394 * Validate the group info using DB
2395 * If the group info is not valid, do not send this request
2396 * AND Check the subscribed or not too
2399 packet = packet_create_noack("unsubscribe", "ss", cluster ? cluster : "", category ? category : "");
2401 ErrPrint("Failed to create a packet\n");
2402 return LB_STATUS_ERROR_FAULT;
2405 return master_rpc_request_only(NULL, packet);
2408 EAPI int livebox_refresh(struct livebox *handler)
2410 struct packet *packet;
2413 ErrPrint("Hnalder is NIL\n");
2414 return LB_STATUS_ERROR_INVALID;
2417 if (handler->state != CREATE || !handler->id)
2418 return LB_STATUS_ERROR_INVALID;
2420 packet = packet_create_noack("update", "ss", handler->pkgname, handler->id);
2422 ErrPrint("Failed to create a packet\n");
2423 return LB_STATUS_ERROR_FAULT;
2426 return master_rpc_request_only(handler, packet);
2429 EAPI int livebox_refresh_group(const char *cluster, const char *category)
2431 struct packet *packet;
2433 if (!cluster || !category) {
2434 ErrPrint("Invalid argument\n");
2435 return LB_STATUS_ERROR_INVALID;
2438 packet = packet_create_noack("refresh_group", "ss", cluster, category);
2440 ErrPrint("Failed to create a packet\n");
2441 return LB_STATUS_ERROR_FAULT;
2444 return master_rpc_request_only(NULL, packet);
2447 EAPI int livebox_set_visibility(struct livebox *handler, enum livebox_visible_state state)
2449 struct packet *packet;
2453 ErrPrint("Handler is NIL\n");
2454 return LB_STATUS_ERROR_INVALID;
2457 if (handler->state != CREATE || !handler->id)
2458 return LB_STATUS_ERROR_INVALID;
2460 if (!handler->is_user) {
2461 /* System cluster livebox cannot be changed its visible states */
2462 if (state == LB_HIDE_WITH_PAUSE) {
2463 ErrPrint("CA Livebox is not able to change the visibility\n");
2464 return LB_STATUS_ERROR_PERMISSION;
2468 DbgPrint("Change the visibility %d <> %d, %s\n", handler->visible, state, handler->id);
2470 if (handler->visible == state)
2471 return LB_STATUS_ERROR_ALREADY;
2473 packet = packet_create_noack("change,visibility", "ssi", handler->pkgname, handler->id, (int)state);
2475 ErrPrint("Failed to create a packet\n");
2476 return LB_STATUS_ERROR_FAULT;
2479 ret = master_rpc_request_only(handler, packet);
2481 handler->visible = state;
2486 EAPI enum livebox_visible_state livebox_visibility(struct livebox *handler)
2489 ErrPrint("Handler is NIL\n");
2490 return LB_VISIBLE_ERROR;
2493 if (handler->state != CREATE || !handler->id)
2494 return LB_VISIBLE_ERROR;
2496 return handler->visible;
2499 int lb_set_group(struct livebox *handler, const char *cluster, const char *category)
2505 pc = strdup(cluster);
2507 CRITICAL_LOG("Heap: %s (cluster: %s)\n", strerror(errno), cluster);
2508 return LB_STATUS_ERROR_MEMORY;
2513 ps = strdup(category);
2515 CRITICAL_LOG("Heap: %s (category: %s)\n", strerror(errno), category);
2517 return LB_STATUS_ERROR_MEMORY;
2521 if (handler->cluster)
2522 free(handler->cluster);
2524 if (handler->category)
2525 free(handler->category);
2527 handler->cluster = pc;
2528 handler->category = ps;
2530 return LB_STATUS_SUCCESS;
2533 void lb_set_size(struct livebox *handler, int w, int h)
2535 handler->lb.width = w;
2536 handler->lb.height = h;
2539 void lb_set_update_mode(struct livebox *handle, int active_mode)
2541 handle->is_active_update = active_mode;
2544 void lb_set_pdsize(struct livebox *handler, int w, int h)
2546 handler->pd.width = w;
2547 handler->pd.height = h;
2550 void lb_set_default_pdsize(struct livebox *handler, int w, int h)
2552 handler->pd.default_width = w;
2553 handler->pd.default_height = h;
2556 void lb_invoke_fault_handler(enum livebox_fault_type event, const char *pkgname, const char *file, const char *func)
2560 struct fault_info *info;
2562 dlist_foreach_safe(s_info.fault_list, l, n, info) {
2563 if (info->handler(event, pkgname, file, func, info->user_data) == EXIT_FAILURE)
2564 s_info.fault_list = dlist_remove(s_info.fault_list, l);
2568 void lb_invoke_event_handler(struct livebox *handler, enum livebox_event_type event)
2572 struct event_info *info;
2574 dlist_foreach_safe(s_info.event_list, l, n, info) {
2575 if (info->handler(handler, event, info->user_data) == EXIT_FAILURE)
2576 s_info.event_list = dlist_remove(s_info.event_list, l);
2580 struct livebox *lb_find_livebox(const char *pkgname, const char *id)
2583 struct livebox *handler;
2585 dlist_foreach(s_info.livebox_list, l, handler) {
2589 if (!strcmp(handler->pkgname, pkgname) && !strcmp(handler->id, id))
2596 struct livebox *lb_find_livebox_by_timestamp(double timestamp)
2599 struct livebox *handler;
2601 dlist_foreach(s_info.livebox_list, l, handler) {
2602 if (handler->timestamp == timestamp)
2609 static inline char *get_file_kept_in_safe(const char *id)
2616 path = util_uri_to_path(id);
2618 ErrPrint("Invalid URI(%s)\n", id);
2625 if (s_info.prevent_overwrite) {
2626 new_path = strdup(path);
2628 ErrPrint("Heap: %s\n", strerror(errno));
2637 while (base_idx > 0 && path[base_idx] != '/') base_idx--;
2638 base_idx += (path[base_idx] == '/');
2640 new_path = malloc(len + 10);
2642 ErrPrint("Heap: %s\n", strerror(errno));
2646 strncpy(new_path, path, base_idx);
2647 snprintf(new_path + base_idx, len + 10 - base_idx, "reader/%s", path + base_idx);
2651 struct livebox *lb_new_livebox(const char *pkgname, const char *id, double timestamp)
2653 struct livebox *handler;
2655 handler = calloc(1, sizeof(*handler));
2657 ErrPrint("Failed to create a new livebox\n");
2661 handler->pkgname = strdup(pkgname);
2662 if (!handler->pkgname) {
2663 ErrPrint("%s\n", strerror(errno));
2668 handler->id = strdup(id);
2670 ErrPrint("%s\n", strerror(errno));
2671 free(handler->pkgname);
2676 handler->filename = get_file_kept_in_safe(id);
2677 if (!handler->filename) {
2678 handler->filename = strdup(util_uri_to_path(id));
2679 if (!handler->filename)
2680 ErrPrint("Error: %s\n", strerror(errno));
2683 handler->timestamp = timestamp;
2684 handler->lb.type = _LB_TYPE_FILE;
2685 handler->pd.type = _PD_TYPE_SCRIPT;
2686 handler->state = CREATE;
2687 handler->visible = LB_SHOW;
2689 s_info.livebox_list = dlist_append(s_info.livebox_list, handler);
2694 int lb_delete_all(void)
2698 struct livebox *handler;
2700 dlist_foreach_safe(s_info.livebox_list, l, n, handler) {
2701 lb_invoke_event_handler(handler, LB_EVENT_DELETED);
2705 return LB_STATUS_SUCCESS;
2708 int lb_set_content(struct livebox *handler, const char *content)
2710 if (handler->content) {
2711 free(handler->content);
2712 handler->content = NULL;
2716 handler->content = strdup(content);
2717 if (!handler->content) {
2718 CRITICAL_LOG("Heap: %s (content: %s)\n", strerror(errno), content);
2719 return LB_STATUS_ERROR_MEMORY;
2723 return LB_STATUS_SUCCESS;
2726 int lb_set_title(struct livebox *handler, const char *title)
2728 if (handler->title) {
2729 free(handler->title);
2730 handler->title = NULL;
2734 handler->title = strdup(title);
2735 if (!handler->title) {
2736 CRITICAL_LOG("Heap: %s (title: %s)\n", strerror(errno), title);
2737 return LB_STATUS_ERROR_MEMORY;
2741 return LB_STATUS_SUCCESS;
2744 void lb_set_size_list(struct livebox *handler, int size_list)
2746 handler->lb.size_list = size_list;
2749 void lb_set_auto_launch(struct livebox *handler, const char *auto_launch)
2751 if (!strlen(auto_launch))
2754 handler->lb.auto_launch = strdup(auto_launch);
2755 if (!handler->lb.auto_launch)
2756 ErrPrint("Heap: %s\n", strerror(errno));
2759 void lb_set_priority(struct livebox *handler, double priority)
2761 handler->lb.priority = priority;
2764 void lb_set_id(struct livebox *handler, const char *id)
2769 handler->id = strdup(id);
2771 ErrPrint("Error: %s\n", strerror(errno));
2773 if (handler->filename)
2774 free(handler->filename);
2776 handler->filename = get_file_kept_in_safe(id);
2777 if (!handler->filename) {
2778 handler->filename = strdup(util_uri_to_path(id));
2779 if (!handler->filename)
2780 ErrPrint("Error: %s\n", strerror(errno));
2784 int lb_set_lb_fb(struct livebox *handler, const char *filename)
2789 return LB_STATUS_ERROR_INVALID;
2791 fb = handler->lb.data.fb;
2792 if (fb && !strcmp(fb_id(fb), filename)) /*!< BUFFER is not changed, */
2793 return LB_STATUS_SUCCESS;
2795 handler->lb.data.fb = NULL;
2797 if (!filename || filename[0] == '\0') {
2800 return LB_STATUS_SUCCESS;
2803 handler->lb.data.fb = fb_create(filename, handler->lb.width, handler->lb.height);
2804 if (!handler->lb.data.fb) {
2805 ErrPrint("Faield to create a FB\n");
2808 return LB_STATUS_ERROR_FAULT;
2814 return LB_STATUS_SUCCESS;
2817 int lb_set_pd_fb(struct livebox *handler, const char *filename)
2822 return LB_STATUS_ERROR_INVALID;
2824 fb = handler->pd.data.fb;
2825 if (fb && !strcmp(fb_id(fb), filename)) {
2826 /* BUFFER is not changed, just update the content */
2827 return LB_STATUS_ERROR_EXIST;
2829 handler->pd.data.fb = NULL;
2831 if (!filename || filename[0] == '\0') {
2834 return LB_STATUS_SUCCESS;
2837 handler->pd.data.fb = fb_create(filename, handler->pd.width, handler->pd.height);
2838 if (!handler->pd.data.fb) {
2839 ErrPrint("Failed to create a FB\n");
2842 return LB_STATUS_ERROR_FAULT;
2847 return LB_STATUS_SUCCESS;
2850 struct fb_info *lb_get_lb_fb(struct livebox *handler)
2852 return handler->lb.data.fb;
2855 struct fb_info *lb_get_pd_fb(struct livebox *handler)
2857 return handler->pd.data.fb;
2860 void lb_set_user(struct livebox *handler, int user)
2862 handler->is_user = user;
2865 void lb_set_pinup(struct livebox *handler, int pinup_supported)
2867 handler->lb.pinup_supported = pinup_supported;
2870 void lb_set_text_lb(struct livebox *handler)
2872 handler->lb.type = _LB_TYPE_TEXT;
2875 void lb_set_text_pd(struct livebox *handler)
2877 handler->pd.type = _PD_TYPE_TEXT;
2880 int lb_text_lb(struct livebox *handler)
2882 return handler->lb.type == _LB_TYPE_TEXT;
2885 int lb_text_pd(struct livebox *handler)
2887 return handler->pd.type == _PD_TYPE_TEXT;
2890 void lb_set_period(struct livebox *handler, double period)
2892 handler->lb.period = period;
2895 struct livebox *lb_ref(struct livebox *handler)
2904 struct livebox *lb_unref(struct livebox *handler)
2910 if (handler->refcnt > 0)
2913 if (handler->created_cb) {
2914 DbgPrint("Clear created event callback\n");
2915 handler->created_cb(handler, LB_STATUS_ERROR_FAULT, handler->created_cbdata);
2916 handler->created_cb = NULL;
2917 handler->created_cbdata = NULL;
2920 if (handler->deleted_cb) {
2921 DbgPrint("Clear deleted event callback\n");
2922 handler->deleted_cb(handler, LB_STATUS_ERROR_FAULT, handler->deleted_cbdata);
2923 handler->deleted_cb = NULL;
2924 handler->deleted_cbdata = NULL;
2927 if (handler->pinup_cb) {
2928 DbgPrint("Clear pinup event callback\n");
2929 handler->pinup_cb(handler, LB_STATUS_ERROR_FAULT, handler->pinup_cbdata);
2930 handler->pinup_cb = NULL;
2931 handler->pinup_cbdata = NULL;
2934 if (handler->group_changed_cb) {
2935 DbgPrint("Clear group changed event callback\n");
2936 handler->group_changed_cb(handler, LB_STATUS_ERROR_FAULT, handler->group_cbdata);
2937 handler->group_changed_cb = NULL;
2938 handler->group_cbdata = NULL;
2941 if (handler->period_changed_cb) {
2942 DbgPrint("Clear period changed event callback\n");
2943 handler->period_changed_cb(handler, LB_STATUS_ERROR_FAULT, handler->period_cbdata);
2944 handler->period_changed_cb = NULL;
2945 handler->period_cbdata = NULL;
2948 if (handler->size_changed_cb) {
2949 DbgPrint("Clear size changed event callback\n");
2950 handler->size_changed_cb(handler, LB_STATUS_ERROR_FAULT, handler->size_cbdata);
2951 handler->size_changed_cb = NULL;
2952 handler->size_cbdata = NULL;
2955 if (handler->pd_created_cb) {
2956 DbgPrint("Clear pd created event callback\n");
2957 handler->pd_created_cb(handler, LB_STATUS_ERROR_FAULT, handler->pd_created_cbdata);
2958 handler->pd_created_cb = NULL;
2959 handler->pd_created_cbdata = NULL;
2962 if (handler->pd_destroyed_cb) {
2963 DbgPrint("Clear pd destroyed event callback\n");
2964 handler->pd_destroyed_cb(handler, LB_STATUS_ERROR_FAULT, handler->pd_destroyed_cbdata);
2965 handler->pd_destroyed_cb = NULL;
2966 handler->pd_destroyed_cbdata = NULL;
2969 if (handler->update_mode_cb) {
2970 DbgPrint("Clear update mode callback\n");
2971 handler->update_mode_cb(handler, LB_STATUS_ERROR_FAULT, handler->update_mode_cbdata);
2972 handler->update_mode_cb = NULL;
2973 handler->update_mode_cbdata = NULL;
2976 if (handler->access_event_cb) {
2977 DbgPrint("Clear access status callback\n");
2978 handler->access_event_cb(handler, LB_STATUS_ERROR_FAULT, handler->access_event_cbdata);
2979 handler->access_event_cb = NULL;
2980 handler->access_event_cbdata = NULL;
2983 if (handler->filename)
2984 util_unlink(handler->filename);
2986 dlist_remove_data(s_info.livebox_list, handler);
2988 handler->state = DESTROYED;
2989 free(handler->cluster);
2990 free(handler->category);
2992 free(handler->pkgname);
2993 free(handler->filename);
2994 free(handler->lb.auto_launch);
2996 if (handler->lb.data.fb) {
2997 fb_destroy(handler->lb.data.fb);
2998 handler->lb.data.fb = NULL;
3001 if (handler->pd.data.fb) {
3002 fb_destroy(handler->pd.data.fb);
3003 handler->pd.data.fb = NULL;
3010 int lb_send_delete(struct livebox *handler, ret_cb_t cb, void *data)
3012 struct packet *packet;
3013 struct cb_info *cbinfo;
3016 if (!cb && !!data) {
3017 ErrPrint("Invalid argument\n");
3018 return LB_STATUS_ERROR_INVALID;
3021 if (handler->deleted_cb) {
3022 ErrPrint("Already in-progress\n");
3023 return LB_STATUS_ERROR_BUSY;
3026 packet = packet_create("delete", "ss", handler->pkgname, handler->id);
3028 ErrPrint("Failed to build a param\n");
3030 cb(handler, LB_STATUS_ERROR_FAULT, data);
3032 return LB_STATUS_ERROR_FAULT;
3036 cb = default_delete_cb;
3038 cbinfo = create_cb_info(cb, data);
3040 packet_destroy(packet);
3041 return LB_STATUS_ERROR_FAULT;
3044 ret = master_rpc_async_request(handler, packet, 0, del_ret_cb, cbinfo);
3046 destroy_cb_info(cbinfo);
3051 EAPI int livebox_client_paused(void)
3053 struct packet *packet;
3055 packet = packet_create_noack("client_paused", "d", util_timestamp());
3057 ErrPrint("Failed to create a pause packet\n");
3058 return LB_STATUS_ERROR_FAULT;
3061 return master_rpc_request_only(NULL, packet);
3064 EAPI int livebox_client_resumed(void)
3066 struct packet *packet;
3068 packet = packet_create_noack("client_resumed", "d", util_timestamp());
3070 ErrPrint("Failed to create a resume packet\n");
3071 return LB_STATUS_ERROR_FAULT;
3074 return master_rpc_request_only(NULL, packet);