diff options
author | Hwankyu Jhun <h.jhun@samsung.com> | 2016-07-27 13:17:18 +0900 |
---|---|---|
committer | HwanKyu Jhun <h.jhun@samsung.com> | 2016-08-07 15:09:14 -0700 |
commit | 6800f44d4a319011b58a9710ef2dcfe064ea4a55 (patch) | |
tree | 262a1bb8c85269ebfeb423d3bbd3101ba5d8556a | |
parent | 1250538321122063560f6530a5475ea7ec19ade9 (diff) | |
download | widget-service-6800f44d4a319011b58a9710ef2dcfe064ea4a55.tar.gz widget-service-6800f44d4a319011b58a9710ef2dcfe064ea4a55.tar.bz2 widget-service-6800f44d4a319011b58a9710ef2dcfe064ea4a55.zip |
Implement widget_service_get_widget_max_count APIsubmit/tizen/20160809.011327
Change-Id: I3fb54922e6e9b8a731d672dfce2d24d475fb9d9b
Signed-off-by: Hwankyu Jhun <h.jhun@samsung.com>
-rw-r--r-- | include/widget_errno.h | 1 | ||||
-rw-r--r-- | include/widget_service_internal.h | 4 | ||||
-rw-r--r-- | parser/widget.sql | 1 | ||||
-rw-r--r-- | parser/widget_plugin_parser.c | 17 | ||||
-rw-r--r-- | parser/widget_plugin_parser_db.c | 5 | ||||
-rw-r--r-- | parser/widget_plugin_parser_internal.h | 1 | ||||
-rw-r--r-- | src/widget_service.c | 67 |
7 files changed, 90 insertions, 6 deletions
diff --git a/include/widget_errno.h b/include/widget_errno.h index 367406f..d5756e5 100644 --- a/include/widget_errno.h +++ b/include/widget_errno.h @@ -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; /** diff --git a/include/widget_service_internal.h b/include/widget_service_internal.h index 1047f05..ceca86c 100644 --- a/include/widget_service_internal.h +++ b/include/widget_service_internal.h @@ -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); diff --git a/parser/widget.sql b/parser/widget.sql index c1d9134..fd105db 100644 --- a/parser/widget.sql +++ b/parser/widget.sql @@ -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) ); diff --git a/parser/widget_plugin_parser.c b/parser/widget_plugin_parser.c index 710ee33..e5c025d 100644 --- a/parser/widget_plugin_parser.c +++ b/parser/widget_plugin_parser.c @@ -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: diff --git a/parser/widget_plugin_parser_db.c b/parser/widget_plugin_parser_db.c index d3e84ac..2173b64 100644 --- a/parser/widget_plugin_parser_db.c +++ b/parser/widget_plugin_parser_db.c @@ -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) { diff --git a/parser/widget_plugin_parser_internal.h b/parser/widget_plugin_parser_internal.h index 44f0fdb..bf14b59 100644 --- a/parser/widget_plugin_parser_internal.h +++ b/parser/widget_plugin_parser_internal.h @@ -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; diff --git a/src/widget_service.c b/src/widget_service.c index fda056b..3f29147 100644 --- a/src/widget_service.c +++ b/src/widget_service.c @@ -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; +} + |