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);
320 period = ecore_timer_interval_get(item->timer);
321 pending = ecore_timer_pending_get(item->timer);
322 delay = util_time_delay_for_compensation(period) - pending;
323 ecore_timer_delay(item->timer, delay);
324 DbgPrint("Compensated: %lf\n", delay);
326 if (item->sleep_at == 0.0f)
329 sleep_time = util_timestamp() - item->sleep_at;
330 if (sleep_time > pending) {
331 DbgPrint("Update time elapsed\n");
332 (void)updator_cb(item);
335 item->sleep_at = 0.0f;
338 static inline void timer_freeze(struct item *item)
341 ecore_timer_freeze(item->timer);
343 if (ecore_timer_interval_get(item->timer) <= 1.0f)
346 gettimeofday(&tv, NULL);
347 item->sleep_at = (double)tv.tv_sec + (double)tv.tv_usec / 1000000.0f;
350 static inline void update_monitor_cnt(struct item *item)
355 now = util_timestamp();
356 interval = now - item->update_interval;
360 * If the content update is processed in too short time,
361 * don't increase the monitor counter, instead of it
362 * set the heavy updating flag.
363 * And handling this heavy updating from the
364 * file update callback.
366 if (interval >= MINIMUM_UPDATE_INTERVAL)
369 item->heavy_updating = 1;
371 item->update_interval = now;
374 static inline Eina_List *find_item(struct instance *inst)
379 EINA_LIST_FOREACH(s_info.item_list, l, item) {
380 if (item->inst == inst)
387 static inline int output_handler(struct item *item)
392 if (item->monitor_cnt < 0 || item->heavy_updating) {
393 if (!item->heavy_updating) {
394 WarnPrint("%s has invalid monitor_cnt\n", item->inst->id);
397 item->heavy_updating = 0; /* Reset flag */
400 item->monitor_cnt = 0;
403 if (item->monitor_cnt == 0) {
405 fault_unmark_call(item->inst->item->pkgname, item->inst->id, "update,crashed", NO_ALARM);
408 ecore_timer_del(item->monitor);
409 item->monitor = NULL;
412 if (s_info.update == item)
413 s_info.update = NULL;
415 if (item->deleteme) {
416 provider_send_deleted(item->inst->item->pkgname, item->inst->id);
417 (void)so_destroy(item->inst);
426 static int desc_updated_cb(const char *filename, void *data, int over)
431 WarnPrint("Event Q overflow\n");
435 DbgPrint("DESC %s is updated\n", filename);
436 provider_send_desc_updated(item->inst->item->pkgname, item->inst->id, filename);
440 static int file_updated_cb(const char *filename, void *data, int over)
451 WarnPrint("Event Q overflow\n");
455 ret = util_get_filesize(filename);
457 ErrPrint("Content is updated. but invalid. ret = %d\n", ret);
459 (void)so_get_output_info(item->inst, &w, &h, &priority, &content, &title);
460 provider_send_updated(item->inst->item->pkgname, item->inst->id,
461 item->inst->w, item->inst->h, item->inst->priority, content, title);
463 return output_handler(item);
466 static inline int clear_from_pd_open_pending_list(struct item *item)
471 EINA_LIST_FOREACH(s_info.pd_open_pending_list, l, tmp) {
475 s_info.pd_open_pending_list = eina_list_remove_list(s_info.pd_open_pending_list, l);
476 if (!s_info.pd_open_pending_list)
477 deactivate_pd_open_pending_consumer();
484 static inline int clear_from_pending_list(struct item *item)
489 EINA_LIST_FOREACH(s_info.pending_list, l, tmp) {
493 s_info.pending_list = eina_list_remove_list(s_info.pending_list, l);
494 if (!s_info.pending_list)
495 deactivate_pending_consumer();
502 static Eina_Bool update_timeout_cb(void *data)
508 DbgPrint("UPDATE TIMEOUT ========> %s - %s\n", item->inst->item->pkgname, item->inst->id);
510 if (s_info.update != item)
511 ErrPrint("Updating item is not matched\n");
513 fault_unmark_call(item->inst->item->pkgname, item->inst->id, "update,crashed", NO_ALARM);
514 fault_mark_call(item->inst->item->pkgname, item->inst->id, "update,timeout", NO_ALARM, DEFAULT_LIFE_TIMER);
515 s_info.update = NULL;
518 return ECORE_CALLBACK_CANCEL;
521 static Eina_Bool updator_cb(void *data)
528 if (item->monitor) {/*!< If this item is already in update process */
529 return ECORE_CALLBACK_RENEW;
532 ret = so_is_updated(item->inst);
534 if (so_need_to_destroy(item->inst) == NEED_TO_DESTROY) {
535 provider_send_deleted(item->inst->item->pkgname, item->inst->id);
536 lb_destroy(item->inst->item->pkgname, item->inst->id);
538 ecore_timer_del(item->timer);
540 return ECORE_CALLBACK_CANCEL;
543 return ECORE_CALLBACK_RENEW;
546 if (s_info.update || pd_is_opened(item->inst->item->pkgname) < 0) {
547 DbgPrint("%s is busy\n", s_info.update ? s_info.update->inst->id : item->inst->id);
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 int livebox_request_update_by_id(const char *filename)
699 EINA_LIST_FOREACH(s_info.item_list, l, item) {
700 if (!strcmp(item->inst->id, filename)) {
701 return append_pending_list(item);
708 HAPI int lb_open_pd(const char *pkgname)
713 EINA_LIST_FOREACH(s_info.pd_list, l, tmp) {
714 if (!strcmp(pkgname, tmp))
718 tmp = strdup(pkgname);
720 ErrPrint("Heap: %s\n", strerror(errno));
725 pending_timer_freeze();
727 s_info.pd_list = eina_list_append(s_info.pd_list, tmp);
730 * Find all instances from the pending list.
731 * Move them to pd_open_pending_timer
733 migrate_to_pd_open_pending_list(pkgname);
737 HAPI int lb_close_pd(const char *pkgname)
743 EINA_LIST_FOREACH_SAFE(s_info.pd_list, l, n, tmp) {
744 if (strcmp(tmp, pkgname))
747 s_info.pd_list = eina_list_remove(s_info.pd_list, tmp);
751 pending_timer_thaw();
754 * Move all items in pd_open_pending_list
757 migrate_to_pending_list(pkgname);
764 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)
766 struct instance *inst;
776 inst = so_find_instance(pkgname, id);
778 DbgPrint("Instance is already exists [%s - %s] content[%s], cluster[%s], category[%s], abi[%s]\n", pkgname, id, content_info, cluster, category, abi);
782 if (!skip_need_to_create) {
783 ret = so_create_needed(pkgname, cluster, category, abi);
784 if (ret != NEED_TO_CREATE)
790 item = malloc(sizeof(*item));
792 ErrPrint("Heap: %s (%s - %s, content[%s], cluster[%s], category[%s], abi[%s])\n", strerror(errno), pkgname, id, content_info, cluster, category, abi);
796 item->monitor = NULL;
797 item->monitor_cnt = 0;
799 item->update_interval = 0.0f;
800 item->heavy_updating = 0;
802 item->sleep_at = 0.0f;
804 create_ret = so_create(pkgname, id, content_info, timeout, has_livebox_script, cluster, category, abi, &inst);
805 if (create_ret < 0) {
816 if (period > 0.0f && !s_info.secured) {
817 item->timer = util_timer_add(period, updator_cb, item);
819 ErrPrint("Failed to add timer (%s - %s, content[%s], cluster[%s], category[%s], abi[%s]\n", pkgname, id, content_info, cluster, category, abi);
828 DbgPrint("Local update timer is disabled: %lf (%d)\n", period, s_info.secured);
832 ret = update_monitor_add(item);
836 ecore_timer_del(item->timer);
841 s_info.item_list = eina_list_append(s_info.item_list, item);
843 if (create_ret & NEED_TO_SCHEDULE) {
844 DbgPrint("%s Returns NEED_TO_SCHEDULE\n", pkgname);
845 (void)append_pending_list(item);
848 if (create_ret & OUTPUT_UPDATED) {
852 update_monitor_cnt(item);
855 * To send a output info, get the info forcely.
856 * but the output file monitor will do this again
858 * This function will set the tmp_content and tmp_title
859 * even if it has no updates on the content, title,
860 * it will set them to NULL.
862 (void)so_get_output_info(inst, w, h, priority, &tmp_content, &tmp_title);
866 * These two values will be released by the provider library.
869 *out_content = strdup(tmp_content);
871 ErrPrint("Heap: %s\n", strerror(errno));
875 *out_title = strdup(tmp_title);
877 ErrPrint("Heap: %s\n", strerror(errno));
883 *priority = inst->priority;
884 return need_to_create;
887 HAPI int lb_destroy(const char *pkgname, const char *id)
890 struct instance *inst;
893 inst = so_find_instance(pkgname, id);
895 ErrPrint("Instance %s - %s is not created\n", pkgname, id);
901 ErrPrint("Instance is not found (%s - %s)\n", pkgname, id);
905 item = eina_list_data_get(l);
906 s_info.item_list = eina_list_remove_list(s_info.item_list, l);
908 if (s_info.update == item)
909 s_info.update = NULL;
912 clear_from_pd_open_pending_list(item);
913 clear_from_pending_list(item);
914 ecore_timer_del(item->timer);
920 update_monitor_del(item);
923 if (!item->monitor) {
925 (void)so_destroy(inst);
931 HAPI int lb_resize(const char *pkgname, const char *id, int w, int h)
934 struct instance *inst;
938 inst = so_find_instance(pkgname, id);
940 ErrPrint("Instance %s - %s is not created (%dx%d)\n", pkgname, id, w, h);
946 ErrPrint("Instance is not found (%s - %s, %dx%d)\n", pkgname, id, w, h);
950 item = eina_list_data_get(l);
952 ret = so_resize(inst, w, h);
956 if (ret & NEED_TO_SCHEDULE) {
957 DbgPrint("%s Returns NEED_TO_SCHEDULE\n", pkgname);
958 (void)append_pending_list(item);
961 if (ret & OUTPUT_UPDATED)
962 update_monitor_cnt(item);
967 HAPI char *lb_pinup(const char *pkgname, const char *id, int pinup)
969 struct instance *inst;
972 inst = so_find_instance(pkgname, id);
974 ErrPrint("Instance %s - %s is not found (pinup[%d])\n", pkgname, id, pinup);
978 ret = so_pinup(inst, pinup);
982 HAPI int lb_set_period(const char *pkgname, const char *id, double period)
985 struct instance *inst;
988 inst = so_find_instance(pkgname, id);
990 ErrPrint("Instance %s - %s is not found (period[%lf])\n", pkgname, id, period);
996 ErrPrint("Instance is not found (%s - %s, period[%lf])\n", pkgname, id, period);
1000 item = eina_list_data_get(l);
1002 if (period <= 0.0f) {
1004 ecore_timer_del(item->timer);
1009 util_timer_interval_set(item->timer, period);
1010 } else if (!s_info.secured) {
1011 item->timer = util_timer_add(period, updator_cb, item);
1013 ErrPrint("Failed to add timer (%s - %s)\n", pkgname, id);
1025 HAPI int lb_clicked(const char *pkgname, const char *id, const char *event, double timestamp, double x, double y)
1028 struct instance *inst;
1032 inst = so_find_instance(pkgname, id);
1034 ErrPrint("Instance %s - %s is not exists (event[%s])\n", pkgname, id, event);
1038 l = find_item(inst);
1040 ErrPrint("Instance is not found (%s - %s, event[%s])\n", pkgname, id, event);
1044 item = eina_list_data_get(l);
1046 ret = so_clicked(inst, event, timestamp, x, y);
1050 if (ret & NEED_TO_SCHEDULE) {
1051 DbgPrint("%s Returns NEED_TO_SCHEDULE\n", pkgname);
1052 (void)append_pending_list(item);
1055 if (ret & OUTPUT_UPDATED)
1056 update_monitor_cnt(item);
1061 HAPI int lb_script_event(const char *pkgname, const char *id, const char *emission, const char *source, struct event_info *event_info)
1064 struct instance *inst;
1068 inst = so_find_instance(pkgname, id);
1070 ErrPrint("Instance %s - %s is not exists (emission[%s], source[%s])\n", pkgname, id, emission, source);
1074 l = find_item(inst);
1076 ErrPrint("Instance is not found (%s - %s, emissino[%s], source[%s])\n", pkgname, id, emission, source);
1080 item = eina_list_data_get(l);
1082 ret = so_script_event(inst, emission, source, event_info);
1086 if (ret & NEED_TO_SCHEDULE) {
1087 DbgPrint("%s Returns NEED_TO_SCHEDULE\n", pkgname);
1088 (void)append_pending_list(item);
1091 if (ret & OUTPUT_UPDATED)
1092 update_monitor_cnt(item);
1097 HAPI int lb_is_pinned_up(const char *pkgname, const char *id)
1100 struct instance *inst;
1103 inst = so_find_instance(pkgname, id);
1105 ErrPrint("Instance %s - %s is not created\n", pkgname, id);
1109 l = find_item(inst);
1111 ErrPrint("Instance is not found(%s - %s)\n", pkgname, id);
1115 item = eina_list_data_get(l);
1117 ErrPrint("Invalid item(%s - %s)\n", pkgname, id);
1123 * Maybe this is not neccessary for this operation
1125 return so_is_pinned_up(inst);
1128 HAPI int lb_change_group(const char *pkgname, const char *id, const char *cluster, const char *category)
1131 struct instance *inst;
1135 inst = so_find_instance(pkgname, id);
1137 ErrPrint("Instance %s - %s is not created (cluster[%s], category[%s])\n", pkgname, id, cluster, category);
1141 l = find_item(inst);
1143 ErrPrint("Instance is not found(%s - %s, cluster[%s], category[%s])\n", pkgname, id, cluster, category);
1147 item = eina_list_data_get(l);
1149 ret = so_change_group(inst, cluster, category);
1153 if (ret & NEED_TO_SCHEDULE) {
1154 DbgPrint("%s Returns NEED_TO_SCHEDULE\n", pkgname);
1155 (void)append_pending_list(item);
1158 if (ret & OUTPUT_UPDATED)
1159 update_monitor_cnt(item);
1164 static inline int lb_sys_event(struct instance *inst, struct item *item, int event)
1168 ret = so_sys_event(inst, event);
1172 if (ret & NEED_TO_SCHEDULE)
1173 (void)append_pending_list(item);
1175 if (ret & OUTPUT_UPDATED)
1176 update_monitor_cnt(item);
1181 HAPI int lb_system_event(const char *pkgname, const char *id, int event)
1184 struct instance *inst;
1187 inst = so_find_instance(pkgname, id);
1189 ErrPrint("instance %s - %s is not created\n");
1193 l = find_item(inst);
1195 ErrPrint("Instance is not found(%s - %s)\n", pkgname, id);
1199 item = eina_list_data_get(l);
1200 return lb_sys_event(inst, item, event);
1203 HAPI int lb_update(const char *pkgname, const char *id)
1206 struct instance *inst;
1209 inst = so_find_instance(pkgname, id);
1211 ErrPrint("Instance %s - %s is not created\n", pkgname, id);
1215 l = find_item(inst);
1217 ErrPrint("Instance is not found(%s - %s)\n", pkgname, id);
1221 item = eina_list_data_get(l);
1222 (void)append_pending_list(item);
1226 HAPI int lb_update_all(const char *pkgname, const char *cluster, const char *category)
1232 DbgPrint("Update content for %s\n", pkgname ? pkgname : "(all)");
1233 EINA_LIST_FOREACH_SAFE(s_info.item_list, l, n, item) {
1237 if (cluster && strcasecmp(item->inst->cluster, cluster))
1240 if (category && strcasecmp(item->inst->category, category))
1243 if (pkgname && strlen(pkgname)) {
1244 if (!strcmp(item->inst->item->pkgname, pkgname)) {
1245 (void)append_pending_list(item);
1248 (void)append_pending_list(item);
1255 HAPI int lb_system_event_all(int event)
1261 EINA_LIST_FOREACH_SAFE(s_info.item_list, l, n, item) {
1265 DbgPrint("System event for %s (%d)\n", item->inst->id, event);
1266 lb_sys_event(item->inst, item, event);
1272 HAPI void lb_pause_all(void)
1279 pending_timer_freeze();
1281 EINA_LIST_FOREACH(s_info.item_list, l, item) {
1282 if (item->deleteme) {
1283 DbgPrint("Instance %s skip timer pause (deleteme)\n", item->inst->item->pkgname);
1287 if (item->is_paused) {
1288 DbgPrint("Instance %s is already paused\n", item->inst->id);
1293 DbgPrint("Instance %s freeze timer\n", item->inst->item->pkgname);
1296 DbgPrint("Instance %s has no timer\n", item->inst->item->pkgname);
1299 lb_sys_event(item->inst, item, LB_SYS_EVENT_PAUSED);
1303 HAPI void lb_resume_all(void)
1310 pending_timer_thaw();
1312 EINA_LIST_FOREACH(s_info.item_list, l, item) {
1313 if (item->deleteme) {
1314 DbgPrint("Instance %s skip timer resume (deleteme)\n", item->inst->item->pkgname);
1318 if (item->is_paused) {
1319 DbgPrint("Instance %s is still paused\n", item->inst->id);
1324 DbgPrint("Instance %s resume timer\n", item->inst->item->pkgname);
1328 lb_sys_event(item->inst, item, LB_SYS_EVENT_RESUMED);
1332 HAPI int lb_pause(const char *pkgname, const char *id)
1334 struct instance *inst;
1338 inst = so_find_instance(pkgname, id);
1342 l = find_item(inst);
1344 ErrPrint("Instance is not found (%s - %s)\n", pkgname, id);
1348 item = eina_list_data_get(l);
1352 if (item->deleteme) {
1353 DbgPrint("Instance %s will be deleted (%s)\n", item->inst->item->pkgname, item->inst->id);
1357 item->is_paused = 1;
1359 if (s_info.paused) {
1360 DbgPrint("Already paused: %s\n", item->inst->id);
1367 lb_sys_event(inst, item, LB_SYS_EVENT_PAUSED);
1372 HAPI int lb_resume(const char *pkgname, const char *id)
1374 struct instance *inst;
1378 inst = so_find_instance(pkgname, id);
1382 l = find_item(inst);
1384 ErrPrint("Instance is not found (%s - %s)\n", pkgname, id);
1388 item = eina_list_data_get(l);
1392 if (item->deleteme) {
1393 DbgPrint("Instance %s will be deleted (%s)\n", item->inst->item->pkgname, item->inst->id);
1397 item->is_paused = 0;
1399 if (s_info.paused) {
1400 DbgPrint("Instance %s is still paused\n", item->inst->id);
1407 lb_sys_event(inst, item, LB_SYS_EVENT_RESUMED);
1411 HAPI void lb_turn_secured_on(void)