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;
/**
* @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);
appid TEXT NOT NULL,
pkgid TEXT NOT NULL,
nodisplay INTEGER DEFAULT 0,
+ max_instance INTEGER DEFAULT 0,
PRIMARY KEY(classid)
);
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);
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:
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:
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;
_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) {
int update_period;
char *setup_appid;
char *appid;
+ int max_instance;
int nodisplay;
GList *support_size;
GList *label;
#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
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;
+}
+