2 * Copyright 2012 Samsung Electronics Co., Ltd
4 * Licensed under the Flora License, Version 1.0 (the "License");
5 * you may not use this file except in compliance with the License.
6 * You may obtain a copy of the License at
8 * http://www.tizenopensource.org/license
10 * Unless required by applicable law or agreed to in writing, software
11 * distributed under the License is distributed on an "AS IS" BASIS,
12 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13 * See the License for the specific language governing permissions and
14 * limitations under the License.
19 #include <stdlib.h> /* malloc */
20 #include <string.h> /* strdup */
26 #include <com-core_packet.h>
28 #include <livebox-service.h>
33 #include "livebox_internal.h"
36 #include "master_rpc.h"
38 #include "critical_log.h"
40 #define EAPI __attribute__((visibility("default")))
41 #define MINIMUM_EVENT s_info.event_filter
48 struct dlist *livebox_list;
49 struct dlist *event_list;
50 struct dlist *fault_list;
52 int prevent_overwrite;
59 .prevent_overwrite = 0,
60 .event_filter = 0.02f,
69 int (*handler)(struct livebox *handler, enum livebox_event_type event, void *data);
74 int (*handler)(enum livebox_fault_type event, const char *pkgname, const char *filename, const char *func, void *data);
78 static inline void default_create_cb(struct livebox *handler, int ret, void *data)
80 DbgPrint("Default created event handler: %d\n", ret);
83 static inline void default_delete_cb(struct livebox *handler, int ret, void *data)
85 DbgPrint("Default deleted event handler: %d\n", ret);
88 static inline void default_pinup_cb(struct livebox *handler, int ret, void *data)
90 DbgPrint("Default pinup event handler: %d\n", ret);
93 static inline void default_group_changed_cb(struct livebox *handler, int ret, void *data)
95 DbgPrint("Default group changed event handler: %d\n", ret);
98 static inline void default_period_changed_cb(struct livebox *handler, int ret, void *data)
100 DbgPrint("Default period changed event handler: %d\n", ret);
103 static inline void default_pd_created_cb(struct livebox *handler, int ret, void *data)
105 DbgPrint("Default PD created event handler: %d\n", ret);
108 static inline void default_pd_destroyed_cb(struct livebox *handler, int ret, void *data)
110 DbgPrint("Default PD destroyed event handler: %d\n", ret);
113 static inline void default_lb_size_changed_cb(struct livebox *handler, int ret, void *data)
115 DbgPrint("Default LB size changed event handler: %d\n", ret);
118 static inline __attribute__((always_inline)) struct cb_info *create_cb_info(ret_cb_t cb, void *data)
120 struct cb_info *info;
122 info = malloc(sizeof(*info));
124 CRITICAL_LOG("Heap: %s\n", strerror(errno));
133 static inline void destroy_cb_info(struct cb_info *info)
138 static void resize_cb(struct livebox *handler, const struct packet *result, void *data)
141 struct cb_info *info = data;
147 destroy_cb_info(info);
151 } else if (packet_get(result, "i", &ret) != 1) {
152 ErrPrint("Invalid argument\n");
158 * In case of resize request,
159 * The livebox handler will not have resized value right after this callback,
160 * It can only get the new size when it makes updates.
162 * So the user can only get the resized value(result) from the first update event
163 * after this request.
166 DbgPrint("Resize request is done, prepare the size changed event\n");
167 handler->size_changed_cb = cb;
168 handler->size_cbdata = cbdata;
170 DbgPrint("Resize request is failed: %d\n", ret);
171 cb(handler, ret, cbdata);
175 static void text_signal_cb(struct livebox *handler, const struct packet *result, void *data)
179 struct cb_info *info = data;
184 destroy_cb_info(info);
188 } else if (packet_get(result, "i", &ret) != 1) {
189 ErrPrint("Invalid argument\n");
194 cb(handler, ret, cbdata);
198 static void set_group_ret_cb(struct livebox *handler, const struct packet *result, void *data)
203 struct cb_info *info = data;
207 destroy_cb_info(info);
211 } else if (packet_get(result, "i", &ret) != 1) {
212 ErrPrint("Invalid argument\n");
216 if (ret == 0) { /*!< Group information is successfully changed */
217 handler->group_changed_cb = cb;
218 handler->group_cbdata = cbdata;
220 cb(handler, ret, cbdata);
226 static void period_ret_cb(struct livebox *handler, const struct packet *result, void *data)
228 struct cb_info *info = data;
235 destroy_cb_info(info);
239 } else if (packet_get(result, "i", &ret) != 1) {
240 ErrPrint("Invalid argument\n");
245 handler->period_changed_cb = cb;
246 handler->period_cbdata = cbdata;
248 cb(handler, ret, cbdata);
252 static void del_ret_cb(struct livebox *handler, const struct packet *result, void *data)
254 struct cb_info *info = data;
261 destroy_cb_info(info);
264 ErrPrint("Connection lost?\n");
266 } else if (packet_get(result, "i", &ret) != 1) {
267 ErrPrint("Invalid argument\n");
272 DbgPrint("Returns %d (waiting deleted event)\n", ret);
273 handler->deleted_cb = cb;
274 handler->deleted_cbdata = cbdata;
276 cb(handler, ret, cbdata);
281 * Do not call the deleted callback from here.
282 * master will send the "deleted" event.
283 * Then invoke this callback.
285 * if (handler->deleted_cb)
286 * handler->deleted_cb(handler, ret, handler->deleted_cbdata);
290 static void new_ret_cb(struct livebox *handler, const struct packet *result, void *data)
293 struct cb_info *info = data;
299 destroy_cb_info(info);
303 } else if (packet_get(result, "i", &ret) != 1) {
308 DbgPrint("new request is sent, just waiting the created event\n");
309 handler->created_cb = cb;
310 handler->created_cbdata = cbdata;
314 * Don't go anymore ;)
320 * It means the current instance is not created,
321 * so user has to know about this.
322 * notice it to user using "deleted" event.
324 cb(handler, ret, cbdata);
330 static void pd_create_cb(struct livebox *handler, const struct packet *result, void *data)
332 struct cb_info *info = data;
339 destroy_cb_info(data);
343 } else if (packet_get(result, "i", &ret) != 1) {
348 DbgPrint("PD Created event handler prepared\n");
349 handler->pd_created_cb = cb;
350 handler->pd_created_cbdata = cbdata;
352 DbgPrint("Failed to create a PD\n");
353 cb(handler, ret, cbdata);
357 static void activated_cb(struct livebox *handler, const struct packet *result, void *data)
360 struct cb_info *info = data;
363 const char *pkgname = "";
367 destroy_cb_info(info);
371 } else if (packet_get(result, "is", &ret, &pkgname) != 2) {
376 cb(handler, ret, cbdata);
379 static void pd_destroy_cb(struct livebox *handler, const struct packet *result, void *data)
384 struct cb_info *info = data;
388 destroy_cb_info(info);
391 DbgPrint("Result is NIL (may connection lost)\n");
393 } else if (packet_get(result, "i", &ret) != 1) {
394 DbgPrint("Invalid parameter\n");
399 DbgPrint("PD Destroyed callback prepared\n");
400 handler->pd_destroyed_cb = cb;
401 handler->pd_destroyed_cbdata = cbdata;
403 DbgPrint("PD is not desroyed (forcely reset, pd flag)\n");
404 handler->is_pd_created = 0;
405 cb(handler, ret, cbdata);
409 static void delete_cluster_cb(struct livebox *handler, const struct packet *result, void *data)
411 struct cb_info *info = data;
418 destroy_cb_info(info);
422 } else if (packet_get(result, "i", &ret) != 1) {
426 DbgPrint("Delete category returns: %d\n", ret);
429 cb(handler, ret, cbdata);
432 static void delete_category_cb(struct livebox *handler, const struct packet *result, void *data)
434 struct cb_info *info = data;
441 destroy_cb_info(info);
445 else if (packet_get(result, "i", &ret) != 1)
448 DbgPrint("Delete category returns: %d\n", ret);
451 cb(handler, ret, cbdata);
454 static void pixmap_acquired_cb(struct livebox *handler, const struct packet *result, void *data)
459 struct cb_info *info = data;
463 destroy_cb_info(info);
466 ret = 0; /* PIXMAP 0 means error */
467 else if (packet_get(result, "i", &ret) != 1)
471 cb(handler, ret, cbdata);
474 static void pinup_done_cb(struct livebox *handler, const struct packet *result, void *data)
479 struct cb_info *info = data;
483 destroy_cb_info(info);
487 else if (packet_get(result, "i", &ret) != 1)
491 handler->pinup_cb = cb;
492 handler->pinup_cbdata = cbdata;
494 cb(handler, ret, cbdata);
498 static int send_mouse_event(struct livebox *handler, const char *event, double x, double y, int w, int h)
500 struct packet *packet;
503 timestamp = util_timestamp();
504 packet = packet_create_noack(event, "ssiiddd", handler->pkgname, handler->id, w, h,
507 ErrPrint("Failed to build param\n");
511 return master_rpc_request_only(handler, packet);
514 EAPI int livebox_init(void *disp)
518 if (s_info.init_count > 0) {
522 env = getenv("PROVIDER_DISABLE_PREVENT_OVERWRITE");
523 if (env && !strcasecmp(env, "true"))
524 s_info.prevent_overwrite = 1;
526 env = getenv("PROVIDER_EVENT_FILTER");
528 sscanf(env, "%lf", &MINIMUM_EVENT);
531 char filename[BUFSIZ];
532 snprintf(filename, sizeof(filename), "/tmp/%d.box.log", getpid());
533 __file_log_fp = fopen(filename, "w+t");
535 __file_log_fp = fdopen(1, "w+t");
537 critical_log_init("viewer");
538 livebox_service_init();
547 EAPI int livebox_fini(void)
549 if (s_info.init_count <= 0) {
550 DbgPrint("Didn't initialized\n");
555 if (s_info.init_count > 0) {
556 DbgPrint("init count : %d\n", s_info.init_count);
562 livebox_service_fini();
567 static inline char *lb_pkgname(const char *pkgname)
571 lb = livebox_service_pkgname(pkgname);
573 if (util_validate_livebox_package(pkgname) == 0)
574 return strdup(pkgname);
581 * Just wrapping the livebox_add_with_size function.
583 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)
585 return livebox_add_with_size(pkgname, content, cluster, category, period, LB_SIZE_TYPE_UNKNOWN, cb, data);
588 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)
590 struct livebox *handler;
591 struct packet *packet;
596 if (!pkgname || !cluster || !category || width < 0 || height < 0) {
597 ErrPrint("Invalid arguments: pkgname[%p], cluster[%p], category[%p]\n",
598 pkgname, cluster, category);
602 if (type != LB_SIZE_TYPE_UNKNOWN)
603 livebox_service_get_size(type, &width, &height);
605 handler = calloc(1, sizeof(*handler));
607 ErrPrint("Error: %s\n", strerror(errno));
611 handler->pkgname = lb_pkgname(pkgname);
612 if (!handler->pkgname) {
613 ErrPrint("Error: %s\n", strerror(errno));
618 if (livebox_service_is_enabled(handler->pkgname) == 0) {
619 DbgPrint("Livebox [%s](%s) is disabled package\n", handler->pkgname, pkgname);
620 free(handler->pkgname);
626 handler->content = strdup(content);
627 if (!handler->content) {
628 ErrPrint("Error: %s\n", strerror(errno));
629 free(handler->pkgname);
634 handler->content = livebox_service_content(handler->pkgname);
637 handler->cluster = strdup(cluster);
638 if (!handler->cluster) {
639 ErrPrint("Error: %s\n", strerror(errno));
640 free(handler->content);
641 free(handler->pkgname);
646 handler->category = strdup(category);
647 if (!handler->category) {
648 ErrPrint("Error: %s\n", strerror(errno));
649 free(handler->cluster);
650 free(handler->content);
651 free(handler->pkgname);
657 cb = default_create_cb;
659 /* Data provider will set this */
660 handler->lb.type = _LB_TYPE_FILE;
661 handler->pd.type = _PD_TYPE_SCRIPT;
662 handler->lb.period = period;
664 /* Used for handling the mouse event on a box */
665 handler->lb.mouse_event = livebox_service_mouse_event(handler->pkgname);
667 /* Cluster infomration is not determined yet */
668 handler->nr_of_sizes = 0x01;
670 handler->timestamp = util_timestamp();
671 handler->is_user = 1;
672 handler->visible = LB_SHOW;
674 s_info.livebox_list = dlist_append(s_info.livebox_list, handler);
676 packet = packet_create("new", "dssssdii", handler->timestamp, handler->pkgname, handler->content, cluster, category, period, width, height);
678 ErrPrint("Failed to create a new packet\n");
679 free(handler->category);
680 free(handler->cluster);
681 free(handler->content);
682 free(handler->pkgname);
687 ret = master_rpc_async_request(handler, packet, 0, new_ret_cb, create_cb_info(cb, data));
689 ErrPrint("Failed to send a new packet\n");
690 free(handler->category);
691 free(handler->cluster);
692 free(handler->content);
693 free(handler->pkgname);
698 DbgPrint("Successfully sent a new request ([%lf] %s)\n", handler->timestamp, handler->pkgname);
699 handler->state = CREATE;
700 return lb_ref(handler);
703 EAPI double livebox_period(struct livebox *handler)
705 if (!handler || handler->state != CREATE || !handler->id) {
706 ErrPrint("Handler is not valid\n");
710 return handler->lb.period;
713 EAPI int livebox_set_period(struct livebox *handler, double period, ret_cb_t cb, void *data)
715 struct packet *packet;
717 if (!handler || handler->state != CREATE || !handler->id) {
718 ErrPrint("Handler is not valid\n");
722 if (!handler->is_user) {
723 ErrPrint("CA Livebox is not able to change the period\n");
727 if (handler->lb.period == period) {
728 DbgPrint("No changes\n");
732 if (handler->period_changed_cb)
733 DbgPrint("Already requested\n");
735 packet = packet_create("set_period", "ssd", handler->pkgname, handler->id, period);
737 ErrPrint("Failed to build a packet %s\n", handler->pkgname);
742 cb = default_period_changed_cb;
744 return master_rpc_async_request(handler, packet, 0, period_ret_cb, create_cb_info(cb, data));
747 EAPI int livebox_del(struct livebox *handler, ret_cb_t cb, void *data)
750 ErrPrint("Handler is NIL\n");
754 if (handler->state != CREATE) {
755 ErrPrint("Handler is already deleted\n");
759 handler->state = DELETE;
764 * The id is not determined yet.
765 * It means a user didn't receive created event yet.
766 * Then just stop to delete procedure from here.
767 * Because the "created" event handler will release this.
768 * By the way, if the user adds any callback for getting return status of this,
772 cb(handler, 0, data);
777 cb = default_delete_cb;
779 return lb_send_delete(handler, cb, data);
782 EAPI int livebox_set_fault_handler(int (*cb)(enum livebox_fault_type, const char *, const char *, const char *, void *), void *data)
784 struct fault_info *info;
789 info = malloc(sizeof(*info));
791 CRITICAL_LOG("Heap: %s\n", strerror(errno));
796 info->user_data = data;
798 s_info.fault_list = dlist_append(s_info.fault_list, info);
802 EAPI void *livebox_unset_fault_handler(int (*cb)(enum livebox_fault_type, const char *, const char *, const char *, void *))
804 struct fault_info *info;
807 dlist_foreach(s_info.fault_list, l, info) {
808 if (info->handler == cb) {
810 s_info.fault_list = dlist_remove(s_info.fault_list, l);
811 data = info->user_data;
821 EAPI int livebox_set_event_handler(int (*cb)(struct livebox *, enum livebox_event_type, void *), void *data)
823 struct event_info *info;
826 ErrPrint("Invalid argument cb is nil\n");
830 info = malloc(sizeof(*info));
832 CRITICAL_LOG("Heap: %s\n", strerror(errno));
837 info->user_data = data;
839 s_info.event_list = dlist_append(s_info.event_list, info);
843 EAPI void *livebox_unset_event_handler(int (*cb)(struct livebox *, enum livebox_event_type, void *))
845 struct event_info *info;
848 dlist_foreach(s_info.event_list, l, info) {
849 if (info->handler == cb) {
852 s_info.event_list = dlist_remove(s_info.event_list, l);
853 data = info->user_data;
863 EAPI int livebox_resize(struct livebox *handler, int type, ret_cb_t cb, void *data)
865 struct packet *packet;
870 ErrPrint("Handler is NIL\n");
874 if (handler->state != CREATE || !handler->id) {
875 ErrPrint("Handler is not valid\n");
879 if (!handler->is_user) {
880 ErrPrint("CA Livebox is not able to be resized\n");
884 if (livebox_service_get_size(type, &w, &h) != 0) {
885 ErrPrint("Invalid size type\n");
889 if (handler->lb.width == w && handler->lb.height == h) {
890 DbgPrint("No changes\n");
894 if (handler->size_changed_cb)
895 DbgPrint("Already pended\n");
897 packet = packet_create("resize", "ssii", handler->pkgname, handler->id, w, h);
899 ErrPrint("Failed to build param\n");
904 cb = default_lb_size_changed_cb;
906 return master_rpc_async_request(handler, packet, 0, resize_cb, create_cb_info(cb, data));
909 EAPI int livebox_click(struct livebox *handler, double x, double y)
911 struct packet *packet;
916 ErrPrint("Handler is NIL\n");
920 if (handler->state != CREATE || !handler->id) {
921 ErrPrint("Handler is not valid\n");
925 if (handler->lb.auto_launch)
926 if (aul_launch_app(handler->lb.auto_launch, NULL) < 0)
927 ErrPrint("Failed to launch app %s\n", handler->lb.auto_launch);
929 timestamp = util_timestamp();
930 packet = packet_create_noack("clicked", "sssddd", handler->pkgname, handler->id, "clicked", timestamp, x, y);
932 ErrPrint("Failed to build param\n");
936 ret = master_rpc_request_only(handler, packet);
938 if (!handler->lb.mouse_event && (handler->lb.type == _LB_TYPE_BUFFER || handler->lb.type == _LB_TYPE_SCRIPT)) {
939 int ret; /* Shadow variable */
940 ret = send_mouse_event(handler, "lb_mouse_down", x, y, handler->lb.width, handler->lb.height);
942 DbgPrint("Failed to send Down: %d\n", ret);
944 ret = send_mouse_event(handler, "lb_mouse_move", x, y, handler->lb.width, handler->lb.height);
946 DbgPrint("Failed to send Move: %d\n", ret);
948 ret = send_mouse_event(handler, "lb_mouse_up", x, y, handler->lb.width, handler->lb.height);
950 DbgPrint("Failed to send Up: %d\n", ret);
956 EAPI int livebox_has_pd(struct livebox *handler)
959 ErrPrint("Handler is NIL\n");
963 if (handler->state != CREATE || !handler->id) {
964 ErrPrint("Handler is not valid\n");
968 return !!handler->pd.data.fb;
971 EAPI int livebox_pd_is_created(struct livebox *handler)
974 ErrPrint("Handler is NIL\n");
978 if (!handler->pd.data.fb || handler->state != CREATE || !handler->id) {
979 ErrPrint("Handler is not valid\n");
983 return handler->is_pd_created;
986 EAPI int livebox_create_pd(struct livebox *handler, ret_cb_t cb, void *data)
988 return livebox_create_pd_with_position(handler, -1.0, -1.0, cb, data);
991 EAPI int livebox_create_pd_with_position(struct livebox *handler, double x, double y, ret_cb_t cb, void *data)
993 struct packet *packet;
996 ErrPrint("Handler is NIL\n");
1000 if (!handler->pd.data.fb || handler->state != CREATE || !handler->id) {
1001 ErrPrint("Handler is not valid\n");
1005 if (handler->is_pd_created == 1) {
1006 DbgPrint("PD already created\n");
1010 packet = packet_create("create_pd", "ssdd", handler->pkgname, handler->id, x, y);
1012 ErrPrint("Failed to build param\n");
1017 handler->pd_created_cb = default_pd_created_cb;
1019 return master_rpc_async_request(handler, packet, 0, pd_create_cb, create_cb_info(cb, data));
1022 EAPI int livebox_move_pd(struct livebox *handler, double x, double y)
1024 struct packet *packet;
1027 ErrPrint("Handler is NIL\n");
1031 if (!handler->pd.data.fb || handler->state != CREATE || !handler->id) {
1032 ErrPrint("Handler is not valid\n");
1036 if (!handler->is_pd_created) {
1037 DbgPrint("PD is not created\n");
1041 packet = packet_create_noack("pd_move", "ssdd", handler->pkgname, handler->id, x, y);
1043 ErrPrint("Failed to build param\n");
1047 return master_rpc_request_only(handler, packet);
1050 EAPI int livebox_activate(const char *pkgname, ret_cb_t cb, void *data)
1052 struct packet *packet;
1057 packet = packet_create("activate_package", "s", pkgname);
1059 ErrPrint("Failed to build a param\n");
1063 return master_rpc_async_request(NULL, packet, 0, activated_cb, create_cb_info(cb, data));
1066 EAPI int livebox_destroy_pd(struct livebox *handler, ret_cb_t cb, void *data)
1068 struct packet *packet;
1071 ErrPrint("Handler is NIL\n");
1075 if (!handler->pd.data.fb || handler->state != CREATE || !handler->id) {
1076 ErrPrint("Handler is not valid\n");
1080 if (!handler->is_pd_created) {
1081 ErrPrint("PD is not created\n");
1085 packet = packet_create("destroy_pd", "ss", handler->pkgname, handler->id);
1087 ErrPrint("Failed to build a param\n");
1092 cb = default_pd_destroyed_cb;
1094 return master_rpc_async_request(handler, packet, 0, pd_destroy_cb, create_cb_info(cb, data));
1097 EAPI int livebox_content_event(struct livebox *handler, enum content_event_type type, double x, double y)
1101 char cmd[20] = { '\0', };
1105 ErrPrint("Handler is NIL\n");
1109 if (handler->state != CREATE || !handler->id) {
1110 ErrPrint("Handler is not valid\n");
1114 if (type & CONTENT_EVENT_PD_MASK) {
1115 if (!handler->is_pd_created) {
1116 ErrPrint("PD is not created\n");
1120 if (type & CONTENT_EVENT_MOUSE_MASK) {
1121 if (!handler->pd.data.fb) {
1122 ErrPrint("Handler is not valid\n");
1126 if (type & CONTENT_EVENT_MOUSE_MOVE) {
1127 if (fabs(x - handler->pd.x) < MINIMUM_EVENT && fabs(y - handler->pd.y) < MINIMUM_EVENT)
1132 w = handler->pd.width;
1133 h = handler->pd.height;
1139 if (type & CONTENT_EVENT_MOUSE_MASK) {
1140 if (!handler->lb.mouse_event) {
1141 ErrPrint("Box is not support the mouse event\n");
1145 if (!handler->lb.data.fb) {
1146 ErrPrint("Handler is not valid\n");
1150 if (type & CONTENT_EVENT_MOUSE_MOVE) {
1151 if (fabs(x - handler->lb.x) < MINIMUM_EVENT && fabs(y - handler->lb.y) < MINIMUM_EVENT)
1156 w = handler->lb.width;
1157 h = handler->lb.height;
1164 switch ((type & ~CONTENT_EVENT_PD_MASK)) {
1165 case CONTENT_EVENT_ACCESS_READ | CONTENT_EVENT_ACCESS_MASK:
1166 strcpy(ptr, "_access_read");
1168 case CONTENT_EVENT_ACCESS_READ_PREV | CONTENT_EVENT_ACCESS_MASK:
1169 strcpy(ptr, "_access_read_prev");
1171 case CONTENT_EVENT_ACCESS_READ_NEXT | CONTENT_EVENT_ACCESS_MASK:
1172 strcpy(ptr, "_access_read_next");
1174 case CONTENT_EVENT_ACCESS_ACTIVATE | CONTENT_EVENT_ACCESS_MASK:
1175 strcpy(ptr, "_access_activate");
1177 case CONTENT_EVENT_ACCESS_UP | CONTENT_EVENT_ACCESS_MASK:
1178 strcpy(ptr, "_access_up");
1180 case CONTENT_EVENT_ACCESS_DOWN | CONTENT_EVENT_ACCESS_MASK:
1181 strcpy(ptr, "_access_down");
1183 case CONTENT_EVENT_MOUSE_ENTER | CONTENT_EVENT_MOUSE_MASK:
1184 strcpy(ptr, "_mouse_enter");
1186 case CONTENT_EVENT_MOUSE_LEAVE | CONTENT_EVENT_MOUSE_MASK:
1187 strcpy(ptr, "_mouse_leave");
1189 case CONTENT_EVENT_MOUSE_UP | CONTENT_EVENT_MOUSE_MASK:
1190 strcpy(ptr, "_mouse_up");
1192 case CONTENT_EVENT_MOUSE_DOWN | CONTENT_EVENT_MOUSE_MASK:
1193 strcpy(ptr, "_mouse_down");
1195 case CONTENT_EVENT_MOUSE_MOVE | CONTENT_EVENT_MOUSE_MASK:
1196 strcpy(ptr, "_mouse_move");
1198 case CONTENT_EVENT_KEY_DOWN | CONTENT_EVENT_KEY_MASK:
1199 strcpy(ptr, "_key_down");
1201 case CONTENT_EVENT_KEY_UP | CONTENT_EVENT_KEY_MASK:
1202 strcpy(ptr, "_key_up");
1205 ErrPrint("Invalid event type\n");
1209 return send_mouse_event(handler, cmd, x, y, w, h);
1212 EAPI const char *livebox_filename(struct livebox *handler)
1215 ErrPrint("Handler is NIL\n");
1219 if (handler->state != CREATE || !handler->id) {
1220 ErrPrint("Handler is not valid\n");
1224 if (handler->filename)
1225 return handler->filename;
1228 return util_uri_to_path(handler->id);
1231 EAPI int livebox_get_pdsize(struct livebox *handler, int *w, int *h)
1237 ErrPrint("Handler is NIL\n");
1241 if (handler->state != CREATE || !handler->id) {
1242 ErrPrint("Handler is not valid\n");
1251 if (!handler->is_pd_created) {
1252 DbgPrint("Buffer is not created yet [%dx%d]\n", *w, *h);
1253 *w = handler->pd.default_width;
1254 *h = handler->pd.default_height;
1256 *w = handler->pd.width;
1257 *h = handler->pd.height;
1263 EAPI int livebox_size(struct livebox *handler)
1269 ErrPrint("Handler is NIL\n");
1273 if (handler->state != CREATE || !handler->id) {
1274 ErrPrint("Handler is not valid\n");
1278 w = handler->lb.width;
1279 h = handler->lb.height;
1281 switch (handler->lb.type) {
1282 case _LB_TYPE_BUFFER:
1283 case _LB_TYPE_SCRIPT:
1284 if (!fb_is_created(handler->lb.data.fb)) {
1285 DbgPrint("Buffer is not created yet - reset size\n");
1294 return livebox_service_size_type(w, h);
1297 EAPI int livebox_set_group(struct livebox *handler, const char *cluster, const char *category, ret_cb_t cb, void *data)
1299 struct packet *packet;
1302 ErrPrint("Handler is NIL\n");
1306 if (!cluster || !category || handler->state != CREATE || !handler->id) {
1307 ErrPrint("Invalid argument\n");
1311 if (!handler->is_user) {
1312 ErrPrint("CA Livebox is not able to change the group\n");
1316 if (!strcmp(handler->cluster, cluster) && !strcmp(handler->category, category)) {
1317 DbgPrint("No changes\n");
1321 if (handler->group_changed_cb)
1322 DbgPrint("Already sent\n");
1324 packet = packet_create("change_group", "ssss", handler->pkgname, handler->id, cluster, category);
1326 ErrPrint("Failed to build a param\n");
1331 cb = default_group_changed_cb;
1333 return master_rpc_async_request(handler, packet, 0, set_group_ret_cb, create_cb_info(cb, data));
1336 EAPI int livebox_get_group(struct livebox *handler, char ** const cluster, char ** const category)
1339 ErrPrint("Handler is NIL\n");
1343 if (!cluster || !category || handler->state != CREATE || !handler->id) {
1344 ErrPrint("Invalid argument\n");
1348 *cluster = handler->cluster;
1349 *category = handler->category;
1353 EAPI int livebox_get_supported_sizes(struct livebox *handler, int *cnt, int *size_list)
1358 if (!handler || !size_list) {
1359 ErrPrint("Invalid argument, handler(%p), size_list(%p)\n", handler, size_list);
1363 if (!cnt || handler->state != CREATE || !handler->id) {
1364 ErrPrint("Handler is not valid\n");
1368 for (j = i = 0; i < NR_OF_SIZE_LIST; i++) {
1369 if (handler->lb.size_list & (0x01 << i)) {
1373 size_list[j++] = (0x01 << i);
1381 EAPI const char *livebox_pkgname(struct livebox *handler)
1384 ErrPrint("Handler is NIL\n");
1388 if (handler->state != CREATE) {
1389 ErrPrint("Handler is not valid\n");
1393 return handler->pkgname;
1396 EAPI double livebox_priority(struct livebox *handler)
1399 ErrPrint("Handler is NIL\n");
1403 if (handler->state != CREATE || !handler->id) {
1404 ErrPrint("Handler is not valid (%p)\n", handler);
1408 return handler->lb.priority;
1411 EAPI int livebox_delete_cluster(const char *cluster, ret_cb_t cb, void *data)
1413 struct packet *packet;
1415 packet = packet_create("delete_cluster", "s", cluster);
1417 ErrPrint("Failed to build a param\n");
1421 return master_rpc_async_request(NULL, packet, 0, delete_cluster_cb, create_cb_info(cb, data));
1424 EAPI int livebox_delete_category(const char *cluster, const char *category, ret_cb_t cb, void *data)
1426 struct packet *packet;
1428 packet = packet_create("delete_category", "ss", cluster, category);
1430 ErrPrint("Failed to build a param\n");
1434 return master_rpc_async_request(NULL, packet, 0, delete_category_cb, create_cb_info(cb, data));
1437 EAPI enum livebox_lb_type livebox_lb_type(struct livebox *handler)
1440 ErrPrint("Handler is NIL\n");
1441 return LB_TYPE_INVALID;
1444 if (handler->state != CREATE || !handler->id) {
1445 ErrPrint("Handler is not valid\n");
1446 return LB_TYPE_INVALID;
1449 switch (handler->lb.type) {
1451 return LB_TYPE_IMAGE;
1452 case _LB_TYPE_BUFFER:
1453 case _LB_TYPE_SCRIPT:
1456 id = fb_id(handler->lb.data.fb);
1457 if (id && !strncasecmp(id, SCHEMA_PIXMAP, strlen(SCHEMA_PIXMAP)))
1458 return LB_TYPE_PIXMAP;
1460 return LB_TYPE_BUFFER;
1462 return LB_TYPE_TEXT;
1467 return LB_TYPE_INVALID;
1470 EAPI enum livebox_pd_type livebox_pd_type(struct livebox *handler)
1473 ErrPrint("Handler is NIL\n");
1474 return PD_TYPE_INVALID;
1477 if (handler->state != CREATE || !handler->id) {
1478 ErrPrint("Handler is not valid\n");
1479 return PD_TYPE_INVALID;
1482 switch (handler->pd.type) {
1484 return PD_TYPE_TEXT;
1485 case _PD_TYPE_BUFFER:
1486 case _PD_TYPE_SCRIPT:
1489 id = fb_id(handler->pd.data.fb);
1490 if (id && !strncasecmp(id, SCHEMA_PIXMAP, strlen(SCHEMA_PIXMAP)))
1491 return PD_TYPE_PIXMAP;
1493 return PD_TYPE_BUFFER;
1498 return PD_TYPE_INVALID;
1501 EAPI int livebox_set_pd_text_handler(struct livebox *handler, struct livebox_script_operators *ops)
1504 ErrPrint("Handler is NIL\n");
1508 if (handler->state != CREATE) {
1509 ErrPrint("Handler is not valid\n");
1513 memcpy(&handler->pd.data.ops, ops, sizeof(*ops));
1517 EAPI int livebox_set_text_handler(struct livebox *handler, struct livebox_script_operators *ops)
1520 ErrPrint("Handler is NIL\n");
1524 if (handler->state != CREATE) {
1525 ErrPrint("Handler is not valid\n");
1529 memcpy(&handler->lb.data.ops, ops, sizeof(*ops));
1533 EAPI int livebox_acquire_lb_pixmap(struct livebox *handler, ret_cb_t cb, void *data)
1535 struct packet *packet;
1539 ErrPrint("Handler is NIL\n");
1543 if (handler->state != CREATE || !handler->id) {
1544 ErrPrint("Invalid handle\n");
1548 if (handler->lb.type != _LB_TYPE_SCRIPT && handler->lb.type != _LB_TYPE_BUFFER) {
1549 ErrPrint("Handler is not valid type\n");
1553 id = fb_id(handler->lb.data.fb);
1554 if (!id || strncasecmp(id, SCHEMA_PIXMAP, strlen(SCHEMA_PIXMAP)))
1557 packet = packet_create("lb_acquire_pixmap", "ss", handler->pkgname, handler->id);
1559 ErrPrint("Failed to build a param\n");
1563 return master_rpc_async_request(handler, packet, 0, pixmap_acquired_cb, create_cb_info(cb, data));
1566 EAPI int livebox_release_lb_pixmap(struct livebox *handler, int pixmap)
1568 struct packet *packet;
1571 ErrPrint("Handler is NIL\n");
1575 if (handler->state != CREATE || !handler->id) {
1576 ErrPrint("Invalid handle\n");
1580 if (handler->lb.type != _LB_TYPE_SCRIPT && handler->lb.type != _LB_TYPE_BUFFER) {
1581 ErrPrint("Handler is not valid type\n");
1585 packet = packet_create_noack("lb_release_pixmap", "ssi", handler->pkgname, handler->id, pixmap);
1587 ErrPrint("Failed to build a param\n");
1591 return master_rpc_request_only(handler, packet);
1594 EAPI int livebox_acquire_pd_pixmap(struct livebox *handler, ret_cb_t cb, void *data)
1596 struct packet *packet;
1600 ErrPrint("Handler is NIL\n");
1604 if (handler->state != CREATE || !handler->id) {
1605 ErrPrint("Invalid handle\n");
1609 if (handler->pd.type != _PD_TYPE_SCRIPT && handler->pd.type != _PD_TYPE_BUFFER) {
1610 ErrPrint("Handler is not valid type\n");
1614 id = fb_id(handler->pd.data.fb);
1615 if (!id || strncasecmp(id, SCHEMA_PIXMAP, strlen(SCHEMA_PIXMAP)))
1618 packet = packet_create("pd_acquire_pixmap", "ss", handler->pkgname, handler->id);
1620 ErrPrint("Failed to build a param\n");
1624 return master_rpc_async_request(handler, packet, 0, pixmap_acquired_cb, create_cb_info(cb, data));
1627 EAPI int livebox_pd_pixmap(const struct livebox *handler)
1633 ErrPrint("Handler is NIL\n");
1637 if (handler->state != CREATE || !handler->id) {
1638 ErrPrint("Invalid handler\n");
1642 if (handler->pd.type != _PD_TYPE_SCRIPT && handler->pd.type != _PD_TYPE_BUFFER) {
1643 ErrPrint("Invalid handler\n");
1647 id = fb_id(handler->pd.data.fb);
1648 if (id && sscanf(id, SCHEMA_PIXMAP "%d", &pixmap) != 1) {
1649 ErrPrint("PIXMAP Id is not valid\n");
1656 EAPI int livebox_lb_pixmap(const struct livebox *handler)
1662 ErrPrint("Handler is NIL\n");
1666 if (handler->state != CREATE || !handler->id) {
1667 ErrPrint("Invalid handler\n");
1671 if (handler->lb.type != _LB_TYPE_SCRIPT && handler->lb.type != _LB_TYPE_BUFFER) {
1672 ErrPrint("Invalid handler\n");
1676 id = fb_id(handler->lb.data.fb);
1677 if (id && sscanf(id, SCHEMA_PIXMAP "%d", &pixmap) != 1) {
1678 ErrPrint("PIXMAP Id is not valid\n");
1685 EAPI int livebox_release_pd_pixmap(struct livebox *handler, int pixmap)
1687 struct packet *packet;
1690 ErrPrint("Handler is NIL\n");
1694 if (handler->state != CREATE || !handler->id) {
1695 ErrPrint("Invalid handle\n");
1699 if (handler->pd.type != _PD_TYPE_SCRIPT && handler->pd.type != _PD_TYPE_BUFFER) {
1700 ErrPrint("Handler is not valid type\n");
1704 packet = packet_create_noack("pd_release_pixmap", "ssi", handler->pkgname, handler->id, pixmap);
1706 ErrPrint("Failed to build a param\n");
1710 return master_rpc_request_only(handler, packet);
1713 EAPI void *livebox_acquire_fb(struct livebox *handler)
1716 ErrPrint("Handler is NIL\n");
1720 if (handler->state != CREATE || !handler->id) {
1721 ErrPrint("Invalid handle\n");
1725 if (handler->lb.type != _LB_TYPE_SCRIPT && handler->lb.type != _LB_TYPE_BUFFER) {
1726 ErrPrint("Handler is not valid type\n");
1730 return fb_acquire_buffer(handler->lb.data.fb);
1733 EAPI int livebox_release_fb(void *buffer)
1735 return fb_release_buffer(buffer);
1738 EAPI int livebox_fb_refcnt(void *buffer)
1740 return fb_refcnt(buffer);
1743 EAPI void *livebox_acquire_pdfb(struct livebox *handler)
1746 ErrPrint("Handler is NIL\n");
1750 if (handler->state != CREATE || !handler->id) {
1751 ErrPrint("Invalid handler\n");
1755 if (handler->pd.type != _PD_TYPE_SCRIPT && handler->pd.type != _PD_TYPE_BUFFER) {
1756 ErrPrint("Handler is not valid type\n");
1760 return fb_acquire_buffer(handler->pd.data.fb);
1763 EAPI int livebox_release_pdfb(void *buffer)
1765 return fb_release_buffer(buffer);
1768 EAPI int livebox_pdfb_refcnt(void *buffer)
1770 return fb_refcnt(buffer);
1773 EAPI int livebox_pdfb_bufsz(struct livebox *handler)
1776 ErrPrint("Handler is NIL\n");
1780 if (handler->state != CREATE || !handler->id) {
1781 ErrPrint("Handler is not valid\n");
1785 return fb_size(handler->pd.data.fb);
1788 EAPI int livebox_lbfb_bufsz(struct livebox *handler)
1791 ErrPrint("Handler is NIL\n");
1795 if (handler->state != CREATE || !handler->id) {
1796 ErrPrint("Handler is not valid\n");
1800 return fb_size(handler->lb.data.fb);
1803 EAPI int livebox_is_user(struct livebox *handler)
1806 ErrPrint("Handler is NIL\n");
1810 if (handler->state != CREATE) {
1811 ErrPrint("Handler is invalid\n");
1815 return handler->is_user;
1818 EAPI int livebox_set_pinup(struct livebox *handler, int flag, ret_cb_t cb, void *data)
1820 struct packet *packet;
1823 ErrPrint("Handler is NIL\n");
1827 if (handler->state != CREATE || !handler->id) {
1828 ErrPrint("Handler is not valid\n");
1832 if (handler->is_pinned_up == flag) {
1833 DbgPrint("No changes\n");
1837 if (handler->pinup_cb)
1838 DbgPrint("Already sent\n");
1840 packet = packet_create("pinup_changed", "ssi", handler->pkgname, handler->id, flag);
1842 ErrPrint("Failed to build a param\n");
1847 cb = default_pinup_cb;
1849 return master_rpc_async_request(handler, packet, 0, pinup_done_cb, create_cb_info(cb, data));
1852 EAPI int livebox_is_pinned_up(struct livebox *handler)
1855 ErrPrint("Handler is NIL\n");
1859 if (handler->state != CREATE || !handler->id)
1862 return handler->is_pinned_up;
1865 EAPI int livebox_has_pinup(struct livebox *handler)
1868 ErrPrint("Handler is NIL\n");
1872 if (handler->state != CREATE || !handler->id)
1875 return handler->lb.pinup_supported;
1878 EAPI int livebox_set_data(struct livebox *handler, void *data)
1881 ErrPrint("Handler is NIL\n");
1885 if (handler->state != CREATE)
1888 handler->data = data;
1892 EAPI void *livebox_get_data(struct livebox *handler)
1895 ErrPrint("Handler is NIL\n");
1899 if (handler->state != CREATE)
1902 return handler->data;
1905 EAPI int livebox_is_exists(const char *pkgname)
1909 lb = lb_pkgname(pkgname);
1918 EAPI const char *livebox_content(struct livebox *handler)
1921 ErrPrint("Handler is NIL\n");
1925 if (handler->state != CREATE)
1928 return handler->content;
1931 EAPI const char *livebox_category_title(struct livebox *handler)
1934 ErrPrint("Handler is NIL\n");
1938 if (handler->state != CREATE)
1941 return handler->title;
1944 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)
1946 struct packet *packet;
1949 ErrPrint("Handler is NIL\n");
1953 if ((handler->lb.type != _LB_TYPE_TEXT && handler->pd.type != _PD_TYPE_TEXT) || handler->state != CREATE || !handler->id) {
1954 ErrPrint("Handler is not valid\n");
1964 packet = packet_create("text_signal", "ssssdddd",
1965 handler->pkgname, handler->id, emission, source, sx, sy, ex, ey);
1967 ErrPrint("Failed to build a param\n");
1971 return master_rpc_async_request(handler, packet, 0, text_signal_cb, create_cb_info(cb, data));
1974 EAPI int livebox_subscribe_group(const char *cluster, const char *category)
1976 struct packet *packet;
1980 * Validate the group info using DB
1981 * If the group info is not valid, do not send this request
1984 packet = packet_create_noack("subscribe", "ss", cluster ? cluster : "", category ? category : "");
1986 ErrPrint("Failed to create a packet\n");
1990 return master_rpc_request_only(NULL, packet);
1993 EAPI int livebox_unsubscribe_group(const char *cluster, const char *category)
1995 struct packet *packet;
1999 * Validate the group info using DB
2000 * If the group info is not valid, do not send this request
2001 * AND Check the subscribed or not too
2004 packet = packet_create_noack("unsubscribe", "ss", cluster ? cluster : "", category ? category : "");
2006 ErrPrint("Failed to create a packet\n");
2010 return master_rpc_request_only(NULL, packet);
2013 EAPI int livebox_refresh(struct livebox *handler)
2015 struct packet *packet;
2018 ErrPrint("Hnalder is NIL\n");
2022 if (handler->state != CREATE || !handler->id)
2025 packet = packet_create_noack("update", "ss", handler->pkgname, handler->id);
2027 ErrPrint("Failed to create a packet\n");
2031 return master_rpc_request_only(handler, packet);
2034 EAPI int livebox_refresh_group(const char *cluster, const char *category)
2036 struct packet *packet;
2038 if (!cluster || !category) {
2039 ErrPrint("Invalid argument\n");
2043 packet = packet_create_noack("refresh_group", "ss", cluster, category);
2045 ErrPrint("Failed to create a packet\n");
2049 return master_rpc_request_only(NULL, packet);
2052 EAPI int livebox_set_visibility(struct livebox *handler, enum livebox_visible_state state)
2054 struct packet *packet;
2058 ErrPrint("Handler is NIL\n");
2062 if (handler->state != CREATE || !handler->id)
2065 if (!handler->is_user) {
2066 /* System cluster livebox cannot be changed its visible states */
2067 if (state == LB_HIDE_WITH_PAUSE) {
2068 ErrPrint("CA Livebox is not able to change the visibility\n");
2073 if (handler->visible == state)
2076 packet = packet_create_noack("change,visibility", "ssi", handler->pkgname, handler->id, (int)state);
2078 ErrPrint("Failed to create a packet\n");
2082 ret = master_rpc_request_only(handler, packet);
2084 handler->visible = state;
2089 EAPI enum livebox_visible_state livebox_visibility(struct livebox *handler)
2092 ErrPrint("Handler is NIL\n");
2093 return LB_VISIBLE_ERROR;
2096 if (handler->state != CREATE)
2097 return LB_VISIBLE_ERROR;
2099 return handler->visible;
2102 int lb_set_group(struct livebox *handler, const char *cluster, const char *category)
2108 pc = strdup(cluster);
2110 CRITICAL_LOG("Heap: %s (cluster: %s)\n", strerror(errno), cluster);
2116 ps = strdup(category);
2118 CRITICAL_LOG("Heap: %s (category: %s)\n", strerror(errno), category);
2124 if (handler->cluster)
2125 free(handler->cluster);
2127 if (handler->category)
2128 free(handler->category);
2130 handler->cluster = pc;
2131 handler->category = ps;
2136 void lb_set_size(struct livebox *handler, int w, int h)
2138 handler->lb.width = w;
2139 handler->lb.height = h;
2142 void lb_set_pdsize(struct livebox *handler, int w, int h)
2144 handler->pd.width = w;
2145 handler->pd.height = h;
2148 void lb_set_default_pdsize(struct livebox *handler, int w, int h)
2150 handler->pd.default_width = w;
2151 handler->pd.default_height = h;
2154 void lb_invoke_fault_handler(enum livebox_fault_type event, const char *pkgname, const char *file, const char *func)
2158 struct fault_info *info;
2160 dlist_foreach_safe(s_info.fault_list, l, n, info) {
2161 if (info->handler(event, pkgname, file, func, info->user_data) == EXIT_FAILURE)
2162 s_info.fault_list = dlist_remove(s_info.fault_list, l);
2166 void lb_invoke_event_handler(struct livebox *handler, enum livebox_event_type event)
2170 struct event_info *info;
2172 dlist_foreach_safe(s_info.event_list, l, n, info) {
2173 if (info->handler(handler, event, info->user_data) == EXIT_FAILURE)
2174 s_info.event_list = dlist_remove(s_info.event_list, l);
2178 struct livebox *lb_find_livebox(const char *pkgname, const char *id)
2181 struct livebox *handler;
2183 dlist_foreach(s_info.livebox_list, l, handler) {
2187 if (!strcmp(handler->pkgname, pkgname) && !strcmp(handler->id, id))
2194 struct livebox *lb_find_livebox_by_timestamp(double timestamp)
2197 struct livebox *handler;
2199 dlist_foreach(s_info.livebox_list, l, handler) {
2200 if (handler->timestamp == timestamp)
2207 static inline char *get_file_kept_in_safe(const char *id)
2214 path = util_uri_to_path(id);
2216 ErrPrint("Invalid URI(%s)\n", id);
2223 if (s_info.prevent_overwrite) {
2224 new_path = strdup(path);
2226 ErrPrint("Heap: %s\n", strerror(errno));
2235 while (base_idx > 0 && path[base_idx] != '/') base_idx--;
2236 base_idx += (path[base_idx] == '/');
2238 new_path = malloc(len + 10);
2240 ErrPrint("Heap: %s\n", strerror(errno));
2244 strncpy(new_path, path, base_idx);
2245 snprintf(new_path + base_idx, len + 10 - base_idx, "reader/%s", path + base_idx);
2249 struct livebox *lb_new_livebox(const char *pkgname, const char *id, double timestamp)
2251 struct livebox *handler;
2253 handler = calloc(1, sizeof(*handler));
2255 ErrPrint("Failed to create a new livebox\n");
2259 handler->pkgname = strdup(pkgname);
2260 if (!handler->pkgname) {
2261 ErrPrint("%s\n", strerror(errno));
2266 handler->id = strdup(id);
2268 ErrPrint("%s\n", strerror(errno));
2269 free(handler->pkgname);
2274 handler->filename = get_file_kept_in_safe(id);
2275 if (!handler->filename) {
2276 handler->filename = strdup(util_uri_to_path(id));
2277 if (!handler->filename)
2278 ErrPrint("Error: %s\n", strerror(errno));
2281 handler->timestamp = timestamp;
2282 handler->lb.type = _LB_TYPE_FILE;
2283 handler->pd.type = _PD_TYPE_SCRIPT;
2284 handler->state = CREATE;
2285 handler->visible = LB_SHOW;
2287 s_info.livebox_list = dlist_append(s_info.livebox_list, handler);
2292 int lb_delete_all(void)
2296 struct livebox *handler;
2298 dlist_foreach_safe(s_info.livebox_list, l, n, handler) {
2299 lb_invoke_event_handler(handler, LB_EVENT_DELETED);
2306 int lb_set_content(struct livebox *handler, const char *content)
2308 if (handler->content) {
2309 free(handler->content);
2310 handler->content = NULL;
2314 handler->content = strdup(content);
2315 if (!handler->content) {
2316 CRITICAL_LOG("Heap: %s (content: %s)\n", strerror(errno), content);
2324 int lb_set_title(struct livebox *handler, const char *title)
2326 if (handler->title) {
2327 free(handler->title);
2328 handler->title = NULL;
2332 handler->title = strdup(title);
2333 if (!handler->title) {
2334 CRITICAL_LOG("Heap: %s (title: %s)\n", strerror(errno), title);
2342 void lb_set_size_list(struct livebox *handler, int size_list)
2344 handler->lb.size_list = size_list;
2347 void lb_set_auto_launch(struct livebox *handler, const char *auto_launch)
2349 if (!strlen(auto_launch))
2352 handler->lb.auto_launch = strdup(auto_launch);
2353 if (!handler->lb.auto_launch)
2354 ErrPrint("Heap: %s\n", strerror(errno));
2357 void lb_set_priority(struct livebox *handler, double priority)
2359 handler->lb.priority = priority;
2362 void lb_set_id(struct livebox *handler, const char *id)
2367 handler->id = strdup(id);
2369 ErrPrint("Error: %s\n", strerror(errno));
2371 if (handler->filename)
2372 free(handler->filename);
2374 handler->filename = get_file_kept_in_safe(id);
2375 if (!handler->filename) {
2376 handler->filename = strdup(util_uri_to_path(id));
2377 if (!handler->filename)
2378 ErrPrint("Error: %s\n", strerror(errno));
2382 int lb_set_lb_fb(struct livebox *handler, const char *filename)
2389 fb = handler->lb.data.fb;
2390 if (fb && !strcmp(fb_id(fb), filename)) /*!< BUFFER is not changed, */
2393 handler->lb.data.fb = NULL;
2395 if (!filename || filename[0] == '\0') {
2401 handler->lb.data.fb = fb_create(filename, handler->lb.width, handler->lb.height);
2402 if (!handler->lb.data.fb) {
2403 ErrPrint("Faield to create a FB\n");
2415 int lb_set_pd_fb(struct livebox *handler, const char *filename)
2422 fb = handler->pd.data.fb;
2423 if (fb && !strcmp(fb_id(fb), filename)) {
2424 /* BUFFER is not changed, just update the content */
2427 handler->pd.data.fb = NULL;
2429 if (!filename || filename[0] == '\0') {
2435 handler->pd.data.fb = fb_create(filename, handler->pd.width, handler->pd.height);
2436 if (!handler->pd.data.fb) {
2437 ErrPrint("Failed to create a FB\n");
2448 struct fb_info *lb_get_lb_fb(struct livebox *handler)
2450 return handler->lb.data.fb;
2453 struct fb_info *lb_get_pd_fb(struct livebox *handler)
2455 return handler->pd.data.fb;
2458 void lb_set_user(struct livebox *handler, int user)
2460 handler->is_user = user;
2463 void lb_set_pinup(struct livebox *handler, int pinup_supported)
2465 handler->lb.pinup_supported = pinup_supported;
2468 void lb_set_text_lb(struct livebox *handler)
2470 handler->lb.type = _LB_TYPE_TEXT;
2473 void lb_set_text_pd(struct livebox *handler)
2475 handler->pd.type = _PD_TYPE_TEXT;
2478 int lb_text_lb(struct livebox *handler)
2480 return handler->lb.type == _LB_TYPE_TEXT;
2483 int lb_text_pd(struct livebox *handler)
2485 return handler->pd.type == _PD_TYPE_TEXT;
2488 void lb_set_period(struct livebox *handler, double period)
2490 handler->lb.period = period;
2493 struct livebox *lb_ref(struct livebox *handler)
2502 struct livebox *lb_unref(struct livebox *handler)
2508 if (handler->refcnt > 0)
2511 dlist_remove_data(s_info.livebox_list, handler);
2513 handler->state = DESTROYED;
2514 free(handler->cluster);
2515 free(handler->category);
2517 free(handler->pkgname);
2518 free(handler->filename);
2519 free(handler->lb.auto_launch);
2521 if (handler->lb.data.fb) {
2522 fb_destroy(handler->lb.data.fb);
2523 handler->lb.data.fb = NULL;
2526 if (handler->pd.data.fb) {
2527 fb_destroy(handler->pd.data.fb);
2528 handler->pd.data.fb = NULL;
2535 int lb_send_delete(struct livebox *handler, ret_cb_t cb, void *data)
2537 struct packet *packet;
2539 if (!cb && !!data) {
2540 ErrPrint("Invalid argument\n");
2544 if (handler->deleted_cb) {
2545 ErrPrint("Already in-progress\n");
2546 return -EINPROGRESS;
2549 packet = packet_create("delete", "ss", handler->pkgname, handler->id);
2551 ErrPrint("Failed to build a param\n");
2553 cb(handler, -EFAULT, data);
2559 cb = default_delete_cb;
2561 return master_rpc_async_request(handler, packet, 0, del_ret_cb, create_cb_info(cb, data));
2564 EAPI int livebox_client_paused(void)
2566 struct packet *packet;
2568 packet = packet_create_noack("client_paused", "d", util_timestamp());
2570 ErrPrint("Failed to create a pause packet\n");
2574 return master_rpc_request_only(NULL, packet);
2577 EAPI int livebox_client_resumed(void)
2579 struct packet *packet;
2581 packet = packet_create_noack("client_resumed", "d", util_timestamp());
2583 ErrPrint("Failed to create a resume packet\n");
2587 return master_rpc_request_only(NULL, packet);