summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorhyunho kang <hhstark.kang@samsung.com>2015-12-11 16:13:15 +0900
committerHyunho Kang <hhstark.kang@samsung.com>2016-01-03 16:40:29 -0800
commitd2e1ea21f9faf51ca35ce4bb606deadbe7ab386a (patch)
tree7fc0b7d312f0c5360c49a630cb5bff9b2fdb5efc
parent790035cf2e93231f2b709d397a82d90f648edede (diff)
downloadlibrua-d2e1ea21f9faf51ca35ce4bb606deadbe7ab386a.tar.gz
librua-d2e1ea21f9faf51ca35ce4bb606deadbe7ab386a.tar.bz2
librua-d2e1ea21f9faf51ca35ce4bb606deadbe7ab386a.zip
- Access rua db indirectly using aul_svc_delete_rua_history. Change-Id: I5f347ee01b477135d40304b64009e7d78436d6e1 Signed-off-by: hyunho kang <hhstark.kang@samsung.com>
-rw-r--r--CMakeLists.txt2
-rwxr-xr-xinclude/rua.h11
-rw-r--r--packaging/librua.spec2
-rw-r--r--src/rua.c92
-rw-r--r--test/rua-test.c2
5 files changed, 69 insertions, 40 deletions
diff --git a/CMakeLists.txt b/CMakeLists.txt
index 4ea97f8..c8be007 100644
--- a/CMakeLists.txt
+++ b/CMakeLists.txt
@@ -15,7 +15,7 @@ SET(SRCS
INCLUDE_DIRECTORIES(${CMAKE_SOURCE_DIR}/include)
INCLUDE(FindPkgConfig)
-pkg_check_modules(pkgs REQUIRED sqlite3 db-util libtzplatform-config)
+pkg_check_modules(pkgs REQUIRED sqlite3 db-util libtzplatform-config bundle aul)
FOREACH(flag ${pkgs_CFLAGS})
SET(EXTRA_CFLAGS "${EXTRA_CFLAGS} ${flag}")
diff --git a/include/rua.h b/include/rua.h
index 2bd8f51..710d471 100755
--- a/include/rua.h
+++ b/include/rua.h
@@ -31,6 +31,7 @@
#define __RUA_H__
#include <sqlite3.h>
+#include <bundle.h>
#include <time.h>
#ifndef API
@@ -67,6 +68,16 @@ struct rua_rec {
time_t launch_time; /**< application launching time */
};
+
+
+/**
+ * @brief Delete history from DB
+ * @return 0 on success, otherwise a nagative error value
+ * @retval 0 on successful
+ * @retval -1 on failed
+ */
+API int rua_delete_history_from_db(bundle *b);
+
/**
* @brief Clear history
* @return 0 on success, otherwise a nagative error value
diff --git a/packaging/librua.spec b/packaging/librua.spec
index f2545cf..1234963 100644
--- a/packaging/librua.spec
+++ b/packaging/librua.spec
@@ -8,6 +8,8 @@ Source0: librua-%{version}.tar.gz
Source1001: librua.manifest
BuildRequires: cmake
BuildRequires: sqlite3
+BuildRequires: pkgconfig(bundle)
+BuildRequires: pkgconfig(aul)
BuildRequires: pkgconfig(db-util)
BuildRequires: pkgconfig(sqlite3)
BuildRequires: pkgconfig(libtzplatform-config)
diff --git a/src/rua.c b/src/rua.c
index 2c0c0ad..e0d93e2 100644
--- a/src/rua.c
+++ b/src/rua.c
@@ -27,8 +27,8 @@
#include <stdio.h>
#include <stdlib.h>
#include <string.h>
-
#include <db-util.h>
+#include <aul.h>
/* For multi-user support */
#include <tzplatform_config.h>
@@ -55,11 +55,16 @@ static int __exec(sqlite3 *db, char *query);
static int __create_table(sqlite3 *db);
static sqlite3 *__db_init();
-int rua_clear_history(void)
+int rua_delete_history_from_db(bundle *b)
{
int r;
- char query[QUERY_MAXLEN];
sqlite3 *db = NULL;
+ char query[QUERY_MAXLEN];
+
+ char *pkg_name = NULL;
+ char *app_path = NULL;
+ char *errmsg = NULL;
+ int result = 0;
db = __db_init();
if (db == NULL) {
@@ -67,61 +72,72 @@ int rua_clear_history(void)
return -1;
}
- snprintf(query, QUERY_MAXLEN, "delete from %s;", RUA_HISTORY);
-
- r = __exec(db, query);
- db_util_close(db);
- return r;
-}
+ if (b != NULL) {
+ bundle_get_str(b, AUL_K_RUA_PKGNAME, &pkg_name);
+ bundle_get_str(b, AUL_K_RUA_APPPATH, &app_path);
+ }
-int rua_delete_history_with_pkgname(char *pkg_name)
-{
- int r;
- char query[QUERY_MAXLEN];
+ if (pkg_name != NULL)
+ snprintf(query, QUERY_MAXLEN, "delete from rua_history where pkg_name = '%s';", pkg_name);
+ else if (app_path != NULL)
+ snprintf(query, QUERY_MAXLEN, "delete from rua_history where app_path = '%s';", app_path);
+ else
+ snprintf(query, QUERY_MAXLEN, "delete from rua_history;");
- sqlite3 *db = NULL;
+ LOGI("rua_delete_history_from_db : %s", query);
+ r = sqlite3_exec(db, query, NULL, NULL, &errmsg);
- db = __db_init();
- if (db == NULL) {
- LOGE("Error db null");
- return -1;
+ if (r != SQLITE_OK) {
+ LOGE("fail to exec delete query %s : %s", query, errmsg);
+ sqlite3_free(errmsg);
+ result = -1;
}
- if (pkg_name == NULL) {
+ if (db != NULL)
db_util_close(db);
- return -1;
- }
- snprintf(query, QUERY_MAXLEN, "delete from %s where pkg_name = '%s';",
- RUA_HISTORY, pkg_name);
+ return result;
- r = __exec(db, query);
- db_util_close(db);
- return r;
}
-int rua_delete_history_with_apppath(char *app_path)
+int rua_clear_history(void)
{
int r;
- char query[QUERY_MAXLEN];
- sqlite3 *db = NULL;
+ r = aul_delete_rua_history(NULL);
+ LOGI("rua_clear_history result : %d ", r);
+ return r;
+}
- db = __db_init();
- if (db == NULL) {
- LOGE("Error db null");
+int rua_delete_history_with_pkgname(char *pkg_name)
+{
+ int r;
+ bundle *b = bundle_create();
+ if (b == NULL) {
+ LOGE("bundle_create fail out of memory.");
return -1;
}
- if (app_path == NULL) {
- db_util_close(db);
+ bundle_add_str(b, AUL_K_RUA_PKGNAME, pkg_name);
+ r = aul_delete_rua_history(b);
+ LOGI("rua_delete_history_with_pkgname result : %d ", r);
+ bundle_free(b);
+ return r;
+}
+
+int rua_delete_history_with_apppath(char *app_path)
+{
+ int r;
+ bundle *b = bundle_create();
+ if (b == NULL) {
+ LOGE("bundle_create fail out of memory.");
return -1;
}
- snprintf(query, QUERY_MAXLEN, "delete from %s where app_path = '%s';",
- RUA_HISTORY, app_path);
+ bundle_add_str(b, AUL_K_RUA_APPPATH, app_path);
+ r = aul_delete_rua_history(b);
+ LOGI("rua_delete_history_with_apppath result : %d ", r);
+ bundle_free(b);
- r = __exec(db, query);
- db_util_close(db);
return r;
}
diff --git a/test/rua-test.c b/test/rua-test.c
index 03a7032..bfd72c7 100644
--- a/test/rua-test.c
+++ b/test/rua-test.c
@@ -60,5 +60,5 @@ int main(int argc, char* argv[])
if (argc != 2)
return 0;
ret = __add_history(argv[1]);
- return 0;
+ return ret;
}