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 struct cb_info *create_cb_info(ret_cb_t cb, void *data)
115 struct cb_info *info;
117 info = malloc(sizeof(*info));
119 CRITICAL_LOG("Heap: %s\n", strerror(errno));
128 static inline void destroy_cb_info(struct cb_info *info)
133 static void resize_cb(struct livebox *handler, const struct packet *result, void *data)
136 struct cb_info *info = data;
142 destroy_cb_info(info);
146 } else if (packet_get(result, "i", &ret) != 1) {
147 ErrPrint("Invalid argument\n");
153 * In case of resize request,
154 * The livebox handler will not have resized value right after this callback,
155 * It can only get the new size when it makes updates.
157 * So the user can only get the resized value(result) from the first update event
158 * after this request.
162 cb(handler, ret, cbdata);
165 static void text_signal_cb(struct livebox *handler, const struct packet *result, void *data)
169 struct cb_info *info = data;
174 destroy_cb_info(info);
178 } else if (packet_get(result, "i", &ret) != 1) {
179 ErrPrint("Invalid argument\n");
184 cb(handler, ret, cbdata);
188 static void set_group_ret_cb(struct livebox *handler, const struct packet *result, void *data)
193 struct cb_info *info = data;
197 destroy_cb_info(info);
201 } else if (packet_get(result, "i", &ret) != 1) {
202 ErrPrint("Invalid argument\n");
206 if (ret == 0) { /*!< Group information is successfully changed */
207 handler->group_changed_cb = cb;
208 handler->group_cbdata = cbdata;
210 cb(handler, ret, cbdata);
216 static void period_ret_cb(struct livebox *handler, const struct packet *result, void *data)
218 struct cb_info *info = data;
225 destroy_cb_info(info);
229 } else if (packet_get(result, "i", &ret) != 1) {
230 ErrPrint("Invalid argument\n");
235 handler->period_changed_cb = cb;
236 handler->period_cbdata = cbdata;
238 cb(handler, ret, cbdata);
242 static void del_ret_cb(struct livebox *handler, const struct packet *result, void *data)
244 struct cb_info *info = data;
251 destroy_cb_info(info);
254 ErrPrint("Connection lost?\n");
256 } else if (packet_get(result, "i", &ret) != 1) {
257 ErrPrint("Invalid argument\n");
262 DbgPrint("Returns %d (waiting deleted event)\n", ret);
263 handler->deleted_cb = cb;
264 handler->deleted_cbdata = cbdata;
266 cb(handler, ret, cbdata);
271 * Do not call the deleted callback from here.
272 * master will send the "deleted" event.
273 * Then invoke this callback.
275 * if (handler->deleted_cb)
276 * handler->deleted_cb(handler, ret, handler->deleted_cbdata);
280 static void new_ret_cb(struct livebox *handler, const struct packet *result, void *data)
283 struct cb_info *info = data;
289 destroy_cb_info(info);
293 } else if (packet_get(result, "i", &ret) != 1) {
298 DbgPrint("new request is sent, just waiting the created event\n");
299 handler->created_cb = cb;
300 handler->created_cbdata = cbdata;
304 * Don't go anymore ;)
310 * It means the current instance is not created,
311 * so user has to know about this.
312 * notice it to user using "deleted" event.
314 cb(handler, ret, cbdata);
320 static void pd_create_cb(struct livebox *handler, const struct packet *result, void *data)
322 struct cb_info *info = data;
329 destroy_cb_info(data);
333 } else if (packet_get(result, "i", &ret) != 1) {
338 DbgPrint("PD Created event handler prepared\n");
339 handler->pd_created_cb = cb;
340 handler->pd_created_cbdata = cbdata;
342 DbgPrint("Failed to create a PD\n");
343 cb(handler, ret, cbdata);
347 static void activated_cb(struct livebox *handler, const struct packet *result, void *data)
350 struct cb_info *info = data;
353 const char *pkgname = "";
357 destroy_cb_info(info);
361 } else if (packet_get(result, "is", &ret, &pkgname) != 2) {
366 cb(handler, ret, cbdata);
369 static void pd_destroy_cb(struct livebox *handler, const struct packet *result, void *data)
374 struct cb_info *info = data;
378 destroy_cb_info(info);
381 DbgPrint("Result is NIL (may connection lost)\n");
383 } else if (packet_get(result, "i", &ret) != 1) {
384 DbgPrint("Invalid parameter\n");
389 DbgPrint("PD Destroyed callback prepared\n");
390 handler->pd_destroyed_cb = cb;
391 handler->pd_destroyed_cbdata = cbdata;
393 DbgPrint("PD is not desroyed (forcely reset, pd flag)\n");
394 handler->is_pd_created = 0;
395 cb(handler, ret, cbdata);
399 static void delete_cluster_cb(struct livebox *handler, const struct packet *result, void *data)
401 struct cb_info *info = data;
408 destroy_cb_info(info);
412 } else if (packet_get(result, "i", &ret) != 1) {
416 DbgPrint("Delete category returns: %d\n", ret);
419 cb(handler, ret, cbdata);
422 static void delete_category_cb(struct livebox *handler, const struct packet *result, void *data)
424 struct cb_info *info = data;
431 destroy_cb_info(info);
435 else if (packet_get(result, "i", &ret) != 1)
438 DbgPrint("Delete category returns: %d\n", ret);
441 cb(handler, ret, cbdata);
444 static void pixmap_acquired_cb(struct livebox *handler, const struct packet *result, void *data)
449 struct cb_info *info = data;
453 destroy_cb_info(info);
456 ret = 0; /* PIXMAP 0 means error */
457 else if (packet_get(result, "i", &ret) != 1)
461 cb(handler, ret, cbdata);
464 static void pinup_done_cb(struct livebox *handler, const struct packet *result, void *data)
469 struct cb_info *info = data;
473 destroy_cb_info(info);
477 else if (packet_get(result, "i", &ret) != 1)
481 handler->pinup_cb = cb;
482 handler->pinup_cbdata = cbdata;
484 cb(handler, ret, cbdata);
488 static int send_mouse_event(struct livebox *handler, const char *event, double x, double y, int w, int h)
490 struct packet *packet;
493 timestamp = util_timestamp();
494 packet = packet_create_noack(event, "ssiiddd", handler->pkgname, handler->id, w, h,
497 ErrPrint("Failed to build param\n");
501 return master_rpc_request_only(handler, packet);
504 EAPI int livebox_init(void *disp)
508 if (s_info.init_count > 0) {
512 env = getenv("PROVIDER_DISABLE_PREVENT_OVERWRITE");
513 if (env && !strcasecmp(env, "true"))
514 s_info.prevent_overwrite = 1;
516 env = getenv("PROVIDER_EVENT_FILTER");
518 sscanf(env, "%lf", &MINIMUM_EVENT);
521 char filename[BUFSIZ];
522 snprintf(filename, sizeof(filename), "/tmp/%d.box.log", getpid());
523 __file_log_fp = fopen(filename, "w+t");
525 __file_log_fp = fdopen(1, "w+t");
527 critical_log_init("viewer");
528 livebox_service_init();
537 EAPI int livebox_fini(void)
539 if (s_info.init_count <= 0) {
540 DbgPrint("Didn't initialized\n");
545 if (s_info.init_count > 0) {
546 DbgPrint("init count : %d\n", s_info.init_count);
552 livebox_service_fini();
557 static inline char *lb_pkgname(const char *pkgname)
561 lb = livebox_service_pkgname(pkgname);
563 if (util_validate_livebox_package(pkgname) == 0)
564 return strdup(pkgname);
571 * Just wrapping the livebox_add_with_size function.
573 EAPI struct livebox *livebox_add(const char *pkgname, const char *content, const char *cluster, const char *category, double period, ret_cb_t cb, void *data)
575 return livebox_add_with_size(pkgname, content, cluster, category, period, LB_SIZE_TYPE_UNKNOWN, cb, data);
578 EAPI struct livebox *livebox_add_with_size(const char *pkgname, const char *content, const char *cluster, const char *category, double period, int type, ret_cb_t cb, void *data)
580 struct livebox *handler;
581 struct packet *packet;
586 if (!pkgname || !cluster || !category || width < 0 || height < 0) {
587 ErrPrint("Invalid arguments: pkgname[%p], cluster[%p], category[%p]\n",
588 pkgname, cluster, category);
592 if (type != LB_SIZE_TYPE_UNKNOWN)
593 livebox_service_get_size(type, &width, &height);
595 handler = calloc(1, sizeof(*handler));
597 ErrPrint("Error: %s\n", strerror(errno));
601 handler->pkgname = lb_pkgname(pkgname);
602 if (!handler->pkgname) {
603 ErrPrint("Error: %s\n", strerror(errno));
609 handler->content = strdup(content);
610 if (!handler->content) {
611 ErrPrint("Error: %s\n", strerror(errno));
612 free(handler->pkgname);
617 handler->content = livebox_service_content(handler->pkgname);
620 handler->cluster = strdup(cluster);
621 if (!handler->cluster) {
622 ErrPrint("Error: %s\n", strerror(errno));
623 free(handler->content);
624 free(handler->pkgname);
629 handler->category = strdup(category);
630 if (!handler->category) {
631 ErrPrint("Error: %s\n", strerror(errno));
632 free(handler->cluster);
633 free(handler->content);
634 free(handler->pkgname);
640 cb = default_create_cb;
642 /* Data provider will set this */
643 handler->lb.type = _LB_TYPE_FILE;
644 handler->pd.type = _PD_TYPE_SCRIPT;
645 handler->lb.period = period;
647 /* Cluster infomration is not determined yet */
648 handler->nr_of_sizes = 0x01;
650 handler->timestamp = util_timestamp();
651 handler->is_user = 1;
652 handler->visible = LB_SHOW;
654 s_info.livebox_list = dlist_append(s_info.livebox_list, handler);
656 packet = packet_create("new", "dssssdii", handler->timestamp, handler->pkgname, handler->content, cluster, category, period, width, height);
658 ErrPrint("Failed to create a new packet\n");
659 free(handler->category);
660 free(handler->cluster);
661 free(handler->content);
662 free(handler->pkgname);
667 ret = master_rpc_async_request(handler, packet, 0, new_ret_cb, create_cb_info(cb, data));
669 ErrPrint("Failed to send a new packet\n");
670 free(handler->category);
671 free(handler->cluster);
672 free(handler->content);
673 free(handler->pkgname);
678 DbgPrint("Successfully sent a new request ([%lf] %s)\n", handler->timestamp, handler->pkgname);
679 handler->state = CREATE;
680 return lb_ref(handler);
683 EAPI double livebox_period(struct livebox *handler)
685 if (!handler || handler->state != CREATE || !handler->id) {
686 ErrPrint("Handler is not valid\n");
690 return handler->lb.period;
693 EAPI int livebox_set_period(struct livebox *handler, double period, ret_cb_t cb, void *data)
695 struct packet *packet;
697 if (!handler || handler->state != CREATE || !handler->id) {
698 ErrPrint("Handler is not valid\n");
702 if (!handler->is_user) {
703 ErrPrint("CA Livebox is not able to change the period\n");
707 if (handler->lb.period == period) {
708 DbgPrint("No changes\n");
712 packet = packet_create("set_period", "ssd", handler->pkgname, handler->id, period);
714 ErrPrint("Failed to build a packet %s\n", handler->pkgname);
719 cb = default_period_changed_cb;
721 return master_rpc_async_request(handler, packet, 0, period_ret_cb, create_cb_info(cb, data));
724 EAPI int livebox_del(struct livebox *handler, ret_cb_t cb, void *data)
727 ErrPrint("Handler is NIL\n");
731 if (handler->state != CREATE) {
732 ErrPrint("Handler is already deleted\n");
736 handler->state = DELETE;
741 * The id is not determined yet.
742 * It means a user didn't receive created event yet.
743 * Then just stop to delete procedure from here.
744 * Because the "created" event handler will release this.
745 * By the way, if the user adds any callback for getting return status of this,
749 cb(handler, 0, data);
754 cb = default_delete_cb;
756 return lb_send_delete(handler, cb, data);
759 EAPI int livebox_set_fault_handler(int (*cb)(enum livebox_fault_type, const char *, const char *, const char *, void *), void *data)
761 struct fault_info *info;
766 info = malloc(sizeof(*info));
768 CRITICAL_LOG("Heap: %s\n", strerror(errno));
773 info->user_data = data;
775 s_info.fault_list = dlist_append(s_info.fault_list, info);
779 EAPI void *livebox_unset_fault_handler(int (*cb)(enum livebox_fault_type, const char *, const char *, const char *, void *))
781 struct fault_info *info;
784 dlist_foreach(s_info.fault_list, l, info) {
785 if (info->handler == cb) {
787 s_info.fault_list = dlist_remove(s_info.fault_list, l);
788 data = info->user_data;
798 EAPI int livebox_set_event_handler(int (*cb)(struct livebox *, enum livebox_event_type, void *), void *data)
800 struct event_info *info;
803 ErrPrint("Invalid argument cb is nil\n");
807 info = malloc(sizeof(*info));
809 CRITICAL_LOG("Heap: %s\n", strerror(errno));
814 info->user_data = data;
816 s_info.event_list = dlist_append(s_info.event_list, info);
820 EAPI void *livebox_unset_event_handler(int (*cb)(struct livebox *, enum livebox_event_type, void *))
822 struct event_info *info;
825 dlist_foreach(s_info.event_list, l, info) {
826 if (info->handler == cb) {
829 s_info.event_list = dlist_remove(s_info.event_list, l);
830 data = info->user_data;
840 EAPI int livebox_resize(struct livebox *handler, int type, ret_cb_t cb, void *data)
842 struct packet *packet;
847 ErrPrint("Handler is NIL\n");
851 if (handler->state != CREATE || !handler->id) {
852 ErrPrint("Handler is not valid\n");
856 if (!handler->is_user) {
857 ErrPrint("CA Livebox is not able to be resized\n");
861 if (livebox_service_get_size(type, &w, &h) != 0) {
862 ErrPrint("Invalid size type\n");
866 if (handler->lb.width == w && handler->lb.height == h) {
867 DbgPrint("No changes\n");
871 packet = packet_create("resize", "ssii", handler->pkgname, handler->id, w, h);
873 ErrPrint("Failed to build param\n");
877 return master_rpc_async_request(handler, packet, 0, resize_cb, create_cb_info(cb, data));
880 EAPI int livebox_click(struct livebox *handler, double x, double y)
882 struct packet *packet;
886 ErrPrint("Handler is NIL\n");
890 if (handler->state != CREATE || !handler->id) {
891 ErrPrint("Handler is not valid\n");
895 if (handler->lb.auto_launch)
896 if (aul_launch_app(handler->lb.auto_launch, NULL) < 0)
897 ErrPrint("Failed to launch app %s\n", handler->lb.auto_launch);
899 timestamp = util_timestamp();
900 packet = packet_create_noack("clicked", "sssddd", handler->pkgname, handler->id, "clicked", timestamp, x, y);
902 ErrPrint("Failed to build param\n");
906 return master_rpc_request_only(handler, packet);
909 EAPI int livebox_has_pd(struct livebox *handler)
912 ErrPrint("Handler is NIL\n");
916 if (handler->state != CREATE || !handler->id) {
917 ErrPrint("Handler is not valid\n");
921 return !!handler->pd.data.fb;
924 EAPI int livebox_pd_is_created(struct livebox *handler)
927 ErrPrint("Handler is NIL\n");
931 if (!handler->pd.data.fb || handler->state != CREATE || !handler->id) {
932 ErrPrint("Handler is not valid\n");
936 return handler->is_pd_created;
939 EAPI int livebox_create_pd(struct livebox *handler, ret_cb_t cb, void *data)
941 return livebox_create_pd_with_position(handler, -1.0, -1.0, cb, data);
944 EAPI int livebox_create_pd_with_position(struct livebox *handler, double x, double y, ret_cb_t cb, void *data)
946 struct packet *packet;
949 ErrPrint("Handler is NIL\n");
953 if (!handler->pd.data.fb || handler->state != CREATE || !handler->id) {
954 ErrPrint("Handler is not valid\n");
958 if (handler->is_pd_created == 1) {
959 DbgPrint("PD already created\n");
963 packet = packet_create("create_pd", "ssdd", handler->pkgname, handler->id, x, y);
965 ErrPrint("Failed to build param\n");
970 handler->pd_created_cb = default_pd_created_cb;
972 return master_rpc_async_request(handler, packet, 0, pd_create_cb, create_cb_info(cb, data));
975 EAPI int livebox_activate(const char *pkgname, ret_cb_t cb, void *data)
977 struct packet *packet;
982 packet = packet_create("activate_package", "s", pkgname);
984 ErrPrint("Failed to build a param\n");
988 return master_rpc_async_request(NULL, packet, 0, activated_cb, create_cb_info(cb, data));
991 EAPI int livebox_destroy_pd(struct livebox *handler, ret_cb_t cb, void *data)
993 struct packet *packet;
996 ErrPrint("Handler is NIL\n");
1000 if (!handler->pd.data.fb || handler->state != CREATE || !handler->id) {
1001 ErrPrint("Handler is not valid\n");
1005 if (!handler->is_pd_created) {
1006 ErrPrint("PD is not created\n");
1010 packet = packet_create("destroy_pd", "ss", handler->pkgname, handler->id);
1012 ErrPrint("Failed to build a param\n");
1017 cb = default_pd_destroyed_cb;
1019 return master_rpc_async_request(handler, packet, 0, pd_destroy_cb, create_cb_info(cb, data));
1022 EAPI int livebox_content_event(struct livebox *handler, enum content_event_type type, double x, double y)
1029 ErrPrint("Handler is NIL\n");
1033 if (handler->state != CREATE || !handler->id) {
1034 ErrPrint("Handler is not valid\n");
1040 if (!handler->lb.data.fb) {
1041 ErrPrint("Handler is not valid\n");
1045 cmd = "lb_mouse_down";
1046 w = handler->lb.width;
1047 h = handler->lb.height;
1054 if (!handler->lb.data.fb) {
1055 ErrPrint("Handler is not valid\n");
1059 cmd = "lb_mouse_up";
1060 w = handler->lb.width;
1061 h = handler->lb.height;
1065 if (!handler->lb.data.fb) {
1066 ErrPrint("Handler is not valid\n");
1070 if (fabs(x - handler->lb.x) < MINIMUM_EVENT && fabs(y - handler->lb.y) < MINIMUM_EVENT)
1073 cmd = "lb_mouse_move";
1074 w = handler->lb.width;
1075 h = handler->lb.height;
1081 case LB_MOUSE_ENTER:
1082 if (!handler->lb.data.fb) {
1083 ErrPrint("Handler is not valid\n");
1087 cmd = "lb_mouse_enter";
1088 w = handler->lb.width;
1089 h = handler->lb.height;
1092 case LB_MOUSE_LEAVE:
1093 if (!handler->lb.data.fb) {
1094 ErrPrint("Handler is not valid\n");
1098 cmd = "lb_mouse_leave";
1099 w = handler->lb.width;
1100 h = handler->lb.height;
1103 case PD_MOUSE_ENTER:
1104 if (!handler->pd.data.fb) {
1105 ErrPrint("Handler is not valid\n");
1109 cmd = "pd_mouse_enter";
1110 w = handler->pd.width;
1111 h = handler->pd.height;
1114 case PD_MOUSE_LEAVE:
1115 if (!handler->pd.data.fb) {
1116 ErrPrint("Handler is not valid\n");
1120 cmd = "pd_mouse_leave";
1121 w = handler->pd.width;
1122 h = handler->pd.height;
1126 if (!handler->pd.data.fb) {
1127 ErrPrint("Handler is not valid\n");
1131 cmd = "pd_mouse_down";
1132 w = handler->pd.width;
1133 h = handler->pd.height;
1140 if (!handler->pd.data.fb) {
1141 ErrPrint("Handler is not valid\n");
1145 if (fabs(x - handler->pd.x) < MINIMUM_EVENT && fabs(y - handler->pd.y) < MINIMUM_EVENT)
1148 cmd = "pd_mouse_move";
1149 w = handler->pd.width;
1150 h = handler->pd.height;
1157 if (!handler->pd.data.fb) {
1158 ErrPrint("Handler is not valid\n");
1162 cmd = "pd_mouse_up";
1163 w = handler->pd.width;
1164 h = handler->pd.height;
1168 ErrPrint("Invalid event type\n");
1172 return send_mouse_event(handler, cmd, x, y, w, h);
1175 EAPI const char *livebox_filename(struct livebox *handler)
1178 ErrPrint("Handler is NIL\n");
1182 if (handler->state != CREATE || !handler->id) {
1183 ErrPrint("Handler is not valid\n");
1187 if (handler->filename)
1188 return handler->filename;
1191 return util_uri_to_path(handler->id);
1194 EAPI int livebox_get_pdsize(struct livebox *handler, int *w, int *h)
1200 ErrPrint("Handler is NIL\n");
1204 if (handler->state != CREATE || !handler->id) {
1205 ErrPrint("Handler is not valid\n");
1214 *w = handler->pd.width;
1215 *h = handler->pd.height;
1217 switch (handler->pd.type) {
1218 case _PD_TYPE_BUFFER:
1219 case _PD_TYPE_SCRIPT:
1220 if (!handler->is_pd_created) {
1221 DbgPrint("Buffer is not created yet - reset size\n");
1233 EAPI int livebox_size(struct livebox *handler)
1239 ErrPrint("Handler is NIL\n");
1243 if (handler->state != CREATE || !handler->id) {
1244 ErrPrint("Handler is not valid\n");
1248 w = handler->lb.width;
1249 h = handler->lb.height;
1251 switch (handler->lb.type) {
1252 case _LB_TYPE_BUFFER:
1253 case _LB_TYPE_SCRIPT:
1254 if (!fb_is_created(handler->lb.data.fb)) {
1255 DbgPrint("Buffer is not created yet - reset size\n");
1264 return livebox_service_size_type(w, h);
1267 EAPI int livebox_set_group(struct livebox *handler, const char *cluster, const char *category, ret_cb_t cb, void *data)
1269 struct packet *packet;
1272 ErrPrint("Handler is NIL\n");
1276 if (!cluster || !category || handler->state != CREATE || !handler->id) {
1277 ErrPrint("Invalid argument\n");
1281 if (!handler->is_user) {
1282 ErrPrint("CA Livebox is not able to change the group\n");
1286 if (!strcmp(handler->cluster, cluster) && !strcmp(handler->category, category)) {
1287 DbgPrint("No changes\n");
1291 packet = packet_create("change_group", "ssss", handler->pkgname, handler->id, cluster, category);
1293 ErrPrint("Failed to build a param\n");
1298 cb = default_group_changed_cb;
1300 return master_rpc_async_request(handler, packet, 0, set_group_ret_cb, create_cb_info(cb, data));
1303 EAPI int livebox_get_group(struct livebox *handler, char ** const cluster, char ** const category)
1306 ErrPrint("Handler is NIL\n");
1310 if (!cluster || !category || handler->state != CREATE || !handler->id) {
1311 ErrPrint("Invalid argument\n");
1315 *cluster = handler->cluster;
1316 *category = handler->category;
1320 EAPI int livebox_get_supported_sizes(struct livebox *handler, int *cnt, int *size_list)
1325 if (!handler || !size_list) {
1326 ErrPrint("Invalid argument, handler(%p), size_list(%p)\n", handler, size_list);
1330 if (!cnt || handler->state != CREATE || !handler->id) {
1331 ErrPrint("Handler is not valid\n");
1335 for (j = i = 0; i < NR_OF_SIZE_LIST; i++) {
1336 if (handler->lb.size_list & (0x01 << i)) {
1340 size_list[j++] = (0x01 << i);
1348 EAPI const char *livebox_pkgname(struct livebox *handler)
1351 ErrPrint("Handler is NIL\n");
1355 if (handler->state != CREATE) {
1356 ErrPrint("Handler is not valid\n");
1360 return handler->pkgname;
1363 EAPI double livebox_priority(struct livebox *handler)
1366 ErrPrint("Handler is NIL\n");
1370 if (handler->state != CREATE || !handler->id) {
1371 ErrPrint("Handler is not valid (%p)\n", handler);
1375 return handler->lb.priority;
1378 EAPI int livebox_delete_cluster(const char *cluster, ret_cb_t cb, void *data)
1380 struct packet *packet;
1382 packet = packet_create("delete_cluster", "s", cluster);
1384 ErrPrint("Failed to build a param\n");
1388 return master_rpc_async_request(NULL, packet, 0, delete_cluster_cb, create_cb_info(cb, data));
1391 EAPI int livebox_delete_category(const char *cluster, const char *category, ret_cb_t cb, void *data)
1393 struct packet *packet;
1395 packet = packet_create("delete_category", "ss", cluster, category);
1397 ErrPrint("Failed to build a param\n");
1401 return master_rpc_async_request(NULL, packet, 0, delete_category_cb, create_cb_info(cb, data));
1404 EAPI enum livebox_lb_type livebox_lb_type(struct livebox *handler)
1407 ErrPrint("Handler is NIL\n");
1408 return LB_TYPE_INVALID;
1411 if (handler->state != CREATE || !handler->id) {
1412 ErrPrint("Handler is not valid\n");
1413 return LB_TYPE_INVALID;
1416 switch (handler->lb.type) {
1418 return LB_TYPE_IMAGE;
1419 case _LB_TYPE_BUFFER:
1420 case _LB_TYPE_SCRIPT:
1423 id = fb_id(handler->lb.data.fb);
1424 if (id && !strncasecmp(id, SCHEMA_PIXMAP, strlen(SCHEMA_PIXMAP)))
1425 return LB_TYPE_PIXMAP;
1427 return LB_TYPE_BUFFER;
1429 return LB_TYPE_TEXT;
1434 return LB_TYPE_INVALID;
1437 EAPI enum livebox_pd_type livebox_pd_type(struct livebox *handler)
1440 ErrPrint("Handler is NIL\n");
1441 return PD_TYPE_INVALID;
1444 if (handler->state != CREATE || !handler->id) {
1445 ErrPrint("Handler is not valid\n");
1446 return PD_TYPE_INVALID;
1449 switch (handler->pd.type) {
1451 return PD_TYPE_TEXT;
1452 case _PD_TYPE_BUFFER:
1453 case _PD_TYPE_SCRIPT:
1456 id = fb_id(handler->pd.data.fb);
1457 if (id && !strncasecmp(id, SCHEMA_PIXMAP, strlen(SCHEMA_PIXMAP)))
1458 return PD_TYPE_PIXMAP;
1460 return PD_TYPE_BUFFER;
1465 return PD_TYPE_INVALID;
1468 EAPI int livebox_set_pd_text_handler(struct livebox *handler, struct livebox_script_operators *ops)
1471 ErrPrint("Handler is NIL\n");
1475 if (handler->state != CREATE) {
1476 ErrPrint("Handler is not valid\n");
1480 memcpy(&handler->pd.data.ops, ops, sizeof(*ops));
1484 EAPI int livebox_set_text_handler(struct livebox *handler, struct livebox_script_operators *ops)
1487 ErrPrint("Handler is NIL\n");
1491 if (handler->state != CREATE) {
1492 ErrPrint("Handler is not valid\n");
1496 memcpy(&handler->lb.data.ops, ops, sizeof(*ops));
1500 EAPI int livebox_acquire_lb_pixmap(struct livebox *handler, ret_cb_t cb, void *data)
1502 struct packet *packet;
1506 ErrPrint("Handler is NIL\n");
1510 if (handler->state != CREATE || !handler->id) {
1511 ErrPrint("Invalid handle\n");
1515 if (handler->lb.type != _LB_TYPE_SCRIPT && handler->lb.type != _LB_TYPE_BUFFER) {
1516 ErrPrint("Handler is not valid type\n");
1520 id = fb_id(handler->lb.data.fb);
1521 if (!id || strncasecmp(id, SCHEMA_PIXMAP, strlen(SCHEMA_PIXMAP)))
1524 packet = packet_create("lb_acquire_pixmap", "ss", handler->pkgname, handler->id);
1526 ErrPrint("Failed to build a param\n");
1530 return master_rpc_async_request(handler, packet, 0, pixmap_acquired_cb, create_cb_info(cb, data));
1533 EAPI int livebox_release_lb_pixmap(struct livebox *handler, int pixmap)
1535 struct packet *packet;
1538 ErrPrint("Handler is NIL\n");
1542 if (handler->state != CREATE || !handler->id) {
1543 ErrPrint("Invalid handle\n");
1547 if (handler->lb.type != _LB_TYPE_SCRIPT && handler->lb.type != _LB_TYPE_BUFFER) {
1548 ErrPrint("Handler is not valid type\n");
1552 packet = packet_create_noack("lb_release_pixmap", "ssi", handler->pkgname, handler->id, pixmap);
1554 ErrPrint("Failed to build a param\n");
1558 return master_rpc_request_only(handler, packet);
1561 EAPI int livebox_acquire_pd_pixmap(struct livebox *handler, ret_cb_t cb, void *data)
1563 struct packet *packet;
1567 ErrPrint("Handler is NIL\n");
1571 if (handler->state != CREATE || !handler->id) {
1572 ErrPrint("Invalid handle\n");
1576 if (handler->pd.type != _PD_TYPE_SCRIPT && handler->pd.type != _PD_TYPE_BUFFER) {
1577 ErrPrint("Handler is not valid type\n");
1581 id = fb_id(handler->pd.data.fb);
1582 if (!id || strncasecmp(id, SCHEMA_PIXMAP, strlen(SCHEMA_PIXMAP)))
1585 packet = packet_create("pd_acquire_pixmap", "ss", handler->pkgname, handler->id);
1587 ErrPrint("Failed to build a param\n");
1591 return master_rpc_async_request(handler, packet, 0, pixmap_acquired_cb, create_cb_info(cb, data));
1594 EAPI int livebox_pd_pixmap(const struct livebox *handler)
1600 ErrPrint("Handler is NIL\n");
1604 if (handler->state != CREATE || !handler->id) {
1605 ErrPrint("Invalid handler\n");
1609 if (handler->pd.type != _PD_TYPE_SCRIPT && handler->pd.type != _PD_TYPE_BUFFER) {
1610 ErrPrint("Invalid handler\n");
1614 id = fb_id(handler->pd.data.fb);
1615 if (id && sscanf(id, SCHEMA_PIXMAP "%d", &pixmap) != 1) {
1616 ErrPrint("PIXMAP Id is not valid\n");
1623 EAPI int livebox_lb_pixmap(const struct livebox *handler)
1629 ErrPrint("Handler is NIL\n");
1633 if (handler->state != CREATE || !handler->id) {
1634 ErrPrint("Invalid handler\n");
1638 if (handler->lb.type != _LB_TYPE_SCRIPT && handler->lb.type != _LB_TYPE_BUFFER) {
1639 ErrPrint("Invalid handler\n");
1643 id = fb_id(handler->lb.data.fb);
1644 if (id && sscanf(id, SCHEMA_PIXMAP "%d", &pixmap) != 1) {
1645 ErrPrint("PIXMAP Id is not valid\n");
1652 EAPI int livebox_release_pd_pixmap(struct livebox *handler, int pixmap)
1654 struct packet *packet;
1657 ErrPrint("Handler is NIL\n");
1661 if (handler->state != CREATE || !handler->id) {
1662 ErrPrint("Invalid handle\n");
1666 if (handler->pd.type != _PD_TYPE_SCRIPT && handler->pd.type != _PD_TYPE_BUFFER) {
1667 ErrPrint("Handler is not valid type\n");
1671 packet = packet_create_noack("pd_release_pixmap", "ssi", handler->pkgname, handler->id, pixmap);
1673 ErrPrint("Failed to build a param\n");
1677 return master_rpc_request_only(handler, packet);
1680 EAPI void *livebox_acquire_fb(struct livebox *handler)
1683 ErrPrint("Handler is NIL\n");
1687 if (handler->state != CREATE || !handler->id) {
1688 ErrPrint("Invalid handle\n");
1692 if (handler->lb.type != _LB_TYPE_SCRIPT && handler->lb.type != _LB_TYPE_BUFFER) {
1693 ErrPrint("Handler is not valid type\n");
1697 return fb_acquire_buffer(handler->lb.data.fb);
1700 EAPI int livebox_release_fb(void *buffer)
1702 return fb_release_buffer(buffer);
1705 EAPI int livebox_fb_refcnt(void *buffer)
1707 return fb_refcnt(buffer);
1710 EAPI void *livebox_acquire_pdfb(struct livebox *handler)
1713 ErrPrint("Handler is NIL\n");
1717 if (handler->state != CREATE || !handler->id) {
1718 ErrPrint("Invalid handler\n");
1722 if (handler->pd.type != _PD_TYPE_SCRIPT && handler->pd.type != _PD_TYPE_BUFFER) {
1723 ErrPrint("Handler is not valid type\n");
1727 return fb_acquire_buffer(handler->pd.data.fb);
1730 EAPI int livebox_release_pdfb(void *buffer)
1732 return fb_release_buffer(buffer);
1735 EAPI int livebox_pdfb_refcnt(void *buffer)
1737 return fb_refcnt(buffer);
1740 EAPI int livebox_pdfb_bufsz(struct livebox *handler)
1743 ErrPrint("Handler is NIL\n");
1747 if (handler->state != CREATE || !handler->id) {
1748 ErrPrint("Handler is not valid\n");
1752 return fb_size(handler->pd.data.fb);
1755 EAPI int livebox_lbfb_bufsz(struct livebox *handler)
1758 ErrPrint("Handler is NIL\n");
1762 if (handler->state != CREATE || !handler->id) {
1763 ErrPrint("Handler is not valid\n");
1767 return fb_size(handler->lb.data.fb);
1770 EAPI int livebox_is_user(struct livebox *handler)
1773 ErrPrint("Handler is NIL\n");
1777 if (handler->state != CREATE) {
1778 ErrPrint("Handler is invalid\n");
1782 return handler->is_user;
1785 EAPI int livebox_set_pinup(struct livebox *handler, int flag, ret_cb_t cb, void *data)
1787 struct packet *packet;
1790 ErrPrint("Handler is NIL\n");
1794 if (handler->state != CREATE || !handler->id) {
1795 ErrPrint("Handler is not valid\n");
1799 if (handler->is_pinned_up == flag) {
1800 DbgPrint("No changes\n");
1804 packet = packet_create("pinup_changed", "ssi", handler->pkgname, handler->id, flag);
1806 ErrPrint("Failed to build a param\n");
1811 cb = default_pinup_cb;
1813 return master_rpc_async_request(handler, packet, 0, pinup_done_cb, create_cb_info(cb, data));
1816 EAPI int livebox_is_pinned_up(struct livebox *handler)
1819 ErrPrint("Handler is NIL\n");
1823 if (handler->state != CREATE || !handler->id)
1826 return handler->is_pinned_up;
1829 EAPI int livebox_has_pinup(struct livebox *handler)
1832 ErrPrint("Handler is NIL\n");
1836 if (handler->state != CREATE || !handler->id)
1839 return handler->lb.pinup_supported;
1842 EAPI int livebox_set_data(struct livebox *handler, void *data)
1845 ErrPrint("Handler is NIL\n");
1849 if (handler->state != CREATE)
1852 handler->data = data;
1856 EAPI void *livebox_get_data(struct livebox *handler)
1859 ErrPrint("Handler is NIL\n");
1863 if (handler->state != CREATE)
1866 return handler->data;
1869 EAPI int livebox_is_exists(const char *pkgname)
1873 lb = lb_pkgname(pkgname);
1882 EAPI const char *livebox_content(struct livebox *handler)
1885 ErrPrint("Handler is NIL\n");
1889 if (handler->state != CREATE)
1892 return handler->content;
1895 EAPI const char *livebox_category_title(struct livebox *handler)
1898 ErrPrint("Handler is NIL\n");
1902 if (handler->state != CREATE)
1905 return handler->title;
1908 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)
1910 struct packet *packet;
1913 ErrPrint("Handler is NIL\n");
1917 if ((handler->lb.type != _LB_TYPE_TEXT && handler->pd.type != _PD_TYPE_TEXT) || handler->state != CREATE || !handler->id) {
1918 ErrPrint("Handler is not valid\n");
1928 packet = packet_create("text_signal", "ssssdddd",
1929 handler->pkgname, handler->id, emission, source, sx, sy, ex, ey);
1931 ErrPrint("Failed to build a param\n");
1935 return master_rpc_async_request(handler, packet, 0, text_signal_cb, create_cb_info(cb, data));
1938 EAPI int livebox_subscribe_group(const char *cluster, const char *category)
1940 struct packet *packet;
1944 * Validate the group info using DB
1945 * If the group info is not valid, do not send this request
1948 packet = packet_create_noack("subscribe", "ss", cluster ? cluster : "", category ? category : "");
1950 ErrPrint("Failed to create a packet\n");
1954 return master_rpc_request_only(NULL, packet);
1957 EAPI int livebox_unsubscribe_group(const char *cluster, const char *category)
1959 struct packet *packet;
1963 * Validate the group info using DB
1964 * If the group info is not valid, do not send this request
1965 * AND Check the subscribed or not too
1968 packet = packet_create_noack("unsubscribe", "ss", cluster ? cluster : "", category ? category : "");
1970 ErrPrint("Failed to create a packet\n");
1974 return master_rpc_request_only(NULL, packet);
1977 EAPI int livebox_refresh_group(const char *cluster, const char *category)
1979 struct packet *packet;
1981 if (!cluster || !category) {
1982 ErrPrint("Invalid argument\n");
1986 packet = packet_create_noack("refresh_group", "ss", cluster, category);
1988 ErrPrint("Failed to create a packet\n");
1992 return master_rpc_request_only(NULL, packet);
1995 EAPI int livebox_set_visibility(struct livebox *handler, enum livebox_visible_state state)
1997 struct packet *packet;
2001 ErrPrint("Handler is NIL\n");
2005 if (handler->state != CREATE || !handler->id)
2008 if (!handler->is_user) {
2009 /* System cluster livebox cannot be changed its visible states */
2010 if (state == LB_HIDE_WITH_PAUSE) {
2011 ErrPrint("CA Livebox is not able to change the visibility\n");
2016 if (handler->visible == state)
2019 packet = packet_create_noack("change,visibility", "ssi", handler->pkgname, handler->id, (int)state);
2021 ErrPrint("Failed to create a packet\n");
2025 ret = master_rpc_request_only(handler, packet);
2027 handler->visible = state;
2032 EAPI enum livebox_visible_state livebox_visibility(struct livebox *handler)
2035 ErrPrint("Handler is NIL\n");
2036 return LB_VISIBLE_ERROR;
2039 if (handler->state != CREATE)
2040 return LB_VISIBLE_ERROR;
2042 return handler->visible;
2045 int lb_set_group(struct livebox *handler, const char *cluster, const char *category)
2051 pc = strdup(cluster);
2053 CRITICAL_LOG("Heap: %s (cluster: %s)\n", strerror(errno), cluster);
2059 ps = strdup(category);
2061 CRITICAL_LOG("Heap: %s (category: %s)\n", strerror(errno), category);
2067 if (handler->cluster)
2068 free(handler->cluster);
2070 if (handler->category)
2071 free(handler->category);
2073 handler->cluster = pc;
2074 handler->category = ps;
2079 void lb_set_size(struct livebox *handler, int w, int h)
2081 handler->lb.width = w;
2082 handler->lb.height = h;
2085 void lb_set_pdsize(struct livebox *handler, int w, int h)
2087 handler->pd.width = w;
2088 handler->pd.height = h;
2091 void lb_invoke_fault_handler(enum livebox_fault_type event, const char *pkgname, const char *file, const char *func)
2095 struct fault_info *info;
2097 dlist_foreach_safe(s_info.fault_list, l, n, info) {
2098 if (info->handler(event, pkgname, file, func, info->user_data) == EXIT_FAILURE)
2099 s_info.fault_list = dlist_remove(s_info.fault_list, l);
2103 void lb_invoke_event_handler(struct livebox *handler, enum livebox_event_type event)
2107 struct event_info *info;
2109 dlist_foreach_safe(s_info.event_list, l, n, info) {
2110 if (info->handler(handler, event, info->user_data) == EXIT_FAILURE)
2111 s_info.event_list = dlist_remove(s_info.event_list, l);
2115 struct livebox *lb_find_livebox(const char *pkgname, const char *id)
2118 struct livebox *handler;
2120 dlist_foreach(s_info.livebox_list, l, handler) {
2124 if (!strcmp(handler->pkgname, pkgname) && !strcmp(handler->id, id))
2131 struct livebox *lb_find_livebox_by_timestamp(double timestamp)
2134 struct livebox *handler;
2136 dlist_foreach(s_info.livebox_list, l, handler) {
2137 if (handler->timestamp == timestamp)
2144 static inline char *get_file_kept_in_safe(const char *id)
2151 path = util_uri_to_path(id);
2153 ErrPrint("Invalid URI(%s)\n", id);
2160 if (s_info.prevent_overwrite) {
2161 new_path = strdup(path);
2163 ErrPrint("Heap: %s\n", strerror(errno));
2172 while (base_idx > 0 && path[base_idx] != '/') base_idx--;
2173 base_idx += (path[base_idx] == '/');
2175 new_path = malloc(len + 10);
2177 ErrPrint("Heap: %s\n", strerror(errno));
2181 strncpy(new_path, path, base_idx);
2182 snprintf(new_path + base_idx, len + 10 - base_idx, "reader/%s", path + base_idx);
2186 struct livebox *lb_new_livebox(const char *pkgname, const char *id, double timestamp)
2188 struct livebox *handler;
2190 handler = calloc(1, sizeof(*handler));
2192 ErrPrint("Failed to create a new livebox\n");
2196 handler->pkgname = strdup(pkgname);
2197 if (!handler->pkgname) {
2198 ErrPrint("%s\n", strerror(errno));
2203 handler->id = strdup(id);
2205 ErrPrint("%s\n", strerror(errno));
2206 free(handler->pkgname);
2211 handler->filename = get_file_kept_in_safe(id);
2212 if (!handler->filename) {
2213 handler->filename = strdup(util_uri_to_path(id));
2214 if (!handler->filename)
2215 ErrPrint("Error: %s\n", strerror(errno));
2218 handler->timestamp = timestamp;
2219 handler->lb.type = _LB_TYPE_FILE;
2220 handler->pd.type = _PD_TYPE_SCRIPT;
2221 handler->state = CREATE;
2222 handler->visible = LB_SHOW;
2224 s_info.livebox_list = dlist_append(s_info.livebox_list, handler);
2229 int lb_delete_all(void)
2233 struct livebox *handler;
2235 dlist_foreach_safe(s_info.livebox_list, l, n, handler) {
2236 lb_invoke_event_handler(handler, LB_EVENT_DELETED);
2243 int lb_set_content(struct livebox *handler, const char *content)
2245 if (handler->content) {
2246 free(handler->content);
2247 handler->content = NULL;
2251 handler->content = strdup(content);
2252 if (!handler->content) {
2253 CRITICAL_LOG("Heap: %s (content: %s)\n", strerror(errno), content);
2261 int lb_set_title(struct livebox *handler, const char *title)
2263 if (handler->title) {
2264 free(handler->title);
2265 handler->title = NULL;
2269 handler->title = strdup(title);
2270 if (!handler->title) {
2271 CRITICAL_LOG("Heap: %s (title: %s)\n", strerror(errno), title);
2279 void lb_set_size_list(struct livebox *handler, int size_list)
2281 handler->lb.size_list = size_list;
2284 void lb_set_auto_launch(struct livebox *handler, const char *auto_launch)
2286 if (!strlen(auto_launch))
2289 handler->lb.auto_launch = strdup(auto_launch);
2290 if (!handler->lb.auto_launch)
2291 ErrPrint("Heap: %s\n", strerror(errno));
2294 void lb_set_priority(struct livebox *handler, double priority)
2296 handler->lb.priority = priority;
2299 void lb_set_id(struct livebox *handler, const char *id)
2304 handler->id = strdup(id);
2306 ErrPrint("Error: %s\n", strerror(errno));
2308 if (handler->filename)
2309 free(handler->filename);
2311 handler->filename = get_file_kept_in_safe(id);
2312 if (!handler->filename) {
2313 handler->filename = strdup(util_uri_to_path(id));
2314 if (!handler->filename)
2315 ErrPrint("Error: %s\n", strerror(errno));
2319 int lb_set_lb_fb(struct livebox *handler, const char *filename)
2326 fb = handler->lb.data.fb;
2327 if (fb && !strcmp(fb_id(fb), filename)) /*!< BUFFER is not changed, */
2330 handler->lb.data.fb = NULL;
2332 if (!filename || filename[0] == '\0') {
2338 handler->lb.data.fb = fb_create(filename, handler->lb.width, handler->lb.height);
2339 if (!handler->lb.data.fb) {
2340 ErrPrint("Faield to create a FB\n");
2352 int lb_set_pd_fb(struct livebox *handler, const char *filename)
2359 fb = handler->pd.data.fb;
2360 if (fb && !strcmp(fb_id(fb), filename)) {
2361 /* BUFFER is not changed, just update the content */
2364 handler->pd.data.fb = NULL;
2366 if (!filename || filename[0] == '\0') {
2372 handler->pd.data.fb = fb_create(filename, handler->pd.width, handler->pd.height);
2373 if (!handler->pd.data.fb) {
2374 ErrPrint("Failed to create a FB\n");
2385 struct fb_info *lb_get_lb_fb(struct livebox *handler)
2387 return handler->lb.data.fb;
2390 struct fb_info *lb_get_pd_fb(struct livebox *handler)
2392 return handler->pd.data.fb;
2395 void lb_set_user(struct livebox *handler, int user)
2397 handler->is_user = user;
2400 void lb_set_pinup(struct livebox *handler, int pinup_supported)
2402 handler->lb.pinup_supported = pinup_supported;
2405 void lb_set_text_lb(struct livebox *handler)
2407 handler->lb.type = _LB_TYPE_TEXT;
2410 void lb_set_text_pd(struct livebox *handler)
2412 handler->pd.type = _PD_TYPE_TEXT;
2415 int lb_text_lb(struct livebox *handler)
2417 return handler->lb.type == _LB_TYPE_TEXT;
2420 int lb_text_pd(struct livebox *handler)
2422 return handler->pd.type == _PD_TYPE_TEXT;
2425 void lb_set_period(struct livebox *handler, double period)
2427 handler->lb.period = period;
2430 struct livebox *lb_ref(struct livebox *handler)
2439 struct livebox *lb_unref(struct livebox *handler)
2445 if (handler->refcnt > 0)
2448 dlist_remove_data(s_info.livebox_list, handler);
2450 handler->state = DESTROYED;
2451 free(handler->cluster);
2452 free(handler->category);
2454 free(handler->pkgname);
2455 free(handler->filename);
2456 free(handler->lb.auto_launch);
2458 if (handler->lb.data.fb) {
2459 fb_destroy(handler->lb.data.fb);
2460 handler->lb.data.fb = NULL;
2463 if (handler->pd.data.fb) {
2464 fb_destroy(handler->pd.data.fb);
2465 handler->pd.data.fb = NULL;
2472 int lb_send_delete(struct livebox *handler, ret_cb_t cb, void *data)
2474 struct packet *packet;
2476 if (!cb && !!data) {
2477 ErrPrint("Invalid argument\n");
2481 if (handler->deleted_cb) {
2482 ErrPrint("Already in-progress\n");
2483 return -EINPROGRESS;
2486 packet = packet_create("delete", "ss", handler->pkgname, handler->id);
2488 ErrPrint("Failed to build a param\n");
2490 cb(handler, -EFAULT, data);
2496 cb = default_delete_cb;
2498 return master_rpc_async_request(handler, packet, 0, del_ret_cb, create_cb_info(cb, data));