Add a new API "livebox_service_is_primary"
authorSung-jae Park <nicesj.park@samsung.com>
Tue, 5 Mar 2013 08:07:11 +0000 (08:07 +0000)
committerSung-jae Park <nicesj.park@samsung.com>
Tue, 5 Mar 2013 08:07:11 +0000 (08:07 +0000)
This API will returns true(1) or false(0)
Fix the bug of livebox_service_touch_effect & livebox_service_mouse_event function.
Those functions has to return 0 or 1. even if the argument is not valid, returns 0.

Change-Id: I1269a7020c4aff8504c09845dd49f6f757ee4a6b

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

index 89ae687..1de8c31 100644 (file)
@@ -98,12 +98,18 @@ extern int livebox_service_change_period(const char *pkgname, const char *id, do
 extern int livebox_service_get_pkglist(int (*cb)(const char *appid, const char *lbid, int is_prime, void *data), void *data);
 
 /*!
- * \brief Get the name(appid or pkgname) of a primary livebox.
- * \param[in] appid
+ * \brief Get the pkgname of a primary livebox using given lbid or pkgid.
+ * \param[in] id Livebox Id or Package Id
  * \return pkgname String which is allocated on the heap
  */
-extern char *livebox_service_pkgname(const char *appid);
+extern char *livebox_service_pkgname(const char *id);
 
+/*!
+ * \brief Check the pirmary flag of given livebox Id.
+ * \param[in] lbid Livebox Id
+ * \return int 0 if is not a primary or 1
+ */
+extern int livebox_service_is_primary(const char *lbid);
 
 /*!
  * \brief Get the name of a livebox (provider name == livebox appid), you have to release the return value after use it
@@ -113,7 +119,7 @@ extern char *livebox_service_pkgname(const char *appid);
 extern char *livebox_service_provider_name(const char *lbid);
 
 /*!
- * \brief Get the setup app ID
+ * \brief Get the appId of setup app which is specified by given livebox Id's manifest.
  * \param[in] Livebox AppId
  * \return Setup AppId if exists or NULL
  */
index b72e9d0..afc2a7a 100644 (file)
@@ -1,6 +1,6 @@
 Name: liblivebox-service
 Summary: Service API for gathering installed livebox information.
-Version: 0.3.6
+Version: 0.3.7
 Release: 1
 Group: framework/livebox
 License: Flora License
index 0f18359..2dfaa1d 100644 (file)
@@ -40,6 +40,7 @@
 #include "debug.h"
 #include "livebox-service.h"
 
+#define SAMSUNG_PREFIX "com.samsung."
 #define EAPI __attribute__((visibility("default")))
 #define DEFAULT_TIMEOUT 2.0
 #define MAX_COLUMN 80
@@ -870,7 +871,7 @@ EAPI int livebox_service_touch_effect(const char *pkgid)
        lbid = livebox_service_pkgname(pkgid);
        if (!lbid) {
                ErrPrint("Invalid appid (%s)\n", pkgid);
-               ret = -EINVAL;
+               ret = 0;
                goto out;
        }
 
@@ -883,10 +884,12 @@ EAPI int livebox_service_touch_effect(const char *pkgid)
        }
 
        ret = sqlite3_step(stmt);
-       if (ret == SQLITE_ROW)
+       if (ret == SQLITE_ROW) {
                ret = !!sqlite3_column_int(stmt, 0);
-       else
-               ret = 1;
+       } else {
+               ret = 1; /*!< Default true: In this case the DB is corrupted. */
+               ErrPrint("There is no result\n");
+       }
 
 out:
        sqlite3_reset(stmt);
@@ -916,7 +919,7 @@ EAPI int livebox_service_mouse_event(const char *pkgid)
        lbid = livebox_service_pkgname(pkgid);
        if (!lbid) {
                ErrPrint("Failed to get lbid: %s\n", pkgid);
-               ret = -EINVAL;
+               ret = 0;
                goto out;
        }
 
@@ -929,10 +932,12 @@ EAPI int livebox_service_mouse_event(const char *pkgid)
        }
 
        ret = sqlite3_step(stmt);
-       if (ret == SQLITE_ROW)
+       if (ret == SQLITE_ROW) {
                ret = !!sqlite3_column_int(stmt, 0);
-       else
-               ret = 0;
+       } else {
+               ret = 0; /*!< Default is false, In this case the DB is corrupted */
+               ErrPrint("There is no result.\n");
+       }
 
 out:
        sqlite3_reset(stmt);
@@ -1301,7 +1306,7 @@ EAPI char *livebox_service_provider_name(const char *lbid)
        int stage = 0;
        int seq = 0;
        int idx = 0;
-       char *str = "com.samsung.";
+       char *str = SAMSUNG_PREFIX;
 
        if (!lbid)
                return NULL;
@@ -1371,6 +1376,47 @@ EAPI int livebox_service_is_enabled(const char *lbid)
        */
 }
 
+EAPI int livebox_service_is_primary(const char *lbid)
+{
+       sqlite3_stmt *stmt;
+       sqlite3 *handle;
+       int ret = 0;
+
+       if (!lbid)
+               return 0;
+
+       handle = open_db();
+       if (!handle)
+               return 0;
+
+       ret = sqlite3_prepare_v2(handle, "SELECT prime FROM pkgmap WHERE pkgid = ?", -1, &stmt, NULL);
+       if (ret != SQLITE_OK) {
+               ErrPrint("Error: %s\n", sqlite3_errmsg(handle));
+               close_db(handle);
+               return 0;
+       }
+
+       ret = sqlite3_bind_text(stmt, 1, lbid, -1, NULL);
+       if (ret != SQLITE_OK) {
+               ErrPrint("Error: %s\n", sqlite3_errmsg(handle));
+               goto out;
+       }
+
+       ret = sqlite3_step(stmt);
+       if (ret != SQLITE_ROW) {
+               ErrPrint("Error: %s\n", sqlite3_errmsg(handle));
+               goto out;
+       }
+
+       ret = sqlite3_column_int(stmt, 1);
+
+out:
+       sqlite3_reset(stmt);
+       sqlite3_finalize(stmt);
+       close_db(handle);
+       return ret;
+}
+
 /*!
  * appid == Package ID
  * pkgid == Livebox ID