2 * Copyright 2012 Samsung Electronics Co., Ltd
4 * Licensed under the Flora License, Version 1.0 (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://www.tizenopensource.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>
33 #include "livebox_internal.h"
36 #include "master_rpc.h"
38 #include "critical_log.h"
40 #define EAPI __attribute__((visibility("default")))
41 #define MINIMUM_EVENT s_info.event_filter
48 struct dlist *livebox_list;
49 struct dlist *event_list;
50 struct dlist *fault_list;
52 int prevent_overwrite;
59 .prevent_overwrite = 0,
60 .event_filter = 0.02f,
69 int (*handler)(struct livebox *handler, enum livebox_event_type event, void *data);
74 int (*handler)(enum livebox_fault_type event, const char *pkgname, const char *filename, const char *func, void *data);
78 static inline void default_create_cb(struct livebox *handler, int ret, void *data)
80 DbgPrint("Default created event handler: %d\n", ret);
83 static inline void default_delete_cb(struct livebox *handler, int ret, void *data)
85 DbgPrint("Default deleted event handler: %d\n", ret);
88 static inline void default_pinup_cb(struct livebox *handler, int ret, void *data)
90 DbgPrint("Default pinup event handler: %d\n", ret);
93 static inline void default_group_changed_cb(struct livebox *handler, int ret, void *data)
95 DbgPrint("Default group changed event handler: %d\n", ret);
98 static inline void default_period_changed_cb(struct livebox *handler, int ret, void *data)
100 DbgPrint("Default period changed event handler: %d\n", ret);
103 static inline void default_pd_created_cb(struct livebox *handler, int ret, void *data)
105 DbgPrint("Default PD created event handler: %d\n", ret);
108 static inline void default_pd_destroyed_cb(struct livebox *handler, int ret, void *data)
110 DbgPrint("Default PD destroyed event handler: %d\n", ret);
113 static inline void default_lb_size_changed_cb(struct livebox *handler, int ret, void *data)
115 DbgPrint("Default LB size changed event handler: %d\n", ret);
118 static inline __attribute__((always_inline)) struct cb_info *create_cb_info(ret_cb_t cb, void *data)
120 struct cb_info *info;
122 info = malloc(sizeof(*info));
124 CRITICAL_LOG("Heap: %s\n", strerror(errno));
133 static inline void destroy_cb_info(struct cb_info *info)
138 static void resize_cb(struct livebox *handler, const struct packet *result, void *data)
141 struct cb_info *info = data;
147 destroy_cb_info(info);
151 } else if (packet_get(result, "i", &ret) != 1) {
152 ErrPrint("Invalid argument\n");
158 * In case of resize request,
159 * The livebox handler will not have resized value right after this callback,
160 * It can only get the new size when it makes updates.
162 * So the user can only get the resized value(result) from the first update event
163 * after this request.
166 handler->size_changed_cb = cb;
167 handler->size_cbdata = cbdata;
169 cb(handler, ret, cbdata);
173 static void text_signal_cb(struct livebox *handler, const struct packet *result, void *data)
177 struct cb_info *info = data;
182 destroy_cb_info(info);
186 } else if (packet_get(result, "i", &ret) != 1) {
187 ErrPrint("Invalid argument\n");
192 cb(handler, ret, cbdata);
196 static void set_group_ret_cb(struct livebox *handler, const struct packet *result, void *data)
201 struct cb_info *info = data;
205 destroy_cb_info(info);
209 } else if (packet_get(result, "i", &ret) != 1) {
210 ErrPrint("Invalid argument\n");
214 if (ret == 0) { /*!< Group information is successfully changed */
215 handler->group_changed_cb = cb;
216 handler->group_cbdata = cbdata;
218 cb(handler, ret, cbdata);
224 static void period_ret_cb(struct livebox *handler, const struct packet *result, void *data)
226 struct cb_info *info = data;
233 destroy_cb_info(info);
237 } else if (packet_get(result, "i", &ret) != 1) {
238 ErrPrint("Invalid argument\n");
243 handler->period_changed_cb = cb;
244 handler->period_cbdata = cbdata;
246 cb(handler, ret, cbdata);
250 static void del_ret_cb(struct livebox *handler, const struct packet *result, void *data)
252 struct cb_info *info = data;
259 destroy_cb_info(info);
262 ErrPrint("Connection lost?\n");
264 } else if (packet_get(result, "i", &ret) != 1) {
265 ErrPrint("Invalid argument\n");
270 DbgPrint("Returns %d (waiting deleted event)\n", ret);
271 handler->deleted_cb = cb;
272 handler->deleted_cbdata = cbdata;
274 cb(handler, ret, cbdata);
279 * Do not call the deleted callback from here.
280 * master will send the "deleted" event.
281 * Then invoke this callback.
283 * if (handler->deleted_cb)
284 * handler->deleted_cb(handler, ret, handler->deleted_cbdata);
288 static void new_ret_cb(struct livebox *handler, const struct packet *result, void *data)
291 struct cb_info *info = data;
297 destroy_cb_info(info);
301 } else if (packet_get(result, "i", &ret) != 1) {
306 DbgPrint("new request is sent, just waiting the created event\n");
307 handler->created_cb = cb;
308 handler->created_cbdata = cbdata;
312 * Don't go anymore ;)
318 * It means the current instance is not created,
319 * so user has to know about this.
320 * notice it to user using "deleted" event.
322 cb(handler, ret, cbdata);
328 static void pd_create_cb(struct livebox *handler, const struct packet *result, void *data)
330 struct cb_info *info = data;
337 destroy_cb_info(data);
341 } else if (packet_get(result, "i", &ret) != 1) {
346 DbgPrint("PD Created event handler prepared\n");
347 handler->pd_created_cb = cb;
348 handler->pd_created_cbdata = cbdata;
350 DbgPrint("Failed to create a PD\n");
351 cb(handler, ret, cbdata);
355 static void activated_cb(struct livebox *handler, const struct packet *result, void *data)
358 struct cb_info *info = data;
361 const char *pkgname = "";
365 destroy_cb_info(info);
369 } else if (packet_get(result, "is", &ret, &pkgname) != 2) {
374 cb(handler, ret, cbdata);
377 static void pd_destroy_cb(struct livebox *handler, const struct packet *result, void *data)
382 struct cb_info *info = data;
386 destroy_cb_info(info);
389 DbgPrint("Result is NIL (may connection lost)\n");
391 } else if (packet_get(result, "i", &ret) != 1) {
392 DbgPrint("Invalid parameter\n");
397 DbgPrint("PD Destroyed callback prepared\n");
398 handler->pd_destroyed_cb = cb;
399 handler->pd_destroyed_cbdata = cbdata;
401 DbgPrint("PD is not desroyed (forcely reset, pd flag)\n");
402 handler->is_pd_created = 0;
403 cb(handler, ret, cbdata);
407 static void delete_cluster_cb(struct livebox *handler, const struct packet *result, void *data)
409 struct cb_info *info = data;
416 destroy_cb_info(info);
420 } else if (packet_get(result, "i", &ret) != 1) {
424 DbgPrint("Delete category returns: %d\n", ret);
427 cb(handler, ret, cbdata);
430 static void delete_category_cb(struct livebox *handler, const struct packet *result, void *data)
432 struct cb_info *info = data;
439 destroy_cb_info(info);
443 else if (packet_get(result, "i", &ret) != 1)
446 DbgPrint("Delete category returns: %d\n", ret);
449 cb(handler, ret, cbdata);
452 static void pixmap_acquired_cb(struct livebox *handler, const struct packet *result, void *data)
457 struct cb_info *info = data;
461 destroy_cb_info(info);
464 ret = 0; /* PIXMAP 0 means error */
465 else if (packet_get(result, "i", &ret) != 1)
469 cb(handler, ret, cbdata);
472 static void pinup_done_cb(struct livebox *handler, const struct packet *result, void *data)
477 struct cb_info *info = data;
481 destroy_cb_info(info);
485 else if (packet_get(result, "i", &ret) != 1)
489 handler->pinup_cb = cb;
490 handler->pinup_cbdata = cbdata;
492 cb(handler, ret, cbdata);
496 static int send_mouse_event(struct livebox *handler, const char *event, double x, double y, int w, int h)
498 struct packet *packet;
501 timestamp = util_timestamp();
502 packet = packet_create_noack(event, "ssiiddd", handler->pkgname, handler->id, w, h,
505 ErrPrint("Failed to build param\n");
509 return master_rpc_request_only(handler, packet);
512 EAPI int livebox_init(void *disp)
516 if (s_info.init_count > 0) {
520 env = getenv("PROVIDER_DISABLE_PREVENT_OVERWRITE");
521 if (env && !strcasecmp(env, "true"))
522 s_info.prevent_overwrite = 1;
524 env = getenv("PROVIDER_EVENT_FILTER");
526 sscanf(env, "%lf", &MINIMUM_EVENT);
529 char filename[BUFSIZ];
530 snprintf(filename, sizeof(filename), "/tmp/%d.box.log", getpid());
531 __file_log_fp = fopen(filename, "w+t");
533 __file_log_fp = fdopen(1, "w+t");
535 critical_log_init("viewer");
536 livebox_service_init();
545 EAPI int livebox_fini(void)
547 if (s_info.init_count <= 0) {
548 DbgPrint("Didn't initialized\n");
553 if (s_info.init_count > 0) {
554 DbgPrint("init count : %d\n", s_info.init_count);
560 livebox_service_fini();
565 static inline char *lb_pkgname(const char *pkgname)
569 lb = livebox_service_pkgname(pkgname);
571 if (util_validate_livebox_package(pkgname) == 0)
572 return strdup(pkgname);
579 * Just wrapping the livebox_add_with_size function.
581 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)
583 return livebox_add_with_size(pkgname, content, cluster, category, period, LB_SIZE_TYPE_UNKNOWN, cb, data);
586 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)
588 struct livebox *handler;
589 struct packet *packet;
594 if (!pkgname || !cluster || !category || width < 0 || height < 0) {
595 ErrPrint("Invalid arguments: pkgname[%p], cluster[%p], category[%p]\n",
596 pkgname, cluster, category);
600 if (livebox_service_is_enabled(pkgname) == 0) {
601 DbgPrint("Livebox [%s] is disabled package\n", pkgname);
605 if (type != LB_SIZE_TYPE_UNKNOWN)
606 livebox_service_get_size(type, &width, &height);
608 handler = calloc(1, sizeof(*handler));
610 ErrPrint("Error: %s\n", strerror(errno));
614 handler->pkgname = lb_pkgname(pkgname);
615 if (!handler->pkgname) {
616 ErrPrint("Error: %s\n", strerror(errno));
622 handler->content = strdup(content);
623 if (!handler->content) {
624 ErrPrint("Error: %s\n", strerror(errno));
625 free(handler->pkgname);
630 handler->content = livebox_service_content(handler->pkgname);
633 handler->cluster = strdup(cluster);
634 if (!handler->cluster) {
635 ErrPrint("Error: %s\n", strerror(errno));
636 free(handler->content);
637 free(handler->pkgname);
642 handler->category = strdup(category);
643 if (!handler->category) {
644 ErrPrint("Error: %s\n", strerror(errno));
645 free(handler->cluster);
646 free(handler->content);
647 free(handler->pkgname);
653 cb = default_create_cb;
655 /* Data provider will set this */
656 handler->lb.type = _LB_TYPE_FILE;
657 handler->pd.type = _PD_TYPE_SCRIPT;
658 handler->lb.period = period;
660 /* Used for handling the mouse event on a box */
661 handler->lb.mouse_event = livebox_service_mouse_event(handler->pkgname);
663 /* Cluster infomration is not determined yet */
664 handler->nr_of_sizes = 0x01;
666 handler->timestamp = util_timestamp();
667 handler->is_user = 1;
668 handler->visible = LB_SHOW;
670 s_info.livebox_list = dlist_append(s_info.livebox_list, handler);
672 packet = packet_create("new", "dssssdii", handler->timestamp, handler->pkgname, handler->content, cluster, category, period, width, height);
674 ErrPrint("Failed to create a new packet\n");
675 free(handler->category);
676 free(handler->cluster);
677 free(handler->content);
678 free(handler->pkgname);
683 ret = master_rpc_async_request(handler, packet, 0, new_ret_cb, create_cb_info(cb, data));
685 ErrPrint("Failed to send a new packet\n");
686 free(handler->category);
687 free(handler->cluster);
688 free(handler->content);
689 free(handler->pkgname);
694 DbgPrint("Successfully sent a new request ([%lf] %s)\n", handler->timestamp, handler->pkgname);
695 handler->state = CREATE;
696 return lb_ref(handler);
699 EAPI double livebox_period(struct livebox *handler)
701 if (!handler || handler->state != CREATE || !handler->id) {
702 ErrPrint("Handler is not valid\n");
706 return handler->lb.period;
709 EAPI int livebox_set_period(struct livebox *handler, double period, ret_cb_t cb, void *data)
711 struct packet *packet;
713 if (!handler || handler->state != CREATE || !handler->id) {
714 ErrPrint("Handler is not valid\n");
718 if (!handler->is_user) {
719 ErrPrint("CA Livebox is not able to change the period\n");
723 if (handler->lb.period == period) {
724 DbgPrint("No changes\n");
728 packet = packet_create("set_period", "ssd", handler->pkgname, handler->id, period);
730 ErrPrint("Failed to build a packet %s\n", handler->pkgname);
735 cb = default_period_changed_cb;
737 return master_rpc_async_request(handler, packet, 0, period_ret_cb, create_cb_info(cb, data));
740 EAPI int livebox_del(struct livebox *handler, ret_cb_t cb, void *data)
743 ErrPrint("Handler is NIL\n");
747 if (handler->state != CREATE) {
748 ErrPrint("Handler is already deleted\n");
752 handler->state = DELETE;
757 * The id is not determined yet.
758 * It means a user didn't receive created event yet.
759 * Then just stop to delete procedure from here.
760 * Because the "created" event handler will release this.
761 * By the way, if the user adds any callback for getting return status of this,
765 cb(handler, 0, data);
770 cb = default_delete_cb;
772 return lb_send_delete(handler, cb, data);
775 EAPI int livebox_set_fault_handler(int (*cb)(enum livebox_fault_type, const char *, const char *, const char *, void *), void *data)
777 struct fault_info *info;
782 info = malloc(sizeof(*info));
784 CRITICAL_LOG("Heap: %s\n", strerror(errno));
789 info->user_data = data;
791 s_info.fault_list = dlist_append(s_info.fault_list, info);
795 EAPI void *livebox_unset_fault_handler(int (*cb)(enum livebox_fault_type, const char *, const char *, const char *, void *))
797 struct fault_info *info;
800 dlist_foreach(s_info.fault_list, l, info) {
801 if (info->handler == cb) {
803 s_info.fault_list = dlist_remove(s_info.fault_list, l);
804 data = info->user_data;
814 EAPI int livebox_set_event_handler(int (*cb)(struct livebox *, enum livebox_event_type, void *), void *data)
816 struct event_info *info;
819 ErrPrint("Invalid argument cb is nil\n");
823 info = malloc(sizeof(*info));
825 CRITICAL_LOG("Heap: %s\n", strerror(errno));
830 info->user_data = data;
832 s_info.event_list = dlist_append(s_info.event_list, info);
836 EAPI void *livebox_unset_event_handler(int (*cb)(struct livebox *, enum livebox_event_type, void *))
838 struct event_info *info;
841 dlist_foreach(s_info.event_list, l, info) {
842 if (info->handler == cb) {
845 s_info.event_list = dlist_remove(s_info.event_list, l);
846 data = info->user_data;
856 EAPI int livebox_resize(struct livebox *handler, int type, ret_cb_t cb, void *data)
858 struct packet *packet;
863 ErrPrint("Handler is NIL\n");
867 if (handler->state != CREATE || !handler->id) {
868 ErrPrint("Handler is not valid\n");
872 if (!handler->is_user) {
873 ErrPrint("CA Livebox is not able to be resized\n");
877 if (livebox_service_get_size(type, &w, &h) != 0) {
878 ErrPrint("Invalid size type\n");
882 if (handler->lb.width == w && handler->lb.height == h) {
883 DbgPrint("No changes\n");
887 packet = packet_create("resize", "ssii", handler->pkgname, handler->id, w, h);
889 ErrPrint("Failed to build param\n");
894 cb = default_lb_size_changed_cb;
896 return master_rpc_async_request(handler, packet, 0, resize_cb, create_cb_info(cb, data));
899 EAPI int livebox_click(struct livebox *handler, double x, double y)
901 struct packet *packet;
906 ErrPrint("Handler is NIL\n");
910 if (handler->state != CREATE || !handler->id) {
911 ErrPrint("Handler is not valid\n");
915 if (handler->lb.auto_launch)
916 if (aul_launch_app(handler->lb.auto_launch, NULL) < 0)
917 ErrPrint("Failed to launch app %s\n", handler->lb.auto_launch);
919 timestamp = util_timestamp();
920 packet = packet_create_noack("clicked", "sssddd", handler->pkgname, handler->id, "clicked", timestamp, x, y);
922 ErrPrint("Failed to build param\n");
926 ret = master_rpc_request_only(handler, packet);
928 if (!handler->lb.mouse_event && (handler->lb.type == _LB_TYPE_BUFFER || handler->lb.type == _LB_TYPE_SCRIPT)) {
929 int ret; /* Shadow variable */
930 ret = send_mouse_event(handler, "lb_mouse_down", x, y, handler->lb.width, handler->lb.height);
932 DbgPrint("Failed to send Down: %d\n", ret);
934 ret = send_mouse_event(handler, "lb_mouse_move", x, y, handler->lb.width, handler->lb.height);
936 DbgPrint("Failed to send Move: %d\n", ret);
938 ret = send_mouse_event(handler, "lb_mouse_up", x, y, handler->lb.width, handler->lb.height);
940 DbgPrint("Failed to send Up: %d\n", ret);
946 EAPI int livebox_has_pd(struct livebox *handler)
949 ErrPrint("Handler is NIL\n");
953 if (handler->state != CREATE || !handler->id) {
954 ErrPrint("Handler is not valid\n");
958 return !!handler->pd.data.fb;
961 EAPI int livebox_pd_is_created(struct livebox *handler)
964 ErrPrint("Handler is NIL\n");
968 if (!handler->pd.data.fb || handler->state != CREATE || !handler->id) {
969 ErrPrint("Handler is not valid\n");
973 return handler->is_pd_created;
976 EAPI int livebox_create_pd(struct livebox *handler, ret_cb_t cb, void *data)
978 return livebox_create_pd_with_position(handler, -1.0, -1.0, cb, data);
981 EAPI int livebox_create_pd_with_position(struct livebox *handler, double x, double y, ret_cb_t cb, void *data)
983 struct packet *packet;
986 ErrPrint("Handler is NIL\n");
990 if (!handler->pd.data.fb || handler->state != CREATE || !handler->id) {
991 ErrPrint("Handler is not valid\n");
995 if (handler->is_pd_created == 1) {
996 DbgPrint("PD already created\n");
1000 packet = packet_create("create_pd", "ssdd", handler->pkgname, handler->id, x, y);
1002 ErrPrint("Failed to build param\n");
1007 handler->pd_created_cb = default_pd_created_cb;
1009 return master_rpc_async_request(handler, packet, 0, pd_create_cb, create_cb_info(cb, data));
1012 EAPI int livebox_activate(const char *pkgname, ret_cb_t cb, void *data)
1014 struct packet *packet;
1019 packet = packet_create("activate_package", "s", pkgname);
1021 ErrPrint("Failed to build a param\n");
1025 return master_rpc_async_request(NULL, packet, 0, activated_cb, create_cb_info(cb, data));
1028 EAPI int livebox_destroy_pd(struct livebox *handler, ret_cb_t cb, void *data)
1030 struct packet *packet;
1033 ErrPrint("Handler is NIL\n");
1037 if (!handler->pd.data.fb || handler->state != CREATE || !handler->id) {
1038 ErrPrint("Handler is not valid\n");
1042 if (!handler->is_pd_created) {
1043 ErrPrint("PD is not created\n");
1047 packet = packet_create("destroy_pd", "ss", handler->pkgname, handler->id);
1049 ErrPrint("Failed to build a param\n");
1054 cb = default_pd_destroyed_cb;
1056 return master_rpc_async_request(handler, packet, 0, pd_destroy_cb, create_cb_info(cb, data));
1059 EAPI int livebox_content_event(struct livebox *handler, enum content_event_type type, double x, double y)
1063 char cmd[20] = { '\0', };
1067 ErrPrint("Handler is NIL\n");
1071 if (handler->state != CREATE || !handler->id) {
1072 ErrPrint("Handler is not valid\n");
1076 if (type & CONTENT_EVENT_PD_MASK) {
1077 if (!handler->is_pd_created) {
1078 ErrPrint("PD is not created\n");
1082 if (type & CONTENT_EVENT_MOUSE_MASK) {
1083 if (!handler->pd.data.fb) {
1084 ErrPrint("Handler is not valid\n");
1088 if (type & CONTENT_EVENT_MOUSE_MOVE) {
1089 if (fabs(x - handler->pd.x) < MINIMUM_EVENT && fabs(y - handler->pd.y) < MINIMUM_EVENT)
1094 w = handler->pd.width;
1095 h = handler->pd.height;
1101 if (type & CONTENT_EVENT_MOUSE_MASK) {
1102 if (!handler->lb.mouse_event) {
1103 ErrPrint("Box is not support the mouse event\n");
1107 if (!handler->lb.data.fb) {
1108 ErrPrint("Handler is not valid\n");
1112 if (type & CONTENT_EVENT_MOUSE_MOVE) {
1113 if (fabs(x - handler->lb.x) < MINIMUM_EVENT && fabs(y - handler->lb.y) < MINIMUM_EVENT)
1118 w = handler->lb.width;
1119 h = handler->lb.height;
1126 switch ((type & ~CONTENT_EVENT_PD_MASK)) {
1127 case CONTENT_EVENT_ACCESS_READ | CONTENT_EVENT_ACCESS_MASK:
1128 strcpy(ptr, "_access_read");
1130 case CONTENT_EVENT_ACCESS_READ_PREV | CONTENT_EVENT_ACCESS_MASK:
1131 strcpy(ptr, "_access_read_prev");
1133 case CONTENT_EVENT_ACCESS_READ_NEXT | CONTENT_EVENT_ACCESS_MASK:
1134 strcpy(ptr, "_access_read_next");
1136 case CONTENT_EVENT_ACCESS_ACTIVATE | CONTENT_EVENT_ACCESS_MASK:
1137 strcpy(ptr, "_access_activate");
1139 case CONTENT_EVENT_ACCESS_UP | CONTENT_EVENT_ACCESS_MASK:
1140 strcpy(ptr, "_access_up");
1142 case CONTENT_EVENT_ACCESS_DOWN | CONTENT_EVENT_ACCESS_MASK:
1143 strcpy(ptr, "_access_down");
1145 case CONTENT_EVENT_MOUSE_ENTER | CONTENT_EVENT_MOUSE_MASK:
1146 strcpy(ptr, "_mouse_enter");
1148 case CONTENT_EVENT_MOUSE_LEAVE | CONTENT_EVENT_MOUSE_MASK:
1149 strcpy(ptr, "_mouse_leave");
1151 case CONTENT_EVENT_MOUSE_UP | CONTENT_EVENT_MOUSE_MASK:
1152 strcpy(ptr, "_mouse_up");
1154 case CONTENT_EVENT_MOUSE_DOWN | CONTENT_EVENT_MOUSE_MASK:
1155 strcpy(ptr, "_mouse_down");
1157 case CONTENT_EVENT_MOUSE_MOVE | CONTENT_EVENT_MOUSE_MASK:
1158 strcpy(ptr, "_mouse_move");
1160 case CONTENT_EVENT_KEY_DOWN | CONTENT_EVENT_KEY_MASK:
1161 strcpy(ptr, "_key_down");
1163 case CONTENT_EVENT_KEY_UP | CONTENT_EVENT_KEY_MASK:
1164 strcpy(ptr, "_key_up");
1167 ErrPrint("Invalid event type\n");
1171 return send_mouse_event(handler, cmd, x, y, w, h);
1174 EAPI const char *livebox_filename(struct livebox *handler)
1177 ErrPrint("Handler is NIL\n");
1181 if (handler->state != CREATE || !handler->id) {
1182 ErrPrint("Handler is not valid\n");
1186 if (handler->filename)
1187 return handler->filename;
1190 return util_uri_to_path(handler->id);
1193 EAPI int livebox_get_pdsize(struct livebox *handler, int *w, int *h)
1199 ErrPrint("Handler is NIL\n");
1203 if (handler->state != CREATE || !handler->id) {
1204 ErrPrint("Handler is not valid\n");
1213 *w = handler->pd.width;
1214 *h = handler->pd.height;
1216 switch (handler->pd.type) {
1217 case _PD_TYPE_BUFFER:
1218 case _PD_TYPE_SCRIPT:
1219 if (!handler->is_pd_created) {
1220 DbgPrint("Buffer is not created yet - reset size\n");
1232 EAPI int livebox_size(struct livebox *handler)
1238 ErrPrint("Handler is NIL\n");
1242 if (handler->state != CREATE || !handler->id) {
1243 ErrPrint("Handler is not valid\n");
1247 w = handler->lb.width;
1248 h = handler->lb.height;
1250 switch (handler->lb.type) {
1251 case _LB_TYPE_BUFFER:
1252 case _LB_TYPE_SCRIPT:
1253 if (!fb_is_created(handler->lb.data.fb)) {
1254 DbgPrint("Buffer is not created yet - reset size\n");
1263 return livebox_service_size_type(w, h);
1266 EAPI int livebox_set_group(struct livebox *handler, const char *cluster, const char *category, ret_cb_t cb, void *data)
1268 struct packet *packet;
1271 ErrPrint("Handler is NIL\n");
1275 if (!cluster || !category || handler->state != CREATE || !handler->id) {
1276 ErrPrint("Invalid argument\n");
1280 if (!handler->is_user) {
1281 ErrPrint("CA Livebox is not able to change the group\n");
1285 if (!strcmp(handler->cluster, cluster) && !strcmp(handler->category, category)) {
1286 DbgPrint("No changes\n");
1290 packet = packet_create("change_group", "ssss", handler->pkgname, handler->id, cluster, category);
1292 ErrPrint("Failed to build a param\n");
1297 cb = default_group_changed_cb;
1299 return master_rpc_async_request(handler, packet, 0, set_group_ret_cb, create_cb_info(cb, data));
1302 EAPI int livebox_get_group(struct livebox *handler, char ** const cluster, char ** const category)
1305 ErrPrint("Handler is NIL\n");
1309 if (!cluster || !category || handler->state != CREATE || !handler->id) {
1310 ErrPrint("Invalid argument\n");
1314 *cluster = handler->cluster;
1315 *category = handler->category;
1319 EAPI int livebox_get_supported_sizes(struct livebox *handler, int *cnt, int *size_list)
1324 if (!handler || !size_list) {
1325 ErrPrint("Invalid argument, handler(%p), size_list(%p)\n", handler, size_list);
1329 if (!cnt || handler->state != CREATE || !handler->id) {
1330 ErrPrint("Handler is not valid\n");
1334 for (j = i = 0; i < NR_OF_SIZE_LIST; i++) {
1335 if (handler->lb.size_list & (0x01 << i)) {
1339 size_list[j++] = (0x01 << i);
1347 EAPI const char *livebox_pkgname(struct livebox *handler)
1350 ErrPrint("Handler is NIL\n");
1354 if (handler->state != CREATE) {
1355 ErrPrint("Handler is not valid\n");
1359 return handler->pkgname;
1362 EAPI double livebox_priority(struct livebox *handler)
1365 ErrPrint("Handler is NIL\n");
1369 if (handler->state != CREATE || !handler->id) {
1370 ErrPrint("Handler is not valid (%p)\n", handler);
1374 return handler->lb.priority;
1377 EAPI int livebox_delete_cluster(const char *cluster, ret_cb_t cb, void *data)
1379 struct packet *packet;
1381 packet = packet_create("delete_cluster", "s", cluster);
1383 ErrPrint("Failed to build a param\n");
1387 return master_rpc_async_request(NULL, packet, 0, delete_cluster_cb, create_cb_info(cb, data));
1390 EAPI int livebox_delete_category(const char *cluster, const char *category, ret_cb_t cb, void *data)
1392 struct packet *packet;
1394 packet = packet_create("delete_category", "ss", cluster, category);
1396 ErrPrint("Failed to build a param\n");
1400 return master_rpc_async_request(NULL, packet, 0, delete_category_cb, create_cb_info(cb, data));
1403 EAPI enum livebox_lb_type livebox_lb_type(struct livebox *handler)
1406 ErrPrint("Handler is NIL\n");
1407 return LB_TYPE_INVALID;
1410 if (handler->state != CREATE || !handler->id) {
1411 ErrPrint("Handler is not valid\n");
1412 return LB_TYPE_INVALID;
1415 switch (handler->lb.type) {
1417 return LB_TYPE_IMAGE;
1418 case _LB_TYPE_BUFFER:
1419 case _LB_TYPE_SCRIPT:
1422 id = fb_id(handler->lb.data.fb);
1423 if (id && !strncasecmp(id, SCHEMA_PIXMAP, strlen(SCHEMA_PIXMAP)))
1424 return LB_TYPE_PIXMAP;
1426 return LB_TYPE_BUFFER;
1428 return LB_TYPE_TEXT;
1433 return LB_TYPE_INVALID;
1436 EAPI enum livebox_pd_type livebox_pd_type(struct livebox *handler)
1439 ErrPrint("Handler is NIL\n");
1440 return PD_TYPE_INVALID;
1443 if (handler->state != CREATE || !handler->id) {
1444 ErrPrint("Handler is not valid\n");
1445 return PD_TYPE_INVALID;
1448 switch (handler->pd.type) {
1450 return PD_TYPE_TEXT;
1451 case _PD_TYPE_BUFFER:
1452 case _PD_TYPE_SCRIPT:
1455 id = fb_id(handler->pd.data.fb);
1456 if (id && !strncasecmp(id, SCHEMA_PIXMAP, strlen(SCHEMA_PIXMAP)))
1457 return PD_TYPE_PIXMAP;
1459 return PD_TYPE_BUFFER;
1464 return PD_TYPE_INVALID;
1467 EAPI int livebox_set_pd_text_handler(struct livebox *handler, struct livebox_script_operators *ops)
1470 ErrPrint("Handler is NIL\n");
1474 if (handler->state != CREATE) {
1475 ErrPrint("Handler is not valid\n");
1479 memcpy(&handler->pd.data.ops, ops, sizeof(*ops));
1483 EAPI int livebox_set_text_handler(struct livebox *handler, struct livebox_script_operators *ops)
1486 ErrPrint("Handler is NIL\n");
1490 if (handler->state != CREATE) {
1491 ErrPrint("Handler is not valid\n");
1495 memcpy(&handler->lb.data.ops, ops, sizeof(*ops));
1499 EAPI int livebox_acquire_lb_pixmap(struct livebox *handler, ret_cb_t cb, void *data)
1501 struct packet *packet;
1505 ErrPrint("Handler is NIL\n");
1509 if (handler->state != CREATE || !handler->id) {
1510 ErrPrint("Invalid handle\n");
1514 if (handler->lb.type != _LB_TYPE_SCRIPT && handler->lb.type != _LB_TYPE_BUFFER) {
1515 ErrPrint("Handler is not valid type\n");
1519 id = fb_id(handler->lb.data.fb);
1520 if (!id || strncasecmp(id, SCHEMA_PIXMAP, strlen(SCHEMA_PIXMAP)))
1523 packet = packet_create("lb_acquire_pixmap", "ss", handler->pkgname, handler->id);
1525 ErrPrint("Failed to build a param\n");
1529 return master_rpc_async_request(handler, packet, 0, pixmap_acquired_cb, create_cb_info(cb, data));
1532 EAPI int livebox_release_lb_pixmap(struct livebox *handler, int pixmap)
1534 struct packet *packet;
1537 ErrPrint("Handler is NIL\n");
1541 if (handler->state != CREATE || !handler->id) {
1542 ErrPrint("Invalid handle\n");
1546 if (handler->lb.type != _LB_TYPE_SCRIPT && handler->lb.type != _LB_TYPE_BUFFER) {
1547 ErrPrint("Handler is not valid type\n");
1551 packet = packet_create_noack("lb_release_pixmap", "ssi", handler->pkgname, handler->id, pixmap);
1553 ErrPrint("Failed to build a param\n");
1557 return master_rpc_request_only(handler, packet);
1560 EAPI int livebox_acquire_pd_pixmap(struct livebox *handler, ret_cb_t cb, void *data)
1562 struct packet *packet;
1566 ErrPrint("Handler is NIL\n");
1570 if (handler->state != CREATE || !handler->id) {
1571 ErrPrint("Invalid handle\n");
1575 if (handler->pd.type != _PD_TYPE_SCRIPT && handler->pd.type != _PD_TYPE_BUFFER) {
1576 ErrPrint("Handler is not valid type\n");
1580 id = fb_id(handler->pd.data.fb);
1581 if (!id || strncasecmp(id, SCHEMA_PIXMAP, strlen(SCHEMA_PIXMAP)))
1584 packet = packet_create("pd_acquire_pixmap", "ss", handler->pkgname, handler->id);
1586 ErrPrint("Failed to build a param\n");
1590 return master_rpc_async_request(handler, packet, 0, pixmap_acquired_cb, create_cb_info(cb, data));
1593 EAPI int livebox_pd_pixmap(const struct livebox *handler)
1599 ErrPrint("Handler is NIL\n");
1603 if (handler->state != CREATE || !handler->id) {
1604 ErrPrint("Invalid handler\n");
1608 if (handler->pd.type != _PD_TYPE_SCRIPT && handler->pd.type != _PD_TYPE_BUFFER) {
1609 ErrPrint("Invalid handler\n");
1613 id = fb_id(handler->pd.data.fb);
1614 if (id && sscanf(id, SCHEMA_PIXMAP "%d", &pixmap) != 1) {
1615 ErrPrint("PIXMAP Id is not valid\n");
1622 EAPI int livebox_lb_pixmap(const struct livebox *handler)
1628 ErrPrint("Handler is NIL\n");
1632 if (handler->state != CREATE || !handler->id) {
1633 ErrPrint("Invalid handler\n");
1637 if (handler->lb.type != _LB_TYPE_SCRIPT && handler->lb.type != _LB_TYPE_BUFFER) {
1638 ErrPrint("Invalid handler\n");
1642 id = fb_id(handler->lb.data.fb);
1643 if (id && sscanf(id, SCHEMA_PIXMAP "%d", &pixmap) != 1) {
1644 ErrPrint("PIXMAP Id is not valid\n");
1651 EAPI int livebox_release_pd_pixmap(struct livebox *handler, int pixmap)
1653 struct packet *packet;
1656 ErrPrint("Handler is NIL\n");
1660 if (handler->state != CREATE || !handler->id) {
1661 ErrPrint("Invalid handle\n");
1665 if (handler->pd.type != _PD_TYPE_SCRIPT && handler->pd.type != _PD_TYPE_BUFFER) {
1666 ErrPrint("Handler is not valid type\n");
1670 packet = packet_create_noack("pd_release_pixmap", "ssi", handler->pkgname, handler->id, pixmap);
1672 ErrPrint("Failed to build a param\n");
1676 return master_rpc_request_only(handler, packet);
1679 EAPI void *livebox_acquire_fb(struct livebox *handler)
1682 ErrPrint("Handler is NIL\n");
1686 if (handler->state != CREATE || !handler->id) {
1687 ErrPrint("Invalid handle\n");
1691 if (handler->lb.type != _LB_TYPE_SCRIPT && handler->lb.type != _LB_TYPE_BUFFER) {
1692 ErrPrint("Handler is not valid type\n");
1696 return fb_acquire_buffer(handler->lb.data.fb);
1699 EAPI int livebox_release_fb(void *buffer)
1701 return fb_release_buffer(buffer);
1704 EAPI int livebox_fb_refcnt(void *buffer)
1706 return fb_refcnt(buffer);
1709 EAPI void *livebox_acquire_pdfb(struct livebox *handler)
1712 ErrPrint("Handler is NIL\n");
1716 if (handler->state != CREATE || !handler->id) {
1717 ErrPrint("Invalid handler\n");
1721 if (handler->pd.type != _PD_TYPE_SCRIPT && handler->pd.type != _PD_TYPE_BUFFER) {
1722 ErrPrint("Handler is not valid type\n");
1726 return fb_acquire_buffer(handler->pd.data.fb);
1729 EAPI int livebox_release_pdfb(void *buffer)
1731 return fb_release_buffer(buffer);
1734 EAPI int livebox_pdfb_refcnt(void *buffer)
1736 return fb_refcnt(buffer);
1739 EAPI int livebox_pdfb_bufsz(struct livebox *handler)
1742 ErrPrint("Handler is NIL\n");
1746 if (handler->state != CREATE || !handler->id) {
1747 ErrPrint("Handler is not valid\n");
1751 return fb_size(handler->pd.data.fb);
1754 EAPI int livebox_lbfb_bufsz(struct livebox *handler)
1757 ErrPrint("Handler is NIL\n");
1761 if (handler->state != CREATE || !handler->id) {
1762 ErrPrint("Handler is not valid\n");
1766 return fb_size(handler->lb.data.fb);
1769 EAPI int livebox_is_user(struct livebox *handler)
1772 ErrPrint("Handler is NIL\n");
1776 if (handler->state != CREATE) {
1777 ErrPrint("Handler is invalid\n");
1781 return handler->is_user;
1784 EAPI int livebox_set_pinup(struct livebox *handler, int flag, ret_cb_t cb, void *data)
1786 struct packet *packet;
1789 ErrPrint("Handler is NIL\n");
1793 if (handler->state != CREATE || !handler->id) {
1794 ErrPrint("Handler is not valid\n");
1798 if (handler->is_pinned_up == flag) {
1799 DbgPrint("No changes\n");
1803 packet = packet_create("pinup_changed", "ssi", handler->pkgname, handler->id, flag);
1805 ErrPrint("Failed to build a param\n");
1810 cb = default_pinup_cb;
1812 return master_rpc_async_request(handler, packet, 0, pinup_done_cb, create_cb_info(cb, data));
1815 EAPI int livebox_is_pinned_up(struct livebox *handler)
1818 ErrPrint("Handler is NIL\n");
1822 if (handler->state != CREATE || !handler->id)
1825 return handler->is_pinned_up;
1828 EAPI int livebox_has_pinup(struct livebox *handler)
1831 ErrPrint("Handler is NIL\n");
1835 if (handler->state != CREATE || !handler->id)
1838 return handler->lb.pinup_supported;
1841 EAPI int livebox_set_data(struct livebox *handler, void *data)
1844 ErrPrint("Handler is NIL\n");
1848 if (handler->state != CREATE)
1851 handler->data = data;
1855 EAPI void *livebox_get_data(struct livebox *handler)
1858 ErrPrint("Handler is NIL\n");
1862 if (handler->state != CREATE)
1865 return handler->data;
1868 EAPI int livebox_is_exists(const char *pkgname)
1872 lb = lb_pkgname(pkgname);
1881 EAPI const char *livebox_content(struct livebox *handler)
1884 ErrPrint("Handler is NIL\n");
1888 if (handler->state != CREATE)
1891 return handler->content;
1894 EAPI const char *livebox_category_title(struct livebox *handler)
1897 ErrPrint("Handler is NIL\n");
1901 if (handler->state != CREATE)
1904 return handler->title;
1907 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)
1909 struct packet *packet;
1912 ErrPrint("Handler is NIL\n");
1916 if ((handler->lb.type != _LB_TYPE_TEXT && handler->pd.type != _PD_TYPE_TEXT) || handler->state != CREATE || !handler->id) {
1917 ErrPrint("Handler is not valid\n");
1927 packet = packet_create("text_signal", "ssssdddd",
1928 handler->pkgname, handler->id, emission, source, sx, sy, ex, ey);
1930 ErrPrint("Failed to build a param\n");
1934 return master_rpc_async_request(handler, packet, 0, text_signal_cb, create_cb_info(cb, data));
1937 EAPI int livebox_subscribe_group(const char *cluster, const char *category)
1939 struct packet *packet;
1943 * Validate the group info using DB
1944 * If the group info is not valid, do not send this request
1947 packet = packet_create_noack("subscribe", "ss", cluster ? cluster : "", category ? category : "");
1949 ErrPrint("Failed to create a packet\n");
1953 return master_rpc_request_only(NULL, packet);
1956 EAPI int livebox_unsubscribe_group(const char *cluster, const char *category)
1958 struct packet *packet;
1962 * Validate the group info using DB
1963 * If the group info is not valid, do not send this request
1964 * AND Check the subscribed or not too
1967 packet = packet_create_noack("unsubscribe", "ss", cluster ? cluster : "", category ? category : "");
1969 ErrPrint("Failed to create a packet\n");
1973 return master_rpc_request_only(NULL, packet);
1976 EAPI int livebox_refresh(struct livebox *handler)
1978 struct packet *packet;
1981 ErrPrint("Hnalder is NIL\n");
1985 if (handler->state != CREATE || !handler->id)
1988 packet = packet_create_noack("update", "ss", handler->pkgname, handler->id);
1990 ErrPrint("Failed to create a packet\n");
1994 return master_rpc_request_only(handler, packet);
1997 EAPI int livebox_refresh_group(const char *cluster, const char *category)
1999 struct packet *packet;
2001 if (!cluster || !category) {
2002 ErrPrint("Invalid argument\n");
2006 packet = packet_create_noack("refresh_group", "ss", cluster, category);
2008 ErrPrint("Failed to create a packet\n");
2012 return master_rpc_request_only(NULL, packet);
2015 EAPI int livebox_set_visibility(struct livebox *handler, enum livebox_visible_state state)
2017 struct packet *packet;
2021 ErrPrint("Handler is NIL\n");
2025 if (handler->state != CREATE || !handler->id)
2028 if (!handler->is_user) {
2029 /* System cluster livebox cannot be changed its visible states */
2030 if (state == LB_HIDE_WITH_PAUSE) {
2031 ErrPrint("CA Livebox is not able to change the visibility\n");
2036 if (handler->visible == state)
2039 packet = packet_create_noack("change,visibility", "ssi", handler->pkgname, handler->id, (int)state);
2041 ErrPrint("Failed to create a packet\n");
2045 ret = master_rpc_request_only(handler, packet);
2047 handler->visible = state;
2052 EAPI enum livebox_visible_state livebox_visibility(struct livebox *handler)
2055 ErrPrint("Handler is NIL\n");
2056 return LB_VISIBLE_ERROR;
2059 if (handler->state != CREATE)
2060 return LB_VISIBLE_ERROR;
2062 return handler->visible;
2065 int lb_set_group(struct livebox *handler, const char *cluster, const char *category)
2071 pc = strdup(cluster);
2073 CRITICAL_LOG("Heap: %s (cluster: %s)\n", strerror(errno), cluster);
2079 ps = strdup(category);
2081 CRITICAL_LOG("Heap: %s (category: %s)\n", strerror(errno), category);
2087 if (handler->cluster)
2088 free(handler->cluster);
2090 if (handler->category)
2091 free(handler->category);
2093 handler->cluster = pc;
2094 handler->category = ps;
2099 void lb_set_size(struct livebox *handler, int w, int h)
2101 handler->lb.width = w;
2102 handler->lb.height = h;
2105 void lb_set_pdsize(struct livebox *handler, int w, int h)
2107 handler->pd.width = w;
2108 handler->pd.height = h;
2111 void lb_invoke_fault_handler(enum livebox_fault_type event, const char *pkgname, const char *file, const char *func)
2115 struct fault_info *info;
2117 dlist_foreach_safe(s_info.fault_list, l, n, info) {
2118 if (info->handler(event, pkgname, file, func, info->user_data) == EXIT_FAILURE)
2119 s_info.fault_list = dlist_remove(s_info.fault_list, l);
2123 void lb_invoke_event_handler(struct livebox *handler, enum livebox_event_type event)
2127 struct event_info *info;
2129 dlist_foreach_safe(s_info.event_list, l, n, info) {
2130 if (info->handler(handler, event, info->user_data) == EXIT_FAILURE)
2131 s_info.event_list = dlist_remove(s_info.event_list, l);
2135 struct livebox *lb_find_livebox(const char *pkgname, const char *id)
2138 struct livebox *handler;
2140 dlist_foreach(s_info.livebox_list, l, handler) {
2144 if (!strcmp(handler->pkgname, pkgname) && !strcmp(handler->id, id))
2151 struct livebox *lb_find_livebox_by_timestamp(double timestamp)
2154 struct livebox *handler;
2156 dlist_foreach(s_info.livebox_list, l, handler) {
2157 if (handler->timestamp == timestamp)
2164 static inline char *get_file_kept_in_safe(const char *id)
2171 path = util_uri_to_path(id);
2173 ErrPrint("Invalid URI(%s)\n", id);
2180 if (s_info.prevent_overwrite) {
2181 new_path = strdup(path);
2183 ErrPrint("Heap: %s\n", strerror(errno));
2192 while (base_idx > 0 && path[base_idx] != '/') base_idx--;
2193 base_idx += (path[base_idx] == '/');
2195 new_path = malloc(len + 10);
2197 ErrPrint("Heap: %s\n", strerror(errno));
2201 strncpy(new_path, path, base_idx);
2202 snprintf(new_path + base_idx, len + 10 - base_idx, "reader/%s", path + base_idx);
2206 struct livebox *lb_new_livebox(const char *pkgname, const char *id, double timestamp)
2208 struct livebox *handler;
2210 handler = calloc(1, sizeof(*handler));
2212 ErrPrint("Failed to create a new livebox\n");
2216 handler->pkgname = strdup(pkgname);
2217 if (!handler->pkgname) {
2218 ErrPrint("%s\n", strerror(errno));
2223 handler->id = strdup(id);
2225 ErrPrint("%s\n", strerror(errno));
2226 free(handler->pkgname);
2231 handler->filename = get_file_kept_in_safe(id);
2232 if (!handler->filename) {
2233 handler->filename = strdup(util_uri_to_path(id));
2234 if (!handler->filename)
2235 ErrPrint("Error: %s\n", strerror(errno));
2238 handler->timestamp = timestamp;
2239 handler->lb.type = _LB_TYPE_FILE;
2240 handler->pd.type = _PD_TYPE_SCRIPT;
2241 handler->state = CREATE;
2242 handler->visible = LB_SHOW;
2244 s_info.livebox_list = dlist_append(s_info.livebox_list, handler);
2249 int lb_delete_all(void)
2253 struct livebox *handler;
2255 dlist_foreach_safe(s_info.livebox_list, l, n, handler) {
2256 lb_invoke_event_handler(handler, LB_EVENT_DELETED);
2263 int lb_set_content(struct livebox *handler, const char *content)
2265 if (handler->content) {
2266 free(handler->content);
2267 handler->content = NULL;
2271 handler->content = strdup(content);
2272 if (!handler->content) {
2273 CRITICAL_LOG("Heap: %s (content: %s)\n", strerror(errno), content);
2281 int lb_set_title(struct livebox *handler, const char *title)
2283 if (handler->title) {
2284 free(handler->title);
2285 handler->title = NULL;
2289 handler->title = strdup(title);
2290 if (!handler->title) {
2291 CRITICAL_LOG("Heap: %s (title: %s)\n", strerror(errno), title);
2299 void lb_set_size_list(struct livebox *handler, int size_list)
2301 handler->lb.size_list = size_list;
2304 void lb_set_auto_launch(struct livebox *handler, const char *auto_launch)
2306 if (!strlen(auto_launch))
2309 handler->lb.auto_launch = strdup(auto_launch);
2310 if (!handler->lb.auto_launch)
2311 ErrPrint("Heap: %s\n", strerror(errno));
2314 void lb_set_priority(struct livebox *handler, double priority)
2316 handler->lb.priority = priority;
2319 void lb_set_id(struct livebox *handler, const char *id)
2324 handler->id = strdup(id);
2326 ErrPrint("Error: %s\n", strerror(errno));
2328 if (handler->filename)
2329 free(handler->filename);
2331 handler->filename = get_file_kept_in_safe(id);
2332 if (!handler->filename) {
2333 handler->filename = strdup(util_uri_to_path(id));
2334 if (!handler->filename)
2335 ErrPrint("Error: %s\n", strerror(errno));
2339 int lb_set_lb_fb(struct livebox *handler, const char *filename)
2346 fb = handler->lb.data.fb;
2347 if (fb && !strcmp(fb_id(fb), filename)) /*!< BUFFER is not changed, */
2350 handler->lb.data.fb = NULL;
2352 if (!filename || filename[0] == '\0') {
2358 handler->lb.data.fb = fb_create(filename, handler->lb.width, handler->lb.height);
2359 if (!handler->lb.data.fb) {
2360 ErrPrint("Faield to create a FB\n");
2372 int lb_set_pd_fb(struct livebox *handler, const char *filename)
2379 fb = handler->pd.data.fb;
2380 if (fb && !strcmp(fb_id(fb), filename)) {
2381 /* BUFFER is not changed, just update the content */
2384 handler->pd.data.fb = NULL;
2386 if (!filename || filename[0] == '\0') {
2392 handler->pd.data.fb = fb_create(filename, handler->pd.width, handler->pd.height);
2393 if (!handler->pd.data.fb) {
2394 ErrPrint("Failed to create a FB\n");
2405 struct fb_info *lb_get_lb_fb(struct livebox *handler)
2407 return handler->lb.data.fb;
2410 struct fb_info *lb_get_pd_fb(struct livebox *handler)
2412 return handler->pd.data.fb;
2415 void lb_set_user(struct livebox *handler, int user)
2417 handler->is_user = user;
2420 void lb_set_pinup(struct livebox *handler, int pinup_supported)
2422 handler->lb.pinup_supported = pinup_supported;
2425 void lb_set_text_lb(struct livebox *handler)
2427 handler->lb.type = _LB_TYPE_TEXT;
2430 void lb_set_text_pd(struct livebox *handler)
2432 handler->pd.type = _PD_TYPE_TEXT;
2435 int lb_text_lb(struct livebox *handler)
2437 return handler->lb.type == _LB_TYPE_TEXT;
2440 int lb_text_pd(struct livebox *handler)
2442 return handler->pd.type == _PD_TYPE_TEXT;
2445 void lb_set_period(struct livebox *handler, double period)
2447 handler->lb.period = period;
2450 struct livebox *lb_ref(struct livebox *handler)
2459 struct livebox *lb_unref(struct livebox *handler)
2465 if (handler->refcnt > 0)
2468 dlist_remove_data(s_info.livebox_list, handler);
2470 handler->state = DESTROYED;
2471 free(handler->cluster);
2472 free(handler->category);
2474 free(handler->pkgname);
2475 free(handler->filename);
2476 free(handler->lb.auto_launch);
2478 if (handler->lb.data.fb) {
2479 fb_destroy(handler->lb.data.fb);
2480 handler->lb.data.fb = NULL;
2483 if (handler->pd.data.fb) {
2484 fb_destroy(handler->pd.data.fb);
2485 handler->pd.data.fb = NULL;
2492 int lb_send_delete(struct livebox *handler, ret_cb_t cb, void *data)
2494 struct packet *packet;
2496 if (!cb && !!data) {
2497 ErrPrint("Invalid argument\n");
2501 if (handler->deleted_cb) {
2502 ErrPrint("Already in-progress\n");
2503 return -EINPROGRESS;
2506 packet = packet_create("delete", "ss", handler->pkgname, handler->id);
2508 ErrPrint("Failed to build a param\n");
2510 cb(handler, -EFAULT, data);
2516 cb = default_delete_cb;
2518 return master_rpc_async_request(handler, packet, 0, del_ret_cb, create_cb_info(cb, data));