Category getter 38/15838/1
authorSung-jae Park <nicesj.park@samsung.com>
Wed, 29 Jan 2014 03:55:47 +0000 (12:55 +0900)
committerSung-jae Park <nicesj.park@samsung.com>
Wed, 29 Jan 2014 03:55:47 +0000 (12:55 +0900)
Change-Id: Ie090c7e909e14072072fd48ff569618b3007ee0d

include/livebox-service.h
packaging/liblivebox-service.spec
src/livebox-service.c

index 1ddb670..68e0c50 100644 (file)
@@ -356,6 +356,24 @@ extern char *livebox_service_mainappid(const char *lbid);
 extern int livebox_service_get_pkglist_by_pkgid(const char *pkgid, int (*cb)(const char *lbid, int is_prime, void *data), void *data);
 
 /*!
+ * \brief Synchronous package list getter
+ * \details
+ *       callback (lbid)
+ *       lbid == Livebox Package Id
+ *        If the callback returns negative value, the list crawling will be stopped
+ * \remarks N/A
+ * \param[in] category Package Id (Not the UI App Id)
+ * \param[in] cb Callback function
+ * \param[in] data Callback data
+ * \return int
+ * \retval Count of livebox packages
+ * \retval LB_STATUS_ERROR_INVALID Invalid argument
+ * \retval LB_STATUS_ERROR_IO Failed to access DB
+ * \see livebox_service_get_pkglist_by_pkgid
+ */
+extern int livebox_service_get_pkglist_by_category(const char *category, int (*cb)(const char *lbid, void *data), void *data);
+
+/*!
  * \brief Get the lbid of a primary livebox using given lbid or pkgid or UI appid.
  * \details N/A
  * \remarks N/A
@@ -383,6 +401,20 @@ extern char *livebox_service_pkgname(const char *id);
 extern int livebox_service_is_primary(const char *lbid);
 
 /*!
+ * \brief Get the category using given lbid.
+ * \details N/A
+ * \remarks N/A
+ * \param[in] id Livebox Id
+ * \return char *
+ * \retval NULL Failed to get primary lbid
+ * \retval category Category string which is allocated in the heap.
+ * \pre Must be released returned string by manually
+ * \post N/A
+ * \see livebox_service_pkgname
+ */
+extern char *livebox_service_category(const char *lbid);
+
+/*!
  * \brief Get the name of a livebox (provider name == livebox appid), you have to release the return value after use it
  * \details
  *    OSP livebox has provider process for each livebox instances.
index c19a87f..37f0101 100644 (file)
@@ -1,6 +1,6 @@
 Name: liblivebox-service
 Summary: Service API for gathering installed livebox information
-Version: 0.8.1
+Version: 0.9.0
 Release: 1
 VCS:     magnolia/apps/livebox/livebox-service#livebox-service_0.3.9-59-g6d4e64fc994af7a38ff90fb508e21f1b8bcbcd86
 Group: HomeTF/Livebox
index 020e160..78400a3 100644 (file)
@@ -786,6 +786,62 @@ out:
        return ret;
 }
 
+EAPI int livebox_service_get_pkglist_by_category(const char *category, int (*cb)(const char *lbid, void *data), void *data)
+{
+       int ret;
+       sqlite3_stmt *stmt;
+       const char *lbid;
+       sqlite3 *handle;
+
+       if (!cb || !category) {
+               return LB_STATUS_ERROR_INVALID;
+       }
+
+       handle = open_db();
+       if (!handle) {
+               return LB_STATUS_ERROR_IO;
+       }
+
+       ret = sqlite3_prepare_v2(handle, "SELECT pkgid FROM pkgmap WHERE category = ?", -1, &stmt, NULL);
+       if (ret != SQLITE_OK) {
+               ErrPrint("Error: %s\n", sqlite3_errmsg(handle));
+               ret = LB_STATUS_ERROR_IO;
+               goto out;
+       }
+
+       ret = sqlite3_bind_text(stmt, 1, category, -1, SQLITE_TRANSIENT);
+       if (ret != SQLITE_OK) {
+               ErrPrint("Error: %s\n", sqlite3_errmsg(handle));
+               sqlite3_reset(stmt);
+               sqlite3_finalize(stmt);
+               ret = LB_STATUS_ERROR_IO;
+               goto out;
+       }
+
+       ret = 0;
+       while (sqlite3_step(stmt) == SQLITE_ROW) {
+               lbid = (const char *)sqlite3_column_text(stmt, 0);
+               if (!lbid || !strlen(lbid)) {
+                       ErrPrint("LBID is not valid\n");
+                       continue;
+               }
+
+               ret++;
+
+               if (cb(lbid, data) < 0) {
+                       DbgPrint("Callback stopped package crawling\n");
+                       break;
+               }
+       }
+
+       sqlite3_reset(stmt);
+       sqlite3_finalize(stmt);
+
+out:
+       close_db(handle);
+       return ret;
+}
+
 struct pkgmgr_cbdata {
        const char *lbid;
        void (*cb)(const char *lbid, const char *appid, void *data);
@@ -2206,6 +2262,77 @@ out:
        return ret;
 }
 
+EAPI char *livebox_service_category(const char *lbid)
+{
+       sqlite3_stmt *stmt;
+       char *category = NULL;
+       char *tmp;
+       sqlite3 *handle;
+       int ret;
+
+       if (!lbid) {
+               return NULL;
+       }
+
+       category = NULL;
+       handle = open_db();
+       if (!handle) {
+               return NULL;
+       }
+
+       ret = sqlite3_prepare_v2(handle, "SELECT category FROM pkgmap WHERE pkgid = ? OR appid = ?", -1, &stmt, NULL);
+       if (ret != SQLITE_OK) {
+               ErrPrint("Error: %s\n", sqlite3_errmsg(handle));
+               goto out;
+       }
+
+       ret = sqlite3_bind_text(stmt, 1, lbid, -1, SQLITE_TRANSIENT);
+       if (ret != SQLITE_OK) {
+               ErrPrint("Error: %s\n", sqlite3_errmsg(handle));
+               sqlite3_reset(stmt);
+               sqlite3_finalize(stmt);
+               goto out;
+       }
+
+       ret = sqlite3_bind_text(stmt, 2, lbid, -1, SQLITE_TRANSIENT);
+       if (ret != SQLITE_OK) {
+               ErrPrint("Error: %s\n", sqlite3_errmsg(handle));
+               sqlite3_reset(stmt);
+               sqlite3_finalize(stmt);
+               goto out;
+       }
+
+       ret = sqlite3_step(stmt);
+       if (ret != SQLITE_ROW) {
+               ErrPrint("Has no record?: %s\n", sqlite3_errmsg(handle));
+               sqlite3_reset(stmt);
+               sqlite3_finalize(stmt);
+               goto out;
+       }
+
+       tmp = (char *)sqlite3_column_text(stmt, 0);
+       if (!tmp || !strlen(tmp)) {
+               ErrPrint("APPID is NIL\n");
+               sqlite3_reset(stmt);
+               sqlite3_finalize(stmt);
+               goto out;
+       }
+
+       category = strdup(tmp);
+       if (!category) {
+               ErrPrint("Heap: %s\n", strerror(errno));
+               sqlite3_reset(stmt);
+               sqlite3_finalize(stmt);
+               goto out;
+       }
+
+       sqlite3_reset(stmt);
+       sqlite3_finalize(stmt);
+out:
+       close_db(handle);
+       return category;
+}
+
 EAPI char *livebox_service_appid(const char *pkgname)
 {
        sqlite3_stmt *stmt;