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 (livebox_service_is_enabled(pkgname) == 0) {
593 DbgPrint("Livebox [%s] is disabled package\n", pkgname);
597 if (type != LB_SIZE_TYPE_UNKNOWN)
598 livebox_service_get_size(type, &width, &height);
600 handler = calloc(1, sizeof(*handler));
602 ErrPrint("Error: %s\n", strerror(errno));
606 handler->pkgname = lb_pkgname(pkgname);
607 if (!handler->pkgname) {
608 ErrPrint("Error: %s\n", strerror(errno));
614 handler->content = strdup(content);
615 if (!handler->content) {
616 ErrPrint("Error: %s\n", strerror(errno));
617 free(handler->pkgname);
622 handler->content = livebox_service_content(handler->pkgname);
625 handler->cluster = strdup(cluster);
626 if (!handler->cluster) {
627 ErrPrint("Error: %s\n", strerror(errno));
628 free(handler->content);
629 free(handler->pkgname);
634 handler->category = strdup(category);
635 if (!handler->category) {
636 ErrPrint("Error: %s\n", strerror(errno));
637 free(handler->cluster);
638 free(handler->content);
639 free(handler->pkgname);
645 cb = default_create_cb;
647 /* Data provider will set this */
648 handler->lb.type = _LB_TYPE_FILE;
649 handler->pd.type = _PD_TYPE_SCRIPT;
650 handler->lb.period = period;
652 /* Used for handling the mouse event on a box */
653 handler->lb.mouse_event = livebox_service_mouse_event(handler->pkgname);
655 /* Cluster infomration is not determined yet */
656 handler->nr_of_sizes = 0x01;
658 handler->timestamp = util_timestamp();
659 handler->is_user = 1;
660 handler->visible = LB_SHOW;
662 s_info.livebox_list = dlist_append(s_info.livebox_list, handler);
664 packet = packet_create("new", "dssssdii", handler->timestamp, handler->pkgname, handler->content, cluster, category, period, width, height);
666 ErrPrint("Failed to create a new packet\n");
667 free(handler->category);
668 free(handler->cluster);
669 free(handler->content);
670 free(handler->pkgname);
675 ret = master_rpc_async_request(handler, packet, 0, new_ret_cb, create_cb_info(cb, data));
677 ErrPrint("Failed to send a new packet\n");
678 free(handler->category);
679 free(handler->cluster);
680 free(handler->content);
681 free(handler->pkgname);
686 DbgPrint("Successfully sent a new request ([%lf] %s)\n", handler->timestamp, handler->pkgname);
687 handler->state = CREATE;
688 return lb_ref(handler);
691 EAPI double livebox_period(struct livebox *handler)
693 if (!handler || handler->state != CREATE || !handler->id) {
694 ErrPrint("Handler is not valid\n");
698 return handler->lb.period;
701 EAPI int livebox_set_period(struct livebox *handler, double period, ret_cb_t cb, void *data)
703 struct packet *packet;
705 if (!handler || handler->state != CREATE || !handler->id) {
706 ErrPrint("Handler is not valid\n");
710 if (!handler->is_user) {
711 ErrPrint("CA Livebox is not able to change the period\n");
715 if (handler->lb.period == period) {
716 DbgPrint("No changes\n");
720 packet = packet_create("set_period", "ssd", handler->pkgname, handler->id, period);
722 ErrPrint("Failed to build a packet %s\n", handler->pkgname);
727 cb = default_period_changed_cb;
729 return master_rpc_async_request(handler, packet, 0, period_ret_cb, create_cb_info(cb, data));
732 EAPI int livebox_del(struct livebox *handler, ret_cb_t cb, void *data)
735 ErrPrint("Handler is NIL\n");
739 if (handler->state != CREATE) {
740 ErrPrint("Handler is already deleted\n");
744 handler->state = DELETE;
749 * The id is not determined yet.
750 * It means a user didn't receive created event yet.
751 * Then just stop to delete procedure from here.
752 * Because the "created" event handler will release this.
753 * By the way, if the user adds any callback for getting return status of this,
757 cb(handler, 0, data);
762 cb = default_delete_cb;
764 return lb_send_delete(handler, cb, data);
767 EAPI int livebox_set_fault_handler(int (*cb)(enum livebox_fault_type, const char *, const char *, const char *, void *), void *data)
769 struct fault_info *info;
774 info = malloc(sizeof(*info));
776 CRITICAL_LOG("Heap: %s\n", strerror(errno));
781 info->user_data = data;
783 s_info.fault_list = dlist_append(s_info.fault_list, info);
787 EAPI void *livebox_unset_fault_handler(int (*cb)(enum livebox_fault_type, const char *, const char *, const char *, void *))
789 struct fault_info *info;
792 dlist_foreach(s_info.fault_list, l, info) {
793 if (info->handler == cb) {
795 s_info.fault_list = dlist_remove(s_info.fault_list, l);
796 data = info->user_data;
806 EAPI int livebox_set_event_handler(int (*cb)(struct livebox *, enum livebox_event_type, void *), void *data)
808 struct event_info *info;
811 ErrPrint("Invalid argument cb is nil\n");
815 info = malloc(sizeof(*info));
817 CRITICAL_LOG("Heap: %s\n", strerror(errno));
822 info->user_data = data;
824 s_info.event_list = dlist_append(s_info.event_list, info);
828 EAPI void *livebox_unset_event_handler(int (*cb)(struct livebox *, enum livebox_event_type, void *))
830 struct event_info *info;
833 dlist_foreach(s_info.event_list, l, info) {
834 if (info->handler == cb) {
837 s_info.event_list = dlist_remove(s_info.event_list, l);
838 data = info->user_data;
848 EAPI int livebox_resize(struct livebox *handler, int type, ret_cb_t cb, void *data)
850 struct packet *packet;
855 ErrPrint("Handler is NIL\n");
859 if (handler->state != CREATE || !handler->id) {
860 ErrPrint("Handler is not valid\n");
864 if (!handler->is_user) {
865 ErrPrint("CA Livebox is not able to be resized\n");
869 if (livebox_service_get_size(type, &w, &h) != 0) {
870 ErrPrint("Invalid size type\n");
874 if (handler->lb.width == w && handler->lb.height == h) {
875 DbgPrint("No changes\n");
879 packet = packet_create("resize", "ssii", handler->pkgname, handler->id, w, h);
881 ErrPrint("Failed to build param\n");
885 return master_rpc_async_request(handler, packet, 0, resize_cb, create_cb_info(cb, data));
888 EAPI int livebox_click(struct livebox *handler, double x, double y)
890 struct packet *packet;
895 ErrPrint("Handler is NIL\n");
899 if (handler->state != CREATE || !handler->id) {
900 ErrPrint("Handler is not valid\n");
904 if (handler->lb.auto_launch)
905 if (aul_launch_app(handler->lb.auto_launch, NULL) < 0)
906 ErrPrint("Failed to launch app %s\n", handler->lb.auto_launch);
908 timestamp = util_timestamp();
909 packet = packet_create_noack("clicked", "sssddd", handler->pkgname, handler->id, "clicked", timestamp, x, y);
911 ErrPrint("Failed to build param\n");
915 ret = master_rpc_request_only(handler, packet);
917 if (!handler->lb.mouse_event && (handler->lb.type == _LB_TYPE_BUFFER || handler->lb.type == _LB_TYPE_SCRIPT)) {
918 int ret; /* Shadow variable */
919 ret = send_mouse_event(handler, "lb_mouse_down", x, y, handler->lb.width, handler->lb.height);
921 DbgPrint("Failed to send Down: %d\n", ret);
923 ret = send_mouse_event(handler, "lb_mouse_move", x, y, handler->lb.width, handler->lb.height);
925 DbgPrint("Failed to send Move: %d\n", ret);
927 ret = send_mouse_event(handler, "lb_mouse_up", x, y, handler->lb.width, handler->lb.height);
929 DbgPrint("Failed to send Up: %d\n", ret);
935 EAPI int livebox_has_pd(struct livebox *handler)
938 ErrPrint("Handler is NIL\n");
942 if (handler->state != CREATE || !handler->id) {
943 ErrPrint("Handler is not valid\n");
947 return !!handler->pd.data.fb;
950 EAPI int livebox_pd_is_created(struct livebox *handler)
953 ErrPrint("Handler is NIL\n");
957 if (!handler->pd.data.fb || handler->state != CREATE || !handler->id) {
958 ErrPrint("Handler is not valid\n");
962 return handler->is_pd_created;
965 EAPI int livebox_create_pd(struct livebox *handler, ret_cb_t cb, void *data)
967 return livebox_create_pd_with_position(handler, -1.0, -1.0, cb, data);
970 EAPI int livebox_create_pd_with_position(struct livebox *handler, double x, double y, ret_cb_t cb, void *data)
972 struct packet *packet;
975 ErrPrint("Handler is NIL\n");
979 if (!handler->pd.data.fb || handler->state != CREATE || !handler->id) {
980 ErrPrint("Handler is not valid\n");
984 if (handler->is_pd_created == 1) {
985 DbgPrint("PD already created\n");
989 packet = packet_create("create_pd", "ssdd", handler->pkgname, handler->id, x, y);
991 ErrPrint("Failed to build param\n");
996 handler->pd_created_cb = default_pd_created_cb;
998 return master_rpc_async_request(handler, packet, 0, pd_create_cb, create_cb_info(cb, data));
1001 EAPI int livebox_activate(const char *pkgname, ret_cb_t cb, void *data)
1003 struct packet *packet;
1008 packet = packet_create("activate_package", "s", pkgname);
1010 ErrPrint("Failed to build a param\n");
1014 return master_rpc_async_request(NULL, packet, 0, activated_cb, create_cb_info(cb, data));
1017 EAPI int livebox_destroy_pd(struct livebox *handler, ret_cb_t cb, void *data)
1019 struct packet *packet;
1022 ErrPrint("Handler is NIL\n");
1026 if (!handler->pd.data.fb || handler->state != CREATE || !handler->id) {
1027 ErrPrint("Handler is not valid\n");
1031 if (!handler->is_pd_created) {
1032 ErrPrint("PD is not created\n");
1036 packet = packet_create("destroy_pd", "ss", handler->pkgname, handler->id);
1038 ErrPrint("Failed to build a param\n");
1043 cb = default_pd_destroyed_cb;
1045 return master_rpc_async_request(handler, packet, 0, pd_destroy_cb, create_cb_info(cb, data));
1048 EAPI int livebox_content_event(struct livebox *handler, enum content_event_type type, double x, double y)
1052 char cmd[20] = { '\0', };
1056 ErrPrint("Handler is NIL\n");
1060 if (handler->state != CREATE || !handler->id) {
1061 ErrPrint("Handler is not valid\n");
1065 if (type & CONTENT_EVENT_PD_MASK) {
1066 if (!handler->is_pd_created) {
1067 ErrPrint("PD is not created\n");
1071 if (type & CONTENT_EVENT_MOUSE_MASK) {
1072 if (!handler->pd.data.fb) {
1073 ErrPrint("Handler is not valid\n");
1077 if (type & CONTENT_EVENT_MOUSE_MOVE) {
1078 if (fabs(x - handler->pd.x) < MINIMUM_EVENT && fabs(y - handler->pd.y) < MINIMUM_EVENT)
1083 w = handler->pd.width;
1084 h = handler->pd.height;
1090 if (type & CONTENT_EVENT_MOUSE_MASK) {
1091 if (!handler->lb.mouse_event) {
1092 ErrPrint("Box is not support the mouse event\n");
1096 if (!handler->lb.data.fb) {
1097 ErrPrint("Handler is not valid\n");
1101 if (type & CONTENT_EVENT_MOUSE_MOVE) {
1102 if (fabs(x - handler->lb.x) < MINIMUM_EVENT && fabs(y - handler->lb.y) < MINIMUM_EVENT)
1107 w = handler->lb.width;
1108 h = handler->lb.height;
1115 switch ((type & ~CONTENT_EVENT_PD_MASK)) {
1116 case CONTENT_EVENT_ACCESS_READ | CONTENT_EVENT_ACCESS_MASK:
1117 strcpy(ptr, "_access_read");
1119 case CONTENT_EVENT_ACCESS_READ_PREV | CONTENT_EVENT_ACCESS_MASK:
1120 strcpy(ptr, "_access_read_prev");
1122 case CONTENT_EVENT_ACCESS_READ_NEXT | CONTENT_EVENT_ACCESS_MASK:
1123 strcpy(ptr, "_access_read_next");
1125 case CONTENT_EVENT_ACCESS_ACTIVATE | CONTENT_EVENT_ACCESS_MASK:
1126 strcpy(ptr, "_access_activate");
1128 case CONTENT_EVENT_ACCESS_UP | CONTENT_EVENT_ACCESS_MASK:
1129 strcpy(ptr, "_access_up");
1131 case CONTENT_EVENT_ACCESS_DOWN | CONTENT_EVENT_ACCESS_MASK:
1132 strcpy(ptr, "_access_down");
1134 case CONTENT_EVENT_MOUSE_ENTER | CONTENT_EVENT_MOUSE_MASK:
1135 strcpy(ptr, "_mouse_enter");
1137 case CONTENT_EVENT_MOUSE_LEAVE | CONTENT_EVENT_MOUSE_MASK:
1138 strcpy(ptr, "_mouse_leave");
1140 case CONTENT_EVENT_MOUSE_UP | CONTENT_EVENT_MOUSE_MASK:
1141 strcpy(ptr, "_mouse_up");
1143 case CONTENT_EVENT_MOUSE_DOWN | CONTENT_EVENT_MOUSE_MASK:
1144 strcpy(ptr, "_mouse_down");
1146 case CONTENT_EVENT_MOUSE_MOVE | CONTENT_EVENT_MOUSE_MASK:
1147 strcpy(ptr, "_mouse_move");
1149 case CONTENT_EVENT_KEY_DOWN | CONTENT_EVENT_KEY_MASK:
1150 strcpy(ptr, "_key_down");
1152 case CONTENT_EVENT_KEY_UP | CONTENT_EVENT_KEY_MASK:
1153 strcpy(ptr, "_key_up");
1156 ErrPrint("Invalid event type\n");
1160 return send_mouse_event(handler, cmd, x, y, w, h);
1163 EAPI const char *livebox_filename(struct livebox *handler)
1166 ErrPrint("Handler is NIL\n");
1170 if (handler->state != CREATE || !handler->id) {
1171 ErrPrint("Handler is not valid\n");
1175 if (handler->filename)
1176 return handler->filename;
1179 return util_uri_to_path(handler->id);
1182 EAPI int livebox_get_pdsize(struct livebox *handler, int *w, int *h)
1188 ErrPrint("Handler is NIL\n");
1192 if (handler->state != CREATE || !handler->id) {
1193 ErrPrint("Handler is not valid\n");
1202 *w = handler->pd.width;
1203 *h = handler->pd.height;
1205 switch (handler->pd.type) {
1206 case _PD_TYPE_BUFFER:
1207 case _PD_TYPE_SCRIPT:
1208 if (!handler->is_pd_created) {
1209 DbgPrint("Buffer is not created yet - reset size\n");
1221 EAPI int livebox_size(struct livebox *handler)
1227 ErrPrint("Handler is NIL\n");
1231 if (handler->state != CREATE || !handler->id) {
1232 ErrPrint("Handler is not valid\n");
1236 w = handler->lb.width;
1237 h = handler->lb.height;
1239 switch (handler->lb.type) {
1240 case _LB_TYPE_BUFFER:
1241 case _LB_TYPE_SCRIPT:
1242 if (!fb_is_created(handler->lb.data.fb)) {
1243 DbgPrint("Buffer is not created yet - reset size\n");
1252 return livebox_service_size_type(w, h);
1255 EAPI int livebox_set_group(struct livebox *handler, const char *cluster, const char *category, ret_cb_t cb, void *data)
1257 struct packet *packet;
1260 ErrPrint("Handler is NIL\n");
1264 if (!cluster || !category || handler->state != CREATE || !handler->id) {
1265 ErrPrint("Invalid argument\n");
1269 if (!handler->is_user) {
1270 ErrPrint("CA Livebox is not able to change the group\n");
1274 if (!strcmp(handler->cluster, cluster) && !strcmp(handler->category, category)) {
1275 DbgPrint("No changes\n");
1279 packet = packet_create("change_group", "ssss", handler->pkgname, handler->id, cluster, category);
1281 ErrPrint("Failed to build a param\n");
1286 cb = default_group_changed_cb;
1288 return master_rpc_async_request(handler, packet, 0, set_group_ret_cb, create_cb_info(cb, data));
1291 EAPI int livebox_get_group(struct livebox *handler, char ** const cluster, char ** const category)
1294 ErrPrint("Handler is NIL\n");
1298 if (!cluster || !category || handler->state != CREATE || !handler->id) {
1299 ErrPrint("Invalid argument\n");
1303 *cluster = handler->cluster;
1304 *category = handler->category;
1308 EAPI int livebox_get_supported_sizes(struct livebox *handler, int *cnt, int *size_list)
1313 if (!handler || !size_list) {
1314 ErrPrint("Invalid argument, handler(%p), size_list(%p)\n", handler, size_list);
1318 if (!cnt || handler->state != CREATE || !handler->id) {
1319 ErrPrint("Handler is not valid\n");
1323 for (j = i = 0; i < NR_OF_SIZE_LIST; i++) {
1324 if (handler->lb.size_list & (0x01 << i)) {
1328 size_list[j++] = (0x01 << i);
1336 EAPI const char *livebox_pkgname(struct livebox *handler)
1339 ErrPrint("Handler is NIL\n");
1343 if (handler->state != CREATE) {
1344 ErrPrint("Handler is not valid\n");
1348 return handler->pkgname;
1351 EAPI double livebox_priority(struct livebox *handler)
1354 ErrPrint("Handler is NIL\n");
1358 if (handler->state != CREATE || !handler->id) {
1359 ErrPrint("Handler is not valid (%p)\n", handler);
1363 return handler->lb.priority;
1366 EAPI int livebox_delete_cluster(const char *cluster, ret_cb_t cb, void *data)
1368 struct packet *packet;
1370 packet = packet_create("delete_cluster", "s", cluster);
1372 ErrPrint("Failed to build a param\n");
1376 return master_rpc_async_request(NULL, packet, 0, delete_cluster_cb, create_cb_info(cb, data));
1379 EAPI int livebox_delete_category(const char *cluster, const char *category, ret_cb_t cb, void *data)
1381 struct packet *packet;
1383 packet = packet_create("delete_category", "ss", cluster, category);
1385 ErrPrint("Failed to build a param\n");
1389 return master_rpc_async_request(NULL, packet, 0, delete_category_cb, create_cb_info(cb, data));
1392 EAPI enum livebox_lb_type livebox_lb_type(struct livebox *handler)
1395 ErrPrint("Handler is NIL\n");
1396 return LB_TYPE_INVALID;
1399 if (handler->state != CREATE || !handler->id) {
1400 ErrPrint("Handler is not valid\n");
1401 return LB_TYPE_INVALID;
1404 switch (handler->lb.type) {
1406 return LB_TYPE_IMAGE;
1407 case _LB_TYPE_BUFFER:
1408 case _LB_TYPE_SCRIPT:
1411 id = fb_id(handler->lb.data.fb);
1412 if (id && !strncasecmp(id, SCHEMA_PIXMAP, strlen(SCHEMA_PIXMAP)))
1413 return LB_TYPE_PIXMAP;
1415 return LB_TYPE_BUFFER;
1417 return LB_TYPE_TEXT;
1422 return LB_TYPE_INVALID;
1425 EAPI enum livebox_pd_type livebox_pd_type(struct livebox *handler)
1428 ErrPrint("Handler is NIL\n");
1429 return PD_TYPE_INVALID;
1432 if (handler->state != CREATE || !handler->id) {
1433 ErrPrint("Handler is not valid\n");
1434 return PD_TYPE_INVALID;
1437 switch (handler->pd.type) {
1439 return PD_TYPE_TEXT;
1440 case _PD_TYPE_BUFFER:
1441 case _PD_TYPE_SCRIPT:
1444 id = fb_id(handler->pd.data.fb);
1445 if (id && !strncasecmp(id, SCHEMA_PIXMAP, strlen(SCHEMA_PIXMAP)))
1446 return PD_TYPE_PIXMAP;
1448 return PD_TYPE_BUFFER;
1453 return PD_TYPE_INVALID;
1456 EAPI int livebox_set_pd_text_handler(struct livebox *handler, struct livebox_script_operators *ops)
1459 ErrPrint("Handler is NIL\n");
1463 if (handler->state != CREATE) {
1464 ErrPrint("Handler is not valid\n");
1468 memcpy(&handler->pd.data.ops, ops, sizeof(*ops));
1472 EAPI int livebox_set_text_handler(struct livebox *handler, struct livebox_script_operators *ops)
1475 ErrPrint("Handler is NIL\n");
1479 if (handler->state != CREATE) {
1480 ErrPrint("Handler is not valid\n");
1484 memcpy(&handler->lb.data.ops, ops, sizeof(*ops));
1488 EAPI int livebox_acquire_lb_pixmap(struct livebox *handler, ret_cb_t cb, void *data)
1490 struct packet *packet;
1494 ErrPrint("Handler is NIL\n");
1498 if (handler->state != CREATE || !handler->id) {
1499 ErrPrint("Invalid handle\n");
1503 if (handler->lb.type != _LB_TYPE_SCRIPT && handler->lb.type != _LB_TYPE_BUFFER) {
1504 ErrPrint("Handler is not valid type\n");
1508 id = fb_id(handler->lb.data.fb);
1509 if (!id || strncasecmp(id, SCHEMA_PIXMAP, strlen(SCHEMA_PIXMAP)))
1512 packet = packet_create("lb_acquire_pixmap", "ss", handler->pkgname, handler->id);
1514 ErrPrint("Failed to build a param\n");
1518 return master_rpc_async_request(handler, packet, 0, pixmap_acquired_cb, create_cb_info(cb, data));
1521 EAPI int livebox_release_lb_pixmap(struct livebox *handler, int pixmap)
1523 struct packet *packet;
1526 ErrPrint("Handler is NIL\n");
1530 if (handler->state != CREATE || !handler->id) {
1531 ErrPrint("Invalid handle\n");
1535 if (handler->lb.type != _LB_TYPE_SCRIPT && handler->lb.type != _LB_TYPE_BUFFER) {
1536 ErrPrint("Handler is not valid type\n");
1540 packet = packet_create_noack("lb_release_pixmap", "ssi", handler->pkgname, handler->id, pixmap);
1542 ErrPrint("Failed to build a param\n");
1546 return master_rpc_request_only(handler, packet);
1549 EAPI int livebox_acquire_pd_pixmap(struct livebox *handler, ret_cb_t cb, void *data)
1551 struct packet *packet;
1555 ErrPrint("Handler is NIL\n");
1559 if (handler->state != CREATE || !handler->id) {
1560 ErrPrint("Invalid handle\n");
1564 if (handler->pd.type != _PD_TYPE_SCRIPT && handler->pd.type != _PD_TYPE_BUFFER) {
1565 ErrPrint("Handler is not valid type\n");
1569 id = fb_id(handler->pd.data.fb);
1570 if (!id || strncasecmp(id, SCHEMA_PIXMAP, strlen(SCHEMA_PIXMAP)))
1573 packet = packet_create("pd_acquire_pixmap", "ss", handler->pkgname, handler->id);
1575 ErrPrint("Failed to build a param\n");
1579 return master_rpc_async_request(handler, packet, 0, pixmap_acquired_cb, create_cb_info(cb, data));
1582 EAPI int livebox_pd_pixmap(const struct livebox *handler)
1588 ErrPrint("Handler is NIL\n");
1592 if (handler->state != CREATE || !handler->id) {
1593 ErrPrint("Invalid handler\n");
1597 if (handler->pd.type != _PD_TYPE_SCRIPT && handler->pd.type != _PD_TYPE_BUFFER) {
1598 ErrPrint("Invalid handler\n");
1602 id = fb_id(handler->pd.data.fb);
1603 if (id && sscanf(id, SCHEMA_PIXMAP "%d", &pixmap) != 1) {
1604 ErrPrint("PIXMAP Id is not valid\n");
1611 EAPI int livebox_lb_pixmap(const struct livebox *handler)
1617 ErrPrint("Handler is NIL\n");
1621 if (handler->state != CREATE || !handler->id) {
1622 ErrPrint("Invalid handler\n");
1626 if (handler->lb.type != _LB_TYPE_SCRIPT && handler->lb.type != _LB_TYPE_BUFFER) {
1627 ErrPrint("Invalid handler\n");
1631 id = fb_id(handler->lb.data.fb);
1632 if (id && sscanf(id, SCHEMA_PIXMAP "%d", &pixmap) != 1) {
1633 ErrPrint("PIXMAP Id is not valid\n");
1640 EAPI int livebox_release_pd_pixmap(struct livebox *handler, int pixmap)
1642 struct packet *packet;
1645 ErrPrint("Handler is NIL\n");
1649 if (handler->state != CREATE || !handler->id) {
1650 ErrPrint("Invalid handle\n");
1654 if (handler->pd.type != _PD_TYPE_SCRIPT && handler->pd.type != _PD_TYPE_BUFFER) {
1655 ErrPrint("Handler is not valid type\n");
1659 packet = packet_create_noack("pd_release_pixmap", "ssi", handler->pkgname, handler->id, pixmap);
1661 ErrPrint("Failed to build a param\n");
1665 return master_rpc_request_only(handler, packet);
1668 EAPI void *livebox_acquire_fb(struct livebox *handler)
1671 ErrPrint("Handler is NIL\n");
1675 if (handler->state != CREATE || !handler->id) {
1676 ErrPrint("Invalid handle\n");
1680 if (handler->lb.type != _LB_TYPE_SCRIPT && handler->lb.type != _LB_TYPE_BUFFER) {
1681 ErrPrint("Handler is not valid type\n");
1685 return fb_acquire_buffer(handler->lb.data.fb);
1688 EAPI int livebox_release_fb(void *buffer)
1690 return fb_release_buffer(buffer);
1693 EAPI int livebox_fb_refcnt(void *buffer)
1695 return fb_refcnt(buffer);
1698 EAPI void *livebox_acquire_pdfb(struct livebox *handler)
1701 ErrPrint("Handler is NIL\n");
1705 if (handler->state != CREATE || !handler->id) {
1706 ErrPrint("Invalid handler\n");
1710 if (handler->pd.type != _PD_TYPE_SCRIPT && handler->pd.type != _PD_TYPE_BUFFER) {
1711 ErrPrint("Handler is not valid type\n");
1715 return fb_acquire_buffer(handler->pd.data.fb);
1718 EAPI int livebox_release_pdfb(void *buffer)
1720 return fb_release_buffer(buffer);
1723 EAPI int livebox_pdfb_refcnt(void *buffer)
1725 return fb_refcnt(buffer);
1728 EAPI int livebox_pdfb_bufsz(struct livebox *handler)
1731 ErrPrint("Handler is NIL\n");
1735 if (handler->state != CREATE || !handler->id) {
1736 ErrPrint("Handler is not valid\n");
1740 return fb_size(handler->pd.data.fb);
1743 EAPI int livebox_lbfb_bufsz(struct livebox *handler)
1746 ErrPrint("Handler is NIL\n");
1750 if (handler->state != CREATE || !handler->id) {
1751 ErrPrint("Handler is not valid\n");
1755 return fb_size(handler->lb.data.fb);
1758 EAPI int livebox_is_user(struct livebox *handler)
1761 ErrPrint("Handler is NIL\n");
1765 if (handler->state != CREATE) {
1766 ErrPrint("Handler is invalid\n");
1770 return handler->is_user;
1773 EAPI int livebox_set_pinup(struct livebox *handler, int flag, ret_cb_t cb, void *data)
1775 struct packet *packet;
1778 ErrPrint("Handler is NIL\n");
1782 if (handler->state != CREATE || !handler->id) {
1783 ErrPrint("Handler is not valid\n");
1787 if (handler->is_pinned_up == flag) {
1788 DbgPrint("No changes\n");
1792 packet = packet_create("pinup_changed", "ssi", handler->pkgname, handler->id, flag);
1794 ErrPrint("Failed to build a param\n");
1799 cb = default_pinup_cb;
1801 return master_rpc_async_request(handler, packet, 0, pinup_done_cb, create_cb_info(cb, data));
1804 EAPI int livebox_is_pinned_up(struct livebox *handler)
1807 ErrPrint("Handler is NIL\n");
1811 if (handler->state != CREATE || !handler->id)
1814 return handler->is_pinned_up;
1817 EAPI int livebox_has_pinup(struct livebox *handler)
1820 ErrPrint("Handler is NIL\n");
1824 if (handler->state != CREATE || !handler->id)
1827 return handler->lb.pinup_supported;
1830 EAPI int livebox_set_data(struct livebox *handler, void *data)
1833 ErrPrint("Handler is NIL\n");
1837 if (handler->state != CREATE)
1840 handler->data = data;
1844 EAPI void *livebox_get_data(struct livebox *handler)
1847 ErrPrint("Handler is NIL\n");
1851 if (handler->state != CREATE)
1854 return handler->data;
1857 EAPI int livebox_is_exists(const char *pkgname)
1861 lb = lb_pkgname(pkgname);
1870 EAPI const char *livebox_content(struct livebox *handler)
1873 ErrPrint("Handler is NIL\n");
1877 if (handler->state != CREATE)
1880 return handler->content;
1883 EAPI const char *livebox_category_title(struct livebox *handler)
1886 ErrPrint("Handler is NIL\n");
1890 if (handler->state != CREATE)
1893 return handler->title;
1896 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)
1898 struct packet *packet;
1901 ErrPrint("Handler is NIL\n");
1905 if ((handler->lb.type != _LB_TYPE_TEXT && handler->pd.type != _PD_TYPE_TEXT) || handler->state != CREATE || !handler->id) {
1906 ErrPrint("Handler is not valid\n");
1916 packet = packet_create("text_signal", "ssssdddd",
1917 handler->pkgname, handler->id, emission, source, sx, sy, ex, ey);
1919 ErrPrint("Failed to build a param\n");
1923 return master_rpc_async_request(handler, packet, 0, text_signal_cb, create_cb_info(cb, data));
1926 EAPI int livebox_subscribe_group(const char *cluster, const char *category)
1928 struct packet *packet;
1932 * Validate the group info using DB
1933 * If the group info is not valid, do not send this request
1936 packet = packet_create_noack("subscribe", "ss", cluster ? cluster : "", category ? category : "");
1938 ErrPrint("Failed to create a packet\n");
1942 return master_rpc_request_only(NULL, packet);
1945 EAPI int livebox_unsubscribe_group(const char *cluster, const char *category)
1947 struct packet *packet;
1951 * Validate the group info using DB
1952 * If the group info is not valid, do not send this request
1953 * AND Check the subscribed or not too
1956 packet = packet_create_noack("unsubscribe", "ss", cluster ? cluster : "", category ? category : "");
1958 ErrPrint("Failed to create a packet\n");
1962 return master_rpc_request_only(NULL, packet);
1965 EAPI int livebox_refresh(struct livebox *handler)
1967 struct packet *packet;
1970 ErrPrint("Hnalder is NIL\n");
1974 if (handler->state != CREATE || !handler->id)
1977 packet = packet_create_noack("update", "ss", handler->pkgname, handler->id);
1979 ErrPrint("Failed to create a packet\n");
1983 return master_rpc_request_only(handler, packet);
1986 EAPI int livebox_refresh_group(const char *cluster, const char *category)
1988 struct packet *packet;
1990 if (!cluster || !category) {
1991 ErrPrint("Invalid argument\n");
1995 packet = packet_create_noack("refresh_group", "ss", cluster, category);
1997 ErrPrint("Failed to create a packet\n");
2001 return master_rpc_request_only(NULL, packet);
2004 EAPI int livebox_set_visibility(struct livebox *handler, enum livebox_visible_state state)
2006 struct packet *packet;
2010 ErrPrint("Handler is NIL\n");
2014 if (handler->state != CREATE || !handler->id)
2017 if (!handler->is_user) {
2018 /* System cluster livebox cannot be changed its visible states */
2019 if (state == LB_HIDE_WITH_PAUSE) {
2020 ErrPrint("CA Livebox is not able to change the visibility\n");
2025 if (handler->visible == state)
2028 packet = packet_create_noack("change,visibility", "ssi", handler->pkgname, handler->id, (int)state);
2030 ErrPrint("Failed to create a packet\n");
2034 ret = master_rpc_request_only(handler, packet);
2036 handler->visible = state;
2041 EAPI enum livebox_visible_state livebox_visibility(struct livebox *handler)
2044 ErrPrint("Handler is NIL\n");
2045 return LB_VISIBLE_ERROR;
2048 if (handler->state != CREATE)
2049 return LB_VISIBLE_ERROR;
2051 return handler->visible;
2054 int lb_set_group(struct livebox *handler, const char *cluster, const char *category)
2060 pc = strdup(cluster);
2062 CRITICAL_LOG("Heap: %s (cluster: %s)\n", strerror(errno), cluster);
2068 ps = strdup(category);
2070 CRITICAL_LOG("Heap: %s (category: %s)\n", strerror(errno), category);
2076 if (handler->cluster)
2077 free(handler->cluster);
2079 if (handler->category)
2080 free(handler->category);
2082 handler->cluster = pc;
2083 handler->category = ps;
2088 void lb_set_size(struct livebox *handler, int w, int h)
2090 handler->lb.width = w;
2091 handler->lb.height = h;
2094 void lb_set_pdsize(struct livebox *handler, int w, int h)
2096 handler->pd.width = w;
2097 handler->pd.height = h;
2100 void lb_invoke_fault_handler(enum livebox_fault_type event, const char *pkgname, const char *file, const char *func)
2104 struct fault_info *info;
2106 dlist_foreach_safe(s_info.fault_list, l, n, info) {
2107 if (info->handler(event, pkgname, file, func, info->user_data) == EXIT_FAILURE)
2108 s_info.fault_list = dlist_remove(s_info.fault_list, l);
2112 void lb_invoke_event_handler(struct livebox *handler, enum livebox_event_type event)
2116 struct event_info *info;
2118 dlist_foreach_safe(s_info.event_list, l, n, info) {
2119 if (info->handler(handler, event, info->user_data) == EXIT_FAILURE)
2120 s_info.event_list = dlist_remove(s_info.event_list, l);
2124 struct livebox *lb_find_livebox(const char *pkgname, const char *id)
2127 struct livebox *handler;
2129 dlist_foreach(s_info.livebox_list, l, handler) {
2133 if (!strcmp(handler->pkgname, pkgname) && !strcmp(handler->id, id))
2140 struct livebox *lb_find_livebox_by_timestamp(double timestamp)
2143 struct livebox *handler;
2145 dlist_foreach(s_info.livebox_list, l, handler) {
2146 if (handler->timestamp == timestamp)
2153 static inline char *get_file_kept_in_safe(const char *id)
2160 path = util_uri_to_path(id);
2162 ErrPrint("Invalid URI(%s)\n", id);
2169 if (s_info.prevent_overwrite) {
2170 new_path = strdup(path);
2172 ErrPrint("Heap: %s\n", strerror(errno));
2181 while (base_idx > 0 && path[base_idx] != '/') base_idx--;
2182 base_idx += (path[base_idx] == '/');
2184 new_path = malloc(len + 10);
2186 ErrPrint("Heap: %s\n", strerror(errno));
2190 strncpy(new_path, path, base_idx);
2191 snprintf(new_path + base_idx, len + 10 - base_idx, "reader/%s", path + base_idx);
2195 struct livebox *lb_new_livebox(const char *pkgname, const char *id, double timestamp)
2197 struct livebox *handler;
2199 handler = calloc(1, sizeof(*handler));
2201 ErrPrint("Failed to create a new livebox\n");
2205 handler->pkgname = strdup(pkgname);
2206 if (!handler->pkgname) {
2207 ErrPrint("%s\n", strerror(errno));
2212 handler->id = strdup(id);
2214 ErrPrint("%s\n", strerror(errno));
2215 free(handler->pkgname);
2220 handler->filename = get_file_kept_in_safe(id);
2221 if (!handler->filename) {
2222 handler->filename = strdup(util_uri_to_path(id));
2223 if (!handler->filename)
2224 ErrPrint("Error: %s\n", strerror(errno));
2227 handler->timestamp = timestamp;
2228 handler->lb.type = _LB_TYPE_FILE;
2229 handler->pd.type = _PD_TYPE_SCRIPT;
2230 handler->state = CREATE;
2231 handler->visible = LB_SHOW;
2233 s_info.livebox_list = dlist_append(s_info.livebox_list, handler);
2238 int lb_delete_all(void)
2242 struct livebox *handler;
2244 dlist_foreach_safe(s_info.livebox_list, l, n, handler) {
2245 lb_invoke_event_handler(handler, LB_EVENT_DELETED);
2252 int lb_set_content(struct livebox *handler, const char *content)
2254 if (handler->content) {
2255 free(handler->content);
2256 handler->content = NULL;
2260 handler->content = strdup(content);
2261 if (!handler->content) {
2262 CRITICAL_LOG("Heap: %s (content: %s)\n", strerror(errno), content);
2270 int lb_set_title(struct livebox *handler, const char *title)
2272 if (handler->title) {
2273 free(handler->title);
2274 handler->title = NULL;
2278 handler->title = strdup(title);
2279 if (!handler->title) {
2280 CRITICAL_LOG("Heap: %s (title: %s)\n", strerror(errno), title);
2288 void lb_set_size_list(struct livebox *handler, int size_list)
2290 handler->lb.size_list = size_list;
2293 void lb_set_auto_launch(struct livebox *handler, const char *auto_launch)
2295 if (!strlen(auto_launch))
2298 handler->lb.auto_launch = strdup(auto_launch);
2299 if (!handler->lb.auto_launch)
2300 ErrPrint("Heap: %s\n", strerror(errno));
2303 void lb_set_priority(struct livebox *handler, double priority)
2305 handler->lb.priority = priority;
2308 void lb_set_id(struct livebox *handler, const char *id)
2313 handler->id = strdup(id);
2315 ErrPrint("Error: %s\n", strerror(errno));
2317 if (handler->filename)
2318 free(handler->filename);
2320 handler->filename = get_file_kept_in_safe(id);
2321 if (!handler->filename) {
2322 handler->filename = strdup(util_uri_to_path(id));
2323 if (!handler->filename)
2324 ErrPrint("Error: %s\n", strerror(errno));
2328 int lb_set_lb_fb(struct livebox *handler, const char *filename)
2335 fb = handler->lb.data.fb;
2336 if (fb && !strcmp(fb_id(fb), filename)) /*!< BUFFER is not changed, */
2339 handler->lb.data.fb = NULL;
2341 if (!filename || filename[0] == '\0') {
2347 handler->lb.data.fb = fb_create(filename, handler->lb.width, handler->lb.height);
2348 if (!handler->lb.data.fb) {
2349 ErrPrint("Faield to create a FB\n");
2361 int lb_set_pd_fb(struct livebox *handler, const char *filename)
2368 fb = handler->pd.data.fb;
2369 if (fb && !strcmp(fb_id(fb), filename)) {
2370 /* BUFFER is not changed, just update the content */
2373 handler->pd.data.fb = NULL;
2375 if (!filename || filename[0] == '\0') {
2381 handler->pd.data.fb = fb_create(filename, handler->pd.width, handler->pd.height);
2382 if (!handler->pd.data.fb) {
2383 ErrPrint("Failed to create a FB\n");
2394 struct fb_info *lb_get_lb_fb(struct livebox *handler)
2396 return handler->lb.data.fb;
2399 struct fb_info *lb_get_pd_fb(struct livebox *handler)
2401 return handler->pd.data.fb;
2404 void lb_set_user(struct livebox *handler, int user)
2406 handler->is_user = user;
2409 void lb_set_pinup(struct livebox *handler, int pinup_supported)
2411 handler->lb.pinup_supported = pinup_supported;
2414 void lb_set_text_lb(struct livebox *handler)
2416 handler->lb.type = _LB_TYPE_TEXT;
2419 void lb_set_text_pd(struct livebox *handler)
2421 handler->pd.type = _PD_TYPE_TEXT;
2424 int lb_text_lb(struct livebox *handler)
2426 return handler->lb.type == _LB_TYPE_TEXT;
2429 int lb_text_pd(struct livebox *handler)
2431 return handler->pd.type == _PD_TYPE_TEXT;
2434 void lb_set_period(struct livebox *handler, double period)
2436 handler->lb.period = period;
2439 struct livebox *lb_ref(struct livebox *handler)
2448 struct livebox *lb_unref(struct livebox *handler)
2454 if (handler->refcnt > 0)
2457 dlist_remove_data(s_info.livebox_list, handler);
2459 handler->state = DESTROYED;
2460 free(handler->cluster);
2461 free(handler->category);
2463 free(handler->pkgname);
2464 free(handler->filename);
2465 free(handler->lb.auto_launch);
2467 if (handler->lb.data.fb) {
2468 fb_destroy(handler->lb.data.fb);
2469 handler->lb.data.fb = NULL;
2472 if (handler->pd.data.fb) {
2473 fb_destroy(handler->pd.data.fb);
2474 handler->pd.data.fb = NULL;
2481 int lb_send_delete(struct livebox *handler, ret_cb_t cb, void *data)
2483 struct packet *packet;
2485 if (!cb && !!data) {
2486 ErrPrint("Invalid argument\n");
2490 if (handler->deleted_cb) {
2491 ErrPrint("Already in-progress\n");
2492 return -EINPROGRESS;
2495 packet = packet_create("delete", "ss", handler->pkgname, handler->id);
2497 ErrPrint("Failed to build a param\n");
2499 cb(handler, -EFAULT, data);
2505 cb = default_delete_cb;
2507 return master_rpc_async_request(handler, packet, 0, del_ret_cb, create_cb_info(cb, data));