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 (void)append_pending_list(item);
548 return ECORE_CALLBACK_RENEW;
551 item->monitor = ecore_timer_add(item->inst->item->timeout, update_timeout_cb, item);
552 if (!item->monitor) {
553 ErrPrint("Failed to add update monitor %s(%s):%d\n",
554 item->inst->item->pkgname, item->inst->id, item->inst->item->timeout);
555 return ECORE_CALLBACK_RENEW;
560 * Counter of the event monitor is only used for asynchronous content updating,
561 * So reset it to 1 from here because the async updating is started now,
562 * even if it is accumulated by other event function before this.
564 item->monitor_cnt = 1;
566 s_info.update = item;
568 ret = so_update(item->inst);
572 ecore_timer_del(item->monitor);
573 item->monitor = NULL;
574 s_info.update = NULL;
575 return ECORE_CALLBACK_RENEW;
580 * While waiting the Callback function call,
581 * Add this for finding the crash
583 fault_mark_call(item->inst->item->pkgname, item->inst->id, "update,crashed", NO_ALARM, DEFAULT_LIFE_TIMER);
585 if (ret & NEED_TO_SCHEDULE) {
586 (void)append_pending_list(item);
589 if (ret & OUTPUT_UPDATED)
590 update_monitor_cnt(item);
592 return ECORE_CALLBACK_RENEW;
595 static inline void update_monitor_del(struct item *item)
600 update_monitor_del_update_cb(util_uri_to_path(item->inst->id), file_updated_cb);
602 len = strlen(util_uri_to_path(item->inst->id)) + strlen(".desc") + 1;
605 ErrPrint("Heap: %s (%s.desc)\n", strerror(errno), util_uri_to_path(item->inst->id));
609 snprintf(tmp, len, "%s.desc", util_uri_to_path(item->inst->id));
610 update_monitor_del_update_cb(tmp, desc_updated_cb);
614 static inline int add_desc_update_monitor(struct item *item)
619 len = strlen(util_uri_to_path(item->inst->id)) + strlen(".desc") + 1;
620 filename = malloc(len);
622 ErrPrint("Heap: %s (%s.desc)\n", strerror(errno), util_uri_to_path(item->inst->id));
626 snprintf(filename, len, "%s.desc", util_uri_to_path(item->inst->id));
627 DbgPrint("Add DESC monitor: %s\n", filename);
628 return update_monitor_add_update_cb(filename, desc_updated_cb, item);
631 static inline int add_file_update_monitor(struct item *item)
635 filename = strdup(util_uri_to_path(item->inst->id));
637 ErrPrint("Heap: %s (%s)\n", strerror(errno), item->inst->id);
641 return update_monitor_add_update_cb(filename, file_updated_cb, item);
644 static inline int update_monitor_add(struct item *item)
646 add_file_update_monitor(item);
647 add_desc_update_monitor(item);
651 HAPI int lb_init(void)
656 HAPI int lb_fini(void)
662 deactivate_pending_consumer();
663 deactivate_pd_open_pending_consumer();
665 EINA_LIST_FREE(s_info.pd_open_pending_list, item);
666 EINA_LIST_FREE(s_info.pending_list, item);
668 EINA_LIST_FOREACH_SAFE(s_info.item_list, l, n, item) {
669 provider_send_deleted(item->inst->item->pkgname, item->inst->id);
670 lb_destroy(item->inst->item->pkgname, item->inst->id);
678 * Exported API for each liveboxes.
680 const char *livebox_find_pkgname(const char *filename)
685 EINA_LIST_FOREACH(s_info.item_list, l, item) {
686 if (!strcmp(item->inst->id, filename))
687 return item->inst->item->pkgname;
693 int livebox_request_update_by_id(const char *filename)
698 EINA_LIST_FOREACH(s_info.item_list, l, item) {
699 if (!strcmp(item->inst->id, filename)) {
700 return append_pending_list(item);
707 HAPI int lb_open_pd(const char *pkgname)
712 EINA_LIST_FOREACH(s_info.pd_list, l, tmp) {
713 if (!strcmp(pkgname, tmp))
717 tmp = strdup(pkgname);
719 ErrPrint("Heap: %s\n", strerror(errno));
724 pending_timer_freeze();
726 s_info.pd_list = eina_list_append(s_info.pd_list, tmp);
729 * Find all instances from the pending list.
730 * Move them to pd_open_pending_timer
732 migrate_to_pd_open_pending_list(pkgname);
736 HAPI int lb_close_pd(const char *pkgname)
742 EINA_LIST_FOREACH_SAFE(s_info.pd_list, l, n, tmp) {
743 if (strcmp(tmp, pkgname))
746 s_info.pd_list = eina_list_remove(s_info.pd_list, tmp);
750 pending_timer_thaw();
753 * Move all items in pd_open_pending_list
756 migrate_to_pending_list(pkgname);
763 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)
765 struct instance *inst;
775 inst = so_find_instance(pkgname, id);
777 DbgPrint("Instance is already exists [%s - %s] content[%s], cluster[%s], category[%s], abi[%s]\n", pkgname, id, content_info, cluster, category, abi);
781 if (!skip_need_to_create) {
782 ret = so_create_needed(pkgname, cluster, category, abi);
783 if (ret != NEED_TO_CREATE)
789 item = malloc(sizeof(*item));
791 ErrPrint("Heap: %s (%s - %s, content[%s], cluster[%s], category[%s], abi[%s])\n", strerror(errno), pkgname, id, content_info, cluster, category, abi);
795 item->monitor = NULL;
796 item->monitor_cnt = 0;
798 item->update_interval = 0.0f;
799 item->heavy_updating = 0;
801 item->sleep_at = 0.0f;
803 create_ret = so_create(pkgname, id, content_info, timeout, has_livebox_script, cluster, category, abi, &inst);
804 if (create_ret < 0) {
815 if (period > 0.0f && !s_info.secured) {
816 item->timer = util_timer_add(period, updator_cb, item);
818 ErrPrint("Failed to add timer (%s - %s, content[%s], cluster[%s], category[%s], abi[%s]\n", pkgname, id, content_info, cluster, category, abi);
827 DbgPrint("Local update timer is disabled: %lf (%d)\n", period, s_info.secured);
831 ret = update_monitor_add(item);
835 ecore_timer_del(item->timer);
840 s_info.item_list = eina_list_append(s_info.item_list, item);
842 if (create_ret & NEED_TO_SCHEDULE) {
843 DbgPrint("%s Returns NEED_TO_SCHEDULE\n", pkgname);
844 (void)append_pending_list(item);
847 if (create_ret & OUTPUT_UPDATED) {
851 update_monitor_cnt(item);
854 * To send a output info, get the info forcely.
855 * but the output file monitor will do this again
857 * This function will set the tmp_content and tmp_title
858 * even if it has no updates on the content, title,
859 * it will set them to NULL.
861 (void)so_get_output_info(inst, w, h, priority, &tmp_content, &tmp_title);
865 * These two values will be released by the provider library.
868 *out_content = strdup(tmp_content);
870 ErrPrint("Heap: %s\n", strerror(errno));
874 *out_title = strdup(tmp_title);
876 ErrPrint("Heap: %s\n", strerror(errno));
882 *priority = inst->priority;
883 return need_to_create;
886 HAPI int lb_destroy(const char *pkgname, const char *id)
889 struct instance *inst;
892 inst = so_find_instance(pkgname, id);
894 ErrPrint("Instance %s - %s is not created\n", pkgname, id);
900 ErrPrint("Instance is not found (%s - %s)\n", pkgname, id);
904 item = eina_list_data_get(l);
905 s_info.item_list = eina_list_remove_list(s_info.item_list, l);
907 if (s_info.update == item)
908 s_info.update = NULL;
911 clear_from_pd_open_pending_list(item);
912 clear_from_pending_list(item);
913 ecore_timer_del(item->timer);
919 update_monitor_del(item);
922 if (!item->monitor) {
924 (void)so_destroy(inst);
930 HAPI int lb_resize(const char *pkgname, const char *id, int w, int h)
933 struct instance *inst;
937 inst = so_find_instance(pkgname, id);
939 ErrPrint("Instance %s - %s is not created (%dx%d)\n", pkgname, id, w, h);
945 ErrPrint("Instance is not found (%s - %s, %dx%d)\n", pkgname, id, w, h);
949 item = eina_list_data_get(l);
951 ret = so_resize(inst, w, h);
955 if (ret & NEED_TO_SCHEDULE) {
956 DbgPrint("%s Returns NEED_TO_SCHEDULE\n", pkgname);
957 (void)append_pending_list(item);
960 if (ret & OUTPUT_UPDATED)
961 update_monitor_cnt(item);
966 HAPI char *lb_pinup(const char *pkgname, const char *id, int pinup)
968 struct instance *inst;
971 inst = so_find_instance(pkgname, id);
973 ErrPrint("Instance %s - %s is not found (pinup[%d])\n", pkgname, id, pinup);
977 ret = so_pinup(inst, pinup);
981 HAPI int lb_set_period(const char *pkgname, const char *id, double period)
984 struct instance *inst;
987 inst = so_find_instance(pkgname, id);
989 ErrPrint("Instance %s - %s is not found (period[%lf])\n", pkgname, id, period);
995 ErrPrint("Instance is not found (%s - %s, period[%lf])\n", pkgname, id, period);
999 item = eina_list_data_get(l);
1001 if (period <= 0.0f) {
1003 ecore_timer_del(item->timer);
1008 util_timer_interval_set(item->timer, period);
1009 } else if (!s_info.secured) {
1010 item->timer = util_timer_add(period, updator_cb, item);
1012 ErrPrint("Failed to add timer (%s - %s)\n", pkgname, id);
1024 HAPI int lb_clicked(const char *pkgname, const char *id, const char *event, double timestamp, double x, double y)
1027 struct instance *inst;
1031 inst = so_find_instance(pkgname, id);
1033 ErrPrint("Instance %s - %s is not exists (event[%s])\n", pkgname, id, event);
1037 l = find_item(inst);
1039 ErrPrint("Instance is not found (%s - %s, event[%s])\n", pkgname, id, event);
1043 item = eina_list_data_get(l);
1045 ret = so_clicked(inst, event, timestamp, x, y);
1049 if (ret & NEED_TO_SCHEDULE) {
1050 DbgPrint("%s Returns NEED_TO_SCHEDULE\n", pkgname);
1051 (void)append_pending_list(item);
1054 if (ret & OUTPUT_UPDATED)
1055 update_monitor_cnt(item);
1060 HAPI int lb_script_event(const char *pkgname, const char *id, const char *emission, const char *source, struct event_info *event_info)
1063 struct instance *inst;
1067 inst = so_find_instance(pkgname, id);
1069 ErrPrint("Instance %s - %s is not exists (emission[%s], source[%s])\n", pkgname, id, emission, source);
1073 l = find_item(inst);
1075 ErrPrint("Instance is not found (%s - %s, emissino[%s], source[%s])\n", pkgname, id, emission, source);
1079 item = eina_list_data_get(l);
1081 ret = so_script_event(inst, emission, source, event_info);
1085 if (ret & NEED_TO_SCHEDULE) {
1086 DbgPrint("%s Returns NEED_TO_SCHEDULE\n", pkgname);
1087 (void)append_pending_list(item);
1090 if (ret & OUTPUT_UPDATED)
1091 update_monitor_cnt(item);
1096 HAPI int lb_is_pinned_up(const char *pkgname, const char *id)
1099 struct instance *inst;
1102 inst = so_find_instance(pkgname, id);
1104 ErrPrint("Instance %s - %s is not created\n", pkgname, id);
1108 l = find_item(inst);
1110 ErrPrint("Instance is not found(%s - %s)\n", pkgname, id);
1114 item = eina_list_data_get(l);
1116 ErrPrint("Invalid item(%s - %s)\n", pkgname, id);
1122 * Maybe this is not neccessary for this operation
1124 return so_is_pinned_up(inst);
1127 HAPI int lb_change_group(const char *pkgname, const char *id, const char *cluster, const char *category)
1130 struct instance *inst;
1134 inst = so_find_instance(pkgname, id);
1136 ErrPrint("Instance %s - %s is not created (cluster[%s], category[%s])\n", pkgname, id, cluster, category);
1140 l = find_item(inst);
1142 ErrPrint("Instance is not found(%s - %s, cluster[%s], category[%s])\n", pkgname, id, cluster, category);
1146 item = eina_list_data_get(l);
1148 ret = so_change_group(inst, cluster, category);
1152 if (ret & NEED_TO_SCHEDULE) {
1153 DbgPrint("%s Returns NEED_TO_SCHEDULE\n", pkgname);
1154 (void)append_pending_list(item);
1157 if (ret & OUTPUT_UPDATED)
1158 update_monitor_cnt(item);
1163 static inline int lb_sys_event(struct instance *inst, struct item *item, int event)
1167 ret = so_sys_event(inst, event);
1171 if (ret & NEED_TO_SCHEDULE)
1172 (void)append_pending_list(item);
1174 if (ret & OUTPUT_UPDATED)
1175 update_monitor_cnt(item);
1180 HAPI int lb_system_event(const char *pkgname, const char *id, int event)
1183 struct instance *inst;
1186 inst = so_find_instance(pkgname, id);
1188 ErrPrint("instance %s - %s is not created\n");
1192 l = find_item(inst);
1194 ErrPrint("Instance is not found(%s - %s)\n", pkgname, id);
1198 item = eina_list_data_get(l);
1199 return lb_sys_event(inst, item, event);
1202 HAPI int lb_update(const char *pkgname, const char *id)
1205 struct instance *inst;
1208 inst = so_find_instance(pkgname, id);
1210 ErrPrint("Instance %s - %s is not created\n", pkgname, id);
1214 l = find_item(inst);
1216 ErrPrint("Instance is not found(%s - %s)\n", pkgname, id);
1220 item = eina_list_data_get(l);
1221 (void)append_pending_list(item);
1225 HAPI int lb_update_all(const char *pkgname, const char *cluster, const char *category)
1231 DbgPrint("Update content for %s\n", pkgname ? pkgname : "(all)");
1232 EINA_LIST_FOREACH_SAFE(s_info.item_list, l, n, item) {
1236 if (cluster && strcasecmp(item->inst->cluster, cluster))
1239 if (category && strcasecmp(item->inst->category, category))
1242 if (pkgname && strlen(pkgname)) {
1243 if (!strcmp(item->inst->item->pkgname, pkgname)) {
1244 (void)append_pending_list(item);
1247 (void)append_pending_list(item);
1254 HAPI int lb_system_event_all(int event)
1260 EINA_LIST_FOREACH_SAFE(s_info.item_list, l, n, item) {
1264 DbgPrint("System event for %s (%d)\n", item->inst->id, event);
1265 lb_sys_event(item->inst, item, event);
1271 HAPI void lb_pause_all(void)
1278 pending_timer_freeze();
1280 EINA_LIST_FOREACH(s_info.item_list, l, item) {
1281 if (item->deleteme) {
1282 DbgPrint("Instance %s skip timer pause (deleteme)\n", item->inst->item->pkgname);
1286 if (item->is_paused) {
1287 DbgPrint("Instance %s is already paused\n", item->inst->id);
1292 DbgPrint("Instance %s freeze timer\n", item->inst->item->pkgname);
1295 DbgPrint("Instance %s has no timer\n", item->inst->item->pkgname);
1298 lb_sys_event(item->inst, item, LB_SYS_EVENT_PAUSED);
1302 HAPI void lb_resume_all(void)
1309 pending_timer_thaw();
1311 EINA_LIST_FOREACH(s_info.item_list, l, item) {
1312 if (item->deleteme) {
1313 DbgPrint("Instance %s skip timer resume (deleteme)\n", item->inst->item->pkgname);
1317 if (item->is_paused) {
1318 DbgPrint("Instance %s is still paused\n", item->inst->id);
1323 DbgPrint("Instance %s resume timer\n", item->inst->item->pkgname);
1327 lb_sys_event(item->inst, item, LB_SYS_EVENT_RESUMED);
1331 HAPI int lb_pause(const char *pkgname, const char *id)
1333 struct instance *inst;
1337 inst = so_find_instance(pkgname, id);
1341 l = find_item(inst);
1343 ErrPrint("Instance is not found (%s - %s)\n", pkgname, id);
1347 item = eina_list_data_get(l);
1351 if (item->deleteme) {
1352 DbgPrint("Instance %s will be deleted (%s)\n", item->inst->item->pkgname, item->inst->id);
1356 item->is_paused = 1;
1358 if (s_info.paused) {
1359 DbgPrint("Already paused: %s\n", item->inst->id);
1366 lb_sys_event(inst, item, LB_SYS_EVENT_PAUSED);
1371 HAPI int lb_resume(const char *pkgname, const char *id)
1373 struct instance *inst;
1377 inst = so_find_instance(pkgname, id);
1381 l = find_item(inst);
1383 ErrPrint("Instance is not found (%s - %s)\n", pkgname, id);
1387 item = eina_list_data_get(l);
1391 if (item->deleteme) {
1392 DbgPrint("Instance %s will be deleted (%s)\n", item->inst->item->pkgname, item->inst->id);
1396 item->is_paused = 0;
1398 if (s_info.paused) {
1399 DbgPrint("Instance %s is still paused\n", item->inst->id);
1406 lb_sys_event(inst, item, LB_SYS_EVENT_RESUMED);
1410 HAPI void lb_turn_secured_on(void)