2 * Copyright 2013 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>
29 #include <livebox-errno.h>
34 #include "livebox_internal.h"
37 #include "master_rpc.h"
39 #include "critical_log.h"
41 #define EAPI __attribute__((visibility("default")))
42 #define MINIMUM_EVENT s_info.event_filter
49 struct dlist *livebox_list;
50 struct dlist *event_list;
51 struct dlist *fault_list;
53 int prevent_overwrite;
60 .prevent_overwrite = 0,
61 .event_filter = 0.02f,
70 int (*handler)(struct livebox *handler, enum livebox_event_type event, void *data);
75 int (*handler)(enum livebox_fault_type event, const char *pkgname, const char *filename, const char *func, void *data);
79 static inline void default_create_cb(struct livebox *handler, int ret, void *data)
81 DbgPrint("Default created event handler: %d\n", ret);
84 static inline void default_delete_cb(struct livebox *handler, int ret, void *data)
86 DbgPrint("Default deleted event handler: %d\n", ret);
89 static inline void default_pinup_cb(struct livebox *handler, int ret, void *data)
91 DbgPrint("Default pinup event handler: %d\n", ret);
94 static inline void default_group_changed_cb(struct livebox *handler, int ret, void *data)
96 DbgPrint("Default group changed event handler: %d\n", ret);
99 static inline void default_period_changed_cb(struct livebox *handler, int ret, void *data)
101 DbgPrint("Default period changed event handler: %d\n", ret);
104 static inline void default_pd_created_cb(struct livebox *handler, int ret, void *data)
106 DbgPrint("Default PD created event handler: %d\n", ret);
109 static inline void default_pd_destroyed_cb(struct livebox *handler, int ret, void *data)
111 DbgPrint("Default PD destroyed event handler: %d\n", ret);
114 static inline void default_lb_size_changed_cb(struct livebox *handler, int ret, void *data)
116 DbgPrint("Default LB size changed event handler: %d\n", ret);
119 static inline void default_update_mode_cb(struct livebox *handler, int ret, void *data)
121 DbgPrint("Default update mode set event handler: %d\n", ret);
124 static inline void default_access_event_cb(struct livebox *handler, int ret, void *data)
126 DbgPrint("Default access event handler: %d\n", ret);
129 static inline __attribute__((always_inline)) struct cb_info *create_cb_info(ret_cb_t cb, void *data)
131 struct cb_info *info;
133 info = malloc(sizeof(*info));
135 CRITICAL_LOG("Heap: %s\n", strerror(errno));
144 static inline void destroy_cb_info(struct cb_info *info)
149 static void update_mode_cb(struct livebox *handler, const struct packet *result, void *data)
154 ret = LB_STATUS_ERROR_FAULT;
156 } else if (packet_get(result, "i", &ret) != 1) {
157 ErrPrint("Invalid argument\n");
158 ret = LB_STATUS_ERROR_INVALID;
163 DbgPrint("Resize request is failed: %d\n", ret);
170 handler->update_mode_cb(handler, ret, handler->update_mode_cbdata);
171 handler->update_mode_cb = NULL;
172 handler->update_mode_cbdata = NULL;
176 static void resize_cb(struct livebox *handler, const struct packet *result, void *data)
179 struct cb_info *info = data;
185 destroy_cb_info(info);
188 ret = LB_STATUS_ERROR_FAULT;
190 } else if (packet_get(result, "i", &ret) != 1) {
191 ErrPrint("Invalid argument\n");
192 ret = LB_STATUS_ERROR_INVALID;
198 * In case of resize request,
199 * The livebox handler will not have resized value right after this callback,
200 * It can only get the new size when it makes updates.
202 * So the user can only get the resized value(result) from the first update event
203 * after this request.
206 DbgPrint("Resize request is failed: %d\n", ret);
210 DbgPrint("Resize request is successfully sent\n");
214 handler->size_changed_cb(handler, ret, handler->size_cbdata);
215 handler->size_changed_cb = NULL;
216 handler->size_cbdata = NULL;
219 static void text_signal_cb(struct livebox *handler, const struct packet *result, void *data)
223 struct cb_info *info = data;
228 destroy_cb_info(info);
231 ret = LB_STATUS_ERROR_FAULT;
232 } else if (packet_get(result, "i", &ret) != 1) {
233 ErrPrint("Invalid argument\n");
234 ret = LB_STATUS_ERROR_INVALID;
238 cb(handler, ret, cbdata);
242 static void set_group_ret_cb(struct livebox *handler, const struct packet *result, void *data)
247 ret = LB_STATUS_ERROR_FAULT;
249 } else if (packet_get(result, "i", &ret) != 1) {
250 ErrPrint("Invalid argument\n");
251 ret = LB_STATUS_ERROR_INVALID;
261 handler->group_changed_cb(handler, ret, handler->group_cbdata);
262 handler->group_changed_cb = NULL;
263 handler->group_cbdata = NULL;
266 static void period_ret_cb(struct livebox *handler, const struct packet *result, void *data)
271 ret = LB_STATUS_ERROR_FAULT;
273 } else if (packet_get(result, "i", &ret) != 1) {
274 ErrPrint("Invalid argument\n");
275 ret = LB_STATUS_ERROR_INVALID;
282 DbgPrint("Succeed to send period change request, waiting result\n");
286 handler->period_changed_cb(handler, ret, handler->period_cbdata);
287 handler->period_changed_cb = NULL;
288 handler->period_cbdata = NULL;
291 static void del_ret_cb(struct livebox *handler, const struct packet *result, void *data)
293 struct cb_info *info = data;
300 destroy_cb_info(info);
303 ErrPrint("Connection lost?\n");
304 ret = LB_STATUS_ERROR_FAULT;
305 } else if (packet_get(result, "i", &ret) != 1) {
306 ErrPrint("Invalid argument\n");
307 ret = LB_STATUS_ERROR_INVALID;
311 DbgPrint("Returns %d (waiting deleted event)\n", ret);
312 handler->deleted_cb = cb;
313 handler->deleted_cbdata = cbdata;
315 cb(handler, ret, cbdata);
320 * Do not call the deleted callback from here.
321 * master will send the "deleted" event.
322 * Then invoke this callback.
324 * if (handler->deleted_cb)
325 * handler->deleted_cb(handler, ret, handler->deleted_cbdata);
329 static void new_ret_cb(struct livebox *handler, const struct packet *result, void *data)
332 struct cb_info *info = data;
338 destroy_cb_info(info);
341 ret = LB_STATUS_ERROR_FAULT;
342 } else if (packet_get(result, "i", &ret) != 1) {
343 ret = LB_STATUS_ERROR_INVALID;
347 DbgPrint("new request is sent, just waiting the created event\n");
348 handler->created_cb = cb;
349 handler->created_cbdata = cbdata;
353 * Don't go anymore ;)
359 * It means the current instance is not created,
360 * so user has to know about this.
361 * notice it to user using "deleted" event.
363 cb(handler, ret, cbdata);
369 static void pd_create_cb(struct livebox *handler, const struct packet *result, void *data)
374 ret = LB_STATUS_ERROR_FAULT;
376 } else if (packet_get(result, "i", &ret) != 1) {
377 ret = LB_STATUS_ERROR_INVALID;
382 DbgPrint("Failed to create a PD\n");
389 handler->pd_created_cb(handler, ret, handler->pd_created_cbdata);
390 handler->pd_created_cb = NULL;
391 handler->pd_created_cbdata = NULL;
394 static void activated_cb(struct livebox *handler, const struct packet *result, void *data)
397 struct cb_info *info = data;
400 const char *pkgname = "";
404 destroy_cb_info(info);
407 ret = LB_STATUS_ERROR_FAULT;
408 } else if (packet_get(result, "is", &ret, &pkgname) != 2) {
409 ret = LB_STATUS_ERROR_INVALID;
413 cb(handler, ret, cbdata);
416 static void pd_destroy_cb(struct livebox *handler, const struct packet *result, void *data)
421 struct cb_info *info = data;
425 destroy_cb_info(info);
428 DbgPrint("Result is NIL (may connection lost)\n");
429 ret = LB_STATUS_ERROR_FAULT;
430 } else if (packet_get(result, "i", &ret) != 1) {
431 DbgPrint("Invalid parameter\n");
432 ret = LB_STATUS_ERROR_INVALID;
436 DbgPrint("PD Destroyed callback prepared\n");
437 handler->pd_destroyed_cb = cb;
438 handler->pd_destroyed_cbdata = cbdata;
440 DbgPrint("PD is not desroyed (forcely reset, pd flag)\n");
441 handler->is_pd_created = 0;
442 cb(handler, ret, cbdata);
446 static void delete_cluster_cb(struct livebox *handler, const struct packet *result, void *data)
448 struct cb_info *info = data;
455 destroy_cb_info(info);
458 ret = LB_STATUS_ERROR_FAULT;
459 } else if (packet_get(result, "i", &ret) != 1) {
460 ret = LB_STATUS_ERROR_INVALID;
463 DbgPrint("Delete category returns: %d\n", ret);
466 cb(handler, ret, cbdata);
469 static void delete_category_cb(struct livebox *handler, const struct packet *result, void *data)
471 struct cb_info *info = data;
478 destroy_cb_info(info);
481 ret = LB_STATUS_ERROR_FAULT;
482 else if (packet_get(result, "i", &ret) != 1)
483 ret = LB_STATUS_ERROR_INVALID;
485 DbgPrint("Delete category returns: %d\n", ret);
488 cb(handler, ret, cbdata);
491 static void pixmap_acquired_cb(struct livebox *handler, const struct packet *result, void *data)
496 struct cb_info *info = data;
500 destroy_cb_info(info);
503 ret = 0; /* PIXMAP 0 means error */
504 else if (packet_get(result, "i", &ret) != 1)
508 cb(handler, ret, cbdata);
511 static void pinup_done_cb(struct livebox *handler, const struct packet *result, void *data)
516 ret = LB_STATUS_ERROR_FAULT;
518 } else if (packet_get(result, "i", &ret) != 1) {
528 handler->pinup_cb(handler, ret, handler->pinup_cbdata);
529 handler->pinup_cb = NULL;
530 handler->pinup_cbdata = NULL;
533 static void access_ret_cb(struct livebox *handler, const struct packet *result, void *data)
538 ret = LB_STATUS_ERROR_FAULT;
542 if (packet_get(result, "i", &ret) != 1) {
543 ret = LB_STATUS_ERROR_INVALID;
547 if (ret != LB_STATUS_SUCCESS) {
551 DbgPrint("Access event is successfully sent. waiting result\n");
555 handler->access_event_cb(handler, ret, handler->access_event_cbdata);
556 handler->access_event_cb = NULL;
557 handler->access_event_cbdata = NULL;
561 static int send_access_event(struct livebox *handler, const char *event, int x, int y)
563 struct packet *packet;
566 timestamp = util_timestamp();
568 packet = packet_create(event, "ssdii", handler->pkgname, handler->id, timestamp, x, y);
570 ErrPrint("Failed to build packet\n");
571 return LB_STATUS_ERROR_FAULT;
574 DbgPrint("Send: %dx%d\n", x, y);
576 return master_rpc_async_request(handler, packet, 0, access_ret_cb, NULL);
579 static int send_mouse_event(struct livebox *handler, const char *event, int x, int y)
581 struct packet *packet;
584 timestamp = util_timestamp();
585 packet = packet_create_noack(event, "ssdii", handler->pkgname, handler->id, timestamp, x, y);
587 ErrPrint("Failed to build param\n");
588 return LB_STATUS_ERROR_FAULT;
591 DbgPrint("Send: %dx%d\n", x, y);
593 return master_rpc_request_only(handler, packet);
596 EAPI int livebox_init(void *disp)
600 if (s_info.init_count > 0) {
602 return LB_STATUS_SUCCESS;
604 env = getenv("PROVIDER_DISABLE_PREVENT_OVERWRITE");
605 if (env && !strcasecmp(env, "true"))
606 s_info.prevent_overwrite = 1;
608 env = getenv("PROVIDER_EVENT_FILTER");
610 sscanf(env, "%lf", &MINIMUM_EVENT);
613 char filename[BUFSIZ];
614 snprintf(filename, sizeof(filename), "/tmp/%d.box.log", getpid());
615 __file_log_fp = fopen(filename, "w+t");
617 __file_log_fp = fdopen(1, "w+t");
619 critical_log_init("viewer");
620 livebox_service_init();
626 return LB_STATUS_SUCCESS;
629 EAPI int livebox_fini(void)
631 if (s_info.init_count <= 0) {
632 DbgPrint("Didn't initialized\n");
633 return LB_STATUS_ERROR_INVALID;
637 if (s_info.init_count > 0) {
638 DbgPrint("init count : %d\n", s_info.init_count);
639 return LB_STATUS_SUCCESS;
644 livebox_service_fini();
646 return LB_STATUS_SUCCESS;
649 static inline char *lb_pkgname(const char *pkgname)
653 lb = livebox_service_pkgname(pkgname);
655 if (util_validate_livebox_package(pkgname) == 0)
656 return strdup(pkgname);
663 * Just wrapping the livebox_add_with_size function.
665 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)
667 return livebox_add_with_size(pkgname, content, cluster, category, period, LB_SIZE_TYPE_UNKNOWN, cb, data);
670 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)
672 struct livebox *handler;
673 struct packet *packet;
677 struct cb_info *cbinfo;
679 if (!pkgname || !cluster || !category) {
680 ErrPrint("Invalid arguments: pkgname[%p], cluster[%p], category[%p]\n",
681 pkgname, cluster, category);
685 if (type != LB_SIZE_TYPE_UNKNOWN)
686 livebox_service_get_size(type, &width, &height);
688 handler = calloc(1, sizeof(*handler));
690 ErrPrint("Error: %s\n", strerror(errno));
694 handler->pkgname = lb_pkgname(pkgname);
695 if (!handler->pkgname) {
700 if (livebox_service_is_enabled(handler->pkgname) == 0) {
701 DbgPrint("Livebox [%s](%s) is disabled package\n", handler->pkgname, pkgname);
702 free(handler->pkgname);
708 handler->content = strdup(content);
709 if (!handler->content) {
710 ErrPrint("Error: %s\n", strerror(errno));
711 free(handler->pkgname);
716 handler->content = livebox_service_content(handler->pkgname);
719 handler->cluster = strdup(cluster);
720 if (!handler->cluster) {
721 ErrPrint("Error: %s\n", strerror(errno));
722 free(handler->content);
723 free(handler->pkgname);
728 handler->category = strdup(category);
729 if (!handler->category) {
730 ErrPrint("Error: %s\n", strerror(errno));
731 free(handler->cluster);
732 free(handler->content);
733 free(handler->pkgname);
739 cb = default_create_cb;
741 /* Data provider will set this */
742 handler->lb.type = _LB_TYPE_FILE;
743 handler->pd.type = _PD_TYPE_SCRIPT;
744 handler->lb.period = period;
746 /* Used for handling the mouse event on a box */
747 handler->lb.mouse_event = livebox_service_mouse_event(handler->pkgname);
749 /* Cluster infomration is not determined yet */
750 handler->nr_of_sizes = 0x01;
752 handler->timestamp = util_timestamp();
753 handler->is_user = 1;
754 handler->visible = LB_SHOW;
756 s_info.livebox_list = dlist_append(s_info.livebox_list, handler);
758 packet = packet_create("new", "dssssdii", handler->timestamp, handler->pkgname, handler->content, cluster, category, period, width, height);
760 ErrPrint("Failed to create a new packet\n");
761 free(handler->category);
762 free(handler->cluster);
763 free(handler->content);
764 free(handler->pkgname);
769 cbinfo = create_cb_info(cb, data);
771 ErrPrint("Failed to create a cbinfo\n");
772 packet_destroy(packet);
773 free(handler->category);
774 free(handler->cluster);
775 free(handler->content);
776 free(handler->pkgname);
781 ret = master_rpc_async_request(handler, packet, 0, new_ret_cb, cbinfo);
783 ErrPrint("Failed to send a new packet\n");
784 destroy_cb_info(cbinfo);
785 free(handler->category);
786 free(handler->cluster);
787 free(handler->content);
788 free(handler->pkgname);
793 DbgPrint("Successfully sent a new request ([%lf] %s)\n", handler->timestamp, handler->pkgname);
794 handler->state = CREATE;
795 return lb_ref(handler);
798 EAPI double livebox_period(struct livebox *handler)
800 if (!handler || handler->state != CREATE || !handler->id) {
801 ErrPrint("Handler is not valid\n");
805 return handler->lb.period;
808 EAPI int livebox_set_period(struct livebox *handler, double period, ret_cb_t cb, void *data)
810 struct packet *packet;
813 if (!handler || handler->state != CREATE || !handler->id) {
814 ErrPrint("Handler is not valid\n");
815 return LB_STATUS_ERROR_INVALID;
818 if (handler->period_changed_cb) {
819 ErrPrint("Previous request for changing period is not finished\n");
820 return LB_STATUS_ERROR_BUSY;
823 if (!handler->is_user) {
824 ErrPrint("CA Livebox is not able to change the period\n");
825 return LB_STATUS_ERROR_PERMISSION;
828 if (handler->lb.period == period) {
829 DbgPrint("No changes\n");
830 return LB_STATUS_ERROR_ALREADY;
833 packet = packet_create("set_period", "ssd", handler->pkgname, handler->id, period);
835 ErrPrint("Failed to build a packet %s\n", handler->pkgname);
836 return LB_STATUS_ERROR_FAULT;
840 cb = default_period_changed_cb;
842 handler->period_changed_cb = cb;
843 handler->period_cbdata = data;
845 ret = master_rpc_async_request(handler, packet, 0, period_ret_cb, NULL);
847 handler->period_changed_cb = NULL;
848 handler->period_cbdata = NULL;
854 EAPI int livebox_del(struct livebox *handler, ret_cb_t cb, void *data)
857 ErrPrint("Handler is NIL\n");
858 return LB_STATUS_ERROR_INVALID;
861 if (handler->state != CREATE) {
862 ErrPrint("Handler is already deleted\n");
863 return LB_STATUS_ERROR_INVALID;
866 handler->state = DELETE;
871 * The id is not determined yet.
872 * It means a user didn't receive created event yet.
873 * Then just stop to delete procedure from here.
874 * Because the "created" event handler will release this.
875 * By the way, if the user adds any callback for getting return status of this,
879 cb(handler, 0, data);
880 return LB_STATUS_SUCCESS;
884 cb = default_delete_cb;
886 return lb_send_delete(handler, cb, data);
889 EAPI int livebox_set_fault_handler(int (*cb)(enum livebox_fault_type, const char *, const char *, const char *, void *), void *data)
891 struct fault_info *info;
894 return LB_STATUS_ERROR_INVALID;
896 info = malloc(sizeof(*info));
898 CRITICAL_LOG("Heap: %s\n", strerror(errno));
899 return LB_STATUS_ERROR_MEMORY;
903 info->user_data = data;
905 s_info.fault_list = dlist_append(s_info.fault_list, info);
906 return LB_STATUS_SUCCESS;
909 EAPI void *livebox_unset_fault_handler(int (*cb)(enum livebox_fault_type, const char *, const char *, const char *, void *))
911 struct fault_info *info;
914 dlist_foreach(s_info.fault_list, l, info) {
915 if (info->handler == cb) {
917 s_info.fault_list = dlist_remove(s_info.fault_list, l);
918 data = info->user_data;
928 EAPI int livebox_set_event_handler(int (*cb)(struct livebox *, enum livebox_event_type, void *), void *data)
930 struct event_info *info;
933 ErrPrint("Invalid argument cb is nil\n");
934 return LB_STATUS_ERROR_INVALID;
937 info = malloc(sizeof(*info));
939 CRITICAL_LOG("Heap: %s\n", strerror(errno));
940 return LB_STATUS_ERROR_MEMORY;
944 info->user_data = data;
946 s_info.event_list = dlist_append(s_info.event_list, info);
947 return LB_STATUS_SUCCESS;
950 EAPI void *livebox_unset_event_handler(int (*cb)(struct livebox *, enum livebox_event_type, void *))
952 struct event_info *info;
955 dlist_foreach(s_info.event_list, l, info) {
956 if (info->handler == cb) {
959 s_info.event_list = dlist_remove(s_info.event_list, l);
960 data = info->user_data;
970 EAPI int livebox_set_update_mode(struct livebox *handler, int active_update, ret_cb_t cb, void *data)
972 struct packet *packet;
976 ErrPrint("Handler is NIL\n");
977 return LB_STATUS_ERROR_INVALID;
980 if (handler->state != CREATE || !handler->id)
981 return LB_STATUS_ERROR_INVALID;
983 if (handler->update_mode_cb) {
984 ErrPrint("Previous update_mode cb is not finished yet\n");
985 return LB_STATUS_ERROR_BUSY;
988 if (handler->is_active_update == active_update)
989 return LB_STATUS_ERROR_ALREADY;
991 if (!handler->is_user)
992 return LB_STATUS_ERROR_PERMISSION;
994 packet = packet_create("update_mode", "ssi", handler->pkgname, handler->id, active_update);
996 return LB_STATUS_ERROR_FAULT;
999 cb = default_update_mode_cb;
1001 handler->update_mode_cb = cb;
1002 handler->update_mode_cbdata = data;
1004 ret = master_rpc_async_request(handler, packet, 0, update_mode_cb, NULL);
1006 handler->update_mode_cb = NULL;
1007 handler->update_mode_cbdata = NULL;
1013 EAPI int livebox_is_active_update(struct livebox *handler)
1016 ErrPrint("Handler is NIL\n");
1017 return LB_STATUS_ERROR_INVALID;
1020 if (handler->state != CREATE || !handler->id)
1021 return LB_STATUS_ERROR_INVALID;
1023 return handler->is_active_update;
1026 EAPI int livebox_resize(struct livebox *handler, int type, ret_cb_t cb, void *data)
1028 struct packet *packet;
1034 ErrPrint("Handler is NIL\n");
1035 return LB_STATUS_ERROR_INVALID;
1038 if (handler->state != CREATE || !handler->id) {
1039 ErrPrint("Handler is not valid\n");
1040 return LB_STATUS_ERROR_INVALID;
1043 if (handler->size_changed_cb) {
1044 ErrPrint("Previous resize request is not finished yet\n");
1045 return LB_STATUS_ERROR_BUSY;
1048 if (!handler->is_user) {
1049 ErrPrint("CA Livebox is not able to be resized\n");
1050 return LB_STATUS_ERROR_PERMISSION;
1053 if (livebox_service_get_size(type, &w, &h) != 0) {
1054 ErrPrint("Invalid size type\n");
1055 return LB_STATUS_ERROR_INVALID;
1058 if (handler->lb.width == w && handler->lb.height == h) {
1059 DbgPrint("No changes\n");
1060 return LB_STATUS_ERROR_ALREADY;;
1063 packet = packet_create("resize", "ssii", handler->pkgname, handler->id, w, h);
1065 ErrPrint("Failed to build param\n");
1066 return LB_STATUS_ERROR_FAULT;
1070 cb = default_lb_size_changed_cb;
1072 handler->size_changed_cb = cb;
1073 handler->size_cbdata = data;
1075 ret = master_rpc_async_request(handler, packet, 0, resize_cb, NULL);
1077 handler->size_changed_cb = NULL;
1078 handler->size_cbdata = NULL;
1084 EAPI int livebox_click(struct livebox *handler, double x, double y)
1086 struct packet *packet;
1091 ErrPrint("Handler is NIL\n");
1092 return LB_STATUS_ERROR_INVALID;
1095 if (handler->state != CREATE || !handler->id) {
1096 ErrPrint("Handler is not valid\n");
1097 return LB_STATUS_ERROR_INVALID;
1100 if (handler->lb.auto_launch)
1101 if (aul_open_app(handler->lb.auto_launch) < 0)
1102 ErrPrint("Failed to launch app %s\n", handler->lb.auto_launch);
1104 timestamp = util_timestamp();
1105 packet = packet_create_noack("clicked", "sssddd", handler->pkgname, handler->id, "clicked", timestamp, x, y);
1107 ErrPrint("Failed to build param\n");
1108 return LB_STATUS_ERROR_FAULT;
1111 ret = master_rpc_request_only(handler, packet);
1112 DbgPrint("Click request: %d\n", ret);
1114 if (!handler->lb.mouse_event && (handler->lb.type == _LB_TYPE_BUFFER || handler->lb.type == _LB_TYPE_SCRIPT)) {
1115 int ret; /* Shadow variable */
1116 ret = send_mouse_event(handler, "lb_mouse_down", x * handler->lb.width, y * handler->lb.height);
1118 DbgPrint("Failed to send Down: %d\n", ret);
1120 ret = send_mouse_event(handler, "lb_mouse_move", x * handler->lb.width, y * handler->lb.height);
1122 DbgPrint("Failed to send Move: %d\n", ret);
1124 ret = send_mouse_event(handler, "lb_mouse_up", x * handler->lb.width, y * handler->lb.height);
1126 DbgPrint("Failed to send Up: %d\n", ret);
1132 EAPI int livebox_has_pd(struct livebox *handler)
1135 ErrPrint("Handler is NIL\n");
1136 return LB_STATUS_ERROR_INVALID;
1139 if (handler->state != CREATE || !handler->id) {
1140 ErrPrint("Handler is not valid\n");
1141 return LB_STATUS_ERROR_INVALID;
1144 return !!handler->pd.data.fb;
1147 EAPI int livebox_pd_is_created(struct livebox *handler)
1150 ErrPrint("Handler is NIL\n");
1151 return LB_STATUS_ERROR_INVALID;
1154 if (!handler->pd.data.fb || handler->state != CREATE || !handler->id) {
1155 ErrPrint("Handler is not valid\n");
1156 return LB_STATUS_ERROR_INVALID;
1159 return handler->is_pd_created;
1162 EAPI int livebox_create_pd(struct livebox *handler, ret_cb_t cb, void *data)
1164 return livebox_create_pd_with_position(handler, -1.0, -1.0, cb, data);
1167 EAPI int livebox_create_pd_with_position(struct livebox *handler, double x, double y, ret_cb_t cb, void *data)
1169 struct packet *packet;
1173 ErrPrint("Handler is NIL\n");
1174 return LB_STATUS_ERROR_INVALID;
1177 if (!handler->pd.data.fb || handler->state != CREATE || !handler->id) {
1178 ErrPrint("Handler is not valid\n");
1179 return LB_STATUS_ERROR_INVALID;
1182 if (handler->is_pd_created == 1) {
1183 DbgPrint("PD already created\n");
1184 return LB_STATUS_SUCCESS;
1187 if (handler->pd_created_cb) {
1188 ErrPrint("Previous request is not completed yet\n");
1189 return LB_STATUS_ERROR_BUSY;
1192 packet = packet_create("create_pd", "ssdd", handler->pkgname, handler->id, x, y);
1194 ErrPrint("Failed to build param\n");
1195 return LB_STATUS_ERROR_FAULT;
1199 cb = default_pd_created_cb;
1201 handler->pd_created_cb = cb;
1202 handler->pd_created_cbdata = data;
1204 ret = master_rpc_async_request(handler, packet, 0, pd_create_cb, NULL);
1206 handler->pd_created_cb = NULL;
1207 handler->pd_created_cbdata = NULL;
1213 EAPI int livebox_move_pd(struct livebox *handler, double x, double y)
1215 struct packet *packet;
1218 ErrPrint("Handler is NIL\n");
1219 return LB_STATUS_ERROR_INVALID;
1222 if (!handler->pd.data.fb || handler->state != CREATE || !handler->id) {
1223 ErrPrint("Handler is not valid\n");
1224 return LB_STATUS_ERROR_INVALID;
1227 if (!handler->is_pd_created) {
1228 DbgPrint("PD is not created\n");
1229 return LB_STATUS_ERROR_INVALID;
1232 packet = packet_create_noack("pd_move", "ssdd", handler->pkgname, handler->id, x, y);
1234 ErrPrint("Failed to build param\n");
1235 return LB_STATUS_ERROR_FAULT;
1238 return master_rpc_request_only(handler, packet);
1241 EAPI int livebox_activate(const char *pkgname, ret_cb_t cb, void *data)
1243 struct packet *packet;
1244 struct cb_info *cbinfo;
1248 return LB_STATUS_ERROR_INVALID;
1250 packet = packet_create("activate_package", "s", pkgname);
1252 ErrPrint("Failed to build a param\n");
1253 return LB_STATUS_ERROR_FAULT;
1256 cbinfo = create_cb_info(cb, data);
1258 ErrPrint("Unable to create cbinfo\n");
1259 packet_destroy(packet);
1260 return LB_STATUS_ERROR_FAULT;
1263 ret = master_rpc_async_request(NULL, packet, 0, activated_cb, cbinfo);
1265 destroy_cb_info(cbinfo);
1270 EAPI int livebox_destroy_pd(struct livebox *handler, ret_cb_t cb, void *data)
1272 struct packet *packet;
1273 struct cb_info *cbinfo;
1277 ErrPrint("Handler is NIL\n");
1278 return LB_STATUS_ERROR_INVALID;
1281 if (!handler->pd.data.fb || handler->state != CREATE || !handler->id) {
1282 ErrPrint("Handler is not valid\n");
1283 return LB_STATUS_ERROR_INVALID;
1286 if (!handler->is_pd_created) {
1287 ErrPrint("PD is not created\n");
1288 return LB_STATUS_ERROR_INVALID;
1291 packet = packet_create("destroy_pd", "ss", handler->pkgname, handler->id);
1293 ErrPrint("Failed to build a param\n");
1294 return LB_STATUS_ERROR_FAULT;
1298 cb = default_pd_destroyed_cb;
1300 cbinfo = create_cb_info(cb, data);
1302 packet_destroy(packet);
1303 return LB_STATUS_ERROR_FAULT;
1306 ret = master_rpc_async_request(handler, packet, 0, pd_destroy_cb, cbinfo);
1308 destroy_cb_info(cbinfo);
1313 EAPI int livebox_access_event(struct livebox *handler, enum access_event_type type, double x, double y, ret_cb_t cb, void *data)
1317 char cmd[32] = { '\0', };
1322 ErrPrint("Handler is NIL\n");
1323 return LB_STATUS_ERROR_INVALID;
1326 if (handler->state != CREATE || !handler->id) {
1327 ErrPrint("Handler is not valid\n");
1328 return LB_STATUS_ERROR_INVALID;
1331 if (handler->access_event_cb) {
1332 ErrPrint("Previous access event is not yet done\n");
1333 return LB_STATUS_ERROR_BUSY;
1336 if (type & ACCESS_EVENT_PD_MASK) {
1337 if (!handler->is_pd_created) {
1338 ErrPrint("PD is not created\n");
1339 return LB_STATUS_ERROR_INVALID;
1343 w = handler->pd.width;
1344 h = handler->pd.height;
1345 } else if (type & ACCESS_EVENT_LB_MASK) {
1348 w = handler->lb.width;
1349 h = handler->lb.height;
1351 ErrPrint("Invalid event type\n");
1352 return LB_STATUS_ERROR_INVALID;
1355 switch (type & ~ACCESS_EVENT_PD_MASK) {
1356 case ACCESS_EVENT_HIGHLIGHT:
1357 strcpy(ptr, "_access_hl");
1359 case ACCESS_EVENT_HIGHLIGHT_NEXT:
1360 strcpy(ptr, "_access_hl_next");
1362 case ACCESS_EVENT_HIGHLIGHT_PREV:
1363 strcpy(ptr, "_access_hl_prev");
1365 case ACCESS_EVENT_ACTIVATE:
1366 strcpy(ptr, "_access_activate");
1368 case ACCESS_EVENT_VALUE_CHANGE:
1369 strcpy(ptr, "_access_value_change");
1371 case ACCESS_EVENT_SCROLL:
1372 strcpy(ptr, "_access_scroll");
1374 case ACCESS_EVENT_UNHIGHLIGHT:
1375 strcpy(ptr, "_access_unhighlight");
1378 return LB_STATUS_ERROR_INVALID;
1382 cb = default_access_event_cb;
1384 handler->access_event_cb = cb;
1385 handler->access_event_cbdata = data;
1387 ret = send_access_event(handler, cmd, x * w, y * h);
1389 handler->access_event_cb = NULL;
1390 handler->access_event_cbdata = NULL;
1396 EAPI int livebox_content_event(struct livebox *handler, enum content_event_type type, double x, double y)
1400 char cmd[32] = { '\0', };
1404 ErrPrint("Handler is NIL\n");
1405 return LB_STATUS_ERROR_INVALID;
1408 if (handler->state != CREATE || !handler->id) {
1409 ErrPrint("Handler is not valid\n");
1410 return LB_STATUS_ERROR_INVALID;
1413 if (type & CONTENT_EVENT_PD_MASK) {
1416 if (!handler->is_pd_created) {
1417 ErrPrint("PD is not created\n");
1418 return LB_STATUS_ERROR_INVALID;
1421 if (type & CONTENT_EVENT_MOUSE_MASK) {
1422 if (!handler->pd.data.fb) {
1423 ErrPrint("Handler is not valid\n");
1424 return LB_STATUS_ERROR_INVALID;
1427 if (type & CONTENT_EVENT_MOUSE_MOVE) {
1428 if (fabs(x - handler->pd.x) < MINIMUM_EVENT && fabs(y - handler->pd.y) < MINIMUM_EVENT)
1429 return LB_STATUS_ERROR_BUSY;
1430 } else if (type & CONTENT_EVENT_MOUSE_SET) {
1436 w = handler->pd.width;
1437 h = handler->pd.height;
1446 if (type & CONTENT_EVENT_MOUSE_MASK) {
1447 if (!handler->lb.mouse_event) {
1448 ErrPrint("Box is not support the mouse event\n");
1449 return LB_STATUS_ERROR_INVALID;
1452 if (!handler->lb.data.fb) {
1453 ErrPrint("Handler is not valid\n");
1454 return LB_STATUS_ERROR_INVALID;
1457 if (type & CONTENT_EVENT_MOUSE_MOVE) {
1458 if (fabs(x - handler->lb.x) < MINIMUM_EVENT && fabs(y - handler->lb.y) < MINIMUM_EVENT)
1459 return LB_STATUS_ERROR_BUSY;
1460 } else if (type & CONTENT_EVENT_MOUSE_SET) {
1466 w = handler->lb.width;
1467 h = handler->lb.height;
1476 * Must be short than 29 bytes.
1478 switch ((type & ~CONTENT_EVENT_PD_MASK)) {
1479 case CONTENT_EVENT_MOUSE_ENTER | CONTENT_EVENT_MOUSE_MASK:
1480 strcpy(ptr, "_mouse_enter");
1482 case CONTENT_EVENT_MOUSE_LEAVE | CONTENT_EVENT_MOUSE_MASK:
1483 strcpy(ptr, "_mouse_leave");
1485 case CONTENT_EVENT_MOUSE_UP | CONTENT_EVENT_MOUSE_MASK:
1486 strcpy(ptr, "_mouse_up");
1488 case CONTENT_EVENT_MOUSE_DOWN | CONTENT_EVENT_MOUSE_MASK:
1489 strcpy(ptr, "_mouse_down");
1491 case CONTENT_EVENT_MOUSE_MOVE | CONTENT_EVENT_MOUSE_MASK:
1492 strcpy(ptr, "_mouse_move");
1494 case CONTENT_EVENT_MOUSE_SET | CONTENT_EVENT_MOUSE_MASK:
1495 strcpy(ptr, "_mouse_set");
1497 case CONTENT_EVENT_MOUSE_UNSET | CONTENT_EVENT_MOUSE_MASK:
1498 strcpy(ptr, "_mouse_unset");
1500 case CONTENT_EVENT_KEY_DOWN | CONTENT_EVENT_KEY_MASK:
1501 strcpy(ptr, "_key_down");
1503 case CONTENT_EVENT_KEY_UP | CONTENT_EVENT_KEY_MASK:
1504 strcpy(ptr, "_key_up");
1507 ErrPrint("Invalid event type\n");
1508 return LB_STATUS_ERROR_INVALID;
1511 return send_mouse_event(handler, cmd, x * w, y * h);
1514 EAPI const char *livebox_filename(struct livebox *handler)
1517 ErrPrint("Handler is NIL\n");
1521 if (handler->state != CREATE || !handler->id) {
1522 ErrPrint("Handler is not valid\n");
1526 if (handler->filename)
1527 return handler->filename;
1530 return util_uri_to_path(handler->id);
1533 EAPI int livebox_get_pdsize(struct livebox *handler, int *w, int *h)
1539 ErrPrint("Handler is NIL\n");
1540 return LB_STATUS_ERROR_INVALID;
1543 if (handler->state != CREATE || !handler->id) {
1544 ErrPrint("Handler is not valid\n");
1545 return LB_STATUS_ERROR_INVALID;
1553 if (!handler->is_pd_created) {
1554 DbgPrint("Buffer is not created yet [%dx%d]\n", *w, *h);
1555 *w = handler->pd.default_width;
1556 *h = handler->pd.default_height;
1558 *w = handler->pd.width;
1559 *h = handler->pd.height;
1562 return LB_STATUS_SUCCESS;
1565 EAPI int livebox_size(struct livebox *handler)
1571 ErrPrint("Handler is NIL\n");
1572 return LB_STATUS_ERROR_INVALID;
1575 if (handler->state != CREATE || !handler->id) {
1576 ErrPrint("Handler is not valid\n");
1577 return LB_STATUS_ERROR_INVALID;
1580 w = handler->lb.width;
1581 h = handler->lb.height;
1583 switch (handler->lb.type) {
1584 case _LB_TYPE_BUFFER:
1585 case _LB_TYPE_SCRIPT:
1586 if (!fb_is_created(handler->lb.data.fb)) {
1587 DbgPrint("Buffer is not created yet - reset size\n");
1596 return livebox_service_size_type(w, h);
1599 EAPI int livebox_set_group(struct livebox *handler, const char *cluster, const char *category, ret_cb_t cb, void *data)
1601 struct packet *packet;
1605 ErrPrint("Handler is NIL\n");
1606 return LB_STATUS_ERROR_INVALID;
1609 if (!cluster || !category || handler->state != CREATE || !handler->id) {
1610 ErrPrint("Invalid argument\n");
1611 return LB_STATUS_ERROR_INVALID;
1614 if (handler->group_changed_cb) {
1615 ErrPrint("Previous group changing request is not finished yet\n");
1616 return LB_STATUS_ERROR_BUSY;
1619 if (!handler->is_user) {
1620 ErrPrint("CA Livebox is not able to change the group\n");
1621 return LB_STATUS_ERROR_PERMISSION;
1624 if (!strcmp(handler->cluster, cluster) && !strcmp(handler->category, category)) {
1625 DbgPrint("No changes\n");
1626 return LB_STATUS_ERROR_ALREADY;
1629 packet = packet_create("change_group", "ssss", handler->pkgname, handler->id, cluster, category);
1631 ErrPrint("Failed to build a param\n");
1632 return LB_STATUS_ERROR_FAULT;
1636 cb = default_group_changed_cb;
1638 handler->group_changed_cb = cb;
1639 handler->group_cbdata = data;
1641 ret = master_rpc_async_request(handler, packet, 0, set_group_ret_cb, NULL);
1643 handler->group_changed_cb = NULL;
1644 handler->group_cbdata = NULL;
1650 EAPI int livebox_get_group(struct livebox *handler, char ** const cluster, char ** const category)
1653 ErrPrint("Handler is NIL\n");
1654 return LB_STATUS_ERROR_INVALID;
1657 if (!cluster || !category || handler->state != CREATE || !handler->id) {
1658 ErrPrint("Invalid argument\n");
1659 return LB_STATUS_ERROR_INVALID;
1662 *cluster = handler->cluster;
1663 *category = handler->category;
1664 return LB_STATUS_SUCCESS;
1667 EAPI int livebox_get_supported_sizes(struct livebox *handler, int *cnt, int *size_list)
1672 if (!handler || !size_list) {
1673 ErrPrint("Invalid argument, handler(%p), size_list(%p)\n", handler, size_list);
1674 return LB_STATUS_ERROR_INVALID;
1677 if (!cnt || handler->state != CREATE || !handler->id) {
1678 ErrPrint("Handler is not valid\n");
1679 return LB_STATUS_ERROR_INVALID;
1682 for (j = i = 0; i < NR_OF_SIZE_LIST; i++) {
1683 if (handler->lb.size_list & (0x01 << i)) {
1687 size_list[j++] = (0x01 << i);
1692 return LB_STATUS_SUCCESS;
1695 EAPI const char *livebox_pkgname(struct livebox *handler)
1698 ErrPrint("Handler is NIL\n");
1702 if (handler->state != CREATE) {
1703 ErrPrint("Handler is not valid\n");
1707 return handler->pkgname;
1710 EAPI double livebox_priority(struct livebox *handler)
1713 ErrPrint("Handler is NIL\n");
1717 if (handler->state != CREATE || !handler->id) {
1718 ErrPrint("Handler is not valid (%p)\n", handler);
1722 return handler->lb.priority;
1725 EAPI int livebox_delete_cluster(const char *cluster, ret_cb_t cb, void *data)
1727 struct packet *packet;
1728 struct cb_info *cbinfo;
1731 packet = packet_create("delete_cluster", "s", cluster);
1733 ErrPrint("Failed to build a param\n");
1734 return LB_STATUS_ERROR_FAULT;
1737 cbinfo = create_cb_info(cb, data);
1739 packet_destroy(packet);
1740 return LB_STATUS_ERROR_FAULT;
1743 ret = master_rpc_async_request(NULL, packet, 0, delete_cluster_cb, cbinfo);
1745 destroy_cb_info(cbinfo);
1750 EAPI int livebox_delete_category(const char *cluster, const char *category, ret_cb_t cb, void *data)
1752 struct packet *packet;
1753 struct cb_info *cbinfo;
1756 packet = packet_create("delete_category", "ss", cluster, category);
1758 ErrPrint("Failed to build a param\n");
1759 return LB_STATUS_ERROR_FAULT;
1762 cbinfo = create_cb_info(cb, data);
1764 packet_destroy(packet);
1765 return LB_STATUS_ERROR_FAULT;
1768 ret = master_rpc_async_request(NULL, packet, 0, delete_category_cb, cbinfo);
1770 destroy_cb_info(cbinfo);
1775 EAPI enum livebox_lb_type livebox_lb_type(struct livebox *handler)
1778 ErrPrint("Handler is NIL\n");
1779 return LB_TYPE_INVALID;
1782 if (handler->state != CREATE || !handler->id) {
1783 ErrPrint("Handler is not valid\n");
1784 return LB_TYPE_INVALID;
1787 switch (handler->lb.type) {
1789 return LB_TYPE_IMAGE;
1790 case _LB_TYPE_BUFFER:
1791 case _LB_TYPE_SCRIPT:
1794 id = fb_id(handler->lb.data.fb);
1795 if (id && !strncasecmp(id, SCHEMA_PIXMAP, strlen(SCHEMA_PIXMAP)))
1796 return LB_TYPE_PIXMAP;
1798 return LB_TYPE_BUFFER;
1800 return LB_TYPE_TEXT;
1805 return LB_TYPE_INVALID;
1808 EAPI enum livebox_pd_type livebox_pd_type(struct livebox *handler)
1811 ErrPrint("Handler is NIL\n");
1812 return PD_TYPE_INVALID;
1815 if (handler->state != CREATE || !handler->id) {
1816 ErrPrint("Handler is not valid\n");
1817 return PD_TYPE_INVALID;
1820 switch (handler->pd.type) {
1822 return PD_TYPE_TEXT;
1823 case _PD_TYPE_BUFFER:
1824 case _PD_TYPE_SCRIPT:
1827 id = fb_id(handler->pd.data.fb);
1828 if (id && !strncasecmp(id, SCHEMA_PIXMAP, strlen(SCHEMA_PIXMAP)))
1829 return PD_TYPE_PIXMAP;
1831 return PD_TYPE_BUFFER;
1836 return PD_TYPE_INVALID;
1839 EAPI int livebox_set_pd_text_handler(struct livebox *handler, struct livebox_script_operators *ops)
1842 ErrPrint("Handler is NIL\n");
1843 return LB_STATUS_ERROR_INVALID;
1846 if (handler->state != CREATE) {
1847 ErrPrint("Handler is not valid\n");
1848 return LB_STATUS_ERROR_INVALID;
1851 memcpy(&handler->pd.data.ops, ops, sizeof(*ops));
1852 return LB_STATUS_SUCCESS;
1855 EAPI int livebox_set_text_handler(struct livebox *handler, struct livebox_script_operators *ops)
1858 ErrPrint("Handler is NIL\n");
1859 return LB_STATUS_ERROR_INVALID;
1862 if (handler->state != CREATE) {
1863 ErrPrint("Handler is not valid\n");
1864 return LB_STATUS_ERROR_INVALID;
1867 memcpy(&handler->lb.data.ops, ops, sizeof(*ops));
1868 return LB_STATUS_SUCCESS;
1871 EAPI int livebox_acquire_lb_pixmap(struct livebox *handler, ret_cb_t cb, void *data)
1873 struct packet *packet;
1874 struct cb_info *cbinfo;
1879 ErrPrint("Handler is NIL\n");
1880 return LB_STATUS_ERROR_INVALID;
1883 if (handler->state != CREATE || !handler->id) {
1884 ErrPrint("Invalid handle\n");
1885 return LB_STATUS_ERROR_INVALID;
1888 if (handler->lb.type != _LB_TYPE_SCRIPT && handler->lb.type != _LB_TYPE_BUFFER) {
1889 ErrPrint("Handler is not valid type\n");
1890 return LB_STATUS_ERROR_INVALID;
1893 id = fb_id(handler->lb.data.fb);
1894 if (!id || strncasecmp(id, SCHEMA_PIXMAP, strlen(SCHEMA_PIXMAP)))
1895 return LB_STATUS_ERROR_INVALID;
1897 packet = packet_create("lb_acquire_pixmap", "ss", handler->pkgname, handler->id);
1899 ErrPrint("Failed to build a param\n");
1900 return LB_STATUS_ERROR_FAULT;
1903 cbinfo = create_cb_info(cb, data);
1905 packet_destroy(packet);
1906 return LB_STATUS_ERROR_FAULT;
1909 ret = master_rpc_async_request(handler, packet, 0, pixmap_acquired_cb, cbinfo);
1911 destroy_cb_info(cbinfo);
1916 EAPI int livebox_release_lb_pixmap(struct livebox *handler, int pixmap)
1918 struct packet *packet;
1921 ErrPrint("Handler is NIL\n");
1922 return LB_STATUS_ERROR_INVALID;
1925 if (handler->state != CREATE || !handler->id) {
1926 ErrPrint("Invalid handle\n");
1927 return LB_STATUS_ERROR_INVALID;
1930 if (handler->lb.type != _LB_TYPE_SCRIPT && handler->lb.type != _LB_TYPE_BUFFER) {
1931 ErrPrint("Handler is not valid type\n");
1932 return LB_STATUS_ERROR_INVALID;
1935 packet = packet_create_noack("lb_release_pixmap", "ssi", handler->pkgname, handler->id, pixmap);
1937 ErrPrint("Failed to build a param\n");
1938 return LB_STATUS_ERROR_INVALID;
1941 return master_rpc_request_only(handler, packet);
1944 EAPI int livebox_acquire_pd_pixmap(struct livebox *handler, ret_cb_t cb, void *data)
1946 struct packet *packet;
1947 struct cb_info *cbinfo;
1952 ErrPrint("Handler is NIL\n");
1953 return LB_STATUS_ERROR_INVALID;
1956 if (handler->state != CREATE || !handler->id) {
1957 ErrPrint("Invalid handle\n");
1958 return LB_STATUS_ERROR_INVALID;
1961 if (handler->pd.type != _PD_TYPE_SCRIPT && handler->pd.type != _PD_TYPE_BUFFER) {
1962 ErrPrint("Handler is not valid type\n");
1963 return LB_STATUS_ERROR_INVALID;
1966 id = fb_id(handler->pd.data.fb);
1967 if (!id || strncasecmp(id, SCHEMA_PIXMAP, strlen(SCHEMA_PIXMAP)))
1968 return LB_STATUS_ERROR_INVALID;
1970 packet = packet_create("pd_acquire_pixmap", "ss", handler->pkgname, handler->id);
1972 ErrPrint("Failed to build a param\n");
1973 return LB_STATUS_ERROR_FAULT;
1976 cbinfo = create_cb_info(cb, data);
1978 packet_destroy(packet);
1979 return LB_STATUS_ERROR_FAULT;
1982 ret = master_rpc_async_request(handler, packet, 0, pixmap_acquired_cb, cbinfo);
1984 destroy_cb_info(cbinfo);
1989 EAPI int livebox_pd_pixmap(const struct livebox *handler)
1995 ErrPrint("Handler is NIL\n");
1999 if (handler->state != CREATE || !handler->id) {
2000 ErrPrint("Invalid handler\n");
2004 if (handler->pd.type != _PD_TYPE_SCRIPT && handler->pd.type != _PD_TYPE_BUFFER) {
2005 ErrPrint("Invalid handler\n");
2009 id = fb_id(handler->pd.data.fb);
2010 if (id && sscanf(id, SCHEMA_PIXMAP "%d", &pixmap) != 1) {
2011 ErrPrint("PIXMAP Id is not valid\n");
2018 EAPI int livebox_lb_pixmap(const struct livebox *handler)
2024 ErrPrint("Handler is NIL\n");
2028 if (handler->state != CREATE || !handler->id) {
2029 ErrPrint("Invalid handler\n");
2033 if (handler->lb.type != _LB_TYPE_SCRIPT && handler->lb.type != _LB_TYPE_BUFFER) {
2034 ErrPrint("Invalid handler\n");
2038 id = fb_id(handler->lb.data.fb);
2039 if (id && sscanf(id, SCHEMA_PIXMAP "%d", &pixmap) != 1) {
2040 ErrPrint("PIXMAP Id is not valid\n");
2047 EAPI int livebox_release_pd_pixmap(struct livebox *handler, int pixmap)
2049 struct packet *packet;
2052 ErrPrint("Handler is NIL\n");
2053 return LB_STATUS_ERROR_INVALID;
2056 if (handler->state != CREATE || !handler->id) {
2057 ErrPrint("Invalid handle\n");
2058 return LB_STATUS_ERROR_INVALID;
2061 if (handler->pd.type != _PD_TYPE_SCRIPT && handler->pd.type != _PD_TYPE_BUFFER) {
2062 ErrPrint("Handler is not valid type\n");
2063 return LB_STATUS_ERROR_INVALID;
2066 packet = packet_create_noack("pd_release_pixmap", "ssi", handler->pkgname, handler->id, pixmap);
2068 ErrPrint("Failed to build a param\n");
2069 return LB_STATUS_ERROR_FAULT;
2072 return master_rpc_request_only(handler, packet);
2075 EAPI void *livebox_acquire_fb(struct livebox *handler)
2078 ErrPrint("Handler is NIL\n");
2082 if (handler->state != CREATE || !handler->id) {
2083 ErrPrint("Invalid handle\n");
2087 if (handler->lb.type != _LB_TYPE_SCRIPT && handler->lb.type != _LB_TYPE_BUFFER) {
2088 ErrPrint("Handler is not valid type\n");
2092 return fb_acquire_buffer(handler->lb.data.fb);
2095 EAPI int livebox_release_fb(void *buffer)
2097 return fb_release_buffer(buffer);
2100 EAPI int livebox_fb_refcnt(void *buffer)
2102 return fb_refcnt(buffer);
2105 EAPI void *livebox_acquire_pdfb(struct livebox *handler)
2108 ErrPrint("Handler is NIL\n");
2112 if (handler->state != CREATE || !handler->id) {
2113 ErrPrint("Invalid handler\n");
2117 if (handler->pd.type != _PD_TYPE_SCRIPT && handler->pd.type != _PD_TYPE_BUFFER) {
2118 ErrPrint("Handler is not valid type\n");
2122 return fb_acquire_buffer(handler->pd.data.fb);
2125 EAPI int livebox_release_pdfb(void *buffer)
2127 return fb_release_buffer(buffer);
2130 EAPI int livebox_pdfb_refcnt(void *buffer)
2132 return fb_refcnt(buffer);
2135 EAPI int livebox_pdfb_bufsz(struct livebox *handler)
2138 ErrPrint("Handler is NIL\n");
2139 return LB_STATUS_ERROR_INVALID;
2142 if (handler->state != CREATE || !handler->id) {
2143 ErrPrint("Handler is not valid\n");
2144 return LB_STATUS_ERROR_INVALID;
2147 return fb_size(handler->pd.data.fb);
2150 EAPI int livebox_lbfb_bufsz(struct livebox *handler)
2153 ErrPrint("Handler is NIL\n");
2154 return LB_STATUS_ERROR_INVALID;
2157 if (handler->state != CREATE || !handler->id) {
2158 ErrPrint("Handler is not valid\n");
2159 return LB_STATUS_ERROR_INVALID;
2162 return fb_size(handler->lb.data.fb);
2165 EAPI int livebox_is_user(struct livebox *handler)
2168 ErrPrint("Handler is NIL\n");
2169 return LB_STATUS_ERROR_INVALID;
2172 if (handler->state != CREATE) {
2173 ErrPrint("Handler is invalid\n");
2174 return LB_STATUS_ERROR_INVALID;
2177 return handler->is_user;
2180 EAPI int livebox_set_pinup(struct livebox *handler, int flag, ret_cb_t cb, void *data)
2182 struct packet *packet;
2186 ErrPrint("Handler is NIL\n");
2187 return LB_STATUS_ERROR_INVALID;
2190 if (handler->state != CREATE || !handler->id) {
2191 ErrPrint("Handler is not valid\n");
2192 return LB_STATUS_ERROR_INVALID;
2195 if (handler->pinup_cb) {
2196 ErrPrint("Previous pinup request is not finished\n");
2197 return LB_STATUS_ERROR_BUSY;
2200 if (handler->is_pinned_up == flag) {
2201 DbgPrint("No changes\n");
2202 return LB_STATUS_ERROR_ALREADY;
2205 packet = packet_create("pinup_changed", "ssi", handler->pkgname, handler->id, flag);
2207 ErrPrint("Failed to build a param\n");
2208 return LB_STATUS_ERROR_FAULT;
2212 cb = default_pinup_cb;
2214 handler->pinup_cb = cb;
2215 handler->pinup_cbdata = data;
2217 ret = master_rpc_async_request(handler, packet, 0, pinup_done_cb, NULL);
2219 handler->pinup_cb = NULL;
2220 handler->pinup_cbdata = NULL;
2226 EAPI int livebox_is_pinned_up(struct livebox *handler)
2229 ErrPrint("Handler is NIL\n");
2230 return LB_STATUS_ERROR_INVALID;
2233 if (handler->state != CREATE || !handler->id)
2234 return LB_STATUS_ERROR_INVALID;
2236 return handler->is_pinned_up;
2239 EAPI int livebox_has_pinup(struct livebox *handler)
2242 ErrPrint("Handler is NIL\n");
2243 return LB_STATUS_ERROR_INVALID;
2246 if (handler->state != CREATE || !handler->id)
2247 return LB_STATUS_ERROR_INVALID;
2249 return handler->lb.pinup_supported;
2252 EAPI int livebox_set_data(struct livebox *handler, void *data)
2255 ErrPrint("Handler is NIL\n");
2256 return LB_STATUS_ERROR_INVALID;
2259 if (handler->state != CREATE)
2260 return LB_STATUS_ERROR_INVALID;
2262 handler->data = data;
2263 return LB_STATUS_SUCCESS;
2266 EAPI void *livebox_get_data(struct livebox *handler)
2269 ErrPrint("Handler is NIL\n");
2273 if (handler->state != CREATE)
2276 return handler->data;
2279 EAPI int livebox_is_exists(const char *pkgname)
2283 lb = lb_pkgname(pkgname);
2292 EAPI const char *livebox_content(struct livebox *handler)
2295 ErrPrint("Handler is NIL\n");
2299 if (handler->state != CREATE)
2302 return handler->content;
2305 EAPI const char *livebox_category_title(struct livebox *handler)
2308 ErrPrint("Handler is NIL\n");
2312 if (handler->state != CREATE)
2315 return handler->title;
2318 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)
2320 struct packet *packet;
2321 struct cb_info *cbinfo;
2325 ErrPrint("Handler is NIL\n");
2326 return LB_STATUS_ERROR_INVALID;
2329 if ((handler->lb.type != _LB_TYPE_TEXT && handler->pd.type != _PD_TYPE_TEXT) || handler->state != CREATE || !handler->id) {
2330 ErrPrint("Handler is not valid\n");
2331 return LB_STATUS_ERROR_INVALID;
2340 packet = packet_create("text_signal", "ssssdddd",
2341 handler->pkgname, handler->id, emission, source, sx, sy, ex, ey);
2343 ErrPrint("Failed to build a param\n");
2344 return LB_STATUS_ERROR_FAULT;
2347 cbinfo = create_cb_info(cb, data);
2349 packet_destroy(packet);
2350 return LB_STATUS_ERROR_FAULT;
2353 ret = master_rpc_async_request(handler, packet, 0, text_signal_cb, cbinfo);
2355 destroy_cb_info(cbinfo);
2357 return LB_STATUS_ERROR_FAULT;
2360 EAPI int livebox_subscribe_group(const char *cluster, const char *category)
2362 struct packet *packet;
2366 * Validate the group info using DB
2367 * If the group info is not valid, do not send this request
2370 packet = packet_create_noack("subscribe", "ss", cluster ? cluster : "", category ? category : "");
2372 ErrPrint("Failed to create a packet\n");
2373 return LB_STATUS_ERROR_FAULT;
2376 return master_rpc_request_only(NULL, packet);
2379 EAPI int livebox_unsubscribe_group(const char *cluster, const char *category)
2381 struct packet *packet;
2385 * Validate the group info using DB
2386 * If the group info is not valid, do not send this request
2387 * AND Check the subscribed or not too
2390 packet = packet_create_noack("unsubscribe", "ss", cluster ? cluster : "", category ? category : "");
2392 ErrPrint("Failed to create a packet\n");
2393 return LB_STATUS_ERROR_FAULT;
2396 return master_rpc_request_only(NULL, packet);
2399 EAPI int livebox_refresh(struct livebox *handler)
2401 struct packet *packet;
2404 ErrPrint("Hnalder is NIL\n");
2405 return LB_STATUS_ERROR_INVALID;
2408 if (handler->state != CREATE || !handler->id)
2409 return LB_STATUS_ERROR_INVALID;
2411 packet = packet_create_noack("update", "ss", handler->pkgname, handler->id);
2413 ErrPrint("Failed to create a packet\n");
2414 return LB_STATUS_ERROR_FAULT;
2417 return master_rpc_request_only(handler, packet);
2420 EAPI int livebox_refresh_group(const char *cluster, const char *category)
2422 struct packet *packet;
2424 if (!cluster || !category) {
2425 ErrPrint("Invalid argument\n");
2426 return LB_STATUS_ERROR_INVALID;
2429 packet = packet_create_noack("refresh_group", "ss", cluster, category);
2431 ErrPrint("Failed to create a packet\n");
2432 return LB_STATUS_ERROR_FAULT;
2435 return master_rpc_request_only(NULL, packet);
2438 EAPI int livebox_set_visibility(struct livebox *handler, enum livebox_visible_state state)
2440 struct packet *packet;
2444 ErrPrint("Handler is NIL\n");
2445 return LB_STATUS_ERROR_INVALID;
2448 if (handler->state != CREATE || !handler->id)
2449 return LB_STATUS_ERROR_INVALID;
2451 if (!handler->is_user) {
2452 /* System cluster livebox cannot be changed its visible states */
2453 if (state == LB_HIDE_WITH_PAUSE) {
2454 ErrPrint("CA Livebox is not able to change the visibility\n");
2455 return LB_STATUS_ERROR_PERMISSION;
2459 DbgPrint("Change the visibility %d <> %d, %s\n", handler->visible, state, handler->id);
2461 if (handler->visible == state)
2462 return LB_STATUS_ERROR_ALREADY;
2464 packet = packet_create_noack("change,visibility", "ssi", handler->pkgname, handler->id, (int)state);
2466 ErrPrint("Failed to create a packet\n");
2467 return LB_STATUS_ERROR_FAULT;
2470 ret = master_rpc_request_only(handler, packet);
2472 handler->visible = state;
2477 EAPI enum livebox_visible_state livebox_visibility(struct livebox *handler)
2480 ErrPrint("Handler is NIL\n");
2481 return LB_VISIBLE_ERROR;
2484 if (handler->state != CREATE || !handler->id)
2485 return LB_VISIBLE_ERROR;
2487 return handler->visible;
2490 int lb_set_group(struct livebox *handler, const char *cluster, const char *category)
2496 pc = strdup(cluster);
2498 CRITICAL_LOG("Heap: %s (cluster: %s)\n", strerror(errno), cluster);
2499 return LB_STATUS_ERROR_MEMORY;
2504 ps = strdup(category);
2506 CRITICAL_LOG("Heap: %s (category: %s)\n", strerror(errno), category);
2508 return LB_STATUS_ERROR_MEMORY;
2512 if (handler->cluster)
2513 free(handler->cluster);
2515 if (handler->category)
2516 free(handler->category);
2518 handler->cluster = pc;
2519 handler->category = ps;
2521 return LB_STATUS_SUCCESS;
2524 void lb_set_size(struct livebox *handler, int w, int h)
2526 handler->lb.width = w;
2527 handler->lb.height = h;
2530 void lb_set_update_mode(struct livebox *handle, int active_mode)
2532 handle->is_active_update = active_mode;
2535 void lb_set_pdsize(struct livebox *handler, int w, int h)
2537 handler->pd.width = w;
2538 handler->pd.height = h;
2541 void lb_set_default_pdsize(struct livebox *handler, int w, int h)
2543 handler->pd.default_width = w;
2544 handler->pd.default_height = h;
2547 void lb_invoke_fault_handler(enum livebox_fault_type event, const char *pkgname, const char *file, const char *func)
2551 struct fault_info *info;
2553 dlist_foreach_safe(s_info.fault_list, l, n, info) {
2554 if (info->handler(event, pkgname, file, func, info->user_data) == EXIT_FAILURE)
2555 s_info.fault_list = dlist_remove(s_info.fault_list, l);
2559 void lb_invoke_event_handler(struct livebox *handler, enum livebox_event_type event)
2563 struct event_info *info;
2565 dlist_foreach_safe(s_info.event_list, l, n, info) {
2566 if (info->handler(handler, event, info->user_data) == EXIT_FAILURE)
2567 s_info.event_list = dlist_remove(s_info.event_list, l);
2571 struct livebox *lb_find_livebox(const char *pkgname, const char *id)
2574 struct livebox *handler;
2576 dlist_foreach(s_info.livebox_list, l, handler) {
2580 if (!strcmp(handler->pkgname, pkgname) && !strcmp(handler->id, id))
2587 struct livebox *lb_find_livebox_by_timestamp(double timestamp)
2590 struct livebox *handler;
2592 dlist_foreach(s_info.livebox_list, l, handler) {
2593 if (handler->timestamp == timestamp)
2600 static inline char *get_file_kept_in_safe(const char *id)
2607 path = util_uri_to_path(id);
2609 ErrPrint("Invalid URI(%s)\n", id);
2616 if (s_info.prevent_overwrite) {
2617 new_path = strdup(path);
2619 ErrPrint("Heap: %s\n", strerror(errno));
2628 while (base_idx > 0 && path[base_idx] != '/') base_idx--;
2629 base_idx += (path[base_idx] == '/');
2631 new_path = malloc(len + 10);
2633 ErrPrint("Heap: %s\n", strerror(errno));
2637 strncpy(new_path, path, base_idx);
2638 snprintf(new_path + base_idx, len + 10 - base_idx, "reader/%s", path + base_idx);
2642 struct livebox *lb_new_livebox(const char *pkgname, const char *id, double timestamp)
2644 struct livebox *handler;
2646 handler = calloc(1, sizeof(*handler));
2648 ErrPrint("Failed to create a new livebox\n");
2652 handler->pkgname = strdup(pkgname);
2653 if (!handler->pkgname) {
2654 ErrPrint("%s\n", strerror(errno));
2659 handler->id = strdup(id);
2661 ErrPrint("%s\n", strerror(errno));
2662 free(handler->pkgname);
2667 handler->filename = get_file_kept_in_safe(id);
2668 if (!handler->filename) {
2669 handler->filename = strdup(util_uri_to_path(id));
2670 if (!handler->filename)
2671 ErrPrint("Error: %s\n", strerror(errno));
2674 handler->timestamp = timestamp;
2675 handler->lb.type = _LB_TYPE_FILE;
2676 handler->pd.type = _PD_TYPE_SCRIPT;
2677 handler->state = CREATE;
2678 handler->visible = LB_SHOW;
2680 s_info.livebox_list = dlist_append(s_info.livebox_list, handler);
2685 int lb_delete_all(void)
2689 struct livebox *handler;
2691 dlist_foreach_safe(s_info.livebox_list, l, n, handler) {
2692 lb_invoke_event_handler(handler, LB_EVENT_DELETED);
2696 return LB_STATUS_SUCCESS;
2699 int lb_set_content(struct livebox *handler, const char *content)
2701 if (handler->content) {
2702 free(handler->content);
2703 handler->content = NULL;
2707 handler->content = strdup(content);
2708 if (!handler->content) {
2709 CRITICAL_LOG("Heap: %s (content: %s)\n", strerror(errno), content);
2710 return LB_STATUS_ERROR_MEMORY;
2714 return LB_STATUS_SUCCESS;
2717 int lb_set_title(struct livebox *handler, const char *title)
2719 if (handler->title) {
2720 free(handler->title);
2721 handler->title = NULL;
2725 handler->title = strdup(title);
2726 if (!handler->title) {
2727 CRITICAL_LOG("Heap: %s (title: %s)\n", strerror(errno), title);
2728 return LB_STATUS_ERROR_MEMORY;
2732 return LB_STATUS_SUCCESS;
2735 void lb_set_size_list(struct livebox *handler, int size_list)
2737 handler->lb.size_list = size_list;
2740 void lb_set_auto_launch(struct livebox *handler, const char *auto_launch)
2742 if (!strlen(auto_launch))
2745 handler->lb.auto_launch = strdup(auto_launch);
2746 if (!handler->lb.auto_launch)
2747 ErrPrint("Heap: %s\n", strerror(errno));
2750 void lb_set_priority(struct livebox *handler, double priority)
2752 handler->lb.priority = priority;
2755 void lb_set_id(struct livebox *handler, const char *id)
2760 handler->id = strdup(id);
2762 ErrPrint("Error: %s\n", strerror(errno));
2764 if (handler->filename)
2765 free(handler->filename);
2767 handler->filename = get_file_kept_in_safe(id);
2768 if (!handler->filename) {
2769 handler->filename = strdup(util_uri_to_path(id));
2770 if (!handler->filename)
2771 ErrPrint("Error: %s\n", strerror(errno));
2775 int lb_set_lb_fb(struct livebox *handler, const char *filename)
2780 return LB_STATUS_ERROR_INVALID;
2782 fb = handler->lb.data.fb;
2783 if (fb && !strcmp(fb_id(fb), filename)) /*!< BUFFER is not changed, */
2784 return LB_STATUS_SUCCESS;
2786 handler->lb.data.fb = NULL;
2788 if (!filename || filename[0] == '\0') {
2791 return LB_STATUS_SUCCESS;
2794 handler->lb.data.fb = fb_create(filename, handler->lb.width, handler->lb.height);
2795 if (!handler->lb.data.fb) {
2796 ErrPrint("Faield to create a FB\n");
2799 return LB_STATUS_ERROR_FAULT;
2805 return LB_STATUS_SUCCESS;
2808 int lb_set_pd_fb(struct livebox *handler, const char *filename)
2813 return LB_STATUS_ERROR_INVALID;
2815 fb = handler->pd.data.fb;
2816 if (fb && !strcmp(fb_id(fb), filename)) {
2817 /* BUFFER is not changed, just update the content */
2818 return LB_STATUS_ERROR_EXIST;
2820 handler->pd.data.fb = NULL;
2822 if (!filename || filename[0] == '\0') {
2825 return LB_STATUS_SUCCESS;
2828 handler->pd.data.fb = fb_create(filename, handler->pd.width, handler->pd.height);
2829 if (!handler->pd.data.fb) {
2830 ErrPrint("Failed to create a FB\n");
2833 return LB_STATUS_ERROR_FAULT;
2838 return LB_STATUS_SUCCESS;
2841 struct fb_info *lb_get_lb_fb(struct livebox *handler)
2843 return handler->lb.data.fb;
2846 struct fb_info *lb_get_pd_fb(struct livebox *handler)
2848 return handler->pd.data.fb;
2851 void lb_set_user(struct livebox *handler, int user)
2853 handler->is_user = user;
2856 void lb_set_pinup(struct livebox *handler, int pinup_supported)
2858 handler->lb.pinup_supported = pinup_supported;
2861 void lb_set_text_lb(struct livebox *handler)
2863 handler->lb.type = _LB_TYPE_TEXT;
2866 void lb_set_text_pd(struct livebox *handler)
2868 handler->pd.type = _PD_TYPE_TEXT;
2871 int lb_text_lb(struct livebox *handler)
2873 return handler->lb.type == _LB_TYPE_TEXT;
2876 int lb_text_pd(struct livebox *handler)
2878 return handler->pd.type == _PD_TYPE_TEXT;
2881 void lb_set_period(struct livebox *handler, double period)
2883 handler->lb.period = period;
2886 struct livebox *lb_ref(struct livebox *handler)
2895 struct livebox *lb_unref(struct livebox *handler)
2901 if (handler->refcnt > 0)
2904 if (handler->created_cb) {
2905 DbgPrint("Clear created event callback\n");
2906 handler->created_cb(handler, LB_STATUS_ERROR_FAULT, handler->created_cbdata);
2907 handler->created_cb = NULL;
2908 handler->created_cbdata = NULL;
2911 if (handler->deleted_cb) {
2912 DbgPrint("Clear deleted event callback\n");
2913 handler->deleted_cb(handler, LB_STATUS_ERROR_FAULT, handler->deleted_cbdata);
2914 handler->deleted_cb = NULL;
2915 handler->deleted_cbdata = NULL;
2918 if (handler->pinup_cb) {
2919 DbgPrint("Clear pinup event callback\n");
2920 handler->pinup_cb(handler, LB_STATUS_ERROR_FAULT, handler->pinup_cbdata);
2921 handler->pinup_cb = NULL;
2922 handler->pinup_cbdata = NULL;
2925 if (handler->group_changed_cb) {
2926 DbgPrint("Clear group changed event callback\n");
2927 handler->group_changed_cb(handler, LB_STATUS_ERROR_FAULT, handler->group_cbdata);
2928 handler->group_changed_cb = NULL;
2929 handler->group_cbdata = NULL;
2932 if (handler->period_changed_cb) {
2933 DbgPrint("Clear period changed event callback\n");
2934 handler->period_changed_cb(handler, LB_STATUS_ERROR_FAULT, handler->period_cbdata);
2935 handler->period_changed_cb = NULL;
2936 handler->period_cbdata = NULL;
2939 if (handler->size_changed_cb) {
2940 DbgPrint("Clear size changed event callback\n");
2941 handler->size_changed_cb(handler, LB_STATUS_ERROR_FAULT, handler->size_cbdata);
2942 handler->size_changed_cb = NULL;
2943 handler->size_cbdata = NULL;
2946 if (handler->pd_created_cb) {
2947 DbgPrint("Clear pd created event callback\n");
2948 handler->pd_created_cb(handler, LB_STATUS_ERROR_FAULT, handler->pd_created_cbdata);
2949 handler->pd_created_cb = NULL;
2950 handler->pd_created_cbdata = NULL;
2953 if (handler->pd_destroyed_cb) {
2954 DbgPrint("Clear pd destroyed event callback\n");
2955 handler->pd_destroyed_cb(handler, LB_STATUS_ERROR_FAULT, handler->pd_destroyed_cbdata);
2956 handler->pd_destroyed_cb = NULL;
2957 handler->pd_destroyed_cbdata = NULL;
2960 if (handler->update_mode_cb) {
2961 DbgPrint("Clear update mode callback\n");
2962 handler->update_mode_cb(handler, LB_STATUS_ERROR_FAULT, handler->update_mode_cbdata);
2963 handler->update_mode_cb = NULL;
2964 handler->update_mode_cbdata = NULL;
2967 if (handler->access_event_cb) {
2968 DbgPrint("Clear access status callback\n");
2969 handler->access_event_cb(handler, LB_STATUS_ERROR_FAULT, handler->access_event_cbdata);
2970 handler->access_event_cb = NULL;
2971 handler->access_event_cbdata = NULL;
2974 if (handler->filename)
2975 util_unlink(handler->filename);
2977 dlist_remove_data(s_info.livebox_list, handler);
2979 handler->state = DESTROYED;
2980 free(handler->cluster);
2981 free(handler->category);
2983 free(handler->pkgname);
2984 free(handler->filename);
2985 free(handler->lb.auto_launch);
2987 if (handler->lb.data.fb) {
2988 fb_destroy(handler->lb.data.fb);
2989 handler->lb.data.fb = NULL;
2992 if (handler->pd.data.fb) {
2993 fb_destroy(handler->pd.data.fb);
2994 handler->pd.data.fb = NULL;
3001 int lb_send_delete(struct livebox *handler, ret_cb_t cb, void *data)
3003 struct packet *packet;
3004 struct cb_info *cbinfo;
3007 if (!cb && !!data) {
3008 ErrPrint("Invalid argument\n");
3009 return LB_STATUS_ERROR_INVALID;
3012 if (handler->deleted_cb) {
3013 ErrPrint("Already in-progress\n");
3014 return LB_STATUS_ERROR_BUSY;
3017 packet = packet_create("delete", "ss", handler->pkgname, handler->id);
3019 ErrPrint("Failed to build a param\n");
3021 cb(handler, LB_STATUS_ERROR_FAULT, data);
3023 return LB_STATUS_ERROR_FAULT;
3027 cb = default_delete_cb;
3029 cbinfo = create_cb_info(cb, data);
3031 packet_destroy(packet);
3032 return LB_STATUS_ERROR_FAULT;
3035 ret = master_rpc_async_request(handler, packet, 0, del_ret_cb, cbinfo);
3037 destroy_cb_info(cbinfo);
3042 EAPI int livebox_client_paused(void)
3044 struct packet *packet;
3046 packet = packet_create_noack("client_paused", "d", util_timestamp());
3048 ErrPrint("Failed to create a pause packet\n");
3049 return LB_STATUS_ERROR_FAULT;
3052 return master_rpc_request_only(NULL, packet);
3055 EAPI int livebox_client_resumed(void)
3057 struct packet *packet;
3059 packet = packet_create_noack("client_resumed", "d", util_timestamp());
3061 ErrPrint("Failed to create a resume packet\n");
3062 return LB_STATUS_ERROR_FAULT;
3065 return master_rpc_request_only(NULL, packet);