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, int x, int y)
500 struct packet *packet;
503 timestamp = util_timestamp();
504 packet = packet_create_noack(event, "ssdii", handler->pkgname, handler->id, timestamp, x, y);
506 ErrPrint("Failed to build param\n");
510 DbgPrint("Send: %dx%d\n", x, y);
512 return master_rpc_request_only(handler, packet);
515 EAPI int livebox_init(void *disp)
519 if (s_info.init_count > 0) {
523 env = getenv("PROVIDER_DISABLE_PREVENT_OVERWRITE");
524 if (env && !strcasecmp(env, "true"))
525 s_info.prevent_overwrite = 1;
527 env = getenv("PROVIDER_EVENT_FILTER");
529 sscanf(env, "%lf", &MINIMUM_EVENT);
532 char filename[BUFSIZ];
533 snprintf(filename, sizeof(filename), "/tmp/%d.box.log", getpid());
534 __file_log_fp = fopen(filename, "w+t");
536 __file_log_fp = fdopen(1, "w+t");
538 critical_log_init("viewer");
539 livebox_service_init();
548 EAPI int livebox_fini(void)
550 if (s_info.init_count <= 0) {
551 DbgPrint("Didn't initialized\n");
556 if (s_info.init_count > 0) {
557 DbgPrint("init count : %d\n", s_info.init_count);
563 livebox_service_fini();
568 static inline char *lb_pkgname(const char *pkgname)
572 lb = livebox_service_pkgname(pkgname);
574 if (util_validate_livebox_package(pkgname) == 0)
575 return strdup(pkgname);
582 * Just wrapping the livebox_add_with_size function.
584 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)
586 return livebox_add_with_size(pkgname, content, cluster, category, period, LB_SIZE_TYPE_UNKNOWN, cb, data);
589 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)
591 struct livebox *handler;
592 struct packet *packet;
597 if (!pkgname || !cluster || !category || width < 0 || height < 0) {
598 ErrPrint("Invalid arguments: pkgname[%p], cluster[%p], category[%p]\n",
599 pkgname, cluster, category);
603 if (type != LB_SIZE_TYPE_UNKNOWN)
604 livebox_service_get_size(type, &width, &height);
606 handler = calloc(1, sizeof(*handler));
608 ErrPrint("Error: %s\n", strerror(errno));
612 handler->pkgname = lb_pkgname(pkgname);
613 if (!handler->pkgname) {
614 ErrPrint("Error: %s\n", strerror(errno));
619 if (livebox_service_is_enabled(handler->pkgname) == 0) {
620 DbgPrint("Livebox [%s](%s) is disabled package\n", handler->pkgname, pkgname);
621 free(handler->pkgname);
627 handler->content = strdup(content);
628 if (!handler->content) {
629 ErrPrint("Error: %s\n", strerror(errno));
630 free(handler->pkgname);
635 handler->content = livebox_service_content(handler->pkgname);
638 handler->cluster = strdup(cluster);
639 if (!handler->cluster) {
640 ErrPrint("Error: %s\n", strerror(errno));
641 free(handler->content);
642 free(handler->pkgname);
647 handler->category = strdup(category);
648 if (!handler->category) {
649 ErrPrint("Error: %s\n", strerror(errno));
650 free(handler->cluster);
651 free(handler->content);
652 free(handler->pkgname);
658 cb = default_create_cb;
660 /* Data provider will set this */
661 handler->lb.type = _LB_TYPE_FILE;
662 handler->pd.type = _PD_TYPE_SCRIPT;
663 handler->lb.period = period;
665 /* Used for handling the mouse event on a box */
666 handler->lb.mouse_event = livebox_service_mouse_event(handler->pkgname);
668 /* Cluster infomration is not determined yet */
669 handler->nr_of_sizes = 0x01;
671 handler->timestamp = util_timestamp();
672 handler->is_user = 1;
673 handler->visible = LB_SHOW;
675 s_info.livebox_list = dlist_append(s_info.livebox_list, handler);
677 packet = packet_create("new", "dssssdii", handler->timestamp, handler->pkgname, handler->content, cluster, category, period, width, height);
679 ErrPrint("Failed to create a new packet\n");
680 free(handler->category);
681 free(handler->cluster);
682 free(handler->content);
683 free(handler->pkgname);
688 ret = master_rpc_async_request(handler, packet, 0, new_ret_cb, create_cb_info(cb, data));
690 ErrPrint("Failed to send a new packet\n");
691 free(handler->category);
692 free(handler->cluster);
693 free(handler->content);
694 free(handler->pkgname);
699 DbgPrint("Successfully sent a new request ([%lf] %s)\n", handler->timestamp, handler->pkgname);
700 handler->state = CREATE;
701 return lb_ref(handler);
704 EAPI double livebox_period(struct livebox *handler)
706 if (!handler || handler->state != CREATE || !handler->id) {
707 ErrPrint("Handler is not valid\n");
711 return handler->lb.period;
714 EAPI int livebox_set_period(struct livebox *handler, double period, ret_cb_t cb, void *data)
716 struct packet *packet;
718 if (!handler || handler->state != CREATE || !handler->id) {
719 ErrPrint("Handler is not valid\n");
723 if (handler->period_changed_cb) {
724 ErrPrint("Previous request for changing period is not finished\n");
728 if (!handler->is_user) {
729 ErrPrint("CA Livebox is not able to change the period\n");
733 if (handler->lb.period == period) {
734 DbgPrint("No changes\n");
738 packet = packet_create("set_period", "ssd", handler->pkgname, handler->id, period);
740 ErrPrint("Failed to build a packet %s\n", handler->pkgname);
745 cb = default_period_changed_cb;
747 return master_rpc_async_request(handler, packet, 0, period_ret_cb, create_cb_info(cb, data));
750 EAPI int livebox_del(struct livebox *handler, ret_cb_t cb, void *data)
753 ErrPrint("Handler is NIL\n");
757 if (handler->state != CREATE) {
758 ErrPrint("Handler is already deleted\n");
762 handler->state = DELETE;
767 * The id is not determined yet.
768 * It means a user didn't receive created event yet.
769 * Then just stop to delete procedure from here.
770 * Because the "created" event handler will release this.
771 * By the way, if the user adds any callback for getting return status of this,
775 cb(handler, 0, data);
780 cb = default_delete_cb;
782 return lb_send_delete(handler, cb, data);
785 EAPI int livebox_set_fault_handler(int (*cb)(enum livebox_fault_type, const char *, const char *, const char *, void *), void *data)
787 struct fault_info *info;
792 info = malloc(sizeof(*info));
794 CRITICAL_LOG("Heap: %s\n", strerror(errno));
799 info->user_data = data;
801 s_info.fault_list = dlist_append(s_info.fault_list, info);
805 EAPI void *livebox_unset_fault_handler(int (*cb)(enum livebox_fault_type, const char *, const char *, const char *, void *))
807 struct fault_info *info;
810 dlist_foreach(s_info.fault_list, l, info) {
811 if (info->handler == cb) {
813 s_info.fault_list = dlist_remove(s_info.fault_list, l);
814 data = info->user_data;
824 EAPI int livebox_set_event_handler(int (*cb)(struct livebox *, enum livebox_event_type, void *), void *data)
826 struct event_info *info;
829 ErrPrint("Invalid argument cb is nil\n");
833 info = malloc(sizeof(*info));
835 CRITICAL_LOG("Heap: %s\n", strerror(errno));
840 info->user_data = data;
842 s_info.event_list = dlist_append(s_info.event_list, info);
846 EAPI void *livebox_unset_event_handler(int (*cb)(struct livebox *, enum livebox_event_type, void *))
848 struct event_info *info;
851 dlist_foreach(s_info.event_list, l, info) {
852 if (info->handler == cb) {
855 s_info.event_list = dlist_remove(s_info.event_list, l);
856 data = info->user_data;
866 EAPI int livebox_resize(struct livebox *handler, int type, ret_cb_t cb, void *data)
868 struct packet *packet;
873 ErrPrint("Handler is NIL\n");
877 if (handler->state != CREATE || !handler->id) {
878 ErrPrint("Handler is not valid\n");
882 if (handler->size_changed_cb) {
883 ErrPrint("Previous resize request is not finished yet\n");
887 if (!handler->is_user) {
888 ErrPrint("CA Livebox is not able to be resized\n");
892 if (livebox_service_get_size(type, &w, &h) != 0) {
893 ErrPrint("Invalid size type\n");
897 if (handler->lb.width == w && handler->lb.height == h) {
898 DbgPrint("No changes\n");
902 packet = packet_create("resize", "ssii", handler->pkgname, handler->id, w, h);
904 ErrPrint("Failed to build param\n");
909 cb = default_lb_size_changed_cb;
911 return master_rpc_async_request(handler, packet, 0, resize_cb, create_cb_info(cb, data));
914 EAPI int livebox_click(struct livebox *handler, double x, double y)
916 struct packet *packet;
921 ErrPrint("Handler is NIL\n");
925 if (handler->state != CREATE || !handler->id) {
926 ErrPrint("Handler is not valid\n");
930 if (handler->lb.auto_launch)
931 if (aul_open_app(handler->lb.auto_launch) < 0)
932 ErrPrint("Failed to launch app %s\n", handler->lb.auto_launch);
934 timestamp = util_timestamp();
935 packet = packet_create_noack("clicked", "sssddd", handler->pkgname, handler->id, "clicked", timestamp, x, y);
937 ErrPrint("Failed to build param\n");
941 ret = master_rpc_request_only(handler, packet);
943 if (!handler->lb.mouse_event && (handler->lb.type == _LB_TYPE_BUFFER || handler->lb.type == _LB_TYPE_SCRIPT)) {
944 int ret; /* Shadow variable */
945 ret = send_mouse_event(handler, "lb_mouse_down", x * handler->lb.width, y * handler->lb.height);
947 DbgPrint("Failed to send Down: %d\n", ret);
949 ret = send_mouse_event(handler, "lb_mouse_move", x * handler->lb.width, y * handler->lb.height);
951 DbgPrint("Failed to send Move: %d\n", ret);
953 ret = send_mouse_event(handler, "lb_mouse_up", x * handler->lb.width, y * handler->lb.height);
955 DbgPrint("Failed to send Up: %d\n", ret);
961 EAPI int livebox_has_pd(struct livebox *handler)
964 ErrPrint("Handler is NIL\n");
968 if (handler->state != CREATE || !handler->id) {
969 ErrPrint("Handler is not valid\n");
973 return !!handler->pd.data.fb;
976 EAPI int livebox_pd_is_created(struct livebox *handler)
979 ErrPrint("Handler is NIL\n");
983 if (!handler->pd.data.fb || handler->state != CREATE || !handler->id) {
984 ErrPrint("Handler is not valid\n");
988 return handler->is_pd_created;
991 EAPI int livebox_create_pd(struct livebox *handler, ret_cb_t cb, void *data)
993 return livebox_create_pd_with_position(handler, -1.0, -1.0, cb, data);
996 EAPI int livebox_create_pd_with_position(struct livebox *handler, double x, double y, ret_cb_t cb, void *data)
998 struct packet *packet;
1001 ErrPrint("Handler is NIL\n");
1005 if (!handler->pd.data.fb || handler->state != CREATE || !handler->id) {
1006 ErrPrint("Handler is not valid\n");
1010 if (handler->is_pd_created == 1) {
1011 DbgPrint("PD already created\n");
1015 packet = packet_create("create_pd", "ssdd", handler->pkgname, handler->id, x, y);
1017 ErrPrint("Failed to build param\n");
1022 handler->pd_created_cb = default_pd_created_cb;
1024 return master_rpc_async_request(handler, packet, 0, pd_create_cb, create_cb_info(cb, data));
1027 EAPI int livebox_move_pd(struct livebox *handler, double x, double y)
1029 struct packet *packet;
1032 ErrPrint("Handler is NIL\n");
1036 if (!handler->pd.data.fb || handler->state != CREATE || !handler->id) {
1037 ErrPrint("Handler is not valid\n");
1041 if (!handler->is_pd_created) {
1042 DbgPrint("PD is not created\n");
1046 packet = packet_create_noack("pd_move", "ssdd", handler->pkgname, handler->id, x, y);
1048 ErrPrint("Failed to build param\n");
1052 return master_rpc_request_only(handler, packet);
1055 EAPI int livebox_activate(const char *pkgname, ret_cb_t cb, void *data)
1057 struct packet *packet;
1062 packet = packet_create("activate_package", "s", pkgname);
1064 ErrPrint("Failed to build a param\n");
1068 return master_rpc_async_request(NULL, packet, 0, activated_cb, create_cb_info(cb, data));
1071 EAPI int livebox_destroy_pd(struct livebox *handler, ret_cb_t cb, void *data)
1073 struct packet *packet;
1076 ErrPrint("Handler is NIL\n");
1080 if (!handler->pd.data.fb || handler->state != CREATE || !handler->id) {
1081 ErrPrint("Handler is not valid\n");
1085 if (!handler->is_pd_created) {
1086 ErrPrint("PD is not created\n");
1090 packet = packet_create("destroy_pd", "ss", handler->pkgname, handler->id);
1092 ErrPrint("Failed to build a param\n");
1097 cb = default_pd_destroyed_cb;
1099 return master_rpc_async_request(handler, packet, 0, pd_destroy_cb, create_cb_info(cb, data));
1102 EAPI int livebox_content_event(struct livebox *handler, enum content_event_type type, double x, double y)
1106 char cmd[20] = { '\0', };
1110 ErrPrint("Handler is NIL\n");
1114 if (handler->state != CREATE || !handler->id) {
1115 ErrPrint("Handler is not valid\n");
1119 if (type & CONTENT_EVENT_PD_MASK) {
1122 if (!handler->is_pd_created) {
1123 ErrPrint("PD is not created\n");
1127 if (type & CONTENT_EVENT_MOUSE_MASK) {
1128 if (!handler->pd.data.fb) {
1129 ErrPrint("Handler is not valid\n");
1133 if (type & CONTENT_EVENT_MOUSE_MOVE) {
1134 if (fabs(x - handler->pd.x) < MINIMUM_EVENT && fabs(y - handler->pd.y) < MINIMUM_EVENT)
1136 } else if (type & CONTENT_EVENT_MOUSE_SET) {
1142 w = handler->pd.width;
1143 h = handler->pd.height;
1152 if (type & CONTENT_EVENT_MOUSE_MASK) {
1153 if (!handler->lb.mouse_event) {
1154 ErrPrint("Box is not support the mouse event\n");
1158 if (!handler->lb.data.fb) {
1159 ErrPrint("Handler is not valid\n");
1163 if (type & CONTENT_EVENT_MOUSE_MOVE) {
1164 if (fabs(x - handler->lb.x) < MINIMUM_EVENT && fabs(y - handler->lb.y) < MINIMUM_EVENT)
1166 } else if (type & CONTENT_EVENT_MOUSE_SET) {
1172 w = handler->lb.width;
1173 h = handler->lb.height;
1181 switch ((type & ~CONTENT_EVENT_PD_MASK)) {
1182 case CONTENT_EVENT_ACCESS_READ | CONTENT_EVENT_ACCESS_MASK:
1183 strcpy(ptr, "_access_read");
1185 case CONTENT_EVENT_ACCESS_READ_PREV | CONTENT_EVENT_ACCESS_MASK:
1186 strcpy(ptr, "_access_read_prev");
1188 case CONTENT_EVENT_ACCESS_READ_NEXT | CONTENT_EVENT_ACCESS_MASK:
1189 strcpy(ptr, "_access_read_next");
1191 case CONTENT_EVENT_ACCESS_ACTIVATE | CONTENT_EVENT_ACCESS_MASK:
1192 strcpy(ptr, "_access_activate");
1194 case CONTENT_EVENT_ACCESS_UP | CONTENT_EVENT_ACCESS_MASK:
1195 strcpy(ptr, "_access_up");
1197 case CONTENT_EVENT_ACCESS_DOWN | CONTENT_EVENT_ACCESS_MASK:
1198 strcpy(ptr, "_access_down");
1200 case CONTENT_EVENT_MOUSE_ENTER | CONTENT_EVENT_MOUSE_MASK:
1201 strcpy(ptr, "_mouse_enter");
1203 case CONTENT_EVENT_MOUSE_LEAVE | CONTENT_EVENT_MOUSE_MASK:
1204 strcpy(ptr, "_mouse_leave");
1206 case CONTENT_EVENT_MOUSE_UP | CONTENT_EVENT_MOUSE_MASK:
1207 strcpy(ptr, "_mouse_up");
1209 case CONTENT_EVENT_MOUSE_DOWN | CONTENT_EVENT_MOUSE_MASK:
1210 strcpy(ptr, "_mouse_down");
1212 case CONTENT_EVENT_MOUSE_MOVE | CONTENT_EVENT_MOUSE_MASK:
1213 strcpy(ptr, "_mouse_move");
1215 case CONTENT_EVENT_MOUSE_SET | CONTENT_EVENT_MOUSE_MASK:
1216 strcpy(ptr, "_mouse_set");
1218 case CONTENT_EVENT_MOUSE_UNSET | CONTENT_EVENT_MOUSE_MASK:
1219 strcpy(ptr, "_mouse_unset");
1221 case CONTENT_EVENT_KEY_DOWN | CONTENT_EVENT_KEY_MASK:
1222 strcpy(ptr, "_key_down");
1224 case CONTENT_EVENT_KEY_UP | CONTENT_EVENT_KEY_MASK:
1225 strcpy(ptr, "_key_up");
1228 ErrPrint("Invalid event type\n");
1232 return send_mouse_event(handler, cmd, x * w, y * h);
1235 EAPI const char *livebox_filename(struct livebox *handler)
1238 ErrPrint("Handler is NIL\n");
1242 if (handler->state != CREATE || !handler->id) {
1243 ErrPrint("Handler is not valid\n");
1247 if (handler->filename)
1248 return handler->filename;
1251 return util_uri_to_path(handler->id);
1254 EAPI int livebox_get_pdsize(struct livebox *handler, int *w, int *h)
1260 ErrPrint("Handler is NIL\n");
1264 if (handler->state != CREATE || !handler->id) {
1265 ErrPrint("Handler is not valid\n");
1274 if (!handler->is_pd_created) {
1275 DbgPrint("Buffer is not created yet [%dx%d]\n", *w, *h);
1276 *w = handler->pd.default_width;
1277 *h = handler->pd.default_height;
1279 *w = handler->pd.width;
1280 *h = handler->pd.height;
1286 EAPI int livebox_size(struct livebox *handler)
1292 ErrPrint("Handler is NIL\n");
1296 if (handler->state != CREATE || !handler->id) {
1297 ErrPrint("Handler is not valid\n");
1301 w = handler->lb.width;
1302 h = handler->lb.height;
1304 switch (handler->lb.type) {
1305 case _LB_TYPE_BUFFER:
1306 case _LB_TYPE_SCRIPT:
1307 if (!fb_is_created(handler->lb.data.fb)) {
1308 DbgPrint("Buffer is not created yet - reset size\n");
1317 return livebox_service_size_type(w, h);
1320 EAPI int livebox_set_group(struct livebox *handler, const char *cluster, const char *category, ret_cb_t cb, void *data)
1322 struct packet *packet;
1325 ErrPrint("Handler is NIL\n");
1329 if (!cluster || !category || handler->state != CREATE || !handler->id) {
1330 ErrPrint("Invalid argument\n");
1334 if (handler->group_changed_cb) {
1335 ErrPrint("Previous group changing request is not finished yet\n");
1339 if (!handler->is_user) {
1340 ErrPrint("CA Livebox is not able to change the group\n");
1344 if (!strcmp(handler->cluster, cluster) && !strcmp(handler->category, category)) {
1345 DbgPrint("No changes\n");
1349 packet = packet_create("change_group", "ssss", handler->pkgname, handler->id, cluster, category);
1351 ErrPrint("Failed to build a param\n");
1356 cb = default_group_changed_cb;
1358 return master_rpc_async_request(handler, packet, 0, set_group_ret_cb, create_cb_info(cb, data));
1361 EAPI int livebox_get_group(struct livebox *handler, char ** const cluster, char ** const category)
1364 ErrPrint("Handler is NIL\n");
1368 if (!cluster || !category || handler->state != CREATE || !handler->id) {
1369 ErrPrint("Invalid argument\n");
1373 *cluster = handler->cluster;
1374 *category = handler->category;
1378 EAPI int livebox_get_supported_sizes(struct livebox *handler, int *cnt, int *size_list)
1383 if (!handler || !size_list) {
1384 ErrPrint("Invalid argument, handler(%p), size_list(%p)\n", handler, size_list);
1388 if (!cnt || handler->state != CREATE || !handler->id) {
1389 ErrPrint("Handler is not valid\n");
1393 for (j = i = 0; i < NR_OF_SIZE_LIST; i++) {
1394 if (handler->lb.size_list & (0x01 << i)) {
1398 size_list[j++] = (0x01 << i);
1406 EAPI const char *livebox_pkgname(struct livebox *handler)
1409 ErrPrint("Handler is NIL\n");
1413 if (handler->state != CREATE) {
1414 ErrPrint("Handler is not valid\n");
1418 return handler->pkgname;
1421 EAPI double livebox_priority(struct livebox *handler)
1424 ErrPrint("Handler is NIL\n");
1428 if (handler->state != CREATE || !handler->id) {
1429 ErrPrint("Handler is not valid (%p)\n", handler);
1433 return handler->lb.priority;
1436 EAPI int livebox_delete_cluster(const char *cluster, ret_cb_t cb, void *data)
1438 struct packet *packet;
1440 packet = packet_create("delete_cluster", "s", cluster);
1442 ErrPrint("Failed to build a param\n");
1446 return master_rpc_async_request(NULL, packet, 0, delete_cluster_cb, create_cb_info(cb, data));
1449 EAPI int livebox_delete_category(const char *cluster, const char *category, ret_cb_t cb, void *data)
1451 struct packet *packet;
1453 packet = packet_create("delete_category", "ss", cluster, category);
1455 ErrPrint("Failed to build a param\n");
1459 return master_rpc_async_request(NULL, packet, 0, delete_category_cb, create_cb_info(cb, data));
1462 EAPI enum livebox_lb_type livebox_lb_type(struct livebox *handler)
1465 ErrPrint("Handler is NIL\n");
1466 return LB_TYPE_INVALID;
1469 if (handler->state != CREATE || !handler->id) {
1470 ErrPrint("Handler is not valid\n");
1471 return LB_TYPE_INVALID;
1474 switch (handler->lb.type) {
1476 return LB_TYPE_IMAGE;
1477 case _LB_TYPE_BUFFER:
1478 case _LB_TYPE_SCRIPT:
1481 id = fb_id(handler->lb.data.fb);
1482 if (id && !strncasecmp(id, SCHEMA_PIXMAP, strlen(SCHEMA_PIXMAP)))
1483 return LB_TYPE_PIXMAP;
1485 return LB_TYPE_BUFFER;
1487 return LB_TYPE_TEXT;
1492 return LB_TYPE_INVALID;
1495 EAPI enum livebox_pd_type livebox_pd_type(struct livebox *handler)
1498 ErrPrint("Handler is NIL\n");
1499 return PD_TYPE_INVALID;
1502 if (handler->state != CREATE || !handler->id) {
1503 ErrPrint("Handler is not valid\n");
1504 return PD_TYPE_INVALID;
1507 switch (handler->pd.type) {
1509 return PD_TYPE_TEXT;
1510 case _PD_TYPE_BUFFER:
1511 case _PD_TYPE_SCRIPT:
1514 id = fb_id(handler->pd.data.fb);
1515 if (id && !strncasecmp(id, SCHEMA_PIXMAP, strlen(SCHEMA_PIXMAP)))
1516 return PD_TYPE_PIXMAP;
1518 return PD_TYPE_BUFFER;
1523 return PD_TYPE_INVALID;
1526 EAPI int livebox_set_pd_text_handler(struct livebox *handler, struct livebox_script_operators *ops)
1529 ErrPrint("Handler is NIL\n");
1533 if (handler->state != CREATE) {
1534 ErrPrint("Handler is not valid\n");
1538 memcpy(&handler->pd.data.ops, ops, sizeof(*ops));
1542 EAPI int livebox_set_text_handler(struct livebox *handler, struct livebox_script_operators *ops)
1545 ErrPrint("Handler is NIL\n");
1549 if (handler->state != CREATE) {
1550 ErrPrint("Handler is not valid\n");
1554 memcpy(&handler->lb.data.ops, ops, sizeof(*ops));
1558 EAPI int livebox_acquire_lb_pixmap(struct livebox *handler, ret_cb_t cb, void *data)
1560 struct packet *packet;
1564 ErrPrint("Handler is NIL\n");
1568 if (handler->state != CREATE || !handler->id) {
1569 ErrPrint("Invalid handle\n");
1573 if (handler->lb.type != _LB_TYPE_SCRIPT && handler->lb.type != _LB_TYPE_BUFFER) {
1574 ErrPrint("Handler is not valid type\n");
1578 id = fb_id(handler->lb.data.fb);
1579 if (!id || strncasecmp(id, SCHEMA_PIXMAP, strlen(SCHEMA_PIXMAP)))
1582 packet = packet_create("lb_acquire_pixmap", "ss", handler->pkgname, handler->id);
1584 ErrPrint("Failed to build a param\n");
1588 return master_rpc_async_request(handler, packet, 0, pixmap_acquired_cb, create_cb_info(cb, data));
1591 EAPI int livebox_release_lb_pixmap(struct livebox *handler, int pixmap)
1593 struct packet *packet;
1596 ErrPrint("Handler is NIL\n");
1600 if (handler->state != CREATE || !handler->id) {
1601 ErrPrint("Invalid handle\n");
1605 if (handler->lb.type != _LB_TYPE_SCRIPT && handler->lb.type != _LB_TYPE_BUFFER) {
1606 ErrPrint("Handler is not valid type\n");
1610 packet = packet_create_noack("lb_release_pixmap", "ssi", handler->pkgname, handler->id, pixmap);
1612 ErrPrint("Failed to build a param\n");
1616 return master_rpc_request_only(handler, packet);
1619 EAPI int livebox_acquire_pd_pixmap(struct livebox *handler, ret_cb_t cb, void *data)
1621 struct packet *packet;
1625 ErrPrint("Handler is NIL\n");
1629 if (handler->state != CREATE || !handler->id) {
1630 ErrPrint("Invalid handle\n");
1634 if (handler->pd.type != _PD_TYPE_SCRIPT && handler->pd.type != _PD_TYPE_BUFFER) {
1635 ErrPrint("Handler is not valid type\n");
1639 id = fb_id(handler->pd.data.fb);
1640 if (!id || strncasecmp(id, SCHEMA_PIXMAP, strlen(SCHEMA_PIXMAP)))
1643 packet = packet_create("pd_acquire_pixmap", "ss", handler->pkgname, handler->id);
1645 ErrPrint("Failed to build a param\n");
1649 return master_rpc_async_request(handler, packet, 0, pixmap_acquired_cb, create_cb_info(cb, data));
1652 EAPI int livebox_pd_pixmap(const struct livebox *handler)
1658 ErrPrint("Handler is NIL\n");
1662 if (handler->state != CREATE || !handler->id) {
1663 ErrPrint("Invalid handler\n");
1667 if (handler->pd.type != _PD_TYPE_SCRIPT && handler->pd.type != _PD_TYPE_BUFFER) {
1668 ErrPrint("Invalid handler\n");
1672 id = fb_id(handler->pd.data.fb);
1673 if (id && sscanf(id, SCHEMA_PIXMAP "%d", &pixmap) != 1) {
1674 ErrPrint("PIXMAP Id is not valid\n");
1681 EAPI int livebox_lb_pixmap(const struct livebox *handler)
1687 ErrPrint("Handler is NIL\n");
1691 if (handler->state != CREATE || !handler->id) {
1692 ErrPrint("Invalid handler\n");
1696 if (handler->lb.type != _LB_TYPE_SCRIPT && handler->lb.type != _LB_TYPE_BUFFER) {
1697 ErrPrint("Invalid handler\n");
1701 id = fb_id(handler->lb.data.fb);
1702 if (id && sscanf(id, SCHEMA_PIXMAP "%d", &pixmap) != 1) {
1703 ErrPrint("PIXMAP Id is not valid\n");
1710 EAPI int livebox_release_pd_pixmap(struct livebox *handler, int pixmap)
1712 struct packet *packet;
1715 ErrPrint("Handler is NIL\n");
1719 if (handler->state != CREATE || !handler->id) {
1720 ErrPrint("Invalid handle\n");
1724 if (handler->pd.type != _PD_TYPE_SCRIPT && handler->pd.type != _PD_TYPE_BUFFER) {
1725 ErrPrint("Handler is not valid type\n");
1729 packet = packet_create_noack("pd_release_pixmap", "ssi", handler->pkgname, handler->id, pixmap);
1731 ErrPrint("Failed to build a param\n");
1735 return master_rpc_request_only(handler, packet);
1738 EAPI void *livebox_acquire_fb(struct livebox *handler)
1741 ErrPrint("Handler is NIL\n");
1745 if (handler->state != CREATE || !handler->id) {
1746 ErrPrint("Invalid handle\n");
1750 if (handler->lb.type != _LB_TYPE_SCRIPT && handler->lb.type != _LB_TYPE_BUFFER) {
1751 ErrPrint("Handler is not valid type\n");
1755 return fb_acquire_buffer(handler->lb.data.fb);
1758 EAPI int livebox_release_fb(void *buffer)
1760 return fb_release_buffer(buffer);
1763 EAPI int livebox_fb_refcnt(void *buffer)
1765 return fb_refcnt(buffer);
1768 EAPI void *livebox_acquire_pdfb(struct livebox *handler)
1771 ErrPrint("Handler is NIL\n");
1775 if (handler->state != CREATE || !handler->id) {
1776 ErrPrint("Invalid handler\n");
1780 if (handler->pd.type != _PD_TYPE_SCRIPT && handler->pd.type != _PD_TYPE_BUFFER) {
1781 ErrPrint("Handler is not valid type\n");
1785 return fb_acquire_buffer(handler->pd.data.fb);
1788 EAPI int livebox_release_pdfb(void *buffer)
1790 return fb_release_buffer(buffer);
1793 EAPI int livebox_pdfb_refcnt(void *buffer)
1795 return fb_refcnt(buffer);
1798 EAPI int livebox_pdfb_bufsz(struct livebox *handler)
1801 ErrPrint("Handler is NIL\n");
1805 if (handler->state != CREATE || !handler->id) {
1806 ErrPrint("Handler is not valid\n");
1810 return fb_size(handler->pd.data.fb);
1813 EAPI int livebox_lbfb_bufsz(struct livebox *handler)
1816 ErrPrint("Handler is NIL\n");
1820 if (handler->state != CREATE || !handler->id) {
1821 ErrPrint("Handler is not valid\n");
1825 return fb_size(handler->lb.data.fb);
1828 EAPI int livebox_is_user(struct livebox *handler)
1831 ErrPrint("Handler is NIL\n");
1835 if (handler->state != CREATE) {
1836 ErrPrint("Handler is invalid\n");
1840 return handler->is_user;
1843 EAPI int livebox_set_pinup(struct livebox *handler, int flag, ret_cb_t cb, void *data)
1845 struct packet *packet;
1848 ErrPrint("Handler is NIL\n");
1852 if (handler->state != CREATE || !handler->id) {
1853 ErrPrint("Handler is not valid\n");
1857 if (handler->pinup_cb) {
1858 ErrPrint("Previous pinup request is not finished\n");
1862 if (handler->is_pinned_up == flag) {
1863 DbgPrint("No changes\n");
1867 packet = packet_create("pinup_changed", "ssi", handler->pkgname, handler->id, flag);
1869 ErrPrint("Failed to build a param\n");
1874 cb = default_pinup_cb;
1876 return master_rpc_async_request(handler, packet, 0, pinup_done_cb, create_cb_info(cb, data));
1879 EAPI int livebox_is_pinned_up(struct livebox *handler)
1882 ErrPrint("Handler is NIL\n");
1886 if (handler->state != CREATE || !handler->id)
1889 return handler->is_pinned_up;
1892 EAPI int livebox_has_pinup(struct livebox *handler)
1895 ErrPrint("Handler is NIL\n");
1899 if (handler->state != CREATE || !handler->id)
1902 return handler->lb.pinup_supported;
1905 EAPI int livebox_set_data(struct livebox *handler, void *data)
1908 ErrPrint("Handler is NIL\n");
1912 if (handler->state != CREATE)
1915 handler->data = data;
1919 EAPI void *livebox_get_data(struct livebox *handler)
1922 ErrPrint("Handler is NIL\n");
1926 if (handler->state != CREATE)
1929 return handler->data;
1932 EAPI int livebox_is_exists(const char *pkgname)
1936 lb = lb_pkgname(pkgname);
1945 EAPI const char *livebox_content(struct livebox *handler)
1948 ErrPrint("Handler is NIL\n");
1952 if (handler->state != CREATE)
1955 return handler->content;
1958 EAPI const char *livebox_category_title(struct livebox *handler)
1961 ErrPrint("Handler is NIL\n");
1965 if (handler->state != CREATE)
1968 return handler->title;
1971 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)
1973 struct packet *packet;
1976 ErrPrint("Handler is NIL\n");
1980 if ((handler->lb.type != _LB_TYPE_TEXT && handler->pd.type != _PD_TYPE_TEXT) || handler->state != CREATE || !handler->id) {
1981 ErrPrint("Handler is not valid\n");
1991 packet = packet_create("text_signal", "ssssdddd",
1992 handler->pkgname, handler->id, emission, source, sx, sy, ex, ey);
1994 ErrPrint("Failed to build a param\n");
1998 return master_rpc_async_request(handler, packet, 0, text_signal_cb, create_cb_info(cb, data));
2001 EAPI int livebox_subscribe_group(const char *cluster, const char *category)
2003 struct packet *packet;
2007 * Validate the group info using DB
2008 * If the group info is not valid, do not send this request
2011 packet = packet_create_noack("subscribe", "ss", cluster ? cluster : "", category ? category : "");
2013 ErrPrint("Failed to create a packet\n");
2017 return master_rpc_request_only(NULL, packet);
2020 EAPI int livebox_unsubscribe_group(const char *cluster, const char *category)
2022 struct packet *packet;
2026 * Validate the group info using DB
2027 * If the group info is not valid, do not send this request
2028 * AND Check the subscribed or not too
2031 packet = packet_create_noack("unsubscribe", "ss", cluster ? cluster : "", category ? category : "");
2033 ErrPrint("Failed to create a packet\n");
2037 return master_rpc_request_only(NULL, packet);
2040 EAPI int livebox_refresh(struct livebox *handler)
2042 struct packet *packet;
2045 ErrPrint("Hnalder is NIL\n");
2049 if (handler->state != CREATE || !handler->id)
2052 packet = packet_create_noack("update", "ss", handler->pkgname, handler->id);
2054 ErrPrint("Failed to create a packet\n");
2058 return master_rpc_request_only(handler, packet);
2061 EAPI int livebox_refresh_group(const char *cluster, const char *category)
2063 struct packet *packet;
2065 if (!cluster || !category) {
2066 ErrPrint("Invalid argument\n");
2070 packet = packet_create_noack("refresh_group", "ss", cluster, category);
2072 ErrPrint("Failed to create a packet\n");
2076 return master_rpc_request_only(NULL, packet);
2079 EAPI int livebox_set_visibility(struct livebox *handler, enum livebox_visible_state state)
2081 struct packet *packet;
2085 ErrPrint("Handler is NIL\n");
2089 if (handler->state != CREATE || !handler->id)
2092 if (!handler->is_user) {
2093 /* System cluster livebox cannot be changed its visible states */
2094 if (state == LB_HIDE_WITH_PAUSE) {
2095 ErrPrint("CA Livebox is not able to change the visibility\n");
2100 DbgPrint("Change the visibility %d <> %d, %s\n", handler->visible, state, handler->id);
2102 if (handler->visible == state)
2105 packet = packet_create_noack("change,visibility", "ssi", handler->pkgname, handler->id, (int)state);
2107 ErrPrint("Failed to create a packet\n");
2111 ret = master_rpc_request_only(handler, packet);
2113 handler->visible = state;
2118 EAPI enum livebox_visible_state livebox_visibility(struct livebox *handler)
2121 ErrPrint("Handler is NIL\n");
2122 return LB_VISIBLE_ERROR;
2125 if (handler->state != CREATE)
2126 return LB_VISIBLE_ERROR;
2128 return handler->visible;
2131 int lb_set_group(struct livebox *handler, const char *cluster, const char *category)
2137 pc = strdup(cluster);
2139 CRITICAL_LOG("Heap: %s (cluster: %s)\n", strerror(errno), cluster);
2145 ps = strdup(category);
2147 CRITICAL_LOG("Heap: %s (category: %s)\n", strerror(errno), category);
2153 if (handler->cluster)
2154 free(handler->cluster);
2156 if (handler->category)
2157 free(handler->category);
2159 handler->cluster = pc;
2160 handler->category = ps;
2165 void lb_set_size(struct livebox *handler, int w, int h)
2167 handler->lb.width = w;
2168 handler->lb.height = h;
2171 void lb_set_pdsize(struct livebox *handler, int w, int h)
2173 handler->pd.width = w;
2174 handler->pd.height = h;
2177 void lb_set_default_pdsize(struct livebox *handler, int w, int h)
2179 handler->pd.default_width = w;
2180 handler->pd.default_height = h;
2183 void lb_invoke_fault_handler(enum livebox_fault_type event, const char *pkgname, const char *file, const char *func)
2187 struct fault_info *info;
2189 dlist_foreach_safe(s_info.fault_list, l, n, info) {
2190 if (info->handler(event, pkgname, file, func, info->user_data) == EXIT_FAILURE)
2191 s_info.fault_list = dlist_remove(s_info.fault_list, l);
2195 void lb_invoke_event_handler(struct livebox *handler, enum livebox_event_type event)
2199 struct event_info *info;
2201 dlist_foreach_safe(s_info.event_list, l, n, info) {
2202 if (info->handler(handler, event, info->user_data) == EXIT_FAILURE)
2203 s_info.event_list = dlist_remove(s_info.event_list, l);
2207 struct livebox *lb_find_livebox(const char *pkgname, const char *id)
2210 struct livebox *handler;
2212 dlist_foreach(s_info.livebox_list, l, handler) {
2216 if (!strcmp(handler->pkgname, pkgname) && !strcmp(handler->id, id))
2223 struct livebox *lb_find_livebox_by_timestamp(double timestamp)
2226 struct livebox *handler;
2228 dlist_foreach(s_info.livebox_list, l, handler) {
2229 if (handler->timestamp == timestamp)
2236 static inline char *get_file_kept_in_safe(const char *id)
2243 path = util_uri_to_path(id);
2245 ErrPrint("Invalid URI(%s)\n", id);
2252 if (s_info.prevent_overwrite) {
2253 new_path = strdup(path);
2255 ErrPrint("Heap: %s\n", strerror(errno));
2264 while (base_idx > 0 && path[base_idx] != '/') base_idx--;
2265 base_idx += (path[base_idx] == '/');
2267 new_path = malloc(len + 10);
2269 ErrPrint("Heap: %s\n", strerror(errno));
2273 strncpy(new_path, path, base_idx);
2274 snprintf(new_path + base_idx, len + 10 - base_idx, "reader/%s", path + base_idx);
2278 struct livebox *lb_new_livebox(const char *pkgname, const char *id, double timestamp)
2280 struct livebox *handler;
2282 handler = calloc(1, sizeof(*handler));
2284 ErrPrint("Failed to create a new livebox\n");
2288 handler->pkgname = strdup(pkgname);
2289 if (!handler->pkgname) {
2290 ErrPrint("%s\n", strerror(errno));
2295 handler->id = strdup(id);
2297 ErrPrint("%s\n", strerror(errno));
2298 free(handler->pkgname);
2303 handler->filename = get_file_kept_in_safe(id);
2304 if (!handler->filename) {
2305 handler->filename = strdup(util_uri_to_path(id));
2306 if (!handler->filename)
2307 ErrPrint("Error: %s\n", strerror(errno));
2310 handler->timestamp = timestamp;
2311 handler->lb.type = _LB_TYPE_FILE;
2312 handler->pd.type = _PD_TYPE_SCRIPT;
2313 handler->state = CREATE;
2314 handler->visible = LB_SHOW;
2316 s_info.livebox_list = dlist_append(s_info.livebox_list, handler);
2321 int lb_delete_all(void)
2325 struct livebox *handler;
2327 dlist_foreach_safe(s_info.livebox_list, l, n, handler) {
2328 lb_invoke_event_handler(handler, LB_EVENT_DELETED);
2335 int lb_set_content(struct livebox *handler, const char *content)
2337 if (handler->content) {
2338 free(handler->content);
2339 handler->content = NULL;
2343 handler->content = strdup(content);
2344 if (!handler->content) {
2345 CRITICAL_LOG("Heap: %s (content: %s)\n", strerror(errno), content);
2353 int lb_set_title(struct livebox *handler, const char *title)
2355 if (handler->title) {
2356 free(handler->title);
2357 handler->title = NULL;
2361 handler->title = strdup(title);
2362 if (!handler->title) {
2363 CRITICAL_LOG("Heap: %s (title: %s)\n", strerror(errno), title);
2371 void lb_set_size_list(struct livebox *handler, int size_list)
2373 handler->lb.size_list = size_list;
2376 void lb_set_auto_launch(struct livebox *handler, const char *auto_launch)
2378 if (!strlen(auto_launch))
2381 handler->lb.auto_launch = strdup(auto_launch);
2382 if (!handler->lb.auto_launch)
2383 ErrPrint("Heap: %s\n", strerror(errno));
2386 void lb_set_priority(struct livebox *handler, double priority)
2388 handler->lb.priority = priority;
2391 void lb_set_id(struct livebox *handler, const char *id)
2396 handler->id = strdup(id);
2398 ErrPrint("Error: %s\n", strerror(errno));
2400 if (handler->filename)
2401 free(handler->filename);
2403 handler->filename = get_file_kept_in_safe(id);
2404 if (!handler->filename) {
2405 handler->filename = strdup(util_uri_to_path(id));
2406 if (!handler->filename)
2407 ErrPrint("Error: %s\n", strerror(errno));
2411 int lb_set_lb_fb(struct livebox *handler, const char *filename)
2418 fb = handler->lb.data.fb;
2419 if (fb && !strcmp(fb_id(fb), filename)) /*!< BUFFER is not changed, */
2422 handler->lb.data.fb = NULL;
2424 if (!filename || filename[0] == '\0') {
2430 handler->lb.data.fb = fb_create(filename, handler->lb.width, handler->lb.height);
2431 if (!handler->lb.data.fb) {
2432 ErrPrint("Faield to create a FB\n");
2444 int lb_set_pd_fb(struct livebox *handler, const char *filename)
2451 fb = handler->pd.data.fb;
2452 if (fb && !strcmp(fb_id(fb), filename)) {
2453 /* BUFFER is not changed, just update the content */
2456 handler->pd.data.fb = NULL;
2458 if (!filename || filename[0] == '\0') {
2464 handler->pd.data.fb = fb_create(filename, handler->pd.width, handler->pd.height);
2465 if (!handler->pd.data.fb) {
2466 ErrPrint("Failed to create a FB\n");
2477 struct fb_info *lb_get_lb_fb(struct livebox *handler)
2479 return handler->lb.data.fb;
2482 struct fb_info *lb_get_pd_fb(struct livebox *handler)
2484 return handler->pd.data.fb;
2487 void lb_set_user(struct livebox *handler, int user)
2489 handler->is_user = user;
2492 void lb_set_pinup(struct livebox *handler, int pinup_supported)
2494 handler->lb.pinup_supported = pinup_supported;
2497 void lb_set_text_lb(struct livebox *handler)
2499 handler->lb.type = _LB_TYPE_TEXT;
2502 void lb_set_text_pd(struct livebox *handler)
2504 handler->pd.type = _PD_TYPE_TEXT;
2507 int lb_text_lb(struct livebox *handler)
2509 return handler->lb.type == _LB_TYPE_TEXT;
2512 int lb_text_pd(struct livebox *handler)
2514 return handler->pd.type == _PD_TYPE_TEXT;
2517 void lb_set_period(struct livebox *handler, double period)
2519 handler->lb.period = period;
2522 struct livebox *lb_ref(struct livebox *handler)
2531 struct livebox *lb_unref(struct livebox *handler)
2537 if (handler->refcnt > 0)
2540 dlist_remove_data(s_info.livebox_list, handler);
2542 handler->state = DESTROYED;
2543 free(handler->cluster);
2544 free(handler->category);
2546 free(handler->pkgname);
2547 free(handler->filename);
2548 free(handler->lb.auto_launch);
2550 if (handler->lb.data.fb) {
2551 fb_destroy(handler->lb.data.fb);
2552 handler->lb.data.fb = NULL;
2555 if (handler->pd.data.fb) {
2556 fb_destroy(handler->pd.data.fb);
2557 handler->pd.data.fb = NULL;
2564 int lb_send_delete(struct livebox *handler, ret_cb_t cb, void *data)
2566 struct packet *packet;
2568 if (!cb && !!data) {
2569 ErrPrint("Invalid argument\n");
2573 if (handler->deleted_cb) {
2574 ErrPrint("Already in-progress\n");
2575 return -EINPROGRESS;
2578 packet = packet_create("delete", "ss", handler->pkgname, handler->id);
2580 ErrPrint("Failed to build a param\n");
2582 cb(handler, -EFAULT, data);
2588 cb = default_delete_cb;
2590 return master_rpc_async_request(handler, packet, 0, del_ret_cb, create_cb_info(cb, data));
2593 EAPI int livebox_client_paused(void)
2595 struct packet *packet;
2597 packet = packet_create_noack("client_paused", "d", util_timestamp());
2599 ErrPrint("Failed to create a pause packet\n");
2603 return master_rpc_request_only(NULL, packet);
2606 EAPI int livebox_client_resumed(void)
2608 struct packet *packet;
2610 packet = packet_create_noack("client_resumed", "d", util_timestamp());
2612 ErrPrint("Failed to create a resume packet\n");
2616 return master_rpc_request_only(NULL, packet);