Implement widget operation for 'period' 80/150680/4
authorJunghoon Park <jh9216.park@samsung.com>
Thu, 20 Jul 2017 05:23:36 +0000 (14:23 +0900)
committerHyunho Kang <hhstark.kang@samsung.com>
Thu, 21 Sep 2017 08:35:30 +0000 (08:35 +0000)
- This patch is associated with widget_service_change_period()
- This operation is responsible for changing current update-period

Change-Id: I32abe9b865941040d223d467984dac8e72e9d748
Signed-off-by: Junghoon Park <jh9216.park@samsung.com>
Signed-off-by: Hyunho Kang <hhstark.kang@samsung.com>
src/base/widget_base.c

index d479c52..c10cd8d 100644 (file)
@@ -510,6 +510,48 @@ static void __control_destroy(const char *class_id, const char *id, bundle *b)
        __check_empty_instance();
 }
 
+static void __control_change_period(const char *class_id, const char *id,
+               bundle *b)
+{
+       appcore_multiwindow_base_instance_h instance_h;
+       widget_base_instance_data *data;
+       double *period = NULL;
+       size_t size;
+       int ret;
+
+       instance_h = appcore_multiwindow_base_instance_find(id);
+       if (!instance_h) {
+               LOGE("context not found: %s", id);
+               return;
+       }
+
+       data = (widget_base_instance_data *)
+                       appcore_multiwindow_base_instance_get_extra(instance_h);
+
+       if (!data) {
+               LOGE("could not find instance data: %s", id);
+               return;
+       }
+
+       if (data->periodic_timer) {
+               LOGD("Remove timer!");
+               g_source_remove(data->periodic_timer);
+               data->periodic_timer = 0;
+       }
+
+       ret = bundle_get_byte(b, WIDGET_K_PERIOD, (void **)&period, &size);
+       if (ret == BUNDLE_ERROR_NONE)
+               data->period = *period;
+
+       if (data->period > 0) {
+               LOGD("Restart timer!");
+               data->periodic_timer = g_timeout_add_seconds(data->period,
+                               __timeout_cb, data);
+       }
+
+       return;
+}
+
 static int __multiwindow_create(void *data)
 {
        char pkgid[256] = {0, };
@@ -601,6 +643,8 @@ static int __multiwindow_control(bundle *b, void *data)
                __control_pause(class_id, id, b);
        else if (strcmp(operation, "terminate") == 0)
                __control_destroy(class_id, id, b);
+       else if (strcmp(operation, "period") == 0)
+               __control_change_period(class_id, id, b);
 
        return 0;
 }