remove the DB I/O related codes.
authorSung-jae Park <nicesj.park@samsung.com>
Thu, 11 Oct 2012 09:03:44 +0000 (18:03 +0900)
committerSung-jae Park <nicesj.park@samsung.com>
Fri, 12 Oct 2012 02:20:00 +0000 (11:20 +0900)
Move them to livebox-service library.

Change-Id: I7e14b8f933c5778c0cdfb93ba3d87336466ac50a

CMakeLists.txt
debian/changelog
include/io.h [deleted file]
include/livebox.h
packaging/liblivebox-viewer.spec
src/io.c [deleted file]
src/livebox.c

index 7e31fad..ca8db33 100644 (file)
@@ -24,6 +24,7 @@ pkg_check_modules(pkgs REQUIRED
        xext
        sqlite3
        db-util
+       livebox-service
 )
 
 FOREACH(flag ${pkgs_CFLAGS})
@@ -50,7 +51,6 @@ ADD_LIBRARY(${PROJECT_NAME} SHARED
        src/master_rpc.c
        src/client.c
        src/critical_log.c
-       src/io.c
 )
 SET_TARGET_PROPERTIES(${PROJECT_NAME} PROPERTIES SOVERSION ${VERSION_MAJOR})
 SET_TARGET_PROPERTIES(${PROJECT_NAME} PROPERTIES VERSION ${VERSION})
index 287cd7a..6e91e5b 100644 (file)
@@ -1,3 +1,10 @@
+livebox-viewer (0.6.7) unstable; urgency=low
+
+  * Git: slp/pkgs/l/livebox-viewer
+  * Tag: livebox-viewer_0.6.7
+
+ -- Sung-jae Park <nicesj.park@samsung.com>  Fri, 12 Oct 2012 11:19:47 +0900
+
 livebox-viewer (0.6.6) unstable; urgency=low
 
   * Git: slp/pkgs/l/livebox-viewer
diff --git a/include/io.h b/include/io.h
deleted file mode 100644 (file)
index 0adf550..0000000
+++ /dev/null
@@ -1,9 +0,0 @@
-extern int io_init(void);
-extern int io_fini(void);
-extern char *io_lb_pkgname(const char *pkgname);
-extern char *io_app_pkgname(const char *lbpkg);
-extern int io_enumerate_cluster_list(int (*cb)(const char *cluster, void *data), void *data);
-extern int io_enumerate_category_list(const char *cluster, int (*cb)(const char *cluster, const char *category, void *data), void *data);
-extern int io_get_supported_sizes(const char *pkgid, int *cnt, int *w, int *h);
-
-/* End of a file */
index f7221ae..c5a3ba7 100644 (file)
@@ -385,7 +385,6 @@ extern int livebox_get_pdsize(struct livebox *handler, int *w, int *h);
  * \return int
  */
 extern int livebox_get_supported_sizes(struct livebox *handler, int *cnt, int *w, int *h);
-extern int livebox_get_supported_sizes_by_pkgname(const char *pkgname, int *cnt, int *w, int *h);
 
 /*!
  * \brief BUFFER SIZE of the livebox if it is a buffer type
@@ -544,21 +543,6 @@ extern int livebox_subscribe_group(const char *cluster, const char *category);
 extern int livebox_unsubscribe_group(const char *cluster, const char *category);
 
 /*!
- * \brief Get the list of cluster (SYNC Callback)
- * \param[in] cb Callback for getting the name(id) list of the cluster, the callback will be called before return from this function.
- * \return int Number of listed items, or negative value(errno) for error
- */
-extern int livebox_enumerate_cluster_list(int (*cb)(const char *cluster, void *data), void *data);
-
-/*!
- * \brief Get the list of sub-cluster of the "cluster" (SYNC Callback)
- * \param[in] cluster Cluster ID for getting the sub-cluster list
- * \param[in] cb Callback for getting the name(id) list of the category of the "cluster", the callback will be called before return from this function
- * \return int Number of listed items, or negative value(errno) for error
- */
-extern int livebox_enumerate_category_list(const char *cluster, int (*cb)(const char *cluster, const char *category, void *data), void *data);
-
-/*!
  * \brief Refresh the group(cluster/sub-cluser(aka. category))
  * \param[in] cluster Cluster ID
  * \param[in] category Sub-cluster ID
@@ -639,19 +623,6 @@ extern int livebox_set_visibility(struct livebox *handler, enum livebox_visible_
  */
 extern enum livebox_visible_state livebox_visibility(struct livebox *handler);
 
-/*!
- * \brief Get the package name of a livebox.
- * \param[in] pkgname Application package name or the livebox package name
- * \return pkgname livebox package name or NULL
- */
-extern char *livebox_lb_pkgname(const char *pkgname);
-
-/*!
- * \brief Get the application package name of given package name
- * \param[in] pkgname Livebox package name
- * \return pkgname Application package name which including the given livebox package.
- */
-extern char *livebox_app_pkgname(const char *pkgname);
 #ifdef __cplusplus
 }
 #endif
index be72f99..d2da27c 100644 (file)
@@ -1,6 +1,6 @@
 Name: liblivebox-viewer
 Summary: Library for the development of a livebox viewer
-Version: 0.6.6
+Version: 0.6.7
 Release: 1
 Group: main/app
 License: Samsung Proprietary License
@@ -15,6 +15,7 @@ BuildRequires: pkgconfig(x11)
 BuildRequires: pkgconfig(xext)
 BuildRequires: pkgconfig(sqlite3)
 BuildRequires: pkgconfig(db-util)
+BuildRequires: pkgconfig(livebox-service)
 
 %description
 Livebox viewer development library
diff --git a/src/io.c b/src/io.c
deleted file mode 100644 (file)
index 1b17a29..0000000
--- a/src/io.c
+++ /dev/null
@@ -1,289 +0,0 @@
-#include <stdio.h>
-#include <errno.h>
-#include <stdlib.h>
-#include <string.h>
-#include <unistd.h>
-
-#include <sqlite3.h>
-
-#include <dlog.h>
-#include <db-util.h>
-
-#include "dlist.h"
-#include "util.h"
-#include "debug.h"
-#include "io.h"
-#include "livebox.h"
-
-static struct {
-       sqlite3 *handle;
-       const char *dbfile;
-} s_info = {
-       .handle = NULL,
-       .dbfile = "/opt/dbspace/.livebox.db",
-};
-
-int io_init(void)
-{
-       int ret;
-
-       if (s_info.handle)
-               return -EALREADY;
-
-       ret = db_util_open(s_info.dbfile, &s_info.handle, DB_UTIL_REGISTER_HOOK_METHOD);
-       if (ret != SQLITE_OK) {
-               ErrPrint("Failed to open a DB\n");
-               return -EIO;
-       }
-
-       return 0;
-}
-
-int io_fini(void)
-{
-       if (!s_info.handle)
-               return -EINVAL;
-
-       db_util_close(s_info.handle);
-       s_info.handle = NULL;
-       return 0;
-}
-
-char *io_lb_pkgname(const char *appid)
-{
-       sqlite3_stmt *stmt;
-       char *tmp;
-       int ret;
-       char *pkgname;
-
-       if (!s_info.handle) {
-               ErrPrint("IO is not initialized\n");
-               return NULL;
-       }
-
-       pkgname = NULL;
-       ret = sqlite3_prepare_v2(s_info.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(s_info.handle));
-               return NULL;
-       }
-
-       ret = sqlite3_bind_text(stmt, 1, appid, -1, NULL);
-       if (ret != SQLITE_OK) {
-               ErrPrint("Error: %s\n", sqlite3_errmsg(s_info.handle));
-               goto out;
-       }
-
-       ret = sqlite3_bind_text(stmt, 2, appid, -1, NULL);
-       if (ret != SQLITE_OK) {
-               ErrPrint("Error: %s\n", sqlite3_errmsg(s_info.handle));
-               goto out;
-       }
-
-       ret = sqlite3_step(stmt);
-       if (ret != SQLITE_ROW) {
-               ErrPrint("Error: %s\n", sqlite3_errmsg(s_info.handle));
-               goto out;
-       }
-
-       tmp = (char *)sqlite3_column_text(stmt, 0);
-       if (tmp && strlen(tmp)) {
-               pkgname = strdup(tmp);
-               if (!pkgname)
-                       ErrPrint("Heap: %s\n", strerror(errno));
-       }
-
-out:
-       sqlite3_reset(stmt);
-       sqlite3_finalize(stmt);
-       return pkgname;
-}
-
-char *io_app_pkgname(const char *lbpkg)
-{
-       sqlite3_stmt *stmt;
-       char *tmp;
-       int ret;
-       char *pkgname;
-
-       if (!s_info.handle) {
-               ErrPrint("IO is not initialized\n");
-               return NULL;
-       }
-
-       pkgname = NULL;
-       ret = sqlite3_prepare_v2(s_info.handle, "SELECT appid FROM pkgmap WHERE appid = ? OR (pkgid = ? AND prime = 1)", -1, &stmt, NULL);
-       if (ret != SQLITE_OK) {
-               ErrPrint("Error: %s\n", sqlite3_errmsg(s_info.handle));
-               return NULL;
-       }
-
-       ret = sqlite3_bind_text(stmt, 1, lbpkg, -1, NULL);
-       if (ret != SQLITE_OK) {
-               ErrPrint("Error: %s\n", sqlite3_errmsg(s_info.handle));
-               goto out;
-       }
-
-       ret = sqlite3_bind_text(stmt, 2, lbpkg, -1, NULL);
-       if (ret != SQLITE_OK) {
-               ErrPrint("Error: %s\n", sqlite3_errmsg(s_info.handle));
-               goto out;
-       }
-
-       ret = sqlite3_step(stmt);
-       if (ret != SQLITE_ROW) {
-               ErrPrint("Error: %s\n", sqlite3_errmsg(s_info.handle));
-               goto out;
-       }
-
-       tmp = (char *)sqlite3_column_text(stmt, 0);
-       if (tmp && strlen(tmp)) {
-               pkgname = strdup(tmp);
-               if (!pkgname)
-                       ErrPrint("Heap: %s\n", strerror(errno));
-       }
-
-out:
-       sqlite3_reset(stmt);
-       sqlite3_finalize(stmt);
-       return pkgname;
-}
-
-int io_enumerate_cluster_list(int (*cb)(const char *cluster, void *data), void *data)
-{
-       sqlite3_stmt *stmt;
-       const char *cluster;
-       int cnt;
-       int ret;
-
-       if (!s_info.handle)
-               return -EIO;
-
-       cnt = 0;
-       ret = sqlite3_prepare_v2(s_info.handle, "SELECT DISTINCT cluster FROM groupinfo", -1, &stmt, NULL);
-       if (ret != SQLITE_OK) {
-               ErrPrint("Error: %s\n", sqlite3_errmsg(s_info.handle)); 
-               return -EIO;
-       }
-
-       while (sqlite3_step(stmt) == SQLITE_ROW) {
-               cluster = (const char *)sqlite3_column_text(stmt, 0);
-               if (!cluster || !strlen(cluster))
-                       continue;
-
-               if (cb(cluster, data) < 0)
-                       break;
-
-               cnt++;
-       }
-
-       sqlite3_reset(stmt);
-       sqlite3_finalize(stmt);
-       return cnt;
-}
-
-int io_enumerate_category_list(const char *cluster, int (*cb)(const char *cluster, const char *category, void *data), void *data)
-{
-       sqlite3_stmt *stmt;
-       const char *category;
-       int cnt;
-       int ret;
-
-       if (!s_info.handle)
-               return -EIO;
-
-       cnt = 0;
-       ret = sqlite3_prepare_v2(s_info.handle, "SELECT DISTINCT category FROM groupinfo WHERE cluster = ?", -1, &stmt, NULL);
-       if (ret != SQLITE_OK) {
-               ErrPrint("Error: %s\n", sqlite3_errmsg(s_info.handle));
-               return -EIO;
-       }
-
-       while (sqlite3_step(stmt) == SQLITE_ROW) {
-               category = (const char *)sqlite3_column_text(stmt, 0);
-               if (!category || !strlen(category))
-                       continue;
-
-               if (cb(cluster, category, data) < 0)
-                       break;
-
-               cnt++;
-       }
-
-       sqlite3_reset(stmt);
-       sqlite3_finalize(stmt);
-       return cnt;
-}
-
-int io_get_supported_sizes(const char *pkgid, int *cnt, int *w, int *h)
-{
-       sqlite3_stmt *stmt;
-       int size;
-       int ret;
-       int idx;
-
-       if (!s_info.handle) {
-               ErrPrint("IO is not initialized\n");
-               return -EINVAL;
-       }
-
-       ret = sqlite3_prepare_v2(s_info.handle, "SELECT size_type FROM box_size WHERE pkgid = ? ORDER BY size_type ASC", -1, &stmt, NULL);
-       if (ret != SQLITE_OK) {
-               ErrPrint("Error: %s\n", sqlite3_errmsg(s_info.handle));
-               ret = -EIO;
-               goto out;
-       }
-
-       ret = sqlite3_bind_text(stmt, 1, pkgid, -1, NULL);
-       if (ret != SQLITE_OK) {
-               ErrPrint("Error: %s\n", sqlite3_errmsg(s_info.handle));
-               sqlite3_reset(stmt);
-               sqlite3_finalize(stmt);
-               ret = -EIO;
-               goto out;
-       }
-
-       ret = 0;
-       while (sqlite3_step(stmt) == SQLITE_ROW && ret < *cnt) {
-               size = sqlite3_column_int(stmt, 0);
-               switch (size) {
-               case 0x01:
-                       idx = 0;
-                       break;
-               case 0x02:
-                       idx = 1;
-                       break;
-               case 0x04:
-                       idx = 2;
-                       break;
-               case 0x08:
-                       idx = 3;
-                       break;
-               case 0x10:
-                       idx = 4;
-                       break;
-               case 0x20:
-                       idx = 5;
-                       break;
-               default:
-                       ErrPrint("Invalid size type: %d\n", size);
-                       continue;
-               }
-
-               if (w)
-                       w[ret] = SIZE_LIST[idx].w;
-               if (h)
-                       h[ret] = SIZE_LIST[idx].h;
-
-               ret++;
-       }
-
-       *cnt = ret;
-       sqlite3_reset(stmt);
-       sqlite3_finalize(stmt);
-       ret = 0;
-out:
-       return ret;
-}
-
-/* End of a file */
index cad09a9..a7efb74 100644 (file)
@@ -8,6 +8,7 @@
 
 #include <com-core_packet.h>
 #include <packet.h>
+#include <livebox-service.h>
 
 #include "debug.h"
 #include "fb.h"
@@ -18,7 +19,6 @@
 #include "master_rpc.h"
 #include "client.h"
 #include "critical_log.h"
-#include "io.h"
 
 #define EAPI __attribute__((visibility("default")))
 
@@ -31,11 +31,13 @@ static struct info {
        struct dlist *event_list;
        struct dlist *fault_list;
        double event_interval;
+       int init_count;
 } s_info = {
        .livebox_list = NULL,
        .event_list = NULL,
        .fault_list = NULL,
        .event_interval = 0.01f,
+       .init_count = 0,
 };
 
 struct cb_info {
@@ -506,6 +508,11 @@ EAPI int livebox_init(void *disp)
 {
        const char *env;
 
+       if (s_info.init_count > 0) {
+               s_info.init_count++;
+               return 0;
+       }
+
        env = getenv("LIVE_EVENT_INTERVAL");
        if (env && sscanf(env, "%lf", &s_info.event_interval) == 1)
                ErrPrint("Allowed event interval is updated to %lf\n", s_info.event_interval);
@@ -518,18 +525,31 @@ EAPI int livebox_init(void *disp)
                __file_log_fp = fdopen(1, "w+t");
 #endif
        critical_log_init();
-       io_init();
+       livebox_service_init();
        fb_init(disp);
 
        client_init();
+
+       s_info.init_count++;
        return 0;
 }
 
 EAPI int livebox_fini(void)
 {
+       if (s_info.init_count <= 0) {
+               DbgPrint("Didn't initialized\n");
+               return -EINVAL;
+       }
+
+       s_info.init_count--;
+       if (s_info.init_count > 0) {
+               DbgPrint("init count : %d\n", s_info.init_count);
+               return 0;
+       }
+
        client_fini();
        fb_fini();
-       io_fini();
+       livebox_service_fini();
        critical_log_fini();
        return 0;
 }
@@ -538,7 +558,7 @@ static inline char *lb_pkgname(const char *pkgname)
 {
        char *lb;
 
-       lb = io_lb_pkgname(pkgname);
+       lb = livebox_service_pkgname(pkgname);
        if (!lb) {
                if (util_validate_livebox_package(pkgname) == 0)
                        return strdup(pkgname);
@@ -547,19 +567,6 @@ static inline char *lb_pkgname(const char *pkgname)
        return lb;
 }
 
-static inline char *app_pkgname(const char *pkgname)
-{
-       char *app;
-
-       app = io_app_pkgname(pkgname);
-       if (!app) {
-               if (util_validate_livebox_package(pkgname) == 0)
-                       return strdup(app);
-       }
-
-       return app;
-}
-
 /*!
  * Just wrapping the livebox_add_with_size function.
  */
@@ -1292,11 +1299,6 @@ EAPI int livebox_get_supported_sizes(struct livebox *handler, int *cnt, int *w,
        register int i;
        register int j;
 
-       /*!
-        * \TODO:
-        * Replace this with DB Manipulate function
-        */
-
        if (!handler) {
                ErrPrint("Handler is NIL\n");
                return -EINVAL;
@@ -1324,27 +1326,6 @@ EAPI int livebox_get_supported_sizes(struct livebox *handler, int *cnt, int *w,
        return 0;
 }
 
-EAPI int livebox_get_supported_sizes_by_pkgname(const char *pkgname, int *cnt, int *w, int *h)
-{
-       char *lb;
-       int ret;
-
-       if (!pkgname || !cnt)
-               return -EINVAL;
-
-       lb = lb_pkgname(pkgname);
-       if (!lb)
-               return -EINVAL;
-
-       if (*cnt > NR_OF_SIZE_LIST)
-               *cnt = NR_OF_SIZE_LIST;
-
-       ret = io_get_supported_sizes(lb, cnt, w, h);
-       free(lb);
-
-       return ret;
-}
-
 EAPI const char *livebox_pkgname(struct livebox *handler)
 {
        if (!handler) {
@@ -1870,7 +1851,7 @@ EAPI int livebox_is_exists(const char *pkgname)
 {
        char *lb;
 
-       lb = io_lb_pkgname(pkgname);
+       lb = livebox_service_pkgname(pkgname);
        if (!lb)
                return util_validate_livebox_package(pkgname) == 0;
 
@@ -1878,22 +1859,6 @@ EAPI int livebox_is_exists(const char *pkgname)
        return 1;
 }
 
-EAPI char *livebox_lb_pkgname(const char *pkgname)
-{
-       if (!pkgname)
-               return NULL;
-
-       return lb_pkgname(pkgname);
-}
-
-EAPI char *livebox_app_pkgname(const char *pkgname)
-{
-       if (!pkgname)
-               return NULL;
-
-       return app_pkgname(pkgname);
-}
-
 EAPI const char *livebox_content(struct livebox *handler)
 {
        if (!handler) {
@@ -1989,22 +1954,6 @@ EAPI int livebox_unsubscribe_group(const char *cluster, const char *category)
        return master_rpc_request_only(NULL, packet);
 }
 
-EAPI int livebox_enumerate_cluster_list(int (*cb)(const char *cluster, void *data), void *data)
-{
-       if (!cb)
-               return -EINVAL;
-
-       return io_enumerate_cluster_list(cb, data);
-}
-
-EAPI int livebox_enumerate_category_list(const char *cluster, int (*cb)(const char *cluster, const char *category, void *data), void *data)
-{
-       if (!cluster || !cb)
-               return -EINVAL;
-
-       return io_enumerate_category_list(cluster, cb, data);
-}
-
 EAPI int livebox_refresh_group(const char *cluster, const char *category)
 {
        struct packet *packet;