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 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 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 gettimeofday(&tv, NULL);
350 item->sleep_at = (double)tv.tv_sec + (double)tv.tv_usec / 1000000.0f;
353 static inline void update_monitor_cnt(struct item *item)
358 now = util_timestamp();
359 interval = now - item->update_interval;
363 * If the content update is processed in too short time,
364 * don't increase the monitor counter, instead of it
365 * set the heavy updating flag.
366 * And handling this heavy updating from the
367 * file update callback.
369 if (interval >= MINIMUM_UPDATE_INTERVAL)
372 item->heavy_updating = 1;
374 item->update_interval = now;
377 static inline Eina_List *find_item(struct instance *inst)
382 EINA_LIST_FOREACH(s_info.item_list, l, item) {
383 if (item->inst == inst)
390 static inline int output_handler(struct item *item)
395 if (item->monitor_cnt < 0 || item->heavy_updating) {
396 if (!item->heavy_updating) {
397 WarnPrint("%s has invalid monitor_cnt\n", item->inst->id);
400 item->heavy_updating = 0; /* Reset flag */
403 item->monitor_cnt = 0;
406 if (item->monitor_cnt == 0) {
408 fault_unmark_call(item->inst->item->pkgname, item->inst->id, "update,crashed", NO_ALARM);
411 ecore_timer_del(item->monitor);
412 item->monitor = NULL;
415 if (s_info.update == item)
416 s_info.update = NULL;
418 if (item->deleteme) {
419 provider_send_deleted(item->inst->item->pkgname, item->inst->id);
420 (void)so_destroy(item->inst);
429 static int desc_updated_cb(const char *filename, void *data, int over)
434 WarnPrint("Event Q overflow\n");
438 DbgPrint("DESC %s is updated\n", filename);
439 provider_send_desc_updated(item->inst->item->pkgname, item->inst->id, filename);
443 static int file_updated_cb(const char *filename, void *data, int over)
453 WarnPrint("Event Q overflow\n");
457 (void)so_get_output_info(item->inst, &w, &h, &priority, &content, &title);
458 provider_send_updated(item->inst->item->pkgname, item->inst->id,
459 item->inst->w, item->inst->h, item->inst->priority, content, title);
461 return output_handler(item);
464 static inline int clear_from_pd_open_pending_list(struct item *item)
469 EINA_LIST_FOREACH(s_info.pd_open_pending_list, l, tmp) {
473 s_info.pd_open_pending_list = eina_list_remove_list(s_info.pd_open_pending_list, l);
474 if (!s_info.pd_open_pending_list)
475 deactivate_pd_open_pending_consumer();
482 static inline int clear_from_pending_list(struct item *item)
487 EINA_LIST_FOREACH(s_info.pending_list, l, tmp) {
491 s_info.pending_list = eina_list_remove_list(s_info.pending_list, l);
492 if (!s_info.pending_list)
493 deactivate_pending_consumer();
500 static Eina_Bool update_timeout_cb(void *data)
506 DbgPrint("UPDATE TIMEOUT ========> %s - %s\n", item->inst->item->pkgname, item->inst->id);
508 if (s_info.update != item)
509 ErrPrint("Updating item is not matched\n");
511 fault_unmark_call(item->inst->item->pkgname, item->inst->id, "update,crashed", NO_ALARM);
512 fault_mark_call(item->inst->item->pkgname, item->inst->id, "update,timeout", NO_ALARM, DEFAULT_LIFE_TIMER);
513 s_info.update = NULL;
516 return ECORE_CALLBACK_CANCEL;
519 static Eina_Bool updator_cb(void *data)
526 if (item->monitor) {/*!< If this item is already in update process */
527 return ECORE_CALLBACK_RENEW;
530 ret = so_is_updated(item->inst);
532 if (so_need_to_destroy(item->inst) == NEED_TO_DESTROY) {
533 provider_send_deleted(item->inst->item->pkgname, item->inst->id);
534 lb_destroy(item->inst->item->pkgname, item->inst->id);
536 ecore_timer_del(item->timer);
538 return ECORE_CALLBACK_CANCEL;
541 return ECORE_CALLBACK_RENEW;
544 if (s_info.update || pd_is_opened(item->inst->item->pkgname) < 0) {
545 (void)append_pending_list(item);
546 return ECORE_CALLBACK_RENEW;
549 item->monitor = ecore_timer_add(item->inst->item->timeout, update_timeout_cb, item);
550 if (!item->monitor) {
551 ErrPrint("Failed to add update monitor %s(%s):%d\n",
552 item->inst->item->pkgname, item->inst->id, item->inst->item->timeout);
553 return ECORE_CALLBACK_RENEW;
558 * Counter of the event monitor is only used for asynchronous content updating,
559 * So reset it to 1 from here because the async updating is started now,
560 * even if it is accumulated by other event function before this.
562 item->monitor_cnt = 1;
564 s_info.update = item;
566 ret = so_update(item->inst);
570 ecore_timer_del(item->monitor);
571 item->monitor = NULL;
572 s_info.update = NULL;
573 return ECORE_CALLBACK_RENEW;
578 * While waiting the Callback function call,
579 * Add this for finding the crash
581 fault_mark_call(item->inst->item->pkgname, item->inst->id, "update,crashed", NO_ALARM, DEFAULT_LIFE_TIMER);
583 if (ret & NEED_TO_SCHEDULE) {
584 (void)append_pending_list(item);
587 if (ret & OUTPUT_UPDATED)
588 update_monitor_cnt(item);
590 return ECORE_CALLBACK_RENEW;
593 static inline void update_monitor_del(struct item *item)
598 update_monitor_del_update_cb(util_uri_to_path(item->inst->id), file_updated_cb);
600 len = strlen(util_uri_to_path(item->inst->id)) + strlen(".desc") + 1;
603 ErrPrint("Heap: %s (%s.desc)\n", strerror(errno), util_uri_to_path(item->inst->id));
607 snprintf(tmp, len, "%s.desc", util_uri_to_path(item->inst->id));
608 update_monitor_del_update_cb(tmp, desc_updated_cb);
612 static inline int add_desc_update_monitor(struct item *item)
617 len = strlen(util_uri_to_path(item->inst->id)) + strlen(".desc") + 1;
618 filename = malloc(len);
620 ErrPrint("Heap: %s (%s.desc)\n", strerror(errno), util_uri_to_path(item->inst->id));
624 snprintf(filename, len, "%s.desc", util_uri_to_path(item->inst->id));
625 DbgPrint("Add DESC monitor: %s\n", filename);
626 return update_monitor_add_update_cb(filename, desc_updated_cb, item);
629 static inline int add_file_update_monitor(struct item *item)
633 filename = strdup(util_uri_to_path(item->inst->id));
635 ErrPrint("Heap: %s (%s)\n", strerror(errno), item->inst->id);
639 return update_monitor_add_update_cb(filename, file_updated_cb, item);
642 static inline int update_monitor_add(struct item *item)
644 add_file_update_monitor(item);
645 add_desc_update_monitor(item);
649 HAPI int lb_init(void)
654 HAPI int lb_fini(void)
660 deactivate_pending_consumer();
661 deactivate_pd_open_pending_consumer();
663 EINA_LIST_FREE(s_info.pd_open_pending_list, item);
664 EINA_LIST_FREE(s_info.pending_list, item);
666 EINA_LIST_FOREACH_SAFE(s_info.item_list, l, n, item) {
667 provider_send_deleted(item->inst->item->pkgname, item->inst->id);
668 lb_destroy(item->inst->item->pkgname, item->inst->id);
676 * Exported API for each liveboxes.
678 const char *livebox_find_pkgname(const char *filename)
683 EINA_LIST_FOREACH(s_info.item_list, l, item) {
684 if (!strcmp(item->inst->id, filename))
685 return item->inst->item->pkgname;
691 HAPI int lb_open_pd(const char *pkgname)
696 EINA_LIST_FOREACH(s_info.pd_list, l, tmp) {
697 if (!strcmp(pkgname, tmp))
701 tmp = strdup(pkgname);
703 ErrPrint("Heap: %s\n", strerror(errno));
708 pending_timer_freeze();
710 s_info.pd_list = eina_list_append(s_info.pd_list, tmp);
713 * Find all instances from the pending list.
714 * Move them to pd_open_pending_timer
716 migrate_to_pd_open_pending_list(pkgname);
720 HAPI int lb_close_pd(const char *pkgname)
726 EINA_LIST_FOREACH_SAFE(s_info.pd_list, l, n, tmp) {
727 if (strcmp(tmp, pkgname))
730 s_info.pd_list = eina_list_remove(s_info.pd_list, tmp);
734 pending_timer_thaw();
737 * Move all items in pd_open_pending_list
740 migrate_to_pending_list(pkgname);
747 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)
749 struct instance *inst;
759 inst = so_find_instance(pkgname, id);
761 DbgPrint("Instance is already exists [%s - %s] content[%s], cluster[%s], category[%s], abi[%s]\n", pkgname, id, content_info, cluster, category, abi);
765 if (!skip_need_to_create) {
766 ret = so_create_needed(pkgname, cluster, category, abi);
767 if (ret != NEED_TO_CREATE)
773 item = malloc(sizeof(*item));
775 ErrPrint("Heap: %s (%s - %s, content[%s], cluster[%s], category[%s], abi[%s])\n", strerror(errno), pkgname, id, content_info, cluster, category, abi);
779 item->monitor = NULL;
780 item->monitor_cnt = 0;
782 item->update_interval = 0.0f;
783 item->heavy_updating = 0;
785 item->sleep_at = 0.0f;
787 create_ret = so_create(pkgname, id, content_info, timeout, has_livebox_script, cluster, category, abi, &inst);
788 if (create_ret < 0) {
799 if (period > 0.0f && !s_info.secured) {
800 item->timer = util_timer_add(period, updator_cb, item);
802 ErrPrint("Failed to add timer (%s - %s, content[%s], cluster[%s], category[%s], abi[%s]\n", pkgname, id, content_info, cluster, category, abi);
811 DbgPrint("Local update timer is disabled: %lf (%d)\n", period, s_info.secured);
815 ret = update_monitor_add(item);
819 ecore_timer_del(item->timer);
824 s_info.item_list = eina_list_append(s_info.item_list, item);
826 if (create_ret & NEED_TO_SCHEDULE) {
827 DbgPrint("%s Returns NEED_TO_SCHEDULE\n", pkgname);
828 (void)append_pending_list(item);
831 if (create_ret & OUTPUT_UPDATED) {
835 update_monitor_cnt(item);
838 * To send a output info, get the info forcely.
839 * but the output file monitor will do this again
841 * This function will set the tmp_content and tmp_title
842 * even if it has no updates on the content, title,
843 * it will set them to NULL.
845 (void)so_get_output_info(inst, w, h, priority, &tmp_content, &tmp_title);
849 * These two values will be released by the provider library.
852 *out_content = strdup(tmp_content);
854 ErrPrint("Heap: %s\n", strerror(errno));
858 *out_title = strdup(tmp_title);
860 ErrPrint("Heap: %s\n", strerror(errno));
866 *priority = inst->priority;
867 return need_to_create;
870 HAPI int lb_destroy(const char *pkgname, const char *id)
873 struct instance *inst;
877 inst = so_find_instance(pkgname, id);
879 ErrPrint("Instance %s - %s is not created\n", pkgname, id);
885 ErrPrint("Instance is not found (%s - %s)\n", pkgname, id);
889 item = eina_list_data_get(l);
890 s_info.item_list = eina_list_remove_list(s_info.item_list, l);
892 if (s_info.update == item)
893 s_info.update = NULL;
896 clear_from_pd_open_pending_list(item);
897 clear_from_pending_list(item);
898 ecore_timer_del(item->timer);
904 update_monitor_del(item);
907 if (!item->monitor) {
909 ret = so_destroy(inst);
915 HAPI int lb_resize(const char *pkgname, const char *id, int w, int h)
918 struct instance *inst;
922 inst = so_find_instance(pkgname, id);
924 ErrPrint("Instance %s - %s is not created (%dx%d)\n", pkgname, id, w, h);
930 ErrPrint("Instance is not found (%s - %s, %dx%d)\n", pkgname, id, w, h);
934 item = eina_list_data_get(l);
936 ret = so_resize(inst, w, h);
940 if (ret & NEED_TO_SCHEDULE) {
941 DbgPrint("%s Returns NEED_TO_SCHEDULE\n", pkgname);
942 (void)append_pending_list(item);
945 if (ret & OUTPUT_UPDATED)
946 update_monitor_cnt(item);
951 HAPI char *lb_pinup(const char *pkgname, const char *id, int pinup)
953 struct instance *inst;
956 inst = so_find_instance(pkgname, id);
958 ErrPrint("Instance %s - %s is not found (pinup[%d])\n", pkgname, id, pinup);
962 ret = so_pinup(inst, pinup);
966 HAPI int lb_set_period(const char *pkgname, const char *id, double period)
969 struct instance *inst;
972 inst = so_find_instance(pkgname, id);
974 ErrPrint("Instance %s - %s is not found (period[%lf])\n", pkgname, id, period);
980 ErrPrint("Instance is not found (%s - %s, period[%lf])\n", pkgname, id, period);
984 item = eina_list_data_get(l);
986 if (period <= 0.0f) {
988 ecore_timer_del(item->timer);
993 util_timer_interval_set(item->timer, period);
994 } else if (!s_info.secured) {
995 item->timer = util_timer_add(period, updator_cb, item);
997 ErrPrint("Failed to add timer (%s - %s)\n", pkgname, id);
1009 HAPI int lb_clicked(const char *pkgname, const char *id, const char *event, double timestamp, double x, double y)
1012 struct instance *inst;
1016 inst = so_find_instance(pkgname, id);
1018 ErrPrint("Instance %s - %s is not exists (event[%s])\n", pkgname, id, event);
1022 l = find_item(inst);
1024 ErrPrint("Instance is not found (%s - %s, event[%s])\n", pkgname, id, event);
1028 item = eina_list_data_get(l);
1030 ret = so_clicked(inst, event, timestamp, x, y);
1034 if (ret & NEED_TO_SCHEDULE) {
1035 DbgPrint("%s Returns NEED_TO_SCHEDULE\n", pkgname);
1036 (void)append_pending_list(item);
1039 if (ret & OUTPUT_UPDATED)
1040 update_monitor_cnt(item);
1045 HAPI int lb_script_event(const char *pkgname, const char *id, const char *emission, const char *source, struct event_info *event_info)
1048 struct instance *inst;
1052 inst = so_find_instance(pkgname, id);
1054 ErrPrint("Instance %s - %s is not exists (emission[%s], source[%s])\n", pkgname, id, emission, source);
1058 l = find_item(inst);
1060 ErrPrint("Instance is not found (%s - %s, emissino[%s], source[%s])\n", pkgname, id, emission, source);
1064 item = eina_list_data_get(l);
1066 ret = so_script_event(inst, emission, source, event_info);
1070 if (ret & NEED_TO_SCHEDULE) {
1071 DbgPrint("%s Returns NEED_TO_SCHEDULE\n", pkgname);
1072 (void)append_pending_list(item);
1075 if (ret & OUTPUT_UPDATED)
1076 update_monitor_cnt(item);
1081 HAPI int lb_is_pinned_up(const char *pkgname, const char *id)
1084 struct instance *inst;
1088 inst = so_find_instance(pkgname, id);
1090 ErrPrint("Instance %s - %s is not created\n", pkgname, id);
1094 l = find_item(inst);
1096 ErrPrint("Instance is not found(%s - %s)\n", pkgname, id);
1100 item = eina_list_data_get(l);
1104 * Maybe this is not neccessary for this operation
1106 ret = so_is_pinned_up(inst);
1110 HAPI int lb_change_group(const char *pkgname, const char *id, const char *cluster, const char *category)
1113 struct instance *inst;
1117 inst = so_find_instance(pkgname, id);
1119 ErrPrint("Instance %s - %s is not created (cluster[%s], category[%s])\n", pkgname, id, cluster, category);
1123 l = find_item(inst);
1125 ErrPrint("Instance is not found(%s - %s, cluster[%s], category[%s])\n", pkgname, id, cluster, category);
1129 item = eina_list_data_get(l);
1131 ret = so_change_group(inst, cluster, category);
1135 if (ret & NEED_TO_SCHEDULE) {
1136 DbgPrint("%s Returns NEED_TO_SCHEDULE\n", pkgname);
1137 (void)append_pending_list(item);
1140 if (ret & OUTPUT_UPDATED)
1141 update_monitor_cnt(item);
1146 static inline int lb_sys_event(struct instance *inst, struct item *item, int event)
1150 ret = so_sys_event(inst, event);
1154 if (ret & NEED_TO_SCHEDULE)
1155 (void)append_pending_list(item);
1157 if (ret & OUTPUT_UPDATED)
1158 update_monitor_cnt(item);
1163 HAPI int lb_system_event(const char *pkgname, const char *id, int event)
1166 struct instance *inst;
1169 inst = so_find_instance(pkgname, id);
1171 ErrPrint("instance %s - %s is not created\n");
1175 l = find_item(inst);
1177 ErrPrint("Instance is not found(%s - %s)\n", pkgname, id);
1181 item = eina_list_data_get(l);
1182 return lb_sys_event(inst, item, event);
1185 HAPI int lb_update(const char *pkgname, const char *id)
1188 struct instance *inst;
1191 inst = so_find_instance(pkgname, id);
1193 ErrPrint("Instance %s - %s is not created\n", pkgname, id);
1197 l = find_item(inst);
1199 ErrPrint("Instance is not found(%s - %s)\n", pkgname, id);
1203 item = eina_list_data_get(l);
1204 (void)append_pending_list(item);
1208 HAPI int lb_update_all(const char *pkgname, const char *cluster, const char *category)
1214 DbgPrint("Update content for %s\n", pkgname ? pkgname : "(all)");
1215 EINA_LIST_FOREACH_SAFE(s_info.item_list, l, n, item) {
1219 if (cluster && strcasecmp(item->inst->cluster, cluster))
1222 if (category && strcasecmp(item->inst->category, category))
1225 if (pkgname && strlen(pkgname)) {
1226 if (!strcmp(item->inst->item->pkgname, pkgname)) {
1227 (void)append_pending_list(item);
1230 (void)append_pending_list(item);
1237 HAPI int lb_system_event_all(int event)
1243 EINA_LIST_FOREACH_SAFE(s_info.item_list, l, n, item) {
1247 DbgPrint("System event for %s (%d)\n", item->inst->id, event);
1248 lb_sys_event(item->inst, item, event);
1254 HAPI void lb_pause_all(void)
1261 pending_timer_freeze();
1263 EINA_LIST_FOREACH(s_info.item_list, l, item) {
1264 if (item->deleteme) {
1265 DbgPrint("Instance %s skip timer pause (deleteme)\n", item->inst->item->pkgname);
1269 if (item->is_paused) {
1270 DbgPrint("Instance %s is already paused\n", item->inst->id);
1275 DbgPrint("Instance %s freeze timer\n", item->inst->item->pkgname);
1278 DbgPrint("Instance %s has no timer\n", item->inst->item->pkgname);
1281 lb_sys_event(item->inst, item, LB_SYS_EVENT_PAUSED);
1285 HAPI void lb_resume_all(void)
1292 pending_timer_thaw();
1294 EINA_LIST_FOREACH(s_info.item_list, l, item) {
1295 if (item->deleteme) {
1296 DbgPrint("Instance %s skip timer resume (deleteme)\n", item->inst->item->pkgname);
1300 if (item->is_paused) {
1301 DbgPrint("Instance %s is still paused\n", item->inst->id);
1306 DbgPrint("Instance %s resume timer\n", item->inst->item->pkgname);
1310 lb_sys_event(item->inst, item, LB_SYS_EVENT_RESUMED);
1314 HAPI int lb_pause(const char *pkgname, const char *id)
1316 struct instance *inst;
1320 inst = so_find_instance(pkgname, id);
1324 l = find_item(inst);
1326 ErrPrint("Instance is not found (%s - %s)\n", pkgname, id);
1330 item = eina_list_data_get(l);
1334 if (item->deleteme) {
1335 DbgPrint("Instance %s will be deleted (%s)\n", item->inst->item->pkgname, item->inst->id);
1339 item->is_paused = 1;
1341 if (s_info.paused) {
1342 DbgPrint("Already paused: %s\n", item->inst->id);
1349 lb_sys_event(inst, item, LB_SYS_EVENT_PAUSED);
1354 HAPI int lb_resume(const char *pkgname, const char *id)
1356 struct instance *inst;
1360 inst = so_find_instance(pkgname, id);
1364 l = find_item(inst);
1366 ErrPrint("Instance is not found (%s - %s)\n", pkgname, id);
1370 item = eina_list_data_get(l);
1374 if (item->deleteme) {
1375 DbgPrint("Instance %s will be deleted (%s)\n", item->inst->item->pkgname, item->inst->id);
1379 item->is_paused = 0;
1381 if (s_info.paused) {
1382 DbgPrint("Instance %s is still paused\n", item->inst->id);
1389 lb_sys_event(inst, item, LB_SYS_EVENT_RESUMED);
1393 HAPI void lb_turn_secured_on(void)