Add new attribute "category" 37/15837/2
authorSung-jae Park <nicesj.park@samsung.com>
Wed, 29 Jan 2014 03:54:53 +0000 (12:54 +0900)
committerSung-jae Park <nicesj.park@samsung.com>
Wed, 29 Jan 2014 12:43:49 +0000 (21:43 +0900)
Each dbox can be grouped by category.

http://tizen.org/category/idle-clock
http://tizen.org/category/default

Change-Id: I4b5ef17edb0123614c792781401dfa5f90d3eae5

packaging/data-provider-master.spec
pkgmgr_livebox/src/service_register.c

index 5691779..776037c 100644 (file)
@@ -1,6 +1,6 @@
 Name: data-provider-master
 Summary: Master service provider for liveboxes
-Version: 0.33.8
+Version: 0.34.0
 Release: 1
 Group: HomeTF/Livebox
 License: Flora
@@ -101,7 +101,7 @@ CREATE TABLE groupinfo ( id INTEGER PRIMARY KEY AUTOINCREMENT, cluster TEXT NOT
 CREATE TABLE groupmap (option_id INTEGER PRIMARY KEY AUTOINCREMENT, id INTEGER, pkgid TEXT NOT NULL, ctx_item TEXT NOT NULL, FOREIGN KEY(id) REFERENCES groupinfo(id), FOREIGN KEY(pkgid) REFERENCES pkgmap(pkgid) ON DELETE CASCADE);
 CREATE TABLE i18n ( pkgid TEXT NOT NULL, lang TEXT COLLATE NOCASE, name TEXT, icon TEXT, FOREIGN KEY(pkgid) REFERENCES pkgmap(pkgid) ON DELETE CASCADE);
 CREATE TABLE option ( pkgid TEXT NOT NULL, option_id INTEGER, key TEXT NOT NULL, value TEXT NOT NULL, FOREIGN KEY(option_id) REFERENCES groupmap(option_id), FOREIGN KEY(pkgid) REFERENCES pkgmap(pkgid) ON DELETE CASCADE);
-CREATE TABLE pkgmap ( pkgid TEXT PRIMARY KEY NOT NULL, appid TEXT, uiapp TEXT, prime INTEGER );
+CREATE TABLE pkgmap ( pkgid TEXT PRIMARY KEY NOT NULL, appid TEXT, uiapp TEXT, prime INTEGER, category TEXT DEFAULT 'http://tizen.org/category/default' );
 CREATE TABLE provider ( pkgid TEXT PRIMARY KEY NOT NULL, network INTEGER, abi TEXT, secured INTEGER, box_type INTEGER, box_src TEXT, box_group TEXT, pd_type INTEGER, pd_src TEXT, pd_group TEXT, libexec TEXT, timeout INTEGER, period TEXT, script TEXT, pinup INTEGER, FOREIGN KEY(pkgid) REFERENCES pkgmap(pkgid) ON DELETE CASCADE);
 EOF
 fi
index e92ec85..80c4c27 100644 (file)
@@ -49,7 +49,9 @@
 #define ErrPrint(format, arg...)       SECURE_LOGE("[\e[32m%s/%s\e[0m:%d] " format, basename(__FILE__), __func__, __LINE__, ##arg)
 #define ErrPrintWithConsole(format, arg...)    do { fprintf(stderr, "[%s/%s:%d] " format, basename(__FILE__), __func__, __LINE__, ##arg); SECURE_LOGE("[\e[32m%s/%s\e[0m:%d] " format, basename(__FILE__), __func__, __LINE__, ##arg); } while (0)
 #endif
-/* End of a file */
+
+#define CUR_VER 2
+#define DEFAULT_CATEGORY       "http://tizen.org/category/default"
 
 /*!
  * \note
  * 
  *
  * pkgmap
- * +-------+-------+-------+-------+
- * | appid | pkgid | uiapp | prime |
- * +-------+-------+-------+-------+
- * |   -   |   -   |   -   |   -   |
- * +-------+-------+-------+-------+
- * CREATE TABLE pkgmap ( pkgid TEXT PRIMARY KEY NOT NULL, appid TEXT, uiapp TEXT, prime INTEGER )
+ * +-------+-------+-------+-------+-------------------+
+ * | appid | pkgid | uiapp | prime | categ(from ver 2) |
+ * +-------+-------+-------+-------+-------------------+
+ * |   -   |   -   |   -   |   -   |         -         |
+ * +-------+-------+-------+-------+-------------------+
+ * CREATE TABLE pkgmap ( pkgid TEXT PRIMARY KEY NOT NULL, appid TEXT, uiapp TEXT, prime INTEGER, category TEXT )
  *
  *
  * provider
@@ -188,6 +190,7 @@ struct livebox {
        xmlChar *content; /* Content information */
        xmlChar *setup;
        xmlChar *uiapp; /* UI App Id */
+       xmlChar *category; /* Category of this box */
 
        int pinup; /* Is this support the pinup feature? */
        int primary; /* Is this primary livebox? */
@@ -406,6 +409,28 @@ static int get_version(void)
        return ret;
 }
 
+/*!
+ * \note
+ * From version 1 to 2
+ */
+static void upgrade_pkgmap_for_category(void)
+{
+       char *err;
+       static const char *ddl;
+
+       ddl = "ALTER TABLE pkgmap ADD COLUMN category TEXT DEFAULT \"" DEFAULT_CATEGORY "\"";
+       if (sqlite3_exec(s_info.handle, ddl, NULL, NULL, &err) != SQLITE_OK) {
+               ErrPrint("Failed to execute the DDL (%s)\n", err);
+               return;
+       }
+
+       if (sqlite3_changes(s_info.handle) == 0) {
+               ErrPrint("No changes to DB\n");
+       }
+
+       return;
+}
+
 static void do_upgrade_db_schema(void)
 {
        int version;
@@ -417,16 +442,18 @@ static void do_upgrade_db_schema(void)
                db_create_version();
                /* Need to create version table */
        case -ENOENT:
-               if (set_version(1) < 0) {
+               if (set_version(CUR_VER) < 0) {
                        ErrPrint("Failed to set version\n");
                }
                /* Need to set version */
-       case 1:
+       case CUR_VER:
                break;
+       case 1:
+               upgrade_pkgmap_for_category();
        default:
                /* Need to update version */
                DbgPrint("Old version: %d\n", version);
-               if (update_version(1) < 0) {
+               if (update_version(CUR_VER) < 0) {
                        ErrPrint("Failed to update version\n");
                }
                break;
@@ -438,7 +465,7 @@ static inline int db_create_pkgmap(void)
        char *err;
        static const char *ddl;
 
-       ddl = "CREATE TABLE pkgmap ( pkgid TEXT PRIMARY KEY NOT NULL, appid TEXT, uiapp TEXT, prime INTEGER )";
+       ddl = "CREATE TABLE pkgmap ( pkgid TEXT PRIMARY KEY NOT NULL, appid TEXT, uiapp TEXT, prime INTEGER, category TEXT )";
        if (sqlite3_exec(s_info.handle, ddl, NULL, NULL, &err) != SQLITE_OK) {
                ErrPrint("Failed to execute the DDL (%s)\n", err);
                return -EIO;
@@ -451,7 +478,7 @@ static inline int db_create_pkgmap(void)
        return 0;
 }
 
-static inline int db_insert_pkgmap(const char *appid, const char *pkgid, const char *uiappid, int primary)
+static inline int db_insert_pkgmap(const char *appid, const char *pkgid, const char *uiappid, int primary, const char *category)
 {
        int ret;
        static const char *dml;
@@ -461,7 +488,7 @@ static inline int db_insert_pkgmap(const char *appid, const char *pkgid, const c
                uiappid = ""; /*!< Could we replace this with Main AppId of this package? */
        }
 
-       dml = "INSERT INTO pkgmap ( appid, pkgid, uiapp, prime ) VALUES (? ,?, ?, ?)";
+       dml = "INSERT INTO pkgmap ( appid, pkgid, uiapp, prime, category ) VALUES (? ,?, ?, ?, ?)";
        ret = sqlite3_prepare_v2(s_info.handle, dml, -1, &stmt, NULL);
        if (ret != SQLITE_OK) {
                DbgPrint("Error: %s\n", sqlite3_errmsg(s_info.handle));
@@ -496,6 +523,13 @@ static inline int db_insert_pkgmap(const char *appid, const char *pkgid, const c
                goto out;
        }
 
+       ret = sqlite3_bind_text(stmt, 5, category, -1, SQLITE_TRANSIENT);
+       if (ret != SQLITE_OK) {
+               DbgPrint("Error: %s\n", sqlite3_errmsg(s_info.handle));
+               ret = -EIO;
+               goto out;
+       }
+
        ret = 0;
        if (sqlite3_step(stmt) != SQLITE_DONE) {
                DbgPrint("Error: %s\n", sqlite3_errmsg(s_info.handle));
@@ -1684,6 +1718,7 @@ static int livebox_destroy(struct livebox *livebox)
        xmlFree(livebox->period);
        xmlFree(livebox->content);
        xmlFree(livebox->setup);
+       xmlFree(livebox->category);
        xmlFree(livebox->preview[0]); /* 1x1 */
        xmlFree(livebox->preview[1]); /* 2x1 */
        xmlFree(livebox->preview[2]); /* 2x2 */
@@ -1833,12 +1868,17 @@ static inline void update_i18n_icon(struct livebox *livebox, xmlNodePtr node)
 static inline void update_launch(struct livebox *livebox, xmlNodePtr node)
 {
        xmlChar *launch;
+
        launch = xmlNodeGetContent(node);
        if (!launch) {
                DbgPrint("Has no launch\n");
                return;
        }
 
+       if (livebox->auto_launch) {
+               xmlFree(livebox->auto_launch);
+       }
+
        livebox->auto_launch = xmlStrdup(launch);
        if (!livebox->auto_launch) {
                ErrPrint("Failed to duplicate string: %s\n", (char *)launch);
@@ -1846,6 +1886,26 @@ static inline void update_launch(struct livebox *livebox, xmlNodePtr node)
        }
 }
 
+static inline void update_category(struct livebox *livebox, xmlNodePtr node)
+{
+       xmlChar *category;
+       category = xmlNodeGetContent(node);
+       if (!category) {
+               DbgPrint("Has no valid category\n");
+               return;
+       }
+
+       if (livebox->category) {
+               xmlFree(livebox->category);
+       }
+
+       livebox->category = xmlStrdup(category);
+       if (!livebox->category) {
+               ErrPrint("Failed to duplicate string: %s\n", (char *)category);
+               return;
+       }
+}
+
 static inline void update_ui_appid(struct livebox *livebox, xmlNodePtr node)
 {
        xmlChar *uiapp;
@@ -1855,6 +1915,10 @@ static inline void update_ui_appid(struct livebox *livebox, xmlNodePtr node)
                return;
        }
 
+       if (livebox->uiapp) {
+               xmlFree(livebox->uiapp);
+       }
+
        livebox->uiapp = xmlStrdup(uiapp);
        if (!livebox->uiapp) {
                ErrPrint("Failed to duplicate string: %s\n", (char *)uiapp);
@@ -1871,6 +1935,10 @@ static inline void update_setup(struct livebox *livebox, xmlNodePtr node)
                return;
        }
 
+       if (livebox->setup) {
+               xmlFree(livebox->setup);
+       }
+
        livebox->setup = xmlStrdup(setup);
        if (!livebox->setup) {
                ErrPrint("Failed to duplicate string: %s\n", (char *)setup);
@@ -1887,6 +1955,10 @@ static inline void update_content(struct livebox *livebox, xmlNodePtr node)
                return;
        }
 
+       if (livebox->content) {
+               xmlFree(livebox->content);
+       }
+
        livebox->content = xmlStrdup(content);
        if (!livebox->content) {
                ErrPrint("Failed to duplicate string: %s\n", (char *)content);
@@ -2342,7 +2414,7 @@ static int db_insert_livebox(struct livebox *livebox, const char *appid)
        struct option *option;
 
        begin_transaction();
-       ret = db_insert_pkgmap(appid, (char *)livebox->pkgid, (char *)livebox->uiapp, livebox->primary);
+       ret = db_insert_pkgmap(appid, (char *)livebox->pkgid, (char *)livebox->uiapp, livebox->primary, (char *)livebox->category);
        if (ret < 0) {
                goto errout;
        }
@@ -2686,6 +2758,11 @@ static int do_install(xmlNodePtr node, const char *appid)
                        update_ui_appid(livebox, node);
                        continue;
                }
+
+               if (!xmlStrcasecmp(node->name, (const xmlChar *)"category")) {
+                       update_category(livebox, node);
+                       continue;
+               }
        }
 
        return db_insert_livebox(livebox, appid);