10 #include <dynamicbox_errno.h>
11 #include <dynamicbox_service.h>
12 #include <dynamicbox_buffer.h>
18 #include "dynamicbox.h"
19 #include "dynamicbox_internal.h"
23 #include "master_rpc.h"
27 typedef enum event_state {
28 INFO_STATE_CALLBACK_IN_IDLE = 0x00,
29 INFO_STATE_CALLBACK_IN_PROCESSING = 0x01
34 int (*handler)(dynamicbox_h handler, dynamicbox_event_type_e event, void *data);
40 int (*handler)(dynamicbox_fault_type_e event, const char *pkgname, const char *filename, const char *func, void *data);
45 struct dlist *dynamicbox_common_list;
46 struct dlist *dynamicbox_list;
47 struct dlist *event_list;
48 struct dlist *fault_list;
49 event_state_e event_state;
50 event_state_e fault_state;
52 .dynamicbox_common_list = NULL,
53 .dynamicbox_list = NULL,
56 .event_state = INFO_STATE_CALLBACK_IN_IDLE,
57 .fault_state = INFO_STATE_CALLBACK_IN_IDLE,
60 static inline void default_delete_cb(dynamicbox_h handler, int ret, void *data)
62 DbgPrint("Default deleted event handler: %d\n", ret);
65 static void del_ret_cb(dynamicbox_h handler, const struct packet *result, void *data)
67 struct cb_info *info = data;
74 dbox_destroy_cb_info(info);
77 ErrPrint("Connection lost?\n");
78 ret = DBOX_STATUS_ERROR_FAULT;
79 } else if (packet_get(result, "i", &ret) != 1) {
80 ErrPrint("Invalid argument\n");
81 ret = DBOX_STATUS_ERROR_INVALID_PARAMETER;
85 handler->cbs.deleted.cb = cb;
86 handler->cbs.deleted.data = cbdata;
88 cb(handler, ret, cbdata);
93 * Do not call the deleted callback from here.
94 * master will send the "deleted" event.
95 * Then invoke this callback.
97 * if (handler->cbs.deleted.cb)
98 * handler->cbs.deleted.cb(handler, ret, handler->cbs.deleted.data);
102 struct dynamicbox_common *dbox_create_common_handle(dynamicbox_h handle, const char *pkgname, const char *cluster, const char *category)
104 struct dynamicbox_common *common;
106 common = calloc(1, sizeof(*common));
108 ErrPrint("Heap: %s\n", strerror(errno));
109 dynamicbox_set_last_status(DBOX_STATUS_ERROR_OUT_OF_MEMORY);
113 common->pkgname = strdup(pkgname);
114 if (!common->pkgname) {
116 dynamicbox_set_last_status(DBOX_STATUS_ERROR_OUT_OF_MEMORY);
120 common->cluster = strdup(cluster);
121 if (!common->cluster) {
122 ErrPrint("Error: %s\n", strerror(errno));
123 free(common->pkgname);
125 dynamicbox_set_last_status(DBOX_STATUS_ERROR_OUT_OF_MEMORY);
129 common->category = strdup(category);
130 if (!common->category) {
131 ErrPrint("Error: %s\n", strerror(errno));
132 free(common->cluster);
133 free(common->pkgname);
135 dynamicbox_set_last_status(DBOX_STATUS_ERROR_OUT_OF_MEMORY);
139 /* Data provider will set this */
140 common->dbox.type = DBOX_TYPE_FILE;
141 common->gbar.type = GBAR_TYPE_SCRIPT;
143 /* Used for handling the mouse event on a box */
144 common->dbox.mouse_event = 0;
146 /* Cluster infomration is not determined yet */
147 common->nr_of_sizes = 0x01;
149 common->timestamp = util_timestamp();
151 common->delete_type = DBOX_DELETE_PERMANENTLY;
153 common->gbar.lock = NULL;
154 common->gbar.last_extra_buffer_idx = DBOX_UNKNOWN_BUFFER;
156 common->dbox.lock = NULL;
157 common->dbox.last_extra_buffer_idx = DBOX_UNKNOWN_BUFFER;
159 common->state = DBOX_STATE_CREATE;
160 common->visible = DBOX_SHOW;
162 s_info.dynamicbox_common_list = dlist_append(s_info.dynamicbox_common_list, common);
166 int dbox_destroy_common_handle(struct dynamicbox_common *common)
168 dlist_remove_data(s_info.dynamicbox_common_list, common);
170 common->state = DBOX_STATE_DESTROYED;
172 if (common->filename) {
173 (void)util_unlink(common->filename);
176 free(common->cluster);
177 free(common->category);
179 free(common->pkgname);
180 free(common->filename);
181 free(common->dbox.auto_launch);
182 free(common->alt.icon);
183 free(common->alt.name);
185 if (common->dbox.fb) {
186 fb_destroy(common->dbox.fb);
187 common->dbox.fb = NULL;
190 if (common->gbar.fb) {
191 fb_destroy(common->gbar.fb);
192 common->gbar.fb = NULL;
198 int dbox_common_ref(struct dynamicbox_common *common, dynamicbox_h handle)
200 common->dynamicbox_list = dlist_append(common->dynamicbox_list, handle);
203 return common->refcnt;
206 int dbox_common_unref(struct dynamicbox_common *common, dynamicbox_h handle)
209 dlist_remove_data(common->dynamicbox_list, handle);
210 refcnt = --common->refcnt;
215 int dbox_set_group(struct dynamicbox_common *common, const char *cluster, const char *category)
221 pc = strdup(cluster);
223 ErrPrint("Heap: %s (cluster: %s)\n", strerror(errno), cluster);
224 return DBOX_STATUS_ERROR_OUT_OF_MEMORY;
229 ps = strdup(category);
231 ErrPrint("Heap: %s (category: %s)\n", strerror(errno), category);
233 return DBOX_STATUS_ERROR_OUT_OF_MEMORY;
237 if (common->cluster) {
238 free(common->cluster);
241 if (common->category) {
242 free(common->category);
245 common->cluster = pc;
246 common->category = ps;
248 return DBOX_STATUS_ERROR_NONE;
251 void dbox_set_size(struct dynamicbox_common *common, int w, int h)
255 common->dbox.width = w;
256 common->dbox.height = h;
258 size_type = dynamicbox_service_size_type(w, h);
259 if (size_type != DBOX_SIZE_TYPE_UNKNOWN) {
260 common->dbox.mouse_event = dynamicbox_service_mouse_event(common->pkgname, size_type);
264 void dbox_set_update_mode(struct dynamicbox_common *common, int active_mode)
266 common->is_active_update = active_mode;
269 void dbox_set_gbarsize(struct dynamicbox_common *common, int w, int h)
271 common->gbar.width = w;
272 common->gbar.height = h;
275 void dbox_set_default_gbarsize(struct dynamicbox_common *common, int w, int h)
277 common->gbar.default_width = w;
278 common->gbar.default_height = h;
281 void dbox_invoke_fault_handler(dynamicbox_fault_type_e event, const char *pkgname, const char *file, const char *func)
285 struct fault_info *info;
287 s_info.fault_state = INFO_STATE_CALLBACK_IN_PROCESSING;
289 dlist_foreach_safe(s_info.fault_list, l, n, info) {
290 if (!info->is_deleted && info->handler(event, pkgname, file, func, info->user_data) == EXIT_FAILURE) {
291 info->is_deleted = 1;
294 if (info->is_deleted) {
295 s_info.fault_list = dlist_remove(s_info.fault_list, l);
300 s_info.fault_state &= ~INFO_STATE_CALLBACK_IN_PROCESSING;
303 void dbox_invoke_event_handler(dynamicbox_h handler, dynamicbox_event_type_e event)
307 struct event_info *info;
309 if (event == DBOX_EVENT_DBOX_UPDATED && handler->common->refcnt > 1) {
310 if (handler->visible != DBOX_SHOW) {
311 DbgPrint("Update requested(pending) - %s\n", handler->common->pkgname);
312 handler->paused_updating++;
315 handler->paused_updating = 0;
319 s_info.event_state = INFO_STATE_CALLBACK_IN_PROCESSING;
321 dlist_foreach_safe(s_info.event_list, l, n, info) {
322 if (!info->is_deleted && info->handler(handler, event, info->user_data) == EXIT_FAILURE) {
323 DbgPrint("Event handler returns EXIT_FAILURE\n");
324 info->is_deleted = 1;
327 if (info->is_deleted) {
328 s_info.event_list = dlist_remove(s_info.event_list, l);
333 s_info.event_state &= ~INFO_STATE_CALLBACK_IN_PROCESSING;
336 struct dynamicbox_common *dbox_find_common_handle(const char *pkgname, const char *id)
339 struct dynamicbox_common *common;
341 dlist_foreach(s_info.dynamicbox_common_list, l, common) {
346 if (!strcmp(common->pkgname, pkgname) && !strcmp(common->id, id)) {
354 struct dynamicbox_common *dbox_find_common_handle_by_timestamp(double timestamp)
357 struct dynamicbox_common *common;
359 dlist_foreach(s_info.dynamicbox_common_list, l, common) {
360 if (common->timestamp == timestamp) {
368 dynamicbox_h dbox_new_dynamicbox(const char *pkgname, const char *id, double timestamp, const char *cluster, const char *category)
370 dynamicbox_h handler;
372 handler = calloc(1, sizeof(*handler));
374 ErrPrint("Failed to create a new dynamicbox\n");
378 handler->common = dbox_create_common_handle(handler, pkgname, cluster, category);
379 if (!handler->common) {
380 ErrPrint("Heap: %s\n", strerror(errno));
385 dbox_common_ref(handler->common, handler);
386 dbox_set_id(handler->common, id);
387 handler->common->timestamp = timestamp;
388 handler->common->state = DBOX_STATE_CREATE;
389 handler->visible = DBOX_SHOW;
390 s_info.dynamicbox_list = dlist_append(s_info.dynamicbox_list, handler);
392 return dbox_ref(handler);
395 int dbox_delete_all(void)
399 dynamicbox_h handler;
401 dlist_foreach_safe(s_info.dynamicbox_list, l, n, handler) {
402 dbox_invoke_event_handler(handler, DBOX_EVENT_DELETED);
403 dbox_unref(handler, 1);
406 return DBOX_STATUS_ERROR_NONE;
409 int dbox_set_content(struct dynamicbox_common *common, const char *content)
414 pc = strdup(content);
416 ErrPrint("heap: %s [%s]\n", strerror(errno), content);
417 return DBOX_STATUS_ERROR_OUT_OF_MEMORY;
421 free(common->content);
422 common->content = pc;
423 return DBOX_STATUS_ERROR_NONE;
426 int dbox_set_title(struct dynamicbox_common *common, const char *title)
433 ErrPrint("heap: %s [%s]\n", strerror(errno), title);
434 return DBOX_STATUS_ERROR_OUT_OF_MEMORY;
440 return DBOX_STATUS_ERROR_NONE;
443 void dbox_set_size_list(struct dynamicbox_common *common, int size_list)
445 common->dbox.size_list = size_list;
448 void dbox_set_auto_launch(struct dynamicbox_common *common, const char *auto_launch)
452 if (!auto_launch || !strlen(auto_launch)) {
456 pa = strdup(auto_launch);
458 ErrPrint("heap: %s, [%s]\n", strerror(errno), auto_launch);
462 free(common->dbox.auto_launch);
463 common->dbox.auto_launch = pa;
466 void dbox_set_priority(struct dynamicbox_common *common, double priority)
468 common->dbox.priority = priority;
471 void dbox_set_id(struct dynamicbox_common *common, const char *id)
478 ErrPrint("heap: %s [%s]\n", strerror(errno), pi);
487 void dbox_unlink_filename(struct dynamicbox_common *common)
489 if (common->dbox.type == DBOX_TYPE_FILE || common->dbox.type == DBOX_TYPE_TEXT) {
490 if (common->filename && common->filename[0] && unlink(common->filename) < 0) {
491 ErrPrint("unlink: %s (%s)\n", strerror(errno), common->filename);
496 void dbox_set_filename(struct dynamicbox_common *common, const char *filename)
498 if (common->filename) {
499 free(common->filename);
502 common->filename = strdup(filename);
503 if (!common->filename) {
504 ErrPrint("Heap: %s\n", strerror(errno));
508 void dbox_set_alt_icon(struct dynamicbox_common *common, const char *icon)
512 if (icon && strlen(icon)) {
513 _icon = strdup(icon);
515 ErrPrint("Heap: %s\n", strerror(errno));
519 free(common->alt.icon);
520 common->alt.icon = _icon;
523 void dbox_set_alt_name(struct dynamicbox_common *common, const char *name)
527 if (name && strlen(name)) {
528 _name = strdup(name);
530 ErrPrint("Heap: %s\n", strerror(errno));
534 free(common->alt.name);
535 common->alt.name = _name;
538 int dbox_set_dbox_fb(struct dynamicbox_common *common, const char *filename)
543 return DBOX_STATUS_ERROR_INVALID_PARAMETER;
546 fb = common->dbox.fb;
547 if (fb && !strcmp(fb_id(fb), filename)) { /*!< BUFFER is not changed, */
548 return DBOX_STATUS_ERROR_NONE;
551 common->dbox.fb = NULL;
553 if (!filename || filename[0] == '\0') {
557 return DBOX_STATUS_ERROR_NONE;
560 common->dbox.fb = fb_create(filename, common->dbox.width, common->dbox.height);
561 if (!common->dbox.fb) {
562 ErrPrint("Faield to create a FB\n");
566 return DBOX_STATUS_ERROR_FAULT;
573 return DBOX_STATUS_ERROR_NONE;
576 int dbox_set_gbar_fb(struct dynamicbox_common *common, const char *filename)
580 if (!common || common->state != DBOX_STATE_CREATE) {
581 return DBOX_STATUS_ERROR_INVALID_PARAMETER;
584 fb = common->gbar.fb;
585 if (fb && !strcmp(fb_id(fb), filename)) {
586 /* BUFFER is not changed, just update the content */
587 return DBOX_STATUS_ERROR_EXIST;
589 common->gbar.fb = NULL;
591 if (!filename || filename[0] == '\0') {
595 return DBOX_STATUS_ERROR_NONE;
598 common->gbar.fb = fb_create(filename, common->gbar.width, common->gbar.height);
599 if (!common->gbar.fb) {
600 ErrPrint("Failed to create a FB\n");
604 return DBOX_STATUS_ERROR_FAULT;
610 return DBOX_STATUS_ERROR_NONE;
613 struct fb_info *dbox_get_dbox_fb(struct dynamicbox_common *common)
615 return common->dbox.fb;
618 struct fb_info *dbox_get_gbar_fb(struct dynamicbox_common *common)
620 return common->gbar.fb;
623 void dbox_set_user(struct dynamicbox_common *common, int user)
625 common->is_user = user;
628 void dbox_set_pinup(struct dynamicbox_common *common, int pinup_supported)
630 common->dbox.pinup_supported = pinup_supported;
633 void dbox_set_text_dbox(struct dynamicbox_common *common)
635 common->dbox.type = DBOX_TYPE_TEXT;
638 void dbox_set_text_gbar(struct dynamicbox_common *common)
640 common->gbar.type = GBAR_TYPE_TEXT;
643 int dbox_text_dbox(struct dynamicbox_common *common)
645 return common->dbox.type == DBOX_TYPE_TEXT;
648 int dbox_text_gbar(struct dynamicbox_common *common)
650 return common->gbar.type == GBAR_TYPE_TEXT;
653 void dbox_set_period(struct dynamicbox_common *common, double period)
655 common->dbox.period = period;
658 dynamicbox_h dbox_ref(dynamicbox_h handler)
668 dynamicbox_h dbox_unref(dynamicbox_h handler, int destroy_common)
675 if (handler->refcnt > 0) {
679 if (handler->cbs.created.cb) {
680 handler->cbs.created.cb(handler, DBOX_STATUS_ERROR_FAULT, handler->cbs.created.data);
681 handler->cbs.created.cb = NULL;
682 handler->cbs.created.data = NULL;
685 if (handler->cbs.deleted.cb) {
686 handler->cbs.deleted.cb(handler, DBOX_STATUS_ERROR_FAULT, handler->cbs.deleted.data);
687 handler->cbs.deleted.cb = NULL;
688 handler->cbs.deleted.data = NULL;
691 if (handler->cbs.pinup.cb) {
692 handler->cbs.pinup.cb(handler, DBOX_STATUS_ERROR_FAULT, handler->cbs.pinup.data);
693 handler->cbs.pinup.cb = NULL;
694 handler->cbs.pinup.data = NULL;
697 if (handler->cbs.group_changed.cb) {
698 handler->cbs.group_changed.cb(handler, DBOX_STATUS_ERROR_FAULT, handler->cbs.group_changed.data);
699 handler->cbs.group_changed.cb = NULL;
700 handler->cbs.group_changed.data = NULL;
703 if (handler->cbs.period_changed.cb) {
704 handler->cbs.period_changed.cb(handler, DBOX_STATUS_ERROR_FAULT, handler->cbs.period_changed.data);
705 handler->cbs.period_changed.cb = NULL;
706 handler->cbs.period_changed.data = NULL;
709 if (handler->cbs.size_changed.cb) {
710 handler->cbs.size_changed.cb(handler, DBOX_STATUS_ERROR_FAULT, handler->cbs.size_changed.data);
711 handler->cbs.size_changed.cb = NULL;
712 handler->cbs.size_changed.data = NULL;
715 if (handler->cbs.gbar_created.cb) {
716 handler->cbs.gbar_created.cb(handler, DBOX_STATUS_ERROR_FAULT, handler->cbs.gbar_created.data);
717 handler->cbs.gbar_created.cb = NULL;
718 handler->cbs.gbar_created.data = NULL;
721 if (handler->cbs.gbar_destroyed.cb) {
722 handler->cbs.gbar_destroyed.cb(handler, DBOX_STATUS_ERROR_FAULT, handler->cbs.gbar_destroyed.data);
723 handler->cbs.gbar_destroyed.cb = NULL;
724 handler->cbs.gbar_destroyed.data = NULL;
727 if (handler->cbs.update_mode.cb) {
728 handler->cbs.update_mode.cb(handler, DBOX_STATUS_ERROR_FAULT, handler->cbs.update_mode.data);
729 handler->cbs.update_mode.cb = NULL;
730 handler->cbs.update_mode.data = NULL;
733 if (handler->cbs.access_event.cb) {
734 handler->cbs.access_event.cb(handler, DBOX_ACCESS_STATUS_ERROR, handler->cbs.access_event.data);
735 handler->cbs.access_event.cb = NULL;
736 handler->cbs.access_event.data = NULL;
739 if (handler->cbs.key_event.cb) {
740 handler->cbs.key_event.cb(handler, DBOX_KEY_STATUS_ERROR, handler->cbs.key_event.data);
741 handler->cbs.key_event.cb = NULL;
742 handler->cbs.key_event.data = NULL;
745 dlist_remove_data(s_info.dynamicbox_list, handler);
747 handler->state = DBOX_STATE_DESTROYED;
748 if (dbox_common_unref(handler->common, handler) == 0) {
749 if (destroy_common) {
752 * Lock file should be deleted after all callbacks are processed.
754 (void)dynamicbox_service_destroy_lock(handler->common->dbox.lock);
755 handler->common->dbox.lock = NULL;
756 dbox_destroy_common_handle(handler->common);
760 DbgPrint("Handler is released\n");
764 int dbox_send_delete(dynamicbox_h handler, int type, dynamicbox_ret_cb cb, void *data)
766 struct packet *packet;
767 struct cb_info *cbinfo;
770 if (handler->common->request.deleted) {
771 ErrPrint("Already in-progress\n");
773 cb(handler, DBOX_STATUS_ERROR_NONE, data);
775 return DBOX_STATUS_ERROR_BUSY;
779 cb = default_delete_cb;
782 packet = packet_create("delete", "ssid", handler->common->pkgname, handler->common->id, type, handler->common->timestamp);
784 ErrPrint("Failed to build a param\n");
786 cb(handler, DBOX_STATUS_ERROR_FAULT, data);
789 return DBOX_STATUS_ERROR_FAULT;
792 cbinfo = dbox_create_cb_info(cb, data);
794 packet_destroy(packet);
795 ErrPrint("Failed to create cbinfo\n");
797 cb(handler, DBOX_STATUS_ERROR_FAULT, data);
800 return DBOX_STATUS_ERROR_FAULT;
803 ret = master_rpc_async_request(handler, packet, 0, del_ret_cb, cbinfo);
806 * Packet is destroyed by master_rpc_async_request.
808 dbox_destroy_cb_info(cbinfo);
811 cb(handler, DBOX_STATUS_ERROR_FAULT, data);
814 handler->common->request.deleted = 1;
820 int dbox_sync_dbox_fb(struct dynamicbox_common *common)
824 if (fb_type(dbox_get_dbox_fb(common)) == DBOX_FB_TYPE_FILE) {
825 (void)dynamicbox_service_acquire_lock(common->dbox.lock);
826 ret = fb_sync(dbox_get_dbox_fb(common), common->dbox.last_damage.x, common->dbox.last_damage.y, common->dbox.last_damage.w, common->dbox.last_damage.h);
827 (void)dynamicbox_service_release_lock(common->dbox.lock);
829 ret = fb_sync(dbox_get_dbox_fb(common), common->dbox.last_damage.x, common->dbox.last_damage.y, common->dbox.last_damage.w, common->dbox.last_damage.h);
835 int dbox_sync_gbar_fb(struct dynamicbox_common *common)
839 if (fb_type(dbox_get_gbar_fb(common)) == DBOX_FB_TYPE_FILE) {
840 (void)dynamicbox_service_acquire_lock(common->gbar.lock);
841 ret = fb_sync(dbox_get_gbar_fb(common), common->gbar.last_damage.x, common->gbar.last_damage.y, common->gbar.last_damage.w, common->gbar.last_damage.h);
842 (void)dynamicbox_service_release_lock(common->gbar.lock);
844 ret = fb_sync(dbox_get_gbar_fb(common), common->gbar.last_damage.x, common->gbar.last_damage.y, common->gbar.last_damage.w, common->gbar.last_damage.h);
850 struct dynamicbox_common *dbox_find_sharable_common_handle(const char *pkgname, const char *content, int w, int h, const char *cluster, const char *category)
853 struct dynamicbox_common *common;
855 if (!conf_shared_content()) {
857 * Shared content option is turnned off.
862 dlist_foreach(s_info.dynamicbox_common_list, l, common) {
863 if (common->state != DBOX_STATE_CREATE) {
867 if (strcmp(common->pkgname, pkgname)) {
871 if (strcmp(common->cluster, cluster)) {
872 DbgPrint("Cluster mismatched\n");
876 if (strcmp(common->category, category)) {
877 DbgPrint("Category mismatched\n");
881 if (common->content && content) {
882 if (strcmp(common->content, content)) {
883 DbgPrint("%s Content ([%s] <> [%s])\n", common->pkgname, common->content, content);
892 * We assumes "" (ZERO length string) to NULL
894 c1_len = common->content ? strlen(common->content) : 0;
895 c2_len = content ? strlen(content) : 0;
896 if (c1_len != c2_len) {
897 DbgPrint("%s Content %p <> %p\n", common->pkgname, common->content, content);
902 if (common->request.size_changed) {
903 DbgPrint("Changing size\n");
906 * Do not re-use resizing instance.
907 * We will not use predicted size.
912 if (common->request.created) {
913 DbgPrint("Creating now but re-use it (%s)\n", common->pkgname);
916 if (common->dbox.width != w || common->dbox.height != h) {
917 DbgPrint("Size mismatched\n");
921 DbgPrint("common handle is found: %p\n", common);
928 dynamicbox_h dbox_find_dbox_in_show(struct dynamicbox_common *common)
933 dlist_foreach(common->dynamicbox_list, l, item) {
934 if (item->visible == DBOX_SHOW) {
935 DbgPrint("%s visibility is not changed\n", common->pkgname);
943 dynamicbox_h dbox_get_dbox_nth(struct dynamicbox_common *common, int nth)
948 l = dlist_nth(common->dynamicbox_list, nth);
949 item = dlist_data(l);
954 int dbox_add_event_handler(dynamicbox_event_handler_cb dbox_cb, void *data)
956 struct event_info *info;
957 info = malloc(sizeof(*info));
959 ErrPrint("Heap: %s\n", strerror(errno));
960 return DBOX_STATUS_ERROR_OUT_OF_MEMORY;
963 info->handler = dbox_cb;
964 info->user_data = data;
965 info->is_deleted = 0;
967 s_info.event_list = dlist_append(s_info.event_list, info);
968 return DBOX_STATUS_ERROR_NONE;
971 void *dbox_remove_event_handler(dynamicbox_event_handler_cb dbox_cb)
973 struct event_info *info;
976 dlist_foreach(s_info.event_list, l, info) {
977 if (info->handler == dbox_cb) {
980 data = info->user_data;
982 if (s_info.event_state == INFO_STATE_CALLBACK_IN_PROCESSING) {
983 info->is_deleted = 1;
985 s_info.event_list = dlist_remove(s_info.event_list, l);
996 int dbox_add_fault_handler(dynamicbox_fault_handler_cb dbox_cb, void *data)
998 struct fault_info *info;
999 info = malloc(sizeof(*info));
1001 ErrPrint("Heap: %s\n", strerror(errno));
1002 return DBOX_STATUS_ERROR_OUT_OF_MEMORY;
1005 info->handler = dbox_cb;
1006 info->user_data = data;
1007 info->is_deleted = 0;
1009 s_info.fault_list = dlist_append(s_info.fault_list, info);
1010 return DBOX_STATUS_ERROR_NONE;
1013 void *dbox_remove_fault_handler(dynamicbox_fault_handler_cb dbox_cb)
1015 struct fault_info *info;
1018 dlist_foreach(s_info.fault_list, l, info) {
1019 if (info->handler == dbox_cb) {
1022 data = info->user_data;
1024 if (s_info.fault_state == INFO_STATE_CALLBACK_IN_PROCESSING) {
1025 info->is_deleted = 1;
1027 s_info.fault_list = dlist_remove(s_info.fault_list, l);
1038 struct cb_info *dbox_create_cb_info(dynamicbox_ret_cb cb, void *data)
1040 struct cb_info *info;
1042 info = malloc(sizeof(*info));
1044 ErrPrint("Heap: %s\n", strerror(errno));
1053 void dbox_destroy_cb_info(struct cb_info *info)