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.
18 #include <stdlib.h> /* exit */
28 #include "critical_log.h"
31 #include "so_handler.h"
33 #include "update_monitor.h"
41 struct instance *inst;
45 double update_interval;
46 int heavy_updating; /* Only for debugging message */
47 int is_paused; /* 1 is paused, 0 is resumed */
54 Eina_List *pending_list;
55 Ecore_Timer *pending_timer;
56 Eina_List *pd_open_pending_list;
57 Ecore_Timer *pd_open_pending_timer;
61 int pending_timer_freezed;
66 .pending_timer = NULL,
67 .pd_open_pending_list = NULL,
68 .pd_open_pending_timer = NULL,
72 .pending_timer_freezed = 0,
75 static Eina_Bool updator_cb(void *data);
77 static void pending_timer_freeze(void)
79 DbgPrint("Freezed Count: %d\n", s_info.pending_timer_freezed);
80 if (s_info.pending_timer && !s_info.pending_timer_freezed) {
81 DbgPrint("Freeze the pending timer\n");
82 ecore_timer_freeze(s_info.pending_timer);
85 s_info.pending_timer_freezed++;
88 static void pending_timer_thaw(void)
90 DbgPrint("Freezed Count: %d\n", s_info.pending_timer_freezed);
91 if (!s_info.pending_timer_freezed)
94 s_info.pending_timer_freezed--;
95 if (s_info.pending_timer && !s_info.pending_timer_freezed) {
96 DbgPrint("Thaw the pending timer\n");
97 ecore_timer_thaw(s_info.pending_timer);
102 * -1 : PD is opened, but not mine
103 * 0 : PD is not opened
104 * 1 : my PD is opened
106 static inline int pd_is_opened(const char *pkgname)
113 EINA_LIST_FOREACH(s_info.pd_list, l, tmp) {
114 if (pkgname && !strcmp(pkgname, tmp))
120 return i > 0 ? -1 : 0;
123 static Eina_Bool pd_open_pended_cmd_consumer_cb(void *data)
127 item = eina_list_nth(s_info.pd_open_pending_list, 0);
132 return ECORE_CALLBACK_RENEW;
134 s_info.pd_open_pending_list = eina_list_remove(s_info.pd_open_pending_list, item);
135 DbgPrint("Consuming pended item: %s\n", item->inst->id);
138 * To prevent from checking the is_updated function
140 (void)updator_cb(item);
141 if (s_info.pd_open_pending_list)
142 return ECORE_CALLBACK_RENEW;
145 s_info.pd_open_pending_timer = NULL;
146 DbgPrint("open pd pending list exhausted\n");
147 return ECORE_CALLBACK_CANCEL;
150 static Eina_Bool pended_cmd_consumer_cb(void *data)
154 item = eina_list_nth(s_info.pending_list, 0);
158 if (s_info.update || pd_is_opened(item->inst->item->pkgname) < 0)
159 return ECORE_CALLBACK_RENEW;
161 s_info.pending_list = eina_list_remove(s_info.pending_list, item);
162 DbgPrint("Consuming pended item: %s\n", item->inst->id);
165 * To prevent from checking the is_updated function
167 (void)updator_cb(item);
168 if (s_info.pending_list)
169 return ECORE_CALLBACK_RENEW;
172 s_info.pending_timer = NULL;
173 s_info.pending_timer_freezed = 0;
174 DbgPrint("pending list exhausted\n");
175 return ECORE_CALLBACK_CANCEL;
178 static inline __attribute__((always_inline)) int activate_pending_consumer(void)
180 if (s_info.pending_timer)
183 s_info.pending_timer = ecore_timer_add(0.000001f, pended_cmd_consumer_cb, NULL);
184 if (!s_info.pending_timer) {
185 ErrPrint("Failed to add a new pended command consumer\n");
190 * Do not increase the freezed counter.
191 * Just freeze the timer.
193 if (s_info.pending_timer_freezed) {
194 DbgPrint("Pending timer created and freezed\n");
195 ecore_timer_freeze(s_info.pending_timer);
201 static inline void deactivate_pending_consumer(void)
203 if (!s_info.pending_timer)
206 ecore_timer_del(s_info.pending_timer);
207 s_info.pending_timer = NULL;
208 s_info.pending_timer_freezed = 0;
209 DbgPrint("Clear the pending timer\n");
212 static inline void deactivate_pd_open_pending_consumer(void)
214 if (!s_info.pd_open_pending_timer)
217 ecore_timer_del(s_info.pd_open_pending_timer);
218 s_info.pd_open_pending_timer = NULL;
219 DbgPrint("Clear the open_pd_pending timer\n");
222 static inline int __attribute__((always_inline)) activate_pd_open_pending_consumer(void)
224 if (s_info.pd_open_pending_timer)
227 s_info.pd_open_pending_timer = ecore_timer_add(0.000001f, pd_open_pended_cmd_consumer_cb, NULL);
228 if (!s_info.pd_open_pending_timer) {
229 ErrPrint("Failed to add a new pended command consumer\n");
236 static inline void migrate_to_pd_open_pending_list(const char *pkgname)
243 EINA_LIST_FOREACH_SAFE(s_info.pending_list, l, n, item) {
244 if (strcmp(pkgname, item->inst->item->pkgname))
247 s_info.pending_list = eina_list_remove(s_info.pending_list, item);
248 s_info.pd_open_pending_list = eina_list_append(s_info.pd_open_pending_list, item);
252 if (s_info.pd_open_pending_list)
253 activate_pd_open_pending_consumer();
255 if (!s_info.pending_list)
256 deactivate_pending_consumer();
258 DbgPrint("%d items are migrated\n", cnt);
261 static inline void migrate_to_pending_list(const char *pkgname)
268 EINA_LIST_FOREACH_SAFE(s_info.pd_open_pending_list, l, n, item) {
269 if (strcmp(pkgname, item->inst->item->pkgname))
272 s_info.pd_open_pending_list = eina_list_remove(s_info.pd_open_pending_list, item);
273 s_info.pending_list = eina_list_append(s_info.pending_list, item);
277 if (s_info.pending_list)
278 activate_pending_consumer();
280 if (!s_info.pd_open_pending_list)
281 deactivate_pd_open_pending_consumer();
283 DbgPrint("%d items are migrated\n", cnt);
286 static inline int append_pending_list(struct item *item)
288 if (pd_is_opened(item->inst->item->pkgname) == 1) {
289 if (eina_list_data_find(s_info.pd_open_pending_list, item) == item) {
290 DbgPrint("Already pended - %s\n", item->inst->item->pkgname);
294 if (activate_pd_open_pending_consumer() < 0)
297 s_info.pd_open_pending_list = eina_list_append(s_info.pd_open_pending_list, item);
299 if (eina_list_data_find(s_info.pending_list, item) == item) {
300 DbgPrint("Already pended - %s\n", item->inst->item->pkgname);
304 if (activate_pending_consumer() < 0)
307 s_info.pending_list = eina_list_append(s_info.pending_list, item);
312 static inline void timer_thaw(struct item *item)
319 ecore_timer_thaw(item->timer);
321 if (item->sleep_at == 0.0f)
324 pending = ecore_timer_pending_get(item->timer);
326 if (gettimeofday(&tv, NULL) < 0) {
327 ErrPrint("Failed to get timeofday: %s\n", strerror(errno));
330 sleep_time = ((double)tv.tv_sec + (double)tv.tv_usec / 1000000.0f) - item->sleep_at;
331 compensate = 60.0f - ((double)(tv.tv_sec % 60) + ((double)tv.tv_usec / 1000000.0f));
333 ecore_timer_delay(item->timer, compensate - pending);
334 DbgPrint("Compensate timer: %lf\n", compensate - pending);
336 if (sleep_time > pending) {
337 DbgPrint("Append pending list to update content\n");
338 (void)append_pending_list(item);
341 item->sleep_at = 0.0f;
344 static inline void timer_freeze(struct item *item)
347 ecore_timer_freeze(item->timer);
349 if (ecore_timer_interval_get(item->timer) <= 1.0f)
352 gettimeofday(&tv, NULL);
353 item->sleep_at = (double)tv.tv_sec + (double)tv.tv_usec / 1000000.0f;
356 static inline void update_monitor_cnt(struct item *item)
361 now = util_timestamp();
362 interval = now - item->update_interval;
366 * If the content update is processed in too short time,
367 * don't increase the monitor counter, instead of it
368 * set the heavy updating flag.
369 * And handling this heavy updating from the
370 * file update callback.
372 if (interval >= MINIMUM_UPDATE_INTERVAL)
375 item->heavy_updating = 1;
377 item->update_interval = now;
380 static inline Eina_List *find_item(struct instance *inst)
385 EINA_LIST_FOREACH(s_info.item_list, l, item) {
386 if (item->inst == inst)
393 static inline int output_handler(struct item *item)
398 if (item->monitor_cnt < 0 || item->heavy_updating) {
399 if (!item->heavy_updating) {
400 WarnPrint("%s has invalid monitor_cnt\n", item->inst->id);
403 item->heavy_updating = 0; /* Reset flag */
406 item->monitor_cnt = 0;
409 if (item->monitor_cnt == 0) {
411 fault_unmark_call(item->inst->item->pkgname, item->inst->id, "update,crashed", NO_ALARM);
414 ecore_timer_del(item->monitor);
415 item->monitor = NULL;
418 if (s_info.update == item)
419 s_info.update = NULL;
421 if (item->deleteme) {
422 provider_send_deleted(item->inst->item->pkgname, item->inst->id);
423 (void)so_destroy(item->inst);
432 static int desc_updated_cb(const char *filename, void *data, int over)
437 WarnPrint("Event Q overflow\n");
441 DbgPrint("DESC %s is updated\n", filename);
442 provider_send_desc_updated(item->inst->item->pkgname, item->inst->id, filename);
446 static int file_updated_cb(const char *filename, void *data, int over)
456 WarnPrint("Event Q overflow\n");
460 (void)so_get_output_info(item->inst, &w, &h, &priority, &content, &title);
461 provider_send_updated(item->inst->item->pkgname, item->inst->id,
462 item->inst->w, item->inst->h, item->inst->priority, content, title);
464 return output_handler(item);
467 static inline int clear_from_pd_open_pending_list(struct item *item)
472 EINA_LIST_FOREACH(s_info.pd_open_pending_list, l, tmp) {
476 s_info.pd_open_pending_list = eina_list_remove_list(s_info.pd_open_pending_list, l);
477 if (!s_info.pd_open_pending_list)
478 deactivate_pd_open_pending_consumer();
485 static inline int clear_from_pending_list(struct item *item)
490 EINA_LIST_FOREACH(s_info.pending_list, l, tmp) {
494 s_info.pending_list = eina_list_remove_list(s_info.pending_list, l);
495 if (!s_info.pending_list)
496 deactivate_pending_consumer();
503 static Eina_Bool update_timeout_cb(void *data)
509 DbgPrint("UPDATE TIMEOUT ========> %s - %s\n", item->inst->item->pkgname, item->inst->id);
511 if (s_info.update != item)
512 ErrPrint("Updating item is not matched\n");
514 fault_unmark_call(item->inst->item->pkgname, item->inst->id, "update,crashed", NO_ALARM);
515 fault_mark_call(item->inst->item->pkgname, item->inst->id, "update,timeout", NO_ALARM, DEFAULT_LIFE_TIMER);
516 s_info.update = NULL;
519 return ECORE_CALLBACK_CANCEL;
522 static Eina_Bool updator_cb(void *data)
529 if (item->monitor) {/*!< If this item is already in update process */
530 return ECORE_CALLBACK_RENEW;
533 ret = so_is_updated(item->inst);
535 if (so_need_to_destroy(item->inst) == NEED_TO_DESTROY) {
536 provider_send_deleted(item->inst->item->pkgname, item->inst->id);
537 lb_destroy(item->inst->item->pkgname, item->inst->id);
539 ecore_timer_del(item->timer);
541 return ECORE_CALLBACK_CANCEL;
544 return ECORE_CALLBACK_RENEW;
547 if (s_info.update || pd_is_opened(item->inst->item->pkgname) < 0) {
548 (void)append_pending_list(item);
549 return ECORE_CALLBACK_RENEW;
552 item->monitor = ecore_timer_add(item->inst->item->timeout, update_timeout_cb, item);
553 if (!item->monitor) {
554 ErrPrint("Failed to add update monitor %s(%s):%d\n",
555 item->inst->item->pkgname, item->inst->id, item->inst->item->timeout);
556 return ECORE_CALLBACK_RENEW;
561 * Counter of the event monitor is only used for asynchronous content updating,
562 * So reset it to 1 from here because the async updating is started now,
563 * even if it is accumulated by other event function before this.
565 item->monitor_cnt = 1;
567 s_info.update = item;
569 ret = so_update(item->inst);
573 ecore_timer_del(item->monitor);
574 item->monitor = NULL;
575 s_info.update = NULL;
576 return ECORE_CALLBACK_RENEW;
581 * While waiting the Callback function call,
582 * Add this for finding the crash
584 fault_mark_call(item->inst->item->pkgname, item->inst->id, "update,crashed", NO_ALARM, DEFAULT_LIFE_TIMER);
586 if (ret & NEED_TO_SCHEDULE) {
587 (void)append_pending_list(item);
590 if (ret & OUTPUT_UPDATED)
591 update_monitor_cnt(item);
593 return ECORE_CALLBACK_RENEW;
596 static inline void update_monitor_del(struct item *item)
601 update_monitor_del_update_cb(util_uri_to_path(item->inst->id), file_updated_cb);
603 len = strlen(util_uri_to_path(item->inst->id)) + strlen(".desc") + 1;
606 ErrPrint("Heap: %s (%s.desc)\n", strerror(errno), util_uri_to_path(item->inst->id));
610 snprintf(tmp, len, "%s.desc", util_uri_to_path(item->inst->id));
611 update_monitor_del_update_cb(tmp, desc_updated_cb);
615 static inline int add_desc_update_monitor(struct item *item)
620 len = strlen(util_uri_to_path(item->inst->id)) + strlen(".desc") + 1;
621 filename = malloc(len);
623 ErrPrint("Heap: %s (%s.desc)\n", strerror(errno), util_uri_to_path(item->inst->id));
627 snprintf(filename, len, "%s.desc", util_uri_to_path(item->inst->id));
628 DbgPrint("Add DESC monitor: %s\n", filename);
629 return update_monitor_add_update_cb(filename, desc_updated_cb, item);
632 static inline int add_file_update_monitor(struct item *item)
636 filename = strdup(util_uri_to_path(item->inst->id));
638 ErrPrint("Heap: %s (%s)\n", strerror(errno), item->inst->id);
642 return update_monitor_add_update_cb(filename, file_updated_cb, item);
645 static inline int update_monitor_add(struct item *item)
647 add_file_update_monitor(item);
648 add_desc_update_monitor(item);
652 HAPI int lb_init(void)
657 HAPI int lb_fini(void)
663 deactivate_pending_consumer();
664 deactivate_pd_open_pending_consumer();
666 EINA_LIST_FREE(s_info.pd_open_pending_list, item);
667 EINA_LIST_FREE(s_info.pending_list, item);
669 EINA_LIST_FOREACH_SAFE(s_info.item_list, l, n, item) {
670 provider_send_deleted(item->inst->item->pkgname, item->inst->id);
671 lb_destroy(item->inst->item->pkgname, item->inst->id);
679 * Exported API for each liveboxes.
681 const char *livebox_find_pkgname(const char *filename)
686 EINA_LIST_FOREACH(s_info.item_list, l, item) {
687 if (!strcmp(item->inst->id, filename))
688 return item->inst->item->pkgname;
694 HAPI int lb_open_pd(const char *pkgname)
699 EINA_LIST_FOREACH(s_info.pd_list, l, tmp) {
700 if (!strcmp(pkgname, tmp))
704 tmp = strdup(pkgname);
706 ErrPrint("Heap: %s\n", strerror(errno));
711 pending_timer_freeze();
713 s_info.pd_list = eina_list_append(s_info.pd_list, tmp);
716 * Find all instances from the pending list.
717 * Move them to pd_open_pending_timer
719 migrate_to_pd_open_pending_list(pkgname);
723 HAPI int lb_close_pd(const char *pkgname)
729 EINA_LIST_FOREACH_SAFE(s_info.pd_list, l, n, tmp) {
730 if (strcmp(tmp, pkgname))
733 s_info.pd_list = eina_list_remove(s_info.pd_list, tmp);
737 pending_timer_thaw();
740 * Move all items in pd_open_pending_list
743 migrate_to_pending_list(pkgname);
750 HAPI int lb_create(const char *pkgname, const char *id, const char *content_info, int timeout, int has_livebox_script, double period, const char *cluster, const char *category, int *w, int *h, double *priority, int skip_need_to_create, const char *abi, char **out_content, char **out_title)
752 struct instance *inst;
762 inst = so_find_instance(pkgname, id);
764 DbgPrint("Instance is already exists [%s - %s] content[%s], cluster[%s], category[%s], abi[%s]\n", pkgname, id, content_info, cluster, category, abi);
768 if (!skip_need_to_create) {
769 ret = so_create_needed(pkgname, cluster, category, abi);
770 if (ret != NEED_TO_CREATE)
776 item = malloc(sizeof(*item));
778 ErrPrint("Heap: %s (%s - %s, content[%s], cluster[%s], category[%s], abi[%s])\n", strerror(errno), pkgname, id, content_info, cluster, category, abi);
782 item->monitor = NULL;
783 item->monitor_cnt = 0;
785 item->update_interval = 0.0f;
786 item->heavy_updating = 0;
788 item->sleep_at = 0.0f;
790 create_ret = so_create(pkgname, id, content_info, timeout, has_livebox_script, cluster, category, abi, &inst);
791 if (create_ret < 0) {
802 if (period > 0.0f && !s_info.secured) {
803 item->timer = util_timer_add(period, updator_cb, item);
805 ErrPrint("Failed to add timer (%s - %s, content[%s], cluster[%s], category[%s], abi[%s]\n", pkgname, id, content_info, cluster, category, abi);
814 DbgPrint("Local update timer is disabled: %lf (%d)\n", period, s_info.secured);
818 ret = update_monitor_add(item);
822 ecore_timer_del(item->timer);
827 s_info.item_list = eina_list_append(s_info.item_list, item);
829 if (create_ret & NEED_TO_SCHEDULE) {
830 DbgPrint("%s Returns NEED_TO_SCHEDULE\n", pkgname);
831 (void)append_pending_list(item);
834 if (create_ret & OUTPUT_UPDATED) {
838 update_monitor_cnt(item);
841 * To send a output info, get the info forcely.
842 * but the output file monitor will do this again
844 * This function will set the tmp_content and tmp_title
845 * even if it has no updates on the content, title,
846 * it will set them to NULL.
848 (void)so_get_output_info(inst, w, h, priority, &tmp_content, &tmp_title);
852 * These two values will be released by the provider library.
855 *out_content = strdup(tmp_content);
857 ErrPrint("Heap: %s\n", strerror(errno));
861 *out_title = strdup(tmp_title);
863 ErrPrint("Heap: %s\n", strerror(errno));
869 *priority = inst->priority;
870 return need_to_create;
873 HAPI int lb_destroy(const char *pkgname, const char *id)
876 struct instance *inst;
880 inst = so_find_instance(pkgname, id);
882 ErrPrint("Instance %s - %s is not created\n", pkgname, id);
888 ErrPrint("Instance is not found (%s - %s)\n", pkgname, id);
892 item = eina_list_data_get(l);
893 s_info.item_list = eina_list_remove_list(s_info.item_list, l);
895 if (s_info.update == item)
896 s_info.update = NULL;
899 clear_from_pd_open_pending_list(item);
900 clear_from_pending_list(item);
901 ecore_timer_del(item->timer);
907 update_monitor_del(item);
910 if (!item->monitor) {
912 ret = so_destroy(inst);
918 HAPI int lb_resize(const char *pkgname, const char *id, int w, int h)
921 struct instance *inst;
925 inst = so_find_instance(pkgname, id);
927 ErrPrint("Instance %s - %s is not created (%dx%d)\n", pkgname, id, w, h);
933 ErrPrint("Instance is not found (%s - %s, %dx%d)\n", pkgname, id, w, h);
937 item = eina_list_data_get(l);
939 ret = so_resize(inst, w, h);
943 if (ret & NEED_TO_SCHEDULE) {
944 DbgPrint("%s Returns NEED_TO_SCHEDULE\n", pkgname);
945 (void)append_pending_list(item);
948 if (ret & OUTPUT_UPDATED)
949 update_monitor_cnt(item);
954 HAPI char *lb_pinup(const char *pkgname, const char *id, int pinup)
956 struct instance *inst;
959 inst = so_find_instance(pkgname, id);
961 ErrPrint("Instance %s - %s is not found (pinup[%d])\n", pkgname, id, pinup);
965 ret = so_pinup(inst, pinup);
969 HAPI int lb_set_period(const char *pkgname, const char *id, double period)
972 struct instance *inst;
975 inst = so_find_instance(pkgname, id);
977 ErrPrint("Instance %s - %s is not found (period[%lf])\n", pkgname, id, period);
983 ErrPrint("Instance is not found (%s - %s, period[%lf])\n", pkgname, id, period);
987 item = eina_list_data_get(l);
989 if (period <= 0.0f) {
991 ecore_timer_del(item->timer);
996 util_timer_interval_set(item->timer, period);
997 } else if (!s_info.secured) {
998 item->timer = util_timer_add(period, updator_cb, item);
1000 ErrPrint("Failed to add timer (%s - %s)\n", pkgname, id);
1012 HAPI int lb_clicked(const char *pkgname, const char *id, const char *event, double timestamp, double x, double y)
1015 struct instance *inst;
1019 inst = so_find_instance(pkgname, id);
1021 ErrPrint("Instance %s - %s is not exists (event[%s])\n", pkgname, id, event);
1025 l = find_item(inst);
1027 ErrPrint("Instance is not found (%s - %s, event[%s])\n", pkgname, id, event);
1031 item = eina_list_data_get(l);
1033 ret = so_clicked(inst, event, timestamp, x, y);
1037 if (ret & NEED_TO_SCHEDULE) {
1038 DbgPrint("%s Returns NEED_TO_SCHEDULE\n", pkgname);
1039 (void)append_pending_list(item);
1042 if (ret & OUTPUT_UPDATED)
1043 update_monitor_cnt(item);
1048 HAPI int lb_script_event(const char *pkgname, const char *id, const char *emission, const char *source, struct event_info *event_info)
1051 struct instance *inst;
1055 inst = so_find_instance(pkgname, id);
1057 ErrPrint("Instance %s - %s is not exists (emission[%s], source[%s])\n", pkgname, id, emission, source);
1061 l = find_item(inst);
1063 ErrPrint("Instance is not found (%s - %s, emissino[%s], source[%s])\n", pkgname, id, emission, source);
1067 item = eina_list_data_get(l);
1069 ret = so_script_event(inst, emission, source, event_info);
1073 if (ret & NEED_TO_SCHEDULE) {
1074 DbgPrint("%s Returns NEED_TO_SCHEDULE\n", pkgname);
1075 (void)append_pending_list(item);
1078 if (ret & OUTPUT_UPDATED)
1079 update_monitor_cnt(item);
1084 HAPI int lb_is_pinned_up(const char *pkgname, const char *id)
1087 struct instance *inst;
1091 inst = so_find_instance(pkgname, id);
1093 ErrPrint("Instance %s - %s is not created\n", pkgname, id);
1097 l = find_item(inst);
1099 ErrPrint("Instance is not found(%s - %s)\n", pkgname, id);
1103 item = eina_list_data_get(l);
1107 * Maybe this is not neccessary for this operation
1109 ret = so_is_pinned_up(inst);
1113 HAPI int lb_change_group(const char *pkgname, const char *id, const char *cluster, const char *category)
1116 struct instance *inst;
1120 inst = so_find_instance(pkgname, id);
1122 ErrPrint("Instance %s - %s is not created (cluster[%s], category[%s])\n", pkgname, id, cluster, category);
1126 l = find_item(inst);
1128 ErrPrint("Instance is not found(%s - %s, cluster[%s], category[%s])\n", pkgname, id, cluster, category);
1132 item = eina_list_data_get(l);
1134 ret = so_change_group(inst, cluster, category);
1138 if (ret & NEED_TO_SCHEDULE) {
1139 DbgPrint("%s Returns NEED_TO_SCHEDULE\n", pkgname);
1140 (void)append_pending_list(item);
1143 if (ret & OUTPUT_UPDATED)
1144 update_monitor_cnt(item);
1149 static inline int lb_sys_event(struct instance *inst, struct item *item, int event)
1153 ret = so_sys_event(inst, event);
1157 if (ret & NEED_TO_SCHEDULE)
1158 (void)append_pending_list(item);
1160 if (ret & OUTPUT_UPDATED)
1161 update_monitor_cnt(item);
1166 HAPI int lb_system_event(const char *pkgname, const char *id, int event)
1169 struct instance *inst;
1172 inst = so_find_instance(pkgname, id);
1174 ErrPrint("instance %s - %s is not created\n");
1178 l = find_item(inst);
1180 ErrPrint("Instance is not found(%s - %s)\n", pkgname, id);
1184 item = eina_list_data_get(l);
1185 return lb_sys_event(inst, item, event);
1188 HAPI int lb_update(const char *pkgname, const char *id)
1191 struct instance *inst;
1194 inst = so_find_instance(pkgname, id);
1196 ErrPrint("Instance %s - %s is not created\n", pkgname, id);
1200 l = find_item(inst);
1202 ErrPrint("Instance is not found(%s - %s)\n", pkgname, id);
1206 item = eina_list_data_get(l);
1207 (void)append_pending_list(item);
1211 HAPI int lb_update_all(const char *pkgname, const char *cluster, const char *category)
1217 DbgPrint("Update content for %s\n", pkgname ? pkgname : "(all)");
1218 EINA_LIST_FOREACH_SAFE(s_info.item_list, l, n, item) {
1222 if (cluster && strcasecmp(item->inst->cluster, cluster))
1225 if (category && strcasecmp(item->inst->category, category))
1228 if (pkgname && strlen(pkgname)) {
1229 if (!strcmp(item->inst->item->pkgname, pkgname)) {
1230 (void)append_pending_list(item);
1233 (void)append_pending_list(item);
1240 HAPI int lb_system_event_all(int event)
1246 EINA_LIST_FOREACH_SAFE(s_info.item_list, l, n, item) {
1250 DbgPrint("System event for %s (%d)\n", item->inst->id, event);
1251 lb_sys_event(item->inst, item, event);
1257 HAPI void lb_pause_all(void)
1264 pending_timer_freeze();
1266 EINA_LIST_FOREACH(s_info.item_list, l, item) {
1267 if (item->deleteme) {
1268 DbgPrint("Instance %s skip timer pause (deleteme)\n", item->inst->item->pkgname);
1272 if (item->is_paused) {
1273 DbgPrint("Instance %s is already paused\n", item->inst->id);
1278 DbgPrint("Instance %s freeze timer\n", item->inst->item->pkgname);
1281 DbgPrint("Instance %s has no timer\n", item->inst->item->pkgname);
1284 lb_sys_event(item->inst, item, LB_SYS_EVENT_PAUSED);
1288 HAPI void lb_resume_all(void)
1295 pending_timer_thaw();
1297 EINA_LIST_FOREACH(s_info.item_list, l, item) {
1298 if (item->deleteme) {
1299 DbgPrint("Instance %s skip timer resume (deleteme)\n", item->inst->item->pkgname);
1303 if (item->is_paused) {
1304 DbgPrint("Instance %s is still paused\n", item->inst->id);
1309 DbgPrint("Instance %s resume timer\n", item->inst->item->pkgname);
1313 lb_sys_event(item->inst, item, LB_SYS_EVENT_RESUMED);
1317 HAPI int lb_pause(const char *pkgname, const char *id)
1319 struct instance *inst;
1323 inst = so_find_instance(pkgname, id);
1327 l = find_item(inst);
1329 ErrPrint("Instance is not found (%s - %s)\n", pkgname, id);
1333 item = eina_list_data_get(l);
1337 if (item->deleteme) {
1338 DbgPrint("Instance %s will be deleted (%s)\n", item->inst->item->pkgname, item->inst->id);
1342 item->is_paused = 1;
1344 if (s_info.paused) {
1345 DbgPrint("Already paused: %s\n", item->inst->id);
1352 lb_sys_event(inst, item, LB_SYS_EVENT_PAUSED);
1357 HAPI int lb_resume(const char *pkgname, const char *id)
1359 struct instance *inst;
1363 inst = so_find_instance(pkgname, id);
1367 l = find_item(inst);
1369 ErrPrint("Instance is not found (%s - %s)\n", pkgname, id);
1373 item = eina_list_data_get(l);
1377 if (item->deleteme) {
1378 DbgPrint("Instance %s will be deleted (%s)\n", item->inst->item->pkgname, item->inst->id);
1382 item->is_paused = 0;
1384 if (s_info.paused) {
1385 DbgPrint("Instance %s is still paused\n", item->inst->id);
1392 lb_sys_event(inst, item, LB_SYS_EVENT_RESUMED);
1396 HAPI void lb_turn_secured_on(void)