Add change_period API
authorSung-jae Park <nicesj.park@samsung.com>
Wed, 27 Feb 2013 02:55:40 +0000 (02:55 +0000)
committerSung-jae Park <nicesj.park@samsung.com>
Wed, 27 Feb 2013 02:55:40 +0000 (02:55 +0000)
Update trigger_update API

Change-Id: Iad14a4e4c8d9963ae7836c55e38e1739add1540a

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

index 864eab9..3dfdcdd 100644 (file)
@@ -38,10 +38,6 @@ SET(CMAKE_C_FLAGS "${CMAKE_C_FLAGS} ${EXTRA_CFLAGS}")
 ADD_DEFINITIONS("-DPREFIX=\"${PREFIX}\"")
 ADD_DEFINITIONS("-DLOG_TAG=\"LIVEBOX_SERVICE\"")
 ADD_DEFINITIONS("-DNDEBUG")
-ADD_DEFINITIONS("-DMASTER_PKGNAME=\"org.tizen.data-provider-master\"")
-ADD_DEFINITIONS("-DINFO_SOCKET=\"/opt/usr/share/live_magazine/.live.socket\"")
-ADD_DEFINITIONS("-DCLIENT_SOCKET=\"/opt/usr/share/live_magazine/.client.socket\"")
-ADD_DEFINITIONS("-DSLAVE_SOCKET=\"/opt/usr/share/live_magazine/.slave.socket\"")
 ADD_DEFINITIONS("-DSERVICE_SOCKET=\"/opt/usr/share/live_magazine/.service.socket\"")
 
 ADD_LIBRARY(${PROJECT_NAME} SHARED
index c5b5acc..89ae687 100644 (file)
@@ -38,6 +38,7 @@ enum livebox_size_type {
 };
 
 /*!
+ * \brief
  * \param[in] type
  * \param[out] width
  * \param[out] height
@@ -46,6 +47,7 @@ enum livebox_size_type {
 extern int livebox_service_get_size(int type, int *width, int *height);
 
 /*!
+ * \brief
  * \param[in] width
  * \param[in] height
  * \return Type of a livebox
@@ -53,20 +55,36 @@ extern int livebox_service_get_size(int type, int *width, int *height);
 extern int livebox_service_size_type(int width, int height);
 
 /*!
+ * \brief
  * \param[in] pkgid Livebox's appid
  * \return true(1) / false(0)
  */
 extern int livebox_service_mouse_event(const char *pkgid);
 
 /*!
+ * \brief
  * \param[in] pkgid Livebox's appid
  * \return true(1) / false(0)
  */
 extern int livebox_service_touch_effect(const char *pkgid);
 
 /*!
+ * \brief
+ * \param[in] pkgname Livebox package name
+ * \param[in] id Set NULL if you don't know what the Id is.
+ * \param[in] cluster Cluster name. Default NULL
+ * \param[in] category Category name, Default NULL
+ * \param[in] force 1 if you want to update your livebox even if the provider is paused or 0. 0 is default
+ */
+extern int livebox_service_trigger_update(const char *pkgname, const char *id, const char *cluster, const char *category, int force);
+
+/*!
+ * \brief Change the period of given livebox instance
+ * \param[in] pkgname Livebox package name
+ * \param[in] id Livebox instance id
+ * \param[in] period New update period in sec
  */
-extern int livebox_service_trigger_update(const char *pkgname, const char *cluster, const char *category);
+extern int livebox_service_change_period(const char *pkgname, const char *id, double period);
 
 /*!
  * \brief Synchronous package list getter
index d19ae30..b72e9d0 100644 (file)
@@ -1,6 +1,6 @@
 Name: liblivebox-service
 Summary: Service API for gathering installed livebox information.
-Version: 0.3.5
+Version: 0.3.6
 Release: 1
 Group: framework/livebox
 License: Flora License
index cfb092a..0f18359 100644 (file)
@@ -358,7 +358,44 @@ static inline int convert_size_from_type(enum livebox_size_type type, int *width
        return 0;
 }
 
-EAPI int livebox_service_trigger_update(const char *pkgname, const char *cluster, const char *category)
+EAPI int livebox_service_change_period(const char *pkgname, const char *id, double period)
+{
+       struct packet *packet;
+       struct packet *result;
+       int ret;
+
+       if (!pkgname || !id || period < 0.0f) {
+               ErrPrint("Invalid argument\n");
+               return -EINVAL;
+       }
+
+       if (!id)
+               id = "";
+
+       packet = packet_create("service_change_period", "ssd", pkgname, id, period);
+       if (!packet) {
+               ErrPrint("Failed to create a packet for period changing\n");
+               return -EFAULT;
+       }
+
+       result = com_core_packet_oneshot_send(SERVICE_SOCKET, packet, DEFAULT_TIMEOUT);
+       packet_unref(packet);
+
+       if (result) {
+               if (packet_get(result, "i", &ret) != 1) {
+                       ErrPrint("Failed to parse a result packet\n");
+                       ret = -EINVAL;
+               }
+               packet_unref(result);
+       } else {
+               ErrPrint("Failed to get result packet\n");
+               ret = -EFAULT;
+       }
+
+       return ret;
+}
+
+EAPI int livebox_service_trigger_update(const char *pkgname, const char *id, const char *cluster, const char *category, int force)
 {
        struct packet *packet;
        struct packet *result;
@@ -369,18 +406,21 @@ EAPI int livebox_service_trigger_update(const char *pkgname, const char *cluster
                return -EINVAL;
        }
 
-       if (access("/tmp/.live.paused", R_OK) == 0) {
+       if (!force && access("/tmp/.live.paused", R_OK) == 0) {
                DbgPrint("Provider is paused\n");
                return -ECANCELED;
        }
 
+       if (!id)
+               id = "";
+
        if (!cluster)
                cluster = "user,created";
 
        if (!category)
                category = "default";
 
-       packet = packet_create("service_update", "sss", pkgname, cluster, category);
+       packet = packet_create("service_update", "ssss", pkgname, id, cluster, category);
        if (!packet) {
                ErrPrint("Failed to create a packet for service_update\n");
                return -EFAULT;
@@ -735,7 +775,7 @@ EAPI int livebox_service_nodisplay(const char *pkgid)
        }
 
        ret = sqlite3_step(stmt);
-       if (ret == SQLITE_ROW) 
+       if (ret == SQLITE_ROW)
                ret = !!sqlite3_column_int(stmt, 0);
        else
                ret = 0;
@@ -747,15 +787,72 @@ out:
        return ret;
 }
 
-EAPI int livebox_service_touch_effect(const char *pkgid)
+static inline char *get_lb_pkgname_by_appid(const char *appid)
 {
        sqlite3_stmt *stmt;
+       char *pkgid;
+       char *tmp;
        sqlite3 *handle;
        int ret;
 
+       if (!appid)
+               return NULL;
+
+       pkgid = NULL;
        handle = open_db();
        if (!handle)
+               return NULL;
+
+       ret = sqlite3_prepare_v2(handle, "SELECT pkgid FROM pkgmap WHERE (appid = ? AND prime = 1) OR pkgid = ?", -1, &stmt, NULL);
+       if (ret != SQLITE_OK) {
+               ErrPrint("Error: %s\n", sqlite3_errmsg(handle));
+               close_db(handle);
+               return NULL;
+       }
+
+       ret = sqlite3_bind_text(stmt, 1, appid, -1, NULL);
+       if (ret != SQLITE_OK) {
+               ErrPrint("Error: %s\n", sqlite3_errmsg(handle));
+               goto out;
+       }
+
+       ret = sqlite3_bind_text(stmt, 2, appid, -1, NULL);
+       if (ret != SQLITE_OK) {
+               ErrPrint("Error: %s\n", sqlite3_errmsg(handle));
+               goto out;
+       }
+
+       if (sqlite3_step(stmt) != SQLITE_ROW) {
+               ErrPrint("Error: %s (has no record? - %s)\n", sqlite3_errmsg(handle), appid);
+               goto out;
+       }
+
+       tmp = (char *)sqlite3_column_text(stmt, 0);
+       if (tmp && strlen(tmp)) {
+               pkgid = strdup(tmp);
+               if (!pkgid)
+                       ErrPrint("Heap: %s\n", strerror(errno));
+       }
+
+out:
+       sqlite3_reset(stmt);
+       sqlite3_finalize(stmt);
+       close_db(handle);
+       return pkgid;
+}
+
+EAPI int livebox_service_touch_effect(const char *pkgid)
+{
+       char *lbid;
+       sqlite3_stmt *stmt;
+       sqlite3 *handle;
+       int ret;
+
+       handle = open_db();
+       if (!handle) {
+               ErrPrint("Unable to open a DB\n");
                return 0;
+       }
 
        ret = sqlite3_prepare_v2(handle, "SELECT touch_effect FROM client WHERE pkgid = ?", -1, &stmt, NULL);
        if (ret != SQLITE_OK) {
@@ -764,7 +861,21 @@ EAPI int livebox_service_touch_effect(const char *pkgid)
                return 0;
        }
 
-       ret = sqlite3_bind_text(stmt, 1, pkgid, -1, NULL);
+       /*!
+        * \note
+        * This function will validate the "pkgid"
+        * call the exported API in the exported API is not recomended
+        * but... I used.
+        */
+       lbid = livebox_service_pkgname(pkgid);
+       if (!lbid) {
+               ErrPrint("Invalid appid (%s)\n", pkgid);
+               ret = -EINVAL;
+               goto out;
+       }
+
+       ret = sqlite3_bind_text(stmt, 1, lbid, -1, NULL);
+       free(lbid);
        if (ret != SQLITE_OK) {
                ErrPrint("Error: %s\n", sqlite3_errmsg(handle));
                ret = 0;
@@ -788,6 +899,7 @@ EAPI int livebox_service_mouse_event(const char *pkgid)
 {
        sqlite3_stmt *stmt;
        sqlite3 *handle;
+       char *lbid;
        int ret;
 
        handle = open_db();
@@ -801,7 +913,15 @@ EAPI int livebox_service_mouse_event(const char *pkgid)
                return 0;
        }
 
-       ret = sqlite3_bind_text(stmt, 1, pkgid, -1, NULL);
+       lbid = livebox_service_pkgname(pkgid);
+       if (!lbid) {
+               ErrPrint("Failed to get lbid: %s\n", pkgid);
+               ret = -EINVAL;
+               goto out;
+       }
+
+       ret = sqlite3_bind_text(stmt, 1, lbid, -1, NULL);
+       free(lbid);
        if (ret != SQLITE_OK) {
                ErrPrint("Error: %s\n", sqlite3_errmsg(handle));
                ret = 0;
@@ -1135,60 +1255,6 @@ out:
        return libexec;
 }
 
-static inline char *get_lb_pkgname_by_appid(const char *appid)
-{
-       sqlite3_stmt *stmt;
-       char *pkgid;
-       char *tmp;
-       sqlite3 *handle;
-       int ret;
-
-       if (!appid)
-               return NULL;
-
-       pkgid = NULL;
-       handle = open_db();
-       if (!handle)
-               return NULL;
-
-       ret = sqlite3_prepare_v2(handle, "SELECT pkgid FROM pkgmap WHERE (appid = ? AND prime = 1) OR pkgid = ?", -1, &stmt, NULL);
-       if (ret != SQLITE_OK) {
-               ErrPrint("Error: %s\n", sqlite3_errmsg(handle));
-               close_db(handle);
-               return NULL;
-       }
-
-       ret = sqlite3_bind_text(stmt, 1, appid, -1, NULL);
-       if (ret != SQLITE_OK) {
-               ErrPrint("Error: %s\n", sqlite3_errmsg(handle));
-               goto out;
-       }
-
-       ret = sqlite3_bind_text(stmt, 2, appid, -1, NULL);
-       if (ret != SQLITE_OK) {
-               ErrPrint("Error: %s\n", sqlite3_errmsg(handle));
-               goto out;
-       }
-
-       if (sqlite3_step(stmt) != SQLITE_ROW) {
-               ErrPrint("Error: %s (has no record? - %s)\n", sqlite3_errmsg(handle), appid);
-               goto out;
-       }
-
-       tmp = (char *)sqlite3_column_text(stmt, 0);
-       if (tmp && strlen(tmp)) {
-               pkgid = strdup(tmp);
-               if (!pkgid)
-                       ErrPrint("Heap: %s\n", strerror(errno));
-       }
-
-out:
-       sqlite3_reset(stmt);
-       sqlite3_finalize(stmt);
-       close_db(handle);
-       return pkgid;
-}
-
 EAPI char *livebox_service_pkgname(const char *appid)
 {
        char *lb_pkgname;