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)
1050 ErrPrint("Handler is NIL\n");
1054 if (handler->state != CREATE || !handler->id) {
1055 ErrPrint("Handler is not valid\n");
1061 if (!handler->lb.mouse_event) {
1062 ErrPrint("Box is not support the mouse event\n");
1066 if (!handler->lb.data.fb) {
1067 ErrPrint("Handler is not valid\n");
1071 cmd = "lb_mouse_down";
1072 w = handler->lb.width;
1073 h = handler->lb.height;
1080 if (!handler->lb.mouse_event) {
1081 ErrPrint("Box is not support the mouse event\n");
1085 if (!handler->lb.data.fb) {
1086 ErrPrint("Handler is not valid\n");
1090 cmd = "lb_mouse_up";
1091 w = handler->lb.width;
1092 h = handler->lb.height;
1096 if (!handler->lb.mouse_event) {
1097 ErrPrint("Box is not support the mouse event\n");
1101 if (!handler->lb.data.fb) {
1102 ErrPrint("Handler is not valid\n");
1106 if (fabs(x - handler->lb.x) < MINIMUM_EVENT && fabs(y - handler->lb.y) < MINIMUM_EVENT)
1109 cmd = "lb_mouse_move";
1110 w = handler->lb.width;
1111 h = handler->lb.height;
1117 case LB_MOUSE_ENTER:
1118 if (!handler->lb.mouse_event) {
1119 ErrPrint("Box is not support the mouse event\n");
1123 if (!handler->lb.data.fb) {
1124 ErrPrint("Handler is not valid\n");
1128 cmd = "lb_mouse_enter";
1129 w = handler->lb.width;
1130 h = handler->lb.height;
1133 case LB_MOUSE_LEAVE:
1134 if (!handler->lb.mouse_event) {
1135 ErrPrint("Box is not support the mouse event\n");
1139 if (!handler->lb.data.fb) {
1140 ErrPrint("Handler is not valid\n");
1144 cmd = "lb_mouse_leave";
1145 w = handler->lb.width;
1146 h = handler->lb.height;
1149 case PD_MOUSE_ENTER:
1150 if (!handler->is_pd_created) {
1151 ErrPrint("PD is not created\n");
1155 if (!handler->pd.data.fb) {
1156 ErrPrint("Handler is not valid\n");
1160 cmd = "pd_mouse_enter";
1161 w = handler->pd.width;
1162 h = handler->pd.height;
1165 case PD_MOUSE_LEAVE:
1166 if (!handler->is_pd_created) {
1167 ErrPrint("PD is not created\n");
1171 if (!handler->pd.data.fb) {
1172 ErrPrint("Handler is not valid\n");
1176 cmd = "pd_mouse_leave";
1177 w = handler->pd.width;
1178 h = handler->pd.height;
1182 if (!handler->is_pd_created) {
1183 ErrPrint("PD is not created\n");
1187 if (!handler->pd.data.fb) {
1188 ErrPrint("Handler is not valid\n");
1192 cmd = "pd_mouse_down";
1193 w = handler->pd.width;
1194 h = handler->pd.height;
1201 if (!handler->is_pd_created) {
1202 ErrPrint("PD is not created\n");
1206 if (!handler->pd.data.fb) {
1207 ErrPrint("Handler is not valid\n");
1211 if (fabs(x - handler->pd.x) < MINIMUM_EVENT && fabs(y - handler->pd.y) < MINIMUM_EVENT)
1214 cmd = "pd_mouse_move";
1215 w = handler->pd.width;
1216 h = handler->pd.height;
1223 if (!handler->is_pd_created) {
1224 ErrPrint("PD is not created\n");
1228 if (!handler->pd.data.fb) {
1229 ErrPrint("Handler is not valid\n");
1233 cmd = "pd_mouse_up";
1234 w = handler->pd.width;
1235 h = handler->pd.height;
1239 ErrPrint("Invalid event type\n");
1243 return send_mouse_event(handler, cmd, x, y, w, h);
1246 EAPI const char *livebox_filename(struct livebox *handler)
1249 ErrPrint("Handler is NIL\n");
1253 if (handler->state != CREATE || !handler->id) {
1254 ErrPrint("Handler is not valid\n");
1258 if (handler->filename)
1259 return handler->filename;
1262 return util_uri_to_path(handler->id);
1265 EAPI int livebox_get_pdsize(struct livebox *handler, int *w, int *h)
1271 ErrPrint("Handler is NIL\n");
1275 if (handler->state != CREATE || !handler->id) {
1276 ErrPrint("Handler is not valid\n");
1285 *w = handler->pd.width;
1286 *h = handler->pd.height;
1288 switch (handler->pd.type) {
1289 case _PD_TYPE_BUFFER:
1290 case _PD_TYPE_SCRIPT:
1291 if (!handler->is_pd_created) {
1292 DbgPrint("Buffer is not created yet - reset size\n");
1304 EAPI int livebox_size(struct livebox *handler)
1310 ErrPrint("Handler is NIL\n");
1314 if (handler->state != CREATE || !handler->id) {
1315 ErrPrint("Handler is not valid\n");
1319 w = handler->lb.width;
1320 h = handler->lb.height;
1322 switch (handler->lb.type) {
1323 case _LB_TYPE_BUFFER:
1324 case _LB_TYPE_SCRIPT:
1325 if (!fb_is_created(handler->lb.data.fb)) {
1326 DbgPrint("Buffer is not created yet - reset size\n");
1335 return livebox_service_size_type(w, h);
1338 EAPI int livebox_set_group(struct livebox *handler, const char *cluster, const char *category, ret_cb_t cb, void *data)
1340 struct packet *packet;
1343 ErrPrint("Handler is NIL\n");
1347 if (!cluster || !category || handler->state != CREATE || !handler->id) {
1348 ErrPrint("Invalid argument\n");
1352 if (!handler->is_user) {
1353 ErrPrint("CA Livebox is not able to change the group\n");
1357 if (!strcmp(handler->cluster, cluster) && !strcmp(handler->category, category)) {
1358 DbgPrint("No changes\n");
1362 packet = packet_create("change_group", "ssss", handler->pkgname, handler->id, cluster, category);
1364 ErrPrint("Failed to build a param\n");
1369 cb = default_group_changed_cb;
1371 return master_rpc_async_request(handler, packet, 0, set_group_ret_cb, create_cb_info(cb, data));
1374 EAPI int livebox_get_group(struct livebox *handler, char ** const cluster, char ** const category)
1377 ErrPrint("Handler is NIL\n");
1381 if (!cluster || !category || handler->state != CREATE || !handler->id) {
1382 ErrPrint("Invalid argument\n");
1386 *cluster = handler->cluster;
1387 *category = handler->category;
1391 EAPI int livebox_get_supported_sizes(struct livebox *handler, int *cnt, int *size_list)
1396 if (!handler || !size_list) {
1397 ErrPrint("Invalid argument, handler(%p), size_list(%p)\n", handler, size_list);
1401 if (!cnt || handler->state != CREATE || !handler->id) {
1402 ErrPrint("Handler is not valid\n");
1406 for (j = i = 0; i < NR_OF_SIZE_LIST; i++) {
1407 if (handler->lb.size_list & (0x01 << i)) {
1411 size_list[j++] = (0x01 << i);
1419 EAPI const char *livebox_pkgname(struct livebox *handler)
1422 ErrPrint("Handler is NIL\n");
1426 if (handler->state != CREATE) {
1427 ErrPrint("Handler is not valid\n");
1431 return handler->pkgname;
1434 EAPI double livebox_priority(struct livebox *handler)
1437 ErrPrint("Handler is NIL\n");
1441 if (handler->state != CREATE || !handler->id) {
1442 ErrPrint("Handler is not valid (%p)\n", handler);
1446 return handler->lb.priority;
1449 EAPI int livebox_delete_cluster(const char *cluster, ret_cb_t cb, void *data)
1451 struct packet *packet;
1453 packet = packet_create("delete_cluster", "s", cluster);
1455 ErrPrint("Failed to build a param\n");
1459 return master_rpc_async_request(NULL, packet, 0, delete_cluster_cb, create_cb_info(cb, data));
1462 EAPI int livebox_delete_category(const char *cluster, const char *category, ret_cb_t cb, void *data)
1464 struct packet *packet;
1466 packet = packet_create("delete_category", "ss", cluster, category);
1468 ErrPrint("Failed to build a param\n");
1472 return master_rpc_async_request(NULL, packet, 0, delete_category_cb, create_cb_info(cb, data));
1475 EAPI enum livebox_lb_type livebox_lb_type(struct livebox *handler)
1478 ErrPrint("Handler is NIL\n");
1479 return LB_TYPE_INVALID;
1482 if (handler->state != CREATE || !handler->id) {
1483 ErrPrint("Handler is not valid\n");
1484 return LB_TYPE_INVALID;
1487 switch (handler->lb.type) {
1489 return LB_TYPE_IMAGE;
1490 case _LB_TYPE_BUFFER:
1491 case _LB_TYPE_SCRIPT:
1494 id = fb_id(handler->lb.data.fb);
1495 if (id && !strncasecmp(id, SCHEMA_PIXMAP, strlen(SCHEMA_PIXMAP)))
1496 return LB_TYPE_PIXMAP;
1498 return LB_TYPE_BUFFER;
1500 return LB_TYPE_TEXT;
1505 return LB_TYPE_INVALID;
1508 EAPI enum livebox_pd_type livebox_pd_type(struct livebox *handler)
1511 ErrPrint("Handler is NIL\n");
1512 return PD_TYPE_INVALID;
1515 if (handler->state != CREATE || !handler->id) {
1516 ErrPrint("Handler is not valid\n");
1517 return PD_TYPE_INVALID;
1520 switch (handler->pd.type) {
1522 return PD_TYPE_TEXT;
1523 case _PD_TYPE_BUFFER:
1524 case _PD_TYPE_SCRIPT:
1527 id = fb_id(handler->pd.data.fb);
1528 if (id && !strncasecmp(id, SCHEMA_PIXMAP, strlen(SCHEMA_PIXMAP)))
1529 return PD_TYPE_PIXMAP;
1531 return PD_TYPE_BUFFER;
1536 return PD_TYPE_INVALID;
1539 EAPI int livebox_set_pd_text_handler(struct livebox *handler, struct livebox_script_operators *ops)
1542 ErrPrint("Handler is NIL\n");
1546 if (handler->state != CREATE) {
1547 ErrPrint("Handler is not valid\n");
1551 memcpy(&handler->pd.data.ops, ops, sizeof(*ops));
1555 EAPI int livebox_set_text_handler(struct livebox *handler, struct livebox_script_operators *ops)
1558 ErrPrint("Handler is NIL\n");
1562 if (handler->state != CREATE) {
1563 ErrPrint("Handler is not valid\n");
1567 memcpy(&handler->lb.data.ops, ops, sizeof(*ops));
1571 EAPI int livebox_acquire_lb_pixmap(struct livebox *handler, ret_cb_t cb, void *data)
1573 struct packet *packet;
1577 ErrPrint("Handler is NIL\n");
1581 if (handler->state != CREATE || !handler->id) {
1582 ErrPrint("Invalid handle\n");
1586 if (handler->lb.type != _LB_TYPE_SCRIPT && handler->lb.type != _LB_TYPE_BUFFER) {
1587 ErrPrint("Handler is not valid type\n");
1591 id = fb_id(handler->lb.data.fb);
1592 if (!id || strncasecmp(id, SCHEMA_PIXMAP, strlen(SCHEMA_PIXMAP)))
1595 packet = packet_create("lb_acquire_pixmap", "ss", handler->pkgname, handler->id);
1597 ErrPrint("Failed to build a param\n");
1601 return master_rpc_async_request(handler, packet, 0, pixmap_acquired_cb, create_cb_info(cb, data));
1604 EAPI int livebox_release_lb_pixmap(struct livebox *handler, int pixmap)
1606 struct packet *packet;
1609 ErrPrint("Handler is NIL\n");
1613 if (handler->state != CREATE || !handler->id) {
1614 ErrPrint("Invalid handle\n");
1618 if (handler->lb.type != _LB_TYPE_SCRIPT && handler->lb.type != _LB_TYPE_BUFFER) {
1619 ErrPrint("Handler is not valid type\n");
1623 packet = packet_create_noack("lb_release_pixmap", "ssi", handler->pkgname, handler->id, pixmap);
1625 ErrPrint("Failed to build a param\n");
1629 return master_rpc_request_only(handler, packet);
1632 EAPI int livebox_acquire_pd_pixmap(struct livebox *handler, ret_cb_t cb, void *data)
1634 struct packet *packet;
1638 ErrPrint("Handler is NIL\n");
1642 if (handler->state != CREATE || !handler->id) {
1643 ErrPrint("Invalid handle\n");
1647 if (handler->pd.type != _PD_TYPE_SCRIPT && handler->pd.type != _PD_TYPE_BUFFER) {
1648 ErrPrint("Handler is not valid type\n");
1652 id = fb_id(handler->pd.data.fb);
1653 if (!id || strncasecmp(id, SCHEMA_PIXMAP, strlen(SCHEMA_PIXMAP)))
1656 packet = packet_create("pd_acquire_pixmap", "ss", handler->pkgname, handler->id);
1658 ErrPrint("Failed to build a param\n");
1662 return master_rpc_async_request(handler, packet, 0, pixmap_acquired_cb, create_cb_info(cb, data));
1665 EAPI int livebox_pd_pixmap(const struct livebox *handler)
1671 ErrPrint("Handler is NIL\n");
1675 if (handler->state != CREATE || !handler->id) {
1676 ErrPrint("Invalid handler\n");
1680 if (handler->pd.type != _PD_TYPE_SCRIPT && handler->pd.type != _PD_TYPE_BUFFER) {
1681 ErrPrint("Invalid handler\n");
1685 id = fb_id(handler->pd.data.fb);
1686 if (id && sscanf(id, SCHEMA_PIXMAP "%d", &pixmap) != 1) {
1687 ErrPrint("PIXMAP Id is not valid\n");
1694 EAPI int livebox_lb_pixmap(const struct livebox *handler)
1700 ErrPrint("Handler is NIL\n");
1704 if (handler->state != CREATE || !handler->id) {
1705 ErrPrint("Invalid handler\n");
1709 if (handler->lb.type != _LB_TYPE_SCRIPT && handler->lb.type != _LB_TYPE_BUFFER) {
1710 ErrPrint("Invalid handler\n");
1714 id = fb_id(handler->lb.data.fb);
1715 if (id && sscanf(id, SCHEMA_PIXMAP "%d", &pixmap) != 1) {
1716 ErrPrint("PIXMAP Id is not valid\n");
1723 EAPI int livebox_release_pd_pixmap(struct livebox *handler, int pixmap)
1725 struct packet *packet;
1728 ErrPrint("Handler is NIL\n");
1732 if (handler->state != CREATE || !handler->id) {
1733 ErrPrint("Invalid handle\n");
1737 if (handler->pd.type != _PD_TYPE_SCRIPT && handler->pd.type != _PD_TYPE_BUFFER) {
1738 ErrPrint("Handler is not valid type\n");
1742 packet = packet_create_noack("pd_release_pixmap", "ssi", handler->pkgname, handler->id, pixmap);
1744 ErrPrint("Failed to build a param\n");
1748 return master_rpc_request_only(handler, packet);
1751 EAPI void *livebox_acquire_fb(struct livebox *handler)
1754 ErrPrint("Handler is NIL\n");
1758 if (handler->state != CREATE || !handler->id) {
1759 ErrPrint("Invalid handle\n");
1763 if (handler->lb.type != _LB_TYPE_SCRIPT && handler->lb.type != _LB_TYPE_BUFFER) {
1764 ErrPrint("Handler is not valid type\n");
1768 return fb_acquire_buffer(handler->lb.data.fb);
1771 EAPI int livebox_release_fb(void *buffer)
1773 return fb_release_buffer(buffer);
1776 EAPI int livebox_fb_refcnt(void *buffer)
1778 return fb_refcnt(buffer);
1781 EAPI void *livebox_acquire_pdfb(struct livebox *handler)
1784 ErrPrint("Handler is NIL\n");
1788 if (handler->state != CREATE || !handler->id) {
1789 ErrPrint("Invalid handler\n");
1793 if (handler->pd.type != _PD_TYPE_SCRIPT && handler->pd.type != _PD_TYPE_BUFFER) {
1794 ErrPrint("Handler is not valid type\n");
1798 return fb_acquire_buffer(handler->pd.data.fb);
1801 EAPI int livebox_release_pdfb(void *buffer)
1803 return fb_release_buffer(buffer);
1806 EAPI int livebox_pdfb_refcnt(void *buffer)
1808 return fb_refcnt(buffer);
1811 EAPI int livebox_pdfb_bufsz(struct livebox *handler)
1814 ErrPrint("Handler is NIL\n");
1818 if (handler->state != CREATE || !handler->id) {
1819 ErrPrint("Handler is not valid\n");
1823 return fb_size(handler->pd.data.fb);
1826 EAPI int livebox_lbfb_bufsz(struct livebox *handler)
1829 ErrPrint("Handler is NIL\n");
1833 if (handler->state != CREATE || !handler->id) {
1834 ErrPrint("Handler is not valid\n");
1838 return fb_size(handler->lb.data.fb);
1841 EAPI int livebox_is_user(struct livebox *handler)
1844 ErrPrint("Handler is NIL\n");
1848 if (handler->state != CREATE) {
1849 ErrPrint("Handler is invalid\n");
1853 return handler->is_user;
1856 EAPI int livebox_set_pinup(struct livebox *handler, int flag, ret_cb_t cb, void *data)
1858 struct packet *packet;
1861 ErrPrint("Handler is NIL\n");
1865 if (handler->state != CREATE || !handler->id) {
1866 ErrPrint("Handler is not valid\n");
1870 if (handler->is_pinned_up == flag) {
1871 DbgPrint("No changes\n");
1875 packet = packet_create("pinup_changed", "ssi", handler->pkgname, handler->id, flag);
1877 ErrPrint("Failed to build a param\n");
1882 cb = default_pinup_cb;
1884 return master_rpc_async_request(handler, packet, 0, pinup_done_cb, create_cb_info(cb, data));
1887 EAPI int livebox_is_pinned_up(struct livebox *handler)
1890 ErrPrint("Handler is NIL\n");
1894 if (handler->state != CREATE || !handler->id)
1897 return handler->is_pinned_up;
1900 EAPI int livebox_has_pinup(struct livebox *handler)
1903 ErrPrint("Handler is NIL\n");
1907 if (handler->state != CREATE || !handler->id)
1910 return handler->lb.pinup_supported;
1913 EAPI int livebox_set_data(struct livebox *handler, void *data)
1916 ErrPrint("Handler is NIL\n");
1920 if (handler->state != CREATE)
1923 handler->data = data;
1927 EAPI void *livebox_get_data(struct livebox *handler)
1930 ErrPrint("Handler is NIL\n");
1934 if (handler->state != CREATE)
1937 return handler->data;
1940 EAPI int livebox_is_exists(const char *pkgname)
1944 lb = lb_pkgname(pkgname);
1953 EAPI const char *livebox_content(struct livebox *handler)
1956 ErrPrint("Handler is NIL\n");
1960 if (handler->state != CREATE)
1963 return handler->content;
1966 EAPI const char *livebox_category_title(struct livebox *handler)
1969 ErrPrint("Handler is NIL\n");
1973 if (handler->state != CREATE)
1976 return handler->title;
1979 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)
1981 struct packet *packet;
1984 ErrPrint("Handler is NIL\n");
1988 if ((handler->lb.type != _LB_TYPE_TEXT && handler->pd.type != _PD_TYPE_TEXT) || handler->state != CREATE || !handler->id) {
1989 ErrPrint("Handler is not valid\n");
1999 packet = packet_create("text_signal", "ssssdddd",
2000 handler->pkgname, handler->id, emission, source, sx, sy, ex, ey);
2002 ErrPrint("Failed to build a param\n");
2006 return master_rpc_async_request(handler, packet, 0, text_signal_cb, create_cb_info(cb, data));
2009 EAPI int livebox_subscribe_group(const char *cluster, const char *category)
2011 struct packet *packet;
2015 * Validate the group info using DB
2016 * If the group info is not valid, do not send this request
2019 packet = packet_create_noack("subscribe", "ss", cluster ? cluster : "", category ? category : "");
2021 ErrPrint("Failed to create a packet\n");
2025 return master_rpc_request_only(NULL, packet);
2028 EAPI int livebox_unsubscribe_group(const char *cluster, const char *category)
2030 struct packet *packet;
2034 * Validate the group info using DB
2035 * If the group info is not valid, do not send this request
2036 * AND Check the subscribed or not too
2039 packet = packet_create_noack("unsubscribe", "ss", cluster ? cluster : "", category ? category : "");
2041 ErrPrint("Failed to create a packet\n");
2045 return master_rpc_request_only(NULL, packet);
2048 EAPI int livebox_refresh_group(const char *cluster, const char *category)
2050 struct packet *packet;
2052 if (!cluster || !category) {
2053 ErrPrint("Invalid argument\n");
2057 packet = packet_create_noack("refresh_group", "ss", cluster, category);
2059 ErrPrint("Failed to create a packet\n");
2063 return master_rpc_request_only(NULL, packet);
2066 EAPI int livebox_set_visibility(struct livebox *handler, enum livebox_visible_state state)
2068 struct packet *packet;
2072 ErrPrint("Handler is NIL\n");
2076 if (handler->state != CREATE || !handler->id)
2079 if (!handler->is_user) {
2080 /* System cluster livebox cannot be changed its visible states */
2081 if (state == LB_HIDE_WITH_PAUSE) {
2082 ErrPrint("CA Livebox is not able to change the visibility\n");
2087 if (handler->visible == state)
2090 packet = packet_create_noack("change,visibility", "ssi", handler->pkgname, handler->id, (int)state);
2092 ErrPrint("Failed to create a packet\n");
2096 ret = master_rpc_request_only(handler, packet);
2098 handler->visible = state;
2103 EAPI enum livebox_visible_state livebox_visibility(struct livebox *handler)
2106 ErrPrint("Handler is NIL\n");
2107 return LB_VISIBLE_ERROR;
2110 if (handler->state != CREATE)
2111 return LB_VISIBLE_ERROR;
2113 return handler->visible;
2116 int lb_set_group(struct livebox *handler, const char *cluster, const char *category)
2122 pc = strdup(cluster);
2124 CRITICAL_LOG("Heap: %s (cluster: %s)\n", strerror(errno), cluster);
2130 ps = strdup(category);
2132 CRITICAL_LOG("Heap: %s (category: %s)\n", strerror(errno), category);
2138 if (handler->cluster)
2139 free(handler->cluster);
2141 if (handler->category)
2142 free(handler->category);
2144 handler->cluster = pc;
2145 handler->category = ps;
2150 void lb_set_size(struct livebox *handler, int w, int h)
2152 handler->lb.width = w;
2153 handler->lb.height = h;
2156 void lb_set_pdsize(struct livebox *handler, int w, int h)
2158 handler->pd.width = w;
2159 handler->pd.height = h;
2162 void lb_invoke_fault_handler(enum livebox_fault_type event, const char *pkgname, const char *file, const char *func)
2166 struct fault_info *info;
2168 dlist_foreach_safe(s_info.fault_list, l, n, info) {
2169 if (info->handler(event, pkgname, file, func, info->user_data) == EXIT_FAILURE)
2170 s_info.fault_list = dlist_remove(s_info.fault_list, l);
2174 void lb_invoke_event_handler(struct livebox *handler, enum livebox_event_type event)
2178 struct event_info *info;
2180 dlist_foreach_safe(s_info.event_list, l, n, info) {
2181 if (info->handler(handler, event, info->user_data) == EXIT_FAILURE)
2182 s_info.event_list = dlist_remove(s_info.event_list, l);
2186 struct livebox *lb_find_livebox(const char *pkgname, const char *id)
2189 struct livebox *handler;
2191 dlist_foreach(s_info.livebox_list, l, handler) {
2195 if (!strcmp(handler->pkgname, pkgname) && !strcmp(handler->id, id))
2202 struct livebox *lb_find_livebox_by_timestamp(double timestamp)
2205 struct livebox *handler;
2207 dlist_foreach(s_info.livebox_list, l, handler) {
2208 if (handler->timestamp == timestamp)
2215 static inline char *get_file_kept_in_safe(const char *id)
2222 path = util_uri_to_path(id);
2224 ErrPrint("Invalid URI(%s)\n", id);
2231 if (s_info.prevent_overwrite) {
2232 new_path = strdup(path);
2234 ErrPrint("Heap: %s\n", strerror(errno));
2243 while (base_idx > 0 && path[base_idx] != '/') base_idx--;
2244 base_idx += (path[base_idx] == '/');
2246 new_path = malloc(len + 10);
2248 ErrPrint("Heap: %s\n", strerror(errno));
2252 strncpy(new_path, path, base_idx);
2253 snprintf(new_path + base_idx, len + 10 - base_idx, "reader/%s", path + base_idx);
2257 struct livebox *lb_new_livebox(const char *pkgname, const char *id, double timestamp)
2259 struct livebox *handler;
2261 handler = calloc(1, sizeof(*handler));
2263 ErrPrint("Failed to create a new livebox\n");
2267 handler->pkgname = strdup(pkgname);
2268 if (!handler->pkgname) {
2269 ErrPrint("%s\n", strerror(errno));
2274 handler->id = strdup(id);
2276 ErrPrint("%s\n", strerror(errno));
2277 free(handler->pkgname);
2282 handler->filename = get_file_kept_in_safe(id);
2283 if (!handler->filename) {
2284 handler->filename = strdup(util_uri_to_path(id));
2285 if (!handler->filename)
2286 ErrPrint("Error: %s\n", strerror(errno));
2289 handler->timestamp = timestamp;
2290 handler->lb.type = _LB_TYPE_FILE;
2291 handler->pd.type = _PD_TYPE_SCRIPT;
2292 handler->state = CREATE;
2293 handler->visible = LB_SHOW;
2295 s_info.livebox_list = dlist_append(s_info.livebox_list, handler);
2300 int lb_delete_all(void)
2304 struct livebox *handler;
2306 dlist_foreach_safe(s_info.livebox_list, l, n, handler) {
2307 lb_invoke_event_handler(handler, LB_EVENT_DELETED);
2314 int lb_set_content(struct livebox *handler, const char *content)
2316 if (handler->content) {
2317 free(handler->content);
2318 handler->content = NULL;
2322 handler->content = strdup(content);
2323 if (!handler->content) {
2324 CRITICAL_LOG("Heap: %s (content: %s)\n", strerror(errno), content);
2332 int lb_set_title(struct livebox *handler, const char *title)
2334 if (handler->title) {
2335 free(handler->title);
2336 handler->title = NULL;
2340 handler->title = strdup(title);
2341 if (!handler->title) {
2342 CRITICAL_LOG("Heap: %s (title: %s)\n", strerror(errno), title);
2350 void lb_set_size_list(struct livebox *handler, int size_list)
2352 handler->lb.size_list = size_list;
2355 void lb_set_auto_launch(struct livebox *handler, const char *auto_launch)
2357 if (!strlen(auto_launch))
2360 handler->lb.auto_launch = strdup(auto_launch);
2361 if (!handler->lb.auto_launch)
2362 ErrPrint("Heap: %s\n", strerror(errno));
2365 void lb_set_priority(struct livebox *handler, double priority)
2367 handler->lb.priority = priority;
2370 void lb_set_id(struct livebox *handler, const char *id)
2375 handler->id = strdup(id);
2377 ErrPrint("Error: %s\n", strerror(errno));
2379 if (handler->filename)
2380 free(handler->filename);
2382 handler->filename = get_file_kept_in_safe(id);
2383 if (!handler->filename) {
2384 handler->filename = strdup(util_uri_to_path(id));
2385 if (!handler->filename)
2386 ErrPrint("Error: %s\n", strerror(errno));
2390 int lb_set_lb_fb(struct livebox *handler, const char *filename)
2397 fb = handler->lb.data.fb;
2398 if (fb && !strcmp(fb_id(fb), filename)) /*!< BUFFER is not changed, */
2401 handler->lb.data.fb = NULL;
2403 if (!filename || filename[0] == '\0') {
2409 handler->lb.data.fb = fb_create(filename, handler->lb.width, handler->lb.height);
2410 if (!handler->lb.data.fb) {
2411 ErrPrint("Faield to create a FB\n");
2423 int lb_set_pd_fb(struct livebox *handler, const char *filename)
2430 fb = handler->pd.data.fb;
2431 if (fb && !strcmp(fb_id(fb), filename)) {
2432 /* BUFFER is not changed, just update the content */
2435 handler->pd.data.fb = NULL;
2437 if (!filename || filename[0] == '\0') {
2443 handler->pd.data.fb = fb_create(filename, handler->pd.width, handler->pd.height);
2444 if (!handler->pd.data.fb) {
2445 ErrPrint("Failed to create a FB\n");
2456 struct fb_info *lb_get_lb_fb(struct livebox *handler)
2458 return handler->lb.data.fb;
2461 struct fb_info *lb_get_pd_fb(struct livebox *handler)
2463 return handler->pd.data.fb;
2466 void lb_set_user(struct livebox *handler, int user)
2468 handler->is_user = user;
2471 void lb_set_pinup(struct livebox *handler, int pinup_supported)
2473 handler->lb.pinup_supported = pinup_supported;
2476 void lb_set_text_lb(struct livebox *handler)
2478 handler->lb.type = _LB_TYPE_TEXT;
2481 void lb_set_text_pd(struct livebox *handler)
2483 handler->pd.type = _PD_TYPE_TEXT;
2486 int lb_text_lb(struct livebox *handler)
2488 return handler->lb.type == _LB_TYPE_TEXT;
2491 int lb_text_pd(struct livebox *handler)
2493 return handler->pd.type == _PD_TYPE_TEXT;
2496 void lb_set_period(struct livebox *handler, double period)
2498 handler->lb.period = period;
2501 struct livebox *lb_ref(struct livebox *handler)
2510 struct livebox *lb_unref(struct livebox *handler)
2516 if (handler->refcnt > 0)
2519 dlist_remove_data(s_info.livebox_list, handler);
2521 handler->state = DESTROYED;
2522 free(handler->cluster);
2523 free(handler->category);
2525 free(handler->pkgname);
2526 free(handler->filename);
2527 free(handler->lb.auto_launch);
2529 if (handler->lb.data.fb) {
2530 fb_destroy(handler->lb.data.fb);
2531 handler->lb.data.fb = NULL;
2534 if (handler->pd.data.fb) {
2535 fb_destroy(handler->pd.data.fb);
2536 handler->pd.data.fb = NULL;
2543 int lb_send_delete(struct livebox *handler, ret_cb_t cb, void *data)
2545 struct packet *packet;
2547 if (!cb && !!data) {
2548 ErrPrint("Invalid argument\n");
2552 if (handler->deleted_cb) {
2553 ErrPrint("Already in-progress\n");
2554 return -EINPROGRESS;
2557 packet = packet_create("delete", "ss", handler->pkgname, handler->id);
2559 ErrPrint("Failed to build a param\n");
2561 cb(handler, -EFAULT, data);
2567 cb = default_delete_cb;
2569 return master_rpc_async_request(handler, packet, 0, del_ret_cb, create_cb_info(cb, data));