Add new API for getting the mainappid using DBox Id.
authorSung-jae Park <nicesj.park@samsung.com>
Mon, 3 Jun 2013 04:37:47 +0000 (13:37 +0900)
committerSung-jae Park <nicesj.park@samsung.com>
Mon, 3 Jun 2013 05:07:33 +0000 (14:07 +0900)
Change-Id: Iab528d86aeaa6ae8efa755fa5fda8c86f83245f7

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

index 68b28ca..a71d882 100644 (file)
@@ -148,6 +148,11 @@ extern int livebox_service_get_pkglist(int (*cb)(const char *pkgid, const char *
 extern int livebox_service_get_applist(const char *lbid, void (*cb)(const char *lbid, const char *appid, void *data), void *data);
 
 /*!
+ * \brief
+ */
+extern char *livebox_service_mainappid(const char *lbid);
+
+/*!
  * \brief Synchronous package list getter
  *       callback (lbid, is_prime)
  *       lbid == Livebox Package Id
index e79d38d..25441de 100644 (file)
@@ -1,6 +1,6 @@
 Name: liblivebox-service
 Summary: Service API for gathering installed livebox information.
-Version: 0.4.4
+Version: 0.4.5
 Release: 1
 Group: HomeTF/Livebox
 License: Flora License
index d63db80..5e76e78 100644 (file)
@@ -607,6 +607,27 @@ static int pkgmgr_cb(const pkgmgrinfo_appinfo_h handle, void *user_data)
        return 0;
 }
 
+static inline char *pkgmgr_get_mainapp(const char *pkgid)
+{
+       pkgmgrinfo_pkginfo_h handle;
+       char *ret = NULL;
+
+       if (pkgmgrinfo_pkginfo_get_pkginfo(pkgid, &handle) != PMINFO_R_OK) {
+               ErrPrint("Unable to get mainapp: %s\n", pkgid);
+               return NULL;
+       }
+
+       if (pkgmgrinfo_pkginfo_get_mainappid(handle, &ret) == PMINFO_R_OK) {
+               ret = strdup(ret);
+       } else {
+               ErrPrint("Failed to get mainappid\n");
+               ret = NULL; /* I cannot believe the pkgmgrinfo_pkginfo_get_mainappid. it maybe able to touch my "ret" even though it fails */
+       }
+
+       pkgmgrinfo_pkginfo_destroy_pkginfo(handle);
+       return ret;
+}
+
 static inline int pkgmgr_get_applist(const char *pkgid, const char *lbid, void (*cb)(const char *lbid, const char *appid, void *data), void *data)
 {
        struct pkgmgr_cbdata cbdata;
@@ -703,6 +724,69 @@ out:
        return ret;
 }
 
+EAPI char *livebox_service_mainappid(const char *lbid)
+{
+       sqlite3_stmt *stmt;
+       const char *tmp;
+       char *pkgid;
+       sqlite3 *handle;
+       char *ret = NULL;
+
+       if (!lbid)
+               return NULL;
+
+       handle = open_db();
+       if (!handle)
+               return NULL;
+
+       if (sqlite3_prepare_v2(handle, "SELECT appid FROM pkgmap WHERE (pkgid = ?) or (appid = ?)", -1, &stmt, NULL) != SQLITE_OK) {
+               ErrPrint("Error: %s\n", sqlite3_errmsg(handle));
+               goto out;
+       }
+
+       if (sqlite3_bind_text(stmt, 1, lbid, -1, SQLITE_TRANSIENT) != SQLITE_OK) {
+               ErrPrint("Error: %s\n", sqlite3_errmsg(handle));
+               goto out;
+       }
+
+       if (sqlite3_bind_text(stmt, 2, lbid, -1, SQLITE_TRANSIENT) != SQLITE_OK) {
+               ErrPrint("Error: %s\n", sqlite3_errmsg(handle));
+               goto out;
+       }
+
+       if (sqlite3_step(stmt) != SQLITE_ROW) {
+               sqlite3_reset(stmt);
+               sqlite3_finalize(stmt);
+               goto out;
+       }
+
+       tmp = (const char *)sqlite3_column_text(stmt, 0);
+       if (!tmp || !strlen(tmp)) {
+               ErrPrint("Invalid package name (%s)\n", lbid);
+               sqlite3_reset(stmt);
+               sqlite3_finalize(stmt);
+               goto out;
+       }
+
+       pkgid = strdup(tmp);
+       if (!pkgid) {
+               ErrPrint("Error: %s\n", strerror(errno));
+               sqlite3_reset(stmt);
+               sqlite3_finalize(stmt);
+               goto out;
+       }
+
+       sqlite3_reset(stmt);
+       sqlite3_finalize(stmt);
+
+       ret = pkgmgr_get_mainapp(pkgid);
+       free(pkgid);
+
+out:
+       close_db(handle);
+       return ret;
+}
+
 EAPI int livebox_service_get_supported_size_types(const char *pkgid, int *cnt, int *types)
 {
        sqlite3_stmt *stmt;