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 __attribute__((always_inline)) struct cb_info *create_cb_info(ret_cb_t cb, void *data)
115 struct cb_info *info;
117 info = malloc(sizeof(*info));
119 CRITICAL_LOG("Heap: %s\n", strerror(errno));
128 static inline void destroy_cb_info(struct cb_info *info)
133 static void resize_cb(struct livebox *handler, const struct packet *result, void *data)
136 struct cb_info *info = data;
142 destroy_cb_info(info);
146 } else if (packet_get(result, "i", &ret) != 1) {
147 ErrPrint("Invalid argument\n");
153 * In case of resize request,
154 * The livebox handler will not have resized value right after this callback,
155 * It can only get the new size when it makes updates.
157 * So the user can only get the resized value(result) from the first update event
158 * after this request.
162 cb(handler, ret, cbdata);
165 static void text_signal_cb(struct livebox *handler, const struct packet *result, void *data)
169 struct cb_info *info = data;
174 destroy_cb_info(info);
178 } else if (packet_get(result, "i", &ret) != 1) {
179 ErrPrint("Invalid argument\n");
184 cb(handler, ret, cbdata);
188 static void set_group_ret_cb(struct livebox *handler, const struct packet *result, void *data)
193 struct cb_info *info = data;
197 destroy_cb_info(info);
201 } else if (packet_get(result, "i", &ret) != 1) {
202 ErrPrint("Invalid argument\n");
206 if (ret == 0) { /*!< Group information is successfully changed */
207 handler->group_changed_cb = cb;
208 handler->group_cbdata = cbdata;
210 cb(handler, ret, cbdata);
216 static void period_ret_cb(struct livebox *handler, const struct packet *result, void *data)
218 struct cb_info *info = data;
225 destroy_cb_info(info);
229 } else if (packet_get(result, "i", &ret) != 1) {
230 ErrPrint("Invalid argument\n");
235 handler->period_changed_cb = cb;
236 handler->period_cbdata = cbdata;
238 cb(handler, ret, cbdata);
242 static void del_ret_cb(struct livebox *handler, const struct packet *result, void *data)
244 struct cb_info *info = data;
251 destroy_cb_info(info);
254 ErrPrint("Connection lost?\n");
256 } else if (packet_get(result, "i", &ret) != 1) {
257 ErrPrint("Invalid argument\n");
262 DbgPrint("Returns %d (waiting deleted event)\n", ret);
263 handler->deleted_cb = cb;
264 handler->deleted_cbdata = cbdata;
266 cb(handler, ret, cbdata);
271 * Do not call the deleted callback from here.
272 * master will send the "deleted" event.
273 * Then invoke this callback.
275 * if (handler->deleted_cb)
276 * handler->deleted_cb(handler, ret, handler->deleted_cbdata);
280 static void new_ret_cb(struct livebox *handler, const struct packet *result, void *data)
283 struct cb_info *info = data;
289 destroy_cb_info(info);
293 } else if (packet_get(result, "i", &ret) != 1) {
298 DbgPrint("new request is sent, just waiting the created event\n");
299 handler->created_cb = cb;
300 handler->created_cbdata = cbdata;
304 * Don't go anymore ;)
310 * It means the current instance is not created,
311 * so user has to know about this.
312 * notice it to user using "deleted" event.
314 cb(handler, ret, cbdata);
320 static void pd_create_cb(struct livebox *handler, const struct packet *result, void *data)
322 struct cb_info *info = data;
329 destroy_cb_info(data);
333 } else if (packet_get(result, "i", &ret) != 1) {
338 DbgPrint("PD Created event handler prepared\n");
339 handler->pd_created_cb = cb;
340 handler->pd_created_cbdata = cbdata;
342 DbgPrint("Failed to create a PD\n");
343 cb(handler, ret, cbdata);
347 static void activated_cb(struct livebox *handler, const struct packet *result, void *data)
350 struct cb_info *info = data;
353 const char *pkgname = "";
357 destroy_cb_info(info);
361 } else if (packet_get(result, "is", &ret, &pkgname) != 2) {
366 cb(handler, ret, cbdata);
369 static void pd_destroy_cb(struct livebox *handler, const struct packet *result, void *data)
374 struct cb_info *info = data;
378 destroy_cb_info(info);
381 DbgPrint("Result is NIL (may connection lost)\n");
383 } else if (packet_get(result, "i", &ret) != 1) {
384 DbgPrint("Invalid parameter\n");
389 DbgPrint("PD Destroyed callback prepared\n");
390 handler->pd_destroyed_cb = cb;
391 handler->pd_destroyed_cbdata = cbdata;
393 DbgPrint("PD is not desroyed (forcely reset, pd flag)\n");
394 handler->is_pd_created = 0;
395 cb(handler, ret, cbdata);
399 static void delete_cluster_cb(struct livebox *handler, const struct packet *result, void *data)
401 struct cb_info *info = data;
408 destroy_cb_info(info);
412 } else if (packet_get(result, "i", &ret) != 1) {
416 DbgPrint("Delete category returns: %d\n", ret);
419 cb(handler, ret, cbdata);
422 static void delete_category_cb(struct livebox *handler, const struct packet *result, void *data)
424 struct cb_info *info = data;
431 destroy_cb_info(info);
435 else if (packet_get(result, "i", &ret) != 1)
438 DbgPrint("Delete category returns: %d\n", ret);
441 cb(handler, ret, cbdata);
444 static void pixmap_acquired_cb(struct livebox *handler, const struct packet *result, void *data)
449 struct cb_info *info = data;
453 destroy_cb_info(info);
456 ret = 0; /* PIXMAP 0 means error */
457 else if (packet_get(result, "i", &ret) != 1)
461 cb(handler, ret, cbdata);
464 static void pinup_done_cb(struct livebox *handler, const struct packet *result, void *data)
469 struct cb_info *info = data;
473 destroy_cb_info(info);
477 else if (packet_get(result, "i", &ret) != 1)
481 handler->pinup_cb = cb;
482 handler->pinup_cbdata = cbdata;
484 cb(handler, ret, cbdata);
488 static int send_mouse_event(struct livebox *handler, const char *event, double x, double y, int w, int h)
490 struct packet *packet;
493 timestamp = util_timestamp();
494 packet = packet_create_noack(event, "ssiiddd", handler->pkgname, handler->id, w, h,
497 ErrPrint("Failed to build param\n");
501 return master_rpc_request_only(handler, packet);
504 EAPI int livebox_init(void *disp)
508 if (s_info.init_count > 0) {
512 env = getenv("PROVIDER_DISABLE_PREVENT_OVERWRITE");
513 if (env && !strcasecmp(env, "true"))
514 s_info.prevent_overwrite = 1;
516 env = getenv("PROVIDER_EVENT_FILTER");
518 sscanf(env, "%lf", &MINIMUM_EVENT);
521 char filename[BUFSIZ];
522 snprintf(filename, sizeof(filename), "/tmp/%d.box.log", getpid());
523 __file_log_fp = fopen(filename, "w+t");
525 __file_log_fp = fdopen(1, "w+t");
527 critical_log_init("viewer");
528 livebox_service_init();
537 EAPI int livebox_fini(void)
539 if (s_info.init_count <= 0) {
540 DbgPrint("Didn't initialized\n");
545 if (s_info.init_count > 0) {
546 DbgPrint("init count : %d\n", s_info.init_count);
552 livebox_service_fini();
557 static inline char *lb_pkgname(const char *pkgname)
561 lb = livebox_service_pkgname(pkgname);
563 if (util_validate_livebox_package(pkgname) == 0)
564 return strdup(pkgname);
571 * Just wrapping the livebox_add_with_size function.
573 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)
575 return livebox_add_with_size(pkgname, content, cluster, category, period, LB_SIZE_TYPE_UNKNOWN, cb, data);
578 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)
580 struct livebox *handler;
581 struct packet *packet;
586 if (!pkgname || !cluster || !category || width < 0 || height < 0) {
587 ErrPrint("Invalid arguments: pkgname[%p], cluster[%p], category[%p]\n",
588 pkgname, cluster, category);
592 if (type != LB_SIZE_TYPE_UNKNOWN)
593 livebox_service_get_size(type, &width, &height);
595 handler = calloc(1, sizeof(*handler));
597 ErrPrint("Error: %s\n", strerror(errno));
601 handler->pkgname = lb_pkgname(pkgname);
602 if (!handler->pkgname) {
603 ErrPrint("Error: %s\n", strerror(errno));
609 handler->content = strdup(content);
610 if (!handler->content) {
611 ErrPrint("Error: %s\n", strerror(errno));
612 free(handler->pkgname);
617 handler->content = livebox_service_content(handler->pkgname);
620 handler->cluster = strdup(cluster);
621 if (!handler->cluster) {
622 ErrPrint("Error: %s\n", strerror(errno));
623 free(handler->content);
624 free(handler->pkgname);
629 handler->category = strdup(category);
630 if (!handler->category) {
631 ErrPrint("Error: %s\n", strerror(errno));
632 free(handler->cluster);
633 free(handler->content);
634 free(handler->pkgname);
640 cb = default_create_cb;
642 /* Data provider will set this */
643 handler->lb.type = _LB_TYPE_FILE;
644 handler->pd.type = _PD_TYPE_SCRIPT;
645 handler->lb.period = period;
647 /* Used for handling the mouse event on a box */
648 handler->lb.mouse_event = livebox_service_mouse_event(handler->pkgname);
650 /* Cluster infomration is not determined yet */
651 handler->nr_of_sizes = 0x01;
653 handler->timestamp = util_timestamp();
654 handler->is_user = 1;
655 handler->visible = LB_SHOW;
657 s_info.livebox_list = dlist_append(s_info.livebox_list, handler);
659 packet = packet_create("new", "dssssdii", handler->timestamp, handler->pkgname, handler->content, cluster, category, period, width, height);
661 ErrPrint("Failed to create a new packet\n");
662 free(handler->category);
663 free(handler->cluster);
664 free(handler->content);
665 free(handler->pkgname);
670 ret = master_rpc_async_request(handler, packet, 0, new_ret_cb, create_cb_info(cb, data));
672 ErrPrint("Failed to send a new packet\n");
673 free(handler->category);
674 free(handler->cluster);
675 free(handler->content);
676 free(handler->pkgname);
681 DbgPrint("Successfully sent a new request ([%lf] %s)\n", handler->timestamp, handler->pkgname);
682 handler->state = CREATE;
683 return lb_ref(handler);
686 EAPI double livebox_period(struct livebox *handler)
688 if (!handler || handler->state != CREATE || !handler->id) {
689 ErrPrint("Handler is not valid\n");
693 return handler->lb.period;
696 EAPI int livebox_set_period(struct livebox *handler, double period, ret_cb_t cb, void *data)
698 struct packet *packet;
700 if (!handler || handler->state != CREATE || !handler->id) {
701 ErrPrint("Handler is not valid\n");
705 if (!handler->is_user) {
706 ErrPrint("CA Livebox is not able to change the period\n");
710 if (handler->lb.period == period) {
711 DbgPrint("No changes\n");
715 packet = packet_create("set_period", "ssd", handler->pkgname, handler->id, period);
717 ErrPrint("Failed to build a packet %s\n", handler->pkgname);
722 cb = default_period_changed_cb;
724 return master_rpc_async_request(handler, packet, 0, period_ret_cb, create_cb_info(cb, data));
727 EAPI int livebox_del(struct livebox *handler, ret_cb_t cb, void *data)
730 ErrPrint("Handler is NIL\n");
734 if (handler->state != CREATE) {
735 ErrPrint("Handler is already deleted\n");
739 handler->state = DELETE;
744 * The id is not determined yet.
745 * It means a user didn't receive created event yet.
746 * Then just stop to delete procedure from here.
747 * Because the "created" event handler will release this.
748 * By the way, if the user adds any callback for getting return status of this,
752 cb(handler, 0, data);
757 cb = default_delete_cb;
759 return lb_send_delete(handler, cb, data);
762 EAPI int livebox_set_fault_handler(int (*cb)(enum livebox_fault_type, const char *, const char *, const char *, void *), void *data)
764 struct fault_info *info;
769 info = malloc(sizeof(*info));
771 CRITICAL_LOG("Heap: %s\n", strerror(errno));
776 info->user_data = data;
778 s_info.fault_list = dlist_append(s_info.fault_list, info);
782 EAPI void *livebox_unset_fault_handler(int (*cb)(enum livebox_fault_type, const char *, const char *, const char *, void *))
784 struct fault_info *info;
787 dlist_foreach(s_info.fault_list, l, info) {
788 if (info->handler == cb) {
790 s_info.fault_list = dlist_remove(s_info.fault_list, l);
791 data = info->user_data;
801 EAPI int livebox_set_event_handler(int (*cb)(struct livebox *, enum livebox_event_type, void *), void *data)
803 struct event_info *info;
806 ErrPrint("Invalid argument cb is nil\n");
810 info = malloc(sizeof(*info));
812 CRITICAL_LOG("Heap: %s\n", strerror(errno));
817 info->user_data = data;
819 s_info.event_list = dlist_append(s_info.event_list, info);
823 EAPI void *livebox_unset_event_handler(int (*cb)(struct livebox *, enum livebox_event_type, void *))
825 struct event_info *info;
828 dlist_foreach(s_info.event_list, l, info) {
829 if (info->handler == cb) {
832 s_info.event_list = dlist_remove(s_info.event_list, l);
833 data = info->user_data;
843 EAPI int livebox_resize(struct livebox *handler, int type, ret_cb_t cb, void *data)
845 struct packet *packet;
850 ErrPrint("Handler is NIL\n");
854 if (handler->state != CREATE || !handler->id) {
855 ErrPrint("Handler is not valid\n");
859 if (!handler->is_user) {
860 ErrPrint("CA Livebox is not able to be resized\n");
864 if (livebox_service_get_size(type, &w, &h) != 0) {
865 ErrPrint("Invalid size type\n");
869 if (handler->lb.width == w && handler->lb.height == h) {
870 DbgPrint("No changes\n");
874 packet = packet_create("resize", "ssii", handler->pkgname, handler->id, w, h);
876 ErrPrint("Failed to build param\n");
880 return master_rpc_async_request(handler, packet, 0, resize_cb, create_cb_info(cb, data));
883 EAPI int livebox_click(struct livebox *handler, double x, double y)
885 struct packet *packet;
890 ErrPrint("Handler is NIL\n");
894 if (handler->state != CREATE || !handler->id) {
895 ErrPrint("Handler is not valid\n");
899 if (handler->lb.auto_launch)
900 if (aul_launch_app(handler->lb.auto_launch, NULL) < 0)
901 ErrPrint("Failed to launch app %s\n", handler->lb.auto_launch);
903 timestamp = util_timestamp();
904 packet = packet_create_noack("clicked", "sssddd", handler->pkgname, handler->id, "clicked", timestamp, x, y);
906 ErrPrint("Failed to build param\n");
910 ret = master_rpc_request_only(handler, packet);
912 if (!handler->lb.mouse_event && (handler->lb.type == _LB_TYPE_BUFFER || handler->lb.type == _LB_TYPE_SCRIPT)) {
913 int ret; /* Shadow variable */
914 ret = send_mouse_event(handler, "lb_mouse_down", x, y, handler->lb.width, handler->lb.height);
916 DbgPrint("Failed to send Down: %d\n", ret);
918 ret = send_mouse_event(handler, "lb_mouse_move", x, y, handler->lb.width, handler->lb.height);
920 DbgPrint("Failed to send Move: %d\n", ret);
922 ret = send_mouse_event(handler, "lb_mouse_up", x, y, handler->lb.width, handler->lb.height);
924 DbgPrint("Failed to send Up: %d\n", ret);
930 EAPI int livebox_has_pd(struct livebox *handler)
933 ErrPrint("Handler is NIL\n");
937 if (handler->state != CREATE || !handler->id) {
938 ErrPrint("Handler is not valid\n");
942 return !!handler->pd.data.fb;
945 EAPI int livebox_pd_is_created(struct livebox *handler)
948 ErrPrint("Handler is NIL\n");
952 if (!handler->pd.data.fb || handler->state != CREATE || !handler->id) {
953 ErrPrint("Handler is not valid\n");
957 return handler->is_pd_created;
960 EAPI int livebox_create_pd(struct livebox *handler, ret_cb_t cb, void *data)
962 return livebox_create_pd_with_position(handler, -1.0, -1.0, cb, data);
965 EAPI int livebox_create_pd_with_position(struct livebox *handler, double x, double y, ret_cb_t cb, void *data)
967 struct packet *packet;
970 ErrPrint("Handler is NIL\n");
974 if (!handler->pd.data.fb || handler->state != CREATE || !handler->id) {
975 ErrPrint("Handler is not valid\n");
979 if (handler->is_pd_created == 1) {
980 DbgPrint("PD already created\n");
984 packet = packet_create("create_pd", "ssdd", handler->pkgname, handler->id, x, y);
986 ErrPrint("Failed to build param\n");
991 handler->pd_created_cb = default_pd_created_cb;
993 return master_rpc_async_request(handler, packet, 0, pd_create_cb, create_cb_info(cb, data));
996 EAPI int livebox_activate(const char *pkgname, ret_cb_t cb, void *data)
998 struct packet *packet;
1003 packet = packet_create("activate_package", "s", pkgname);
1005 ErrPrint("Failed to build a param\n");
1009 return master_rpc_async_request(NULL, packet, 0, activated_cb, create_cb_info(cb, data));
1012 EAPI int livebox_destroy_pd(struct livebox *handler, ret_cb_t cb, void *data)
1014 struct packet *packet;
1017 ErrPrint("Handler is NIL\n");
1021 if (!handler->pd.data.fb || handler->state != CREATE || !handler->id) {
1022 ErrPrint("Handler is not valid\n");
1026 if (!handler->is_pd_created) {
1027 ErrPrint("PD is not created\n");
1031 packet = packet_create("destroy_pd", "ss", handler->pkgname, handler->id);
1033 ErrPrint("Failed to build a param\n");
1038 cb = default_pd_destroyed_cb;
1040 return master_rpc_async_request(handler, packet, 0, pd_destroy_cb, create_cb_info(cb, data));
1043 EAPI int livebox_content_event(struct livebox *handler, enum content_event_type type, double x, double y)
1047 char cmd[20] = { '\0', };
1051 ErrPrint("Handler is NIL\n");
1055 if (handler->state != CREATE || !handler->id) {
1056 ErrPrint("Handler is not valid\n");
1060 if (type & CONTENT_EVENT_PD_MASK) {
1061 if (!handler->is_pd_created) {
1062 ErrPrint("PD is not created\n");
1066 if (type & CONTENT_EVENT_MOUSE_MASK) {
1067 if (!handler->pd.data.fb) {
1068 ErrPrint("Handler is not valid\n");
1072 if (type & CONTENT_EVENT_MOUSE_MOVE) {
1073 if (fabs(x - handler->pd.x) < MINIMUM_EVENT && fabs(y - handler->pd.y) < MINIMUM_EVENT)
1078 w = handler->pd.width;
1079 h = handler->pd.height;
1085 if (type & CONTENT_EVENT_MOUSE_MASK) {
1086 if (!handler->lb.mouse_event) {
1087 ErrPrint("Box is not support the mouse event\n");
1091 if (!handler->lb.data.fb) {
1092 ErrPrint("Handler is not valid\n");
1096 if (type & CONTENT_EVENT_MOUSE_MOVE) {
1097 if (fabs(x - handler->lb.x) < MINIMUM_EVENT && fabs(y - handler->lb.y) < MINIMUM_EVENT)
1102 w = handler->lb.width;
1103 h = handler->lb.height;
1110 switch ((type & ~CONTENT_EVENT_PD_MASK)) {
1111 case CONTENT_EVENT_ACCESS_READ | CONTENT_EVENT_ACCESS_MASK:
1112 strcpy(ptr, "_access_read");
1114 case CONTENT_EVENT_ACCESS_READ_PREV | CONTENT_EVENT_ACCESS_MASK:
1115 strcpy(ptr, "_access_read_prev");
1117 case CONTENT_EVENT_ACCESS_READ_NEXT | CONTENT_EVENT_ACCESS_MASK:
1118 strcpy(ptr, "_access_read_next");
1120 case CONTENT_EVENT_ACCESS_ACTIVATE | CONTENT_EVENT_ACCESS_MASK:
1121 strcpy(ptr, "_access_activate");
1123 case CONTENT_EVENT_ACCESS_UP | CONTENT_EVENT_ACCESS_MASK:
1124 strcpy(ptr, "_access_up");
1126 case CONTENT_EVENT_ACCESS_DOWN | CONTENT_EVENT_ACCESS_MASK:
1127 strcpy(ptr, "_access_down");
1129 case CONTENT_EVENT_MOUSE_ENTER | CONTENT_EVENT_MOUSE_MASK:
1130 strcpy(ptr, "_mouse_enter");
1132 case CONTENT_EVENT_MOUSE_LEAVE | CONTENT_EVENT_MOUSE_MASK:
1133 strcpy(ptr, "_mouse_leave");
1135 case CONTENT_EVENT_MOUSE_UP | CONTENT_EVENT_MOUSE_MASK:
1136 strcpy(ptr, "_mouse_up");
1138 case CONTENT_EVENT_MOUSE_DOWN | CONTENT_EVENT_MOUSE_MASK:
1139 strcpy(ptr, "_mouse_down");
1141 case CONTENT_EVENT_MOUSE_MOVE | CONTENT_EVENT_MOUSE_MASK:
1142 strcpy(ptr, "_mouse_move");
1144 case CONTENT_EVENT_KEY_DOWN | CONTENT_EVENT_KEY_MASK:
1145 strcpy(ptr, "_key_down");
1147 case CONTENT_EVENT_KEY_UP | CONTENT_EVENT_KEY_MASK:
1148 strcpy(ptr, "_key_up");
1151 ErrPrint("Invalid event type\n");
1155 return send_mouse_event(handler, cmd, x, y, w, h);
1158 EAPI const char *livebox_filename(struct livebox *handler)
1161 ErrPrint("Handler is NIL\n");
1165 if (handler->state != CREATE || !handler->id) {
1166 ErrPrint("Handler is not valid\n");
1170 if (handler->filename)
1171 return handler->filename;
1174 return util_uri_to_path(handler->id);
1177 EAPI int livebox_get_pdsize(struct livebox *handler, int *w, int *h)
1183 ErrPrint("Handler is NIL\n");
1187 if (handler->state != CREATE || !handler->id) {
1188 ErrPrint("Handler is not valid\n");
1197 *w = handler->pd.width;
1198 *h = handler->pd.height;
1200 switch (handler->pd.type) {
1201 case _PD_TYPE_BUFFER:
1202 case _PD_TYPE_SCRIPT:
1203 if (!handler->is_pd_created) {
1204 DbgPrint("Buffer is not created yet - reset size\n");
1216 EAPI int livebox_size(struct livebox *handler)
1222 ErrPrint("Handler is NIL\n");
1226 if (handler->state != CREATE || !handler->id) {
1227 ErrPrint("Handler is not valid\n");
1231 w = handler->lb.width;
1232 h = handler->lb.height;
1234 switch (handler->lb.type) {
1235 case _LB_TYPE_BUFFER:
1236 case _LB_TYPE_SCRIPT:
1237 if (!fb_is_created(handler->lb.data.fb)) {
1238 DbgPrint("Buffer is not created yet - reset size\n");
1247 return livebox_service_size_type(w, h);
1250 EAPI int livebox_set_group(struct livebox *handler, const char *cluster, const char *category, ret_cb_t cb, void *data)
1252 struct packet *packet;
1255 ErrPrint("Handler is NIL\n");
1259 if (!cluster || !category || handler->state != CREATE || !handler->id) {
1260 ErrPrint("Invalid argument\n");
1264 if (!handler->is_user) {
1265 ErrPrint("CA Livebox is not able to change the group\n");
1269 if (!strcmp(handler->cluster, cluster) && !strcmp(handler->category, category)) {
1270 DbgPrint("No changes\n");
1274 packet = packet_create("change_group", "ssss", handler->pkgname, handler->id, cluster, category);
1276 ErrPrint("Failed to build a param\n");
1281 cb = default_group_changed_cb;
1283 return master_rpc_async_request(handler, packet, 0, set_group_ret_cb, create_cb_info(cb, data));
1286 EAPI int livebox_get_group(struct livebox *handler, char ** const cluster, char ** const category)
1289 ErrPrint("Handler is NIL\n");
1293 if (!cluster || !category || handler->state != CREATE || !handler->id) {
1294 ErrPrint("Invalid argument\n");
1298 *cluster = handler->cluster;
1299 *category = handler->category;
1303 EAPI int livebox_get_supported_sizes(struct livebox *handler, int *cnt, int *size_list)
1308 if (!handler || !size_list) {
1309 ErrPrint("Invalid argument, handler(%p), size_list(%p)\n", handler, size_list);
1313 if (!cnt || handler->state != CREATE || !handler->id) {
1314 ErrPrint("Handler is not valid\n");
1318 for (j = i = 0; i < NR_OF_SIZE_LIST; i++) {
1319 if (handler->lb.size_list & (0x01 << i)) {
1323 size_list[j++] = (0x01 << i);
1331 EAPI const char *livebox_pkgname(struct livebox *handler)
1334 ErrPrint("Handler is NIL\n");
1338 if (handler->state != CREATE) {
1339 ErrPrint("Handler is not valid\n");
1343 return handler->pkgname;
1346 EAPI double livebox_priority(struct livebox *handler)
1349 ErrPrint("Handler is NIL\n");
1353 if (handler->state != CREATE || !handler->id) {
1354 ErrPrint("Handler is not valid (%p)\n", handler);
1358 return handler->lb.priority;
1361 EAPI int livebox_delete_cluster(const char *cluster, ret_cb_t cb, void *data)
1363 struct packet *packet;
1365 packet = packet_create("delete_cluster", "s", cluster);
1367 ErrPrint("Failed to build a param\n");
1371 return master_rpc_async_request(NULL, packet, 0, delete_cluster_cb, create_cb_info(cb, data));
1374 EAPI int livebox_delete_category(const char *cluster, const char *category, ret_cb_t cb, void *data)
1376 struct packet *packet;
1378 packet = packet_create("delete_category", "ss", cluster, category);
1380 ErrPrint("Failed to build a param\n");
1384 return master_rpc_async_request(NULL, packet, 0, delete_category_cb, create_cb_info(cb, data));
1387 EAPI enum livebox_lb_type livebox_lb_type(struct livebox *handler)
1390 ErrPrint("Handler is NIL\n");
1391 return LB_TYPE_INVALID;
1394 if (handler->state != CREATE || !handler->id) {
1395 ErrPrint("Handler is not valid\n");
1396 return LB_TYPE_INVALID;
1399 switch (handler->lb.type) {
1401 return LB_TYPE_IMAGE;
1402 case _LB_TYPE_BUFFER:
1403 case _LB_TYPE_SCRIPT:
1406 id = fb_id(handler->lb.data.fb);
1407 if (id && !strncasecmp(id, SCHEMA_PIXMAP, strlen(SCHEMA_PIXMAP)))
1408 return LB_TYPE_PIXMAP;
1410 return LB_TYPE_BUFFER;
1412 return LB_TYPE_TEXT;
1417 return LB_TYPE_INVALID;
1420 EAPI enum livebox_pd_type livebox_pd_type(struct livebox *handler)
1423 ErrPrint("Handler is NIL\n");
1424 return PD_TYPE_INVALID;
1427 if (handler->state != CREATE || !handler->id) {
1428 ErrPrint("Handler is not valid\n");
1429 return PD_TYPE_INVALID;
1432 switch (handler->pd.type) {
1434 return PD_TYPE_TEXT;
1435 case _PD_TYPE_BUFFER:
1436 case _PD_TYPE_SCRIPT:
1439 id = fb_id(handler->pd.data.fb);
1440 if (id && !strncasecmp(id, SCHEMA_PIXMAP, strlen(SCHEMA_PIXMAP)))
1441 return PD_TYPE_PIXMAP;
1443 return PD_TYPE_BUFFER;
1448 return PD_TYPE_INVALID;
1451 EAPI int livebox_set_pd_text_handler(struct livebox *handler, struct livebox_script_operators *ops)
1454 ErrPrint("Handler is NIL\n");
1458 if (handler->state != CREATE) {
1459 ErrPrint("Handler is not valid\n");
1463 memcpy(&handler->pd.data.ops, ops, sizeof(*ops));
1467 EAPI int livebox_set_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->lb.data.ops, ops, sizeof(*ops));
1483 EAPI int livebox_acquire_lb_pixmap(struct livebox *handler, ret_cb_t cb, void *data)
1485 struct packet *packet;
1489 ErrPrint("Handler is NIL\n");
1493 if (handler->state != CREATE || !handler->id) {
1494 ErrPrint("Invalid handle\n");
1498 if (handler->lb.type != _LB_TYPE_SCRIPT && handler->lb.type != _LB_TYPE_BUFFER) {
1499 ErrPrint("Handler is not valid type\n");
1503 id = fb_id(handler->lb.data.fb);
1504 if (!id || strncasecmp(id, SCHEMA_PIXMAP, strlen(SCHEMA_PIXMAP)))
1507 packet = packet_create("lb_acquire_pixmap", "ss", handler->pkgname, handler->id);
1509 ErrPrint("Failed to build a param\n");
1513 return master_rpc_async_request(handler, packet, 0, pixmap_acquired_cb, create_cb_info(cb, data));
1516 EAPI int livebox_release_lb_pixmap(struct livebox *handler, int pixmap)
1518 struct packet *packet;
1521 ErrPrint("Handler is NIL\n");
1525 if (handler->state != CREATE || !handler->id) {
1526 ErrPrint("Invalid handle\n");
1530 if (handler->lb.type != _LB_TYPE_SCRIPT && handler->lb.type != _LB_TYPE_BUFFER) {
1531 ErrPrint("Handler is not valid type\n");
1535 packet = packet_create_noack("lb_release_pixmap", "ssi", handler->pkgname, handler->id, pixmap);
1537 ErrPrint("Failed to build a param\n");
1541 return master_rpc_request_only(handler, packet);
1544 EAPI int livebox_acquire_pd_pixmap(struct livebox *handler, ret_cb_t cb, void *data)
1546 struct packet *packet;
1550 ErrPrint("Handler is NIL\n");
1554 if (handler->state != CREATE || !handler->id) {
1555 ErrPrint("Invalid handle\n");
1559 if (handler->pd.type != _PD_TYPE_SCRIPT && handler->pd.type != _PD_TYPE_BUFFER) {
1560 ErrPrint("Handler is not valid type\n");
1564 id = fb_id(handler->pd.data.fb);
1565 if (!id || strncasecmp(id, SCHEMA_PIXMAP, strlen(SCHEMA_PIXMAP)))
1568 packet = packet_create("pd_acquire_pixmap", "ss", handler->pkgname, handler->id);
1570 ErrPrint("Failed to build a param\n");
1574 return master_rpc_async_request(handler, packet, 0, pixmap_acquired_cb, create_cb_info(cb, data));
1577 EAPI int livebox_pd_pixmap(const struct livebox *handler)
1583 ErrPrint("Handler is NIL\n");
1587 if (handler->state != CREATE || !handler->id) {
1588 ErrPrint("Invalid handler\n");
1592 if (handler->pd.type != _PD_TYPE_SCRIPT && handler->pd.type != _PD_TYPE_BUFFER) {
1593 ErrPrint("Invalid handler\n");
1597 id = fb_id(handler->pd.data.fb);
1598 if (id && sscanf(id, SCHEMA_PIXMAP "%d", &pixmap) != 1) {
1599 ErrPrint("PIXMAP Id is not valid\n");
1606 EAPI int livebox_lb_pixmap(const struct livebox *handler)
1612 ErrPrint("Handler is NIL\n");
1616 if (handler->state != CREATE || !handler->id) {
1617 ErrPrint("Invalid handler\n");
1621 if (handler->lb.type != _LB_TYPE_SCRIPT && handler->lb.type != _LB_TYPE_BUFFER) {
1622 ErrPrint("Invalid handler\n");
1626 id = fb_id(handler->lb.data.fb);
1627 if (id && sscanf(id, SCHEMA_PIXMAP "%d", &pixmap) != 1) {
1628 ErrPrint("PIXMAP Id is not valid\n");
1635 EAPI int livebox_release_pd_pixmap(struct livebox *handler, int pixmap)
1637 struct packet *packet;
1640 ErrPrint("Handler is NIL\n");
1644 if (handler->state != CREATE || !handler->id) {
1645 ErrPrint("Invalid handle\n");
1649 if (handler->pd.type != _PD_TYPE_SCRIPT && handler->pd.type != _PD_TYPE_BUFFER) {
1650 ErrPrint("Handler is not valid type\n");
1654 packet = packet_create_noack("pd_release_pixmap", "ssi", handler->pkgname, handler->id, pixmap);
1656 ErrPrint("Failed to build a param\n");
1660 return master_rpc_request_only(handler, packet);
1663 EAPI void *livebox_acquire_fb(struct livebox *handler)
1666 ErrPrint("Handler is NIL\n");
1670 if (handler->state != CREATE || !handler->id) {
1671 ErrPrint("Invalid handle\n");
1675 if (handler->lb.type != _LB_TYPE_SCRIPT && handler->lb.type != _LB_TYPE_BUFFER) {
1676 ErrPrint("Handler is not valid type\n");
1680 return fb_acquire_buffer(handler->lb.data.fb);
1683 EAPI int livebox_release_fb(void *buffer)
1685 return fb_release_buffer(buffer);
1688 EAPI int livebox_fb_refcnt(void *buffer)
1690 return fb_refcnt(buffer);
1693 EAPI void *livebox_acquire_pdfb(struct livebox *handler)
1696 ErrPrint("Handler is NIL\n");
1700 if (handler->state != CREATE || !handler->id) {
1701 ErrPrint("Invalid handler\n");
1705 if (handler->pd.type != _PD_TYPE_SCRIPT && handler->pd.type != _PD_TYPE_BUFFER) {
1706 ErrPrint("Handler is not valid type\n");
1710 return fb_acquire_buffer(handler->pd.data.fb);
1713 EAPI int livebox_release_pdfb(void *buffer)
1715 return fb_release_buffer(buffer);
1718 EAPI int livebox_pdfb_refcnt(void *buffer)
1720 return fb_refcnt(buffer);
1723 EAPI int livebox_pdfb_bufsz(struct livebox *handler)
1726 ErrPrint("Handler is NIL\n");
1730 if (handler->state != CREATE || !handler->id) {
1731 ErrPrint("Handler is not valid\n");
1735 return fb_size(handler->pd.data.fb);
1738 EAPI int livebox_lbfb_bufsz(struct livebox *handler)
1741 ErrPrint("Handler is NIL\n");
1745 if (handler->state != CREATE || !handler->id) {
1746 ErrPrint("Handler is not valid\n");
1750 return fb_size(handler->lb.data.fb);
1753 EAPI int livebox_is_user(struct livebox *handler)
1756 ErrPrint("Handler is NIL\n");
1760 if (handler->state != CREATE) {
1761 ErrPrint("Handler is invalid\n");
1765 return handler->is_user;
1768 EAPI int livebox_set_pinup(struct livebox *handler, int flag, ret_cb_t cb, void *data)
1770 struct packet *packet;
1773 ErrPrint("Handler is NIL\n");
1777 if (handler->state != CREATE || !handler->id) {
1778 ErrPrint("Handler is not valid\n");
1782 if (handler->is_pinned_up == flag) {
1783 DbgPrint("No changes\n");
1787 packet = packet_create("pinup_changed", "ssi", handler->pkgname, handler->id, flag);
1789 ErrPrint("Failed to build a param\n");
1794 cb = default_pinup_cb;
1796 return master_rpc_async_request(handler, packet, 0, pinup_done_cb, create_cb_info(cb, data));
1799 EAPI int livebox_is_pinned_up(struct livebox *handler)
1802 ErrPrint("Handler is NIL\n");
1806 if (handler->state != CREATE || !handler->id)
1809 return handler->is_pinned_up;
1812 EAPI int livebox_has_pinup(struct livebox *handler)
1815 ErrPrint("Handler is NIL\n");
1819 if (handler->state != CREATE || !handler->id)
1822 return handler->lb.pinup_supported;
1825 EAPI int livebox_set_data(struct livebox *handler, void *data)
1828 ErrPrint("Handler is NIL\n");
1832 if (handler->state != CREATE)
1835 handler->data = data;
1839 EAPI void *livebox_get_data(struct livebox *handler)
1842 ErrPrint("Handler is NIL\n");
1846 if (handler->state != CREATE)
1849 return handler->data;
1852 EAPI int livebox_is_exists(const char *pkgname)
1856 lb = lb_pkgname(pkgname);
1865 EAPI const char *livebox_content(struct livebox *handler)
1868 ErrPrint("Handler is NIL\n");
1872 if (handler->state != CREATE)
1875 return handler->content;
1878 EAPI const char *livebox_category_title(struct livebox *handler)
1881 ErrPrint("Handler is NIL\n");
1885 if (handler->state != CREATE)
1888 return handler->title;
1891 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)
1893 struct packet *packet;
1896 ErrPrint("Handler is NIL\n");
1900 if ((handler->lb.type != _LB_TYPE_TEXT && handler->pd.type != _PD_TYPE_TEXT) || handler->state != CREATE || !handler->id) {
1901 ErrPrint("Handler is not valid\n");
1911 packet = packet_create("text_signal", "ssssdddd",
1912 handler->pkgname, handler->id, emission, source, sx, sy, ex, ey);
1914 ErrPrint("Failed to build a param\n");
1918 return master_rpc_async_request(handler, packet, 0, text_signal_cb, create_cb_info(cb, data));
1921 EAPI int livebox_subscribe_group(const char *cluster, const char *category)
1923 struct packet *packet;
1927 * Validate the group info using DB
1928 * If the group info is not valid, do not send this request
1931 packet = packet_create_noack("subscribe", "ss", cluster ? cluster : "", category ? category : "");
1933 ErrPrint("Failed to create a packet\n");
1937 return master_rpc_request_only(NULL, packet);
1940 EAPI int livebox_unsubscribe_group(const char *cluster, const char *category)
1942 struct packet *packet;
1946 * Validate the group info using DB
1947 * If the group info is not valid, do not send this request
1948 * AND Check the subscribed or not too
1951 packet = packet_create_noack("unsubscribe", "ss", cluster ? cluster : "", category ? category : "");
1953 ErrPrint("Failed to create a packet\n");
1957 return master_rpc_request_only(NULL, packet);
1960 EAPI int livebox_refresh(struct livebox *handler)
1962 struct packet *packet;
1965 ErrPrint("Hnalder is NIL\n");
1969 if (handler->state != CREATE || !handler->id)
1972 packet = packet_create_noack("update", "ss", handler->pkgname, handler->id);
1974 ErrPrint("Failed to create a packet\n");
1978 return master_rpc_request_only(handler, packet);
1981 EAPI int livebox_refresh_group(const char *cluster, const char *category)
1983 struct packet *packet;
1985 if (!cluster || !category) {
1986 ErrPrint("Invalid argument\n");
1990 packet = packet_create_noack("refresh_group", "ss", cluster, category);
1992 ErrPrint("Failed to create a packet\n");
1996 return master_rpc_request_only(NULL, packet);
1999 EAPI int livebox_set_visibility(struct livebox *handler, enum livebox_visible_state state)
2001 struct packet *packet;
2005 ErrPrint("Handler is NIL\n");
2009 if (handler->state != CREATE || !handler->id)
2012 if (!handler->is_user) {
2013 /* System cluster livebox cannot be changed its visible states */
2014 if (state == LB_HIDE_WITH_PAUSE) {
2015 ErrPrint("CA Livebox is not able to change the visibility\n");
2020 if (handler->visible == state)
2023 packet = packet_create_noack("change,visibility", "ssi", handler->pkgname, handler->id, (int)state);
2025 ErrPrint("Failed to create a packet\n");
2029 ret = master_rpc_request_only(handler, packet);
2031 handler->visible = state;
2036 EAPI enum livebox_visible_state livebox_visibility(struct livebox *handler)
2039 ErrPrint("Handler is NIL\n");
2040 return LB_VISIBLE_ERROR;
2043 if (handler->state != CREATE)
2044 return LB_VISIBLE_ERROR;
2046 return handler->visible;
2049 int lb_set_group(struct livebox *handler, const char *cluster, const char *category)
2055 pc = strdup(cluster);
2057 CRITICAL_LOG("Heap: %s (cluster: %s)\n", strerror(errno), cluster);
2063 ps = strdup(category);
2065 CRITICAL_LOG("Heap: %s (category: %s)\n", strerror(errno), category);
2071 if (handler->cluster)
2072 free(handler->cluster);
2074 if (handler->category)
2075 free(handler->category);
2077 handler->cluster = pc;
2078 handler->category = ps;
2083 void lb_set_size(struct livebox *handler, int w, int h)
2085 handler->lb.width = w;
2086 handler->lb.height = h;
2089 void lb_set_pdsize(struct livebox *handler, int w, int h)
2091 handler->pd.width = w;
2092 handler->pd.height = h;
2095 void lb_invoke_fault_handler(enum livebox_fault_type event, const char *pkgname, const char *file, const char *func)
2099 struct fault_info *info;
2101 dlist_foreach_safe(s_info.fault_list, l, n, info) {
2102 if (info->handler(event, pkgname, file, func, info->user_data) == EXIT_FAILURE)
2103 s_info.fault_list = dlist_remove(s_info.fault_list, l);
2107 void lb_invoke_event_handler(struct livebox *handler, enum livebox_event_type event)
2111 struct event_info *info;
2113 dlist_foreach_safe(s_info.event_list, l, n, info) {
2114 if (info->handler(handler, event, info->user_data) == EXIT_FAILURE)
2115 s_info.event_list = dlist_remove(s_info.event_list, l);
2119 struct livebox *lb_find_livebox(const char *pkgname, const char *id)
2122 struct livebox *handler;
2124 dlist_foreach(s_info.livebox_list, l, handler) {
2128 if (!strcmp(handler->pkgname, pkgname) && !strcmp(handler->id, id))
2135 struct livebox *lb_find_livebox_by_timestamp(double timestamp)
2138 struct livebox *handler;
2140 dlist_foreach(s_info.livebox_list, l, handler) {
2141 if (handler->timestamp == timestamp)
2148 static inline char *get_file_kept_in_safe(const char *id)
2155 path = util_uri_to_path(id);
2157 ErrPrint("Invalid URI(%s)\n", id);
2164 if (s_info.prevent_overwrite) {
2165 new_path = strdup(path);
2167 ErrPrint("Heap: %s\n", strerror(errno));
2176 while (base_idx > 0 && path[base_idx] != '/') base_idx--;
2177 base_idx += (path[base_idx] == '/');
2179 new_path = malloc(len + 10);
2181 ErrPrint("Heap: %s\n", strerror(errno));
2185 strncpy(new_path, path, base_idx);
2186 snprintf(new_path + base_idx, len + 10 - base_idx, "reader/%s", path + base_idx);
2190 struct livebox *lb_new_livebox(const char *pkgname, const char *id, double timestamp)
2192 struct livebox *handler;
2194 handler = calloc(1, sizeof(*handler));
2196 ErrPrint("Failed to create a new livebox\n");
2200 handler->pkgname = strdup(pkgname);
2201 if (!handler->pkgname) {
2202 ErrPrint("%s\n", strerror(errno));
2207 handler->id = strdup(id);
2209 ErrPrint("%s\n", strerror(errno));
2210 free(handler->pkgname);
2215 handler->filename = get_file_kept_in_safe(id);
2216 if (!handler->filename) {
2217 handler->filename = strdup(util_uri_to_path(id));
2218 if (!handler->filename)
2219 ErrPrint("Error: %s\n", strerror(errno));
2222 handler->timestamp = timestamp;
2223 handler->lb.type = _LB_TYPE_FILE;
2224 handler->pd.type = _PD_TYPE_SCRIPT;
2225 handler->state = CREATE;
2226 handler->visible = LB_SHOW;
2228 s_info.livebox_list = dlist_append(s_info.livebox_list, handler);
2233 int lb_delete_all(void)
2237 struct livebox *handler;
2239 dlist_foreach_safe(s_info.livebox_list, l, n, handler) {
2240 lb_invoke_event_handler(handler, LB_EVENT_DELETED);
2247 int lb_set_content(struct livebox *handler, const char *content)
2249 if (handler->content) {
2250 free(handler->content);
2251 handler->content = NULL;
2255 handler->content = strdup(content);
2256 if (!handler->content) {
2257 CRITICAL_LOG("Heap: %s (content: %s)\n", strerror(errno), content);
2265 int lb_set_title(struct livebox *handler, const char *title)
2267 if (handler->title) {
2268 free(handler->title);
2269 handler->title = NULL;
2273 handler->title = strdup(title);
2274 if (!handler->title) {
2275 CRITICAL_LOG("Heap: %s (title: %s)\n", strerror(errno), title);
2283 void lb_set_size_list(struct livebox *handler, int size_list)
2285 handler->lb.size_list = size_list;
2288 void lb_set_auto_launch(struct livebox *handler, const char *auto_launch)
2290 if (!strlen(auto_launch))
2293 handler->lb.auto_launch = strdup(auto_launch);
2294 if (!handler->lb.auto_launch)
2295 ErrPrint("Heap: %s\n", strerror(errno));
2298 void lb_set_priority(struct livebox *handler, double priority)
2300 handler->lb.priority = priority;
2303 void lb_set_id(struct livebox *handler, const char *id)
2308 handler->id = strdup(id);
2310 ErrPrint("Error: %s\n", strerror(errno));
2312 if (handler->filename)
2313 free(handler->filename);
2315 handler->filename = get_file_kept_in_safe(id);
2316 if (!handler->filename) {
2317 handler->filename = strdup(util_uri_to_path(id));
2318 if (!handler->filename)
2319 ErrPrint("Error: %s\n", strerror(errno));
2323 int lb_set_lb_fb(struct livebox *handler, const char *filename)
2330 fb = handler->lb.data.fb;
2331 if (fb && !strcmp(fb_id(fb), filename)) /*!< BUFFER is not changed, */
2334 handler->lb.data.fb = NULL;
2336 if (!filename || filename[0] == '\0') {
2342 handler->lb.data.fb = fb_create(filename, handler->lb.width, handler->lb.height);
2343 if (!handler->lb.data.fb) {
2344 ErrPrint("Faield to create a FB\n");
2356 int lb_set_pd_fb(struct livebox *handler, const char *filename)
2363 fb = handler->pd.data.fb;
2364 if (fb && !strcmp(fb_id(fb), filename)) {
2365 /* BUFFER is not changed, just update the content */
2368 handler->pd.data.fb = NULL;
2370 if (!filename || filename[0] == '\0') {
2376 handler->pd.data.fb = fb_create(filename, handler->pd.width, handler->pd.height);
2377 if (!handler->pd.data.fb) {
2378 ErrPrint("Failed to create a FB\n");
2389 struct fb_info *lb_get_lb_fb(struct livebox *handler)
2391 return handler->lb.data.fb;
2394 struct fb_info *lb_get_pd_fb(struct livebox *handler)
2396 return handler->pd.data.fb;
2399 void lb_set_user(struct livebox *handler, int user)
2401 handler->is_user = user;
2404 void lb_set_pinup(struct livebox *handler, int pinup_supported)
2406 handler->lb.pinup_supported = pinup_supported;
2409 void lb_set_text_lb(struct livebox *handler)
2411 handler->lb.type = _LB_TYPE_TEXT;
2414 void lb_set_text_pd(struct livebox *handler)
2416 handler->pd.type = _PD_TYPE_TEXT;
2419 int lb_text_lb(struct livebox *handler)
2421 return handler->lb.type == _LB_TYPE_TEXT;
2424 int lb_text_pd(struct livebox *handler)
2426 return handler->pd.type == _PD_TYPE_TEXT;
2429 void lb_set_period(struct livebox *handler, double period)
2431 handler->lb.period = period;
2434 struct livebox *lb_ref(struct livebox *handler)
2443 struct livebox *lb_unref(struct livebox *handler)
2449 if (handler->refcnt > 0)
2452 dlist_remove_data(s_info.livebox_list, handler);
2454 handler->state = DESTROYED;
2455 free(handler->cluster);
2456 free(handler->category);
2458 free(handler->pkgname);
2459 free(handler->filename);
2460 free(handler->lb.auto_launch);
2462 if (handler->lb.data.fb) {
2463 fb_destroy(handler->lb.data.fb);
2464 handler->lb.data.fb = NULL;
2467 if (handler->pd.data.fb) {
2468 fb_destroy(handler->pd.data.fb);
2469 handler->pd.data.fb = NULL;
2476 int lb_send_delete(struct livebox *handler, ret_cb_t cb, void *data)
2478 struct packet *packet;
2480 if (!cb && !!data) {
2481 ErrPrint("Invalid argument\n");
2485 if (handler->deleted_cb) {
2486 ErrPrint("Already in-progress\n");
2487 return -EINPROGRESS;
2490 packet = packet_create("delete", "ss", handler->pkgname, handler->id);
2492 ErrPrint("Failed to build a param\n");
2494 cb(handler, -EFAULT, data);
2500 cb = default_delete_cb;
2502 return master_rpc_async_request(handler, packet, 0, del_ret_cb, create_cb_info(cb, data));