static void _widget_core_set_appcore_event_cb(void);
static void _widget_core_unset_appcore_event_cb(void);
+static int __instance_update(widget_class_h handle, const char *id, int force, const char *content);
static void __free_handler_cb(gpointer data)
{
return 0;
}
+static gboolean __timeout_cb(gpointer user_data)
+{
+ widget_context_s *wc = user_data;
+
+ if (wc->state == WC_RUNNING) {
+ _D("Periodic update!");
+ __instance_update(wc->provider, wc->id, 0, NULL);
+ } else if (wc->state == WC_PAUSED ||
+ wc->state == WC_READY) {
+ wc->pending_update = true;
+ if (wc->periodic_timer) {
+ _D("Remove timer!");
+ g_source_remove(wc->periodic_timer);
+ wc->periodic_timer = 0;
+ }
+ }
+
+ return G_SOURCE_CONTINUE;
+}
+
static int __instance_resume(widget_class_h handle, const char *id, int send_update)
{
widget_context_s *wc = __find_context_by_id(id);
return 0; /* LCOV_EXCL_LINE */
}
+ if (wc->pending_update) {
+ _D("pending update!");
+ wc->pending_update = false;
+ __instance_update(wc->provider, wc->id, 0, NULL);
+
+ if (wc->period > 0) {
+ _D("Restart timer!");
+ wc->periodic_timer = g_timeout_add_seconds(wc->period,
+ __timeout_cb, wc);
+ }
+ }
+
if (handle->ops.resume)
handle->ops.resume(wc, handle->user_data);
}
/* LCOV_EXCL_STOP */
-static int __instance_create(widget_class_h handle, const char *id, const char *content, int w, int h)
+static int __instance_create(widget_class_h handle, const char *id,
+ const char *content, int w, int h, double period)
{
widget_context_s *wc = NULL;
int ret = 0;
if (content_info)
bundle_free(content_info);
+ if (period > 0) {
+ wc->period = period;
+ wc->periodic_timer = g_timeout_add_seconds(period,
+ __timeout_cb, wc);
+ }
+
return ret;
}
if (wc->content)
free(wc->content);
+ if (wc->periodic_timer)
+ g_source_remove(wc->periodic_timer);
+
free(wc);
if (_widget_app_get_contexts() == NULL && !exit_called) /* all instance destroyed */
char *remain = NULL;
int force;
char *force_str = NULL;
+ double *period = NULL;
+ double update_period = 0;
widget_class_h handle = NULL;
+ size_t size;
+ int ret;
bundle_get_str(b, WIDGET_K_CLASS, &class_id);
/* for previous version compatibility, use appid for default class id */
if (h_str)
h = (int)g_ascii_strtoll(h_str, &remain, 10);
+ ret = bundle_get_byte(b, WIDGET_K_PERIOD, (void **)&period, &size);
+ if (ret == BUNDLE_ERROR_NONE)
+ update_period = *period;
+
if (strcmp(operation, "create") == 0) {
- __instance_create(handle, id, content, w, h);
+ __instance_create(handle, id, content, w, h, update_period);
} else if (strcmp(operation, "resize") == 0) {
__resize_window(id, w, h);
__instance_resize(handle, id, w, h);