Add period value into bundle 66/139466/2
authorJunghoon Park <jh9216.park@samsung.com>
Wed, 19 Jul 2017 05:16:15 +0000 (14:16 +0900)
committerJunghoon Park <jh9216.park@samsung.com>
Wed, 19 Jul 2017 05:22:45 +0000 (05:22 +0000)
- When an instance is launched, the update-period value should be sent to provider
  to set the periodic timer

Change-Id: Ic4110b60fec1d3ff604a03fb359d8d0c037f9296
Signed-off-by: Junghoon Park <jh9216.park@samsung.com>
src/widget_instance.c
src/widget_service.c

index cefdd6b..4b321ef 100644 (file)
@@ -116,6 +116,8 @@ struct event_cb_s {
 static int __fault_handler(int pid);
 static void __free_sdk_util(void);
 
+extern int widget_service_get_update_period(const char *widget_id, double *period);
+
 static struct _widget_instance *__pick_instance(const char *instance_id)
 {
        GList *instances = _widget_instances;
@@ -199,6 +201,12 @@ static struct _widget_instance *__add_instance(const char *id, const char *widge
 {
        struct _widget_instance *instance = NULL;
        struct widget_app *app = NULL;
+       double period = 0;
+
+       if (widget_service_get_update_period(widget_id, &period) != WIDGET_ERROR_NONE) {
+               _E("Can't get update-period");
+               return NULL;
+       }
 
        instance = (struct _widget_instance *)malloc(sizeof(struct _widget_instance));
        if (instance == NULL) {
@@ -213,6 +221,7 @@ static struct _widget_instance *__add_instance(const char *id, const char *widge
        instance->widget_id = strdup(widget_id);
        instance->content_info = NULL;
        instance->ref = 0;
+       instance->period = period;
 
        _widget_instances = g_list_append(_widget_instances, instance);
 
@@ -446,6 +455,7 @@ EAPI int widget_instance_launch(const char *instance_id, char *content_info, int
        bundle_add_str(b, AUL_K_WAYLAND_DISPLAY, wayland_display);
        bundle_add_str(b, AUL_K_WAYLAND_WORKING_DIR, xdg_runtime_dir);
        bundle_add_str(b, WIDGET_K_OPERATION, "create");
+       bundle_add_byte(b, WIDGET_K_PERIOD, &(instance->period), sizeof(double));
 
        if (sdk_util.name) {
                bundle_add_str(b, AUL_K_SDK, sdk_util.name);
index 2ebf6df..322ef40 100644 (file)
@@ -200,6 +200,11 @@ static void _get_column_int(sqlite3_stmt *stmt, int idx, int *i)
        *i = sqlite3_column_int(stmt, idx);
 }
 
+static void _get_column_double(sqlite3_stmt *stmt, int idx, double *i)
+{
+       *i = sqlite3_column_double(stmt, idx);
+}
+
 #define WIDGET_SIZE_TYPE_MAX 13
 static int size_list[WIDGET_SIZE_TYPE_MAX][5] = {
        { 1, 1, 175, 175, WIDGET_SIZE_TYPE_1x1 }, /*!< 1x1 */
@@ -1104,6 +1109,56 @@ static int _get_nodisplay(const char *widget_id, uid_t uid)
        return nodisplay;
 }
 
+static int _get_update_period(const char *widget_id, uid_t uid, double *period)
+{
+       static const char query[] =
+               "SELECT update_period FROM widget_class WHERE classid=?";
+       int ret;
+       sqlite3 *db;
+       sqlite3_stmt *stmt;
+
+       db = _open_db(uid);
+       if (db == NULL) {
+               return WIDGET_ERROR_IO_ERROR;
+       }
+
+       ret = sqlite3_prepare_v2(db, query, strlen(query), &stmt, NULL);
+       if (ret != SQLITE_OK) {
+               _E("prepare error: %s", sqlite3_errmsg(db));
+               sqlite3_close_v2(db);
+               return WIDGET_ERROR_FAULT;
+       }
+
+       sqlite3_bind_text(stmt, 1, widget_id, -1, SQLITE_STATIC);
+
+       ret = sqlite3_step(stmt);
+       if (ret != SQLITE_ROW) {
+               _E("step error: %s", sqlite3_errmsg(db));
+               sqlite3_finalize(stmt);
+               sqlite3_close_v2(db);
+               if (ret == SQLITE_DONE)
+                      return WIDGET_ERROR_NOT_EXIST;
+
+               return WIDGET_ERROR_FAULT;
+       }
+
+       _get_column_double(stmt, 0, period);
+       sqlite3_finalize(stmt);
+       sqlite3_close_v2(db);
+
+       return WIDGET_ERROR_NONE;
+}
+
+int widget_service_get_update_period(const char *widget_id, double *period)
+{
+       int ret = _get_update_period(widget_id, getuid(), period);
+
+       if (ret == WIDGET_ERROR_NOT_EXIST)
+               ret = _get_update_period(widget_id, GLOBALAPP_USER, period);
+
+       return ret;
+}
+
 EAPI int widget_service_get_nodisplay(const char *widget_id)
 {
        int nodisplay;