Implement widget_service_get_widget_max_count API 49/81549/10 submit/tizen/20160809.011327
authorHwankyu Jhun <h.jhun@samsung.com>
Wed, 27 Jul 2016 04:17:18 +0000 (13:17 +0900)
committerHwanKyu Jhun <h.jhun@samsung.com>
Sun, 7 Aug 2016 22:09:14 +0000 (15:09 -0700)
Change-Id: I3fb54922e6e9b8a731d672dfce2d24d475fb9d9b
Signed-off-by: Hwankyu Jhun <h.jhun@samsung.com>
include/widget_errno.h
include/widget_service_internal.h
parser/widget.sql
parser/widget_plugin_parser.c
parser/widget_plugin_parser_db.c
parser/widget_plugin_parser_internal.h
src/widget_service.c

index 367406f..d5756e5 100644 (file)
@@ -60,6 +60,7 @@ typedef enum widget_error
        WIDGET_ERROR_ALREADY_STARTED = TIZEN_ERROR_WIDGET | 0x0004, /**< Operation is already started */
        WIDGET_ERROR_NOT_EXIST = TIZEN_ERROR_WIDGET | 0x0008, /**< Not exists */
        WIDGET_ERROR_DISABLED = TIZEN_ERROR_WIDGET | 0x0010,  /**< Disabled */
+       WIDGET_ERROR_MAX_EXCEED = TIZEN_ERROR_WIDGET | 0x0011,  /* *< Max instance exceed */
 } widget_error_e;
 
 /**
index 1047f05..ceca86c 100644 (file)
@@ -741,11 +741,13 @@ extern int widget_service_destroy_widget_list(widget_list_h handle);
  * @param[in] widget_id widget application id
  * @privlevel public
  * @privlege %http://tizen.org/privilege/widget.viewer
- * @return count positive value on success, otherwise a negative error value
+ * @return count non-negative value on success, otherwise a negative error value
  * @retval #WIDGET_ERROR_INVALID_PARAMETER Invalid parameter
  * @retval #WIDGET_ERROR_IO_ERROR Input/Output error (failed to access database)
  * @retval #WIDGET_ERROR_FAULT Unrecorvarable error occurred
  * @retval #WIDGET_ERROR_NOT_SUPPORTED Widget feature is not supported
+ * @retval #WIDGET_ERROR_PERMISSION_DENIED Permission denied
+ * @retval #WIDGET_ERROR_NOT_EXIST Not exists
  */
 extern int widget_service_get_widget_max_count(const char *widget_id);
 
index c1d9134..fd105db 100644 (file)
@@ -11,6 +11,7 @@ CREATE TABLE widget_class (
   appid         TEXT NOT NULL,
   pkgid         TEXT NOT NULL,
   nodisplay     INTEGER DEFAULT 0,
+  max_instance  INTEGER DEFAULT 0,
   PRIMARY KEY(classid)
 );
 
index 710ee33..e5c025d 100644 (file)
@@ -128,10 +128,9 @@ static int _parse_support_size(xmlNode *node, GList **sizes)
 
        size->preview = _get_attribute(node, "preview");
        val = _get_attribute(node, "frame");
-       if (val && !strcasecmp(val, "true")) {
+       if (val && !strcasecmp(val, "true"))
                size->frame = true;
-               free(val);
-       }
+       free(val);
 
        *sizes = g_list_append(*sizes, size);
 
@@ -204,6 +203,11 @@ static int _parse_widget_class(xmlNode *node, const char *appid, GList **apps)
 
        wc->setup_appid = _get_attribute(node, "setup-appid");
 
+       val = _get_attribute(node, "max-instance");
+       if (val)
+               wc->max_instance = atoi(val);
+       free(val);
+
        for (tmp = node->children; tmp; tmp = tmp->next) {
                switch (_get_tag(tmp)) {
                case TAG_SUPPORT_SIZE:
@@ -256,15 +260,22 @@ static int _parse_widget_application(xmlNode *node, GList **list)
        val = _get_attribute(node, "update-period");
        if (val)
                wc->update_period = atoi(val);
+       free(val);
 
        val = _get_attribute(node, "nodisplay");
        if (val && strncmp(val, "true", strlen("true")) == 0)
                wc->nodisplay = 1;
        else
                wc->nodisplay = 0;
+       free(val);
 
        wc->setup_appid = _get_attribute(node, "setup-appid");
 
+       val = _get_attribute(node, "max-instance");
+       if (val)
+               wc->max_instance = atoi(val);
+       free(val);
+
        for (tmp = node->children; tmp; tmp = tmp->next) {
                switch (_get_tag(tmp)) {
                case TAG_SUPPORT_SIZE:
index d3e84ac..2173b64 100644 (file)
@@ -223,8 +223,8 @@ static int _insert_widget_class(sqlite3 *db, const char *pkgid, GList *wcs)
        int ret;
        static const char query[] =
                "INSERT INTO widget_class (classid, update_period, "
-               "setup_appid, appid, pkgid, nodisplay) "
-               "VALUES (?, ?, ?, ?, ?, ?)";
+               "setup_appid, appid, pkgid, nodisplay, max_instance) "
+               "VALUES (?, ?, ?, ?, ?, ?, ?)";
        GList *tmp;
        struct widget_class *wc;
        sqlite3_stmt *stmt = NULL;
@@ -245,6 +245,7 @@ static int _insert_widget_class(sqlite3 *db, const char *pkgid, GList *wcs)
                _bind_text(stmt, idx++, wc->appid);
                _bind_text(stmt, idx++, pkgid);
                sqlite3_bind_int(stmt, idx++, wc->nodisplay);
+               sqlite3_bind_int(stmt, idx++, wc->max_instance);
 
                ret = sqlite3_step(stmt);
                if (ret != SQLITE_DONE) {
index 44f0fdb..bf14b59 100644 (file)
@@ -39,6 +39,7 @@ struct widget_class {
        int update_period;
        char *setup_appid;
        char *appid;
+       int max_instance;
        int nodisplay;
        GList *support_size;
        GList *label;
index fda056b..3f29147 100644 (file)
@@ -38,6 +38,7 @@
 #include "widget_conf.h"
 #include "widget_instance.h"
 #include "widget_service.h"
+#include "widget_service_internal.h"
 
 #define MAX_BUF_SIZE 4096
 #define SMACK_LABEL_LEN 255
@@ -1597,3 +1598,69 @@ EAPI int widget_service_unset_lifecycle_event_cb(const char *widget_id, void **u
        return WIDGET_ERROR_NOT_EXIST;
 }
 
+static int __get_max_instance(const char *widget_id, uid_t uid)
+{
+       static const char query[] =
+               "SELECT max_instance FROM widget_class WHERE classid=?";
+       int ret;
+       sqlite3 *db;
+       sqlite3_stmt *stmt;
+       int max_instance = 0;
+
+       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_int(stmt, 0, &max_instance);
+       _D("widget_id: %s, max-instance: %d", widget_id, max_instance);
+
+       sqlite3_finalize(stmt);
+       sqlite3_close_v2(db);
+
+       return max_instance;
+}
+
+EAPI int widget_service_get_widget_max_count(const char *widget_id)
+{
+       int ret;
+
+       if (!_is_widget_feature_enabled()) {
+               _E("Not supported");
+               return WIDGET_ERROR_NOT_SUPPORTED;
+       }
+
+       if (widget_id == NULL) {
+               _E("Invalid parameter");
+               return WIDGET_ERROR_INVALID_PARAMETER;
+       }
+
+       if (check_privilege("http://tizen.org/privilege/widget.viewer") < 0)
+               return WIDGET_ERROR_PERMISSION_DENIED;
+
+       ret = __get_max_instance(widget_id, getuid());
+       if (ret == WIDGET_ERROR_NOT_EXIST)
+               ret = __get_max_instance(widget_id, GLOBALAPP_USER);
+
+       return ret;
+}
+