From: Jinwoo Nam Date: Tue, 21 Aug 2012 11:52:12 +0000 (+0900) Subject: tizen 2.0 beta X-Git-Tag: 2.0_alpha^0 X-Git-Url: http://review.tizen.org/git/?a=commitdiff_plain;p=platform%2Fcore%2Fappfw%2Flibrua.git tizen 2.0 beta --- diff --git a/CMakeLists.txt b/CMakeLists.txt index fa96a14..01055ed 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -7,7 +7,10 @@ SET(LIBDIR "\${prefix}/lib") SET(INCLUDEDIR "\${prefix}/include/${PROJECT_NAME}") SET(VERSION 0.1.0) -SET(SRCS rua.c) +SET(SRCS + src/perf-measure.c + src/rua.c +) INCLUDE_DIRECTORIES(${CMAKE_SOURCE_DIR}/include) @@ -39,3 +42,5 @@ INSTALL(FILES ${CMAKE_CURRENT_BINARY_DIR}/${PROJECT_NAME}.pc DESTINATION lib/pkg INSTALL(FILES ${CMAKE_CURRENT_SOURCE_DIR}/include/rua.h DESTINATION include/${PROJECT_NAME}) INSTALL(FILES ${CMAKE_CURRENT_SOURCE_DIR}/data/rua_db.sql DESTINATION /opt/share/) + +#ADD_SUBDIRECTORY(test) diff --git a/debian/changelog b/debian/changelog deleted file mode 100644 index 3c7bc9e..0000000 --- a/debian/changelog +++ /dev/null @@ -1,7 +0,0 @@ -librua (0.1.0-33) unstable; urgency=low - - * Initial Release. - * Git: pkgs/l/librua - * Tag: librua_0.1.0-33 - - -- Jinwoo Nam Sat, 17 Mar 2012 16:52:46 +0900 diff --git a/debian/compat b/debian/compat deleted file mode 100644 index 7ed6ff8..0000000 --- a/debian/compat +++ /dev/null @@ -1 +0,0 @@ -5 diff --git a/debian/control b/debian/control deleted file mode 100644 index dcde5e6..0000000 --- a/debian/control +++ /dev/null @@ -1,24 +0,0 @@ -Source: librua -Section: libs -Priority: optional -Maintainer: Jinwoo Nam -Build-Depends: debhelper (>= 5), libsqlite3-dev, libslp-db-util-dev, sqlite3 -Standards-Version: 3.7.2 - -Package: librua-dev -Section: libs -Architecture: any -Depends: librua-0 (= ${Source-Version}), libsqlite3-dev, libslp-db-util-dev, sqlite3 -Description: recently used applcation library (development) - -Package: librua-0 -Section: libs -Architecture: any -Depends: ${shlibs:Depends}, ${misc:Depends}, sqlite3 -Description: recently used application library (shared object) - -Package: librua-dbg -Section: debug -Architecture: any -Depends: ${shlibs:Depends}, ${misc:Depends}, librua-0 (= ${Source-Version}) -Description: recently used application library (unstripped) diff --git a/debian/dirs b/debian/dirs deleted file mode 100644 index ca882bb..0000000 --- a/debian/dirs +++ /dev/null @@ -1,2 +0,0 @@ -usr/bin -usr/sbin diff --git a/debian/docs b/debian/docs deleted file mode 100644 index a0f0008..0000000 --- a/debian/docs +++ /dev/null @@ -1 +0,0 @@ -CMakeLists.txt diff --git a/debian/librua-0.install.in b/debian/librua-0.install.in deleted file mode 100644 index 3199eb6..0000000 --- a/debian/librua-0.install.in +++ /dev/null @@ -1,2 +0,0 @@ -@PREFIX@/lib/*.so.* -/opt/share/* diff --git a/debian/librua-0.postinst.in b/debian/librua-0.postinst.in deleted file mode 100644 index b658109..0000000 --- a/debian/librua-0.postinst.in +++ /dev/null @@ -1,16 +0,0 @@ -#!/bin/sh - -mkdir -p /opt/dbspace/ -sqlite3 /opt/dbspace/.rua.db < /opt/share/rua_db.sql -rm -rf /opt/share/rua_db.sql - -if [ ${USER} = "root" ] -then - chown root:5000 /opt/dbspace/.rua.db - chown root:5000 /opt/dbspace/.rua.db-journal -fi - -chmod 660 @DATADIR@/dbspace/.rua.db -chmod 660 @DATADIR@/dbspace/.rua.db-journal - - diff --git a/debian/librua-dev.install.in b/debian/librua-dev.install.in deleted file mode 100644 index 6975317..0000000 --- a/debian/librua-dev.install.in +++ /dev/null @@ -1,3 +0,0 @@ -@PREFIX@/include/* -@PREFIX@/lib/pkgconfig/*.pc -@PREFIX@/lib/*.so diff --git a/debian/rules b/debian/rules deleted file mode 100755 index 92570a1..0000000 --- a/debian/rules +++ /dev/null @@ -1,117 +0,0 @@ -#!/usr/bin/make -f -# -*- makefile -*- -# Sample debian/rules that uses debhelper. -# This file was originally written by Joey Hess and Craig Small. -# As a special exception, when this file is copied by dh-make into a -# dh-make output file, you may use that output file without restriction. -# This special exception was added by Craig Small in version 0.37 of dh-make. - -# Uncomment this to turn on verbose mode. -#export DH_VERBOSE=1 - -CFLAGS ?= -Wall -g -LDFLAGS ?= -PREFIX ?= /usr -DATADIR ?= /opt - -ifneq (,$(findstring noopt,$(DEB_BUILD_OPTIONS))) - CFLAGS += -O0 -else - CFLAGS += -O2 -endif - -LDFLAGS += -Wl,--rpath=$(PREFIX)/lib -Wl,--as-needed - -configure: configure-stamp -configure-stamp: - dh_testdir - # Add here commands to configure the package. - CFLAGS="$(CFLAGS)" LDFLAGS="$(LDFLAGS)" cmake . -DCMAKE_INSTALL_PREFIX=$(PREFIX) - - touch configure-stamp - -build: build-stamp - -build-stamp: configure-stamp - dh_testdir - - # Add here commands to compile the package. - $(MAKE) - #docbook-to-man debian/wavplayer.sgml > wavplayer.1 - - for f in `find $(CURDIR)/debian/ -name "*.in"`; do \ - cat $$f > $${f%.in}; \ - sed -i -e "s#@PREFIX@#$(PREFIX)#g" $${f%.in}; \ - sed -i -e "s#@DATADIR@#$(DATADIR)#g" $${f%.in}; \ - done - - - touch $@ - -clean: - dh_testdir - dh_testroot - rm -f build-stamp configure-stamp - - # Add here commands to clean up after the build process. - -$(MAKE) clean - rm -rf CMakeCache.txt - rm -rf CMakeFiles - rm -rf cmake_install.cmake - rm -rf Makefile - rm -rf install_manifest.txt - - for f in `find $(CURDIR)/ -name "*.in"`; do \ - rm -f $${f%.in}; \ - done - - dh_clean - -install: build - dh_testdir - dh_testroot - dh_clean -k - dh_installdirs - - # Add here commands to install the package into debian/wavplayer. - $(MAKE) DESTDIR=$(CURDIR)/debian/tmp install - - mkdir -p $(CURDIR)/debian/tmp/opt/dbspace - -# Build architecture-independent files here. -binary-indep: build install -# We have nothing to do by default. - -# Build architecture-dependent files here. -binary-arch: build install - dh_testdir - dh_testroot - dh_installchangelogs - dh_installdocs - dh_installexamples - dh_install --sourcedir=debian/tmp -# dh_installmenu -# dh_installdebconf -# dh_installlogrotate -# dh_installemacsen -# dh_installpam -# dh_installmime -# dh_python -# dh_installinit -# dh_installcron -# dh_installinfo - dh_installman - dh_link - dh_strip --dbg-package=librua-dbg - dh_compress - dh_fixperms -# dh_perl - dh_makeshlibs - dh_installdeb - dh_shlibdeps - dh_gencontrol - dh_md5sums - dh_builddeb - -binary: binary-indep binary-arch -.PHONY: build clean binary-indep binary-arch binary install configure diff --git a/include/perf-measure.h b/include/perf-measure.h new file mode 100644 index 0000000..49dcc68 --- /dev/null +++ b/include/perf-measure.h @@ -0,0 +1,66 @@ +/* + * RUA + * + * Copyright (c) 2000 - 2012 Samsung Electronics Co., Ltd. All rights reserved. + * + * Contact: Jayoun Lee + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + * + */ + +#ifndef __PERF_MEASURE__ +#define __PERF_MEASURE__ + +#include + + +//#define PERF_MEASURE_ENABLE + +#ifdef __cplusplus +extern "C" { +#endif + +#ifdef PERF_MEASURE_ENABLE + +unsigned int _perf_measure_start(const char *tag, char *func_name, int line); +unsigned int _perf_measure_end(const char *tag, unsigned int ts_start, + char *func_name, int line); + +#define PERF_MEASURE_START(tag) _perf_measure_start(tag, __func__,__LINE__) +#define PERF_MEASURE_END(tag, ts_start) \ + _perf_measure_end(tag, ts_start,__func__, __LINE__) + +#else + +#define PERF_MEASURE_START(tag) (0) +#define PERF_MEASURE_END(tag, ts_start) (0) + +#endif + + + + + + + + + + + + + +#ifdef __cplusplus +} +#endif +#endif /*__PERF_MEASURE__*/ diff --git a/include/rua.h b/include/rua.h old mode 100644 new mode 100755 diff --git a/rua.c b/rua.c deleted file mode 100644 index 67a9245..0000000 --- a/rua.c +++ /dev/null @@ -1,342 +0,0 @@ -/* - * RUA - * - * Copyright (c) 2000 - 2012 Samsung Electronics Co., Ltd. All rights reserved. - * - * Contact: Jayoun Lee - * - * Licensed under the Apache License, Version 2.0 (the "License"); - * you may not use this file except in compliance with the License. - * You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. - * - */ - -/* - * @file rua.c - * @author Noha Park (noha.park@samsung.com) - * @version 0.1 - */ - -#include -#include -#include - -#include - -#include "rua.h" -#include "db-schema.h" - -#define RUA_DB_PATH "/opt/dbspace" -#define RUA_DB_NAME ".rua.db" -#define RUA_HISTORY "rua_history" -#define QUERY_MAXLEN 4096 -#define Q_LATEST \ - "select pkg_name from rua_history " \ - "order by launch_time desc limit 1 " - -static sqlite3 *_db = NULL; - -static int __exec(sqlite3 *db, char *query); -static int __create_table(sqlite3 *db); -static sqlite3 *__db_init(char *root); - -int rua_clear_history(void) -{ - int r; - char query[QUERY_MAXLEN]; - - if (_db == NULL) - return -1; - - snprintf(query, QUERY_MAXLEN, "delete from %s;", RUA_HISTORY); - - r = __exec(_db, query); - - return r; -} - -int rua_delete_history_with_pkgname(char *pkg_name) -{ - int r; - char query[QUERY_MAXLEN]; - - if (_db == NULL) - return -1; - - if (pkg_name == NULL) - return -1; - - snprintf(query, QUERY_MAXLEN, "delete from %s where pkg_name = '%s';", - RUA_HISTORY, pkg_name); - - r = __exec(_db, query); - - return r; -} - -int rua_delete_history_with_apppath(char *app_path) -{ - int r; - char query[QUERY_MAXLEN]; - - if (_db == NULL) - return -1; - - if (app_path == NULL) - return -1; - - snprintf(query, QUERY_MAXLEN, "delete from %s where app_path = '%s';", - RUA_HISTORY, app_path); - - r = __exec(_db, query); - - return r; -} - -int rua_add_history(struct rua_rec *rec) -{ - int r; - int cnt = 0; - char query[QUERY_MAXLEN]; - sqlite3_stmt *stmt; - - if (_db == NULL) - return -1; - - if (rec == NULL) - return -1; - - snprintf(query, QUERY_MAXLEN, - "select count(*) from %s where pkg_name = '%s';", RUA_HISTORY, - rec->pkg_name); - - r = sqlite3_prepare(_db, query, sizeof(query), &stmt, NULL); - if (r != SQLITE_OK) { - return -1; - } - - r = sqlite3_step(stmt); - if (r == SQLITE_ROW) { - cnt = sqlite3_column_int(stmt, 0); - } - sqlite3_finalize(stmt); - - if (cnt == 0) - /* insert */ - snprintf(query, QUERY_MAXLEN, - "insert into %s ( pkg_name, app_path, arg, launch_time ) " - " values ( \"%s\", \"%s\", \"%s\", %d ) ", - RUA_HISTORY, - rec->pkg_name ? rec->pkg_name : "", - rec->app_path ? rec->app_path : "", - rec->arg ? rec->arg : "", time(NULL)); - else - /* update */ - snprintf(query, QUERY_MAXLEN, - "update %s set arg='%s', launch_time='%d' where pkg_name = '%s';", - RUA_HISTORY, - rec->arg ? rec->arg : "", time(NULL), rec->pkg_name); - - r = __exec(_db, query); - if (r == -1) { - printf("[RUA ADD HISTORY ERROR] %s\n", query); - return -1; - } - - return r; -} - -int rua_history_load_db(char ***table, int *nrows, int *ncols) -{ - int r; - char query[QUERY_MAXLEN]; - char *db_err = NULL; - char **db_result = NULL; - - if (table == NULL) - return -1; - if (nrows == NULL) - return -1; - if (ncols == NULL) - return -1; - - snprintf(query, QUERY_MAXLEN, - "select * from %s order by launch_time desc;", RUA_HISTORY); - - r = sqlite3_get_table(_db, query, &db_result, nrows, ncols, &db_err); - - if (r == SQLITE_OK) - *table = db_result; - else - sqlite3_free_table(db_result); - - return r; -} - -int rua_history_unload_db(char ***table) -{ - if (*table) { - sqlite3_free_table(*table); - *table = NULL; - return 0; - } - return -1; -} - -int rua_history_get_rec(struct rua_rec *rec, char **table, int nrows, int ncols, - int row) -{ - char **db_result = NULL; - char *tmp = NULL; - - if (rec == NULL) - return -1; - if (table == NULL) - return -1; - if (row >= nrows) - return -1; - - db_result = table + ((row + 1) * ncols); - - tmp = db_result[RUA_COL_ID]; - if (tmp) { - rec->id = atoi(tmp); - } - - tmp = db_result[RUA_COL_PKGNAME]; - if (tmp) { - rec->pkg_name = tmp; - } - - tmp = db_result[RUA_COL_APPPATH]; - if (tmp) { - rec->app_path = tmp; - } - - tmp = db_result[RUA_COL_ARG]; - if (tmp) { - rec->arg = tmp; - } - - tmp = db_result[RUA_COL_LAUNCHTIME]; - if (tmp) { - rec->launch_time = atoi(tmp); - } - - return 0; -} - -int rua_is_latest_app(const char *pkg_name) -{ - int r; - sqlite3_stmt *stmt; - const unsigned char *ct; - - if (!pkg_name || !_db) - return -1; - - r = sqlite3_prepare(_db, Q_LATEST, sizeof(Q_LATEST), &stmt, NULL); - if (r != SQLITE_OK) { - return -1; - } - - r = sqlite3_step(stmt); - if (r == SQLITE_ROW) { - ct = sqlite3_column_text(stmt, 0); - if (ct == NULL || ct[0] == '\0') { - sqlite3_finalize(stmt); - return -1; - } - - if (strncmp(pkg_name, ct, strlen(pkg_name)) == 0) { - sqlite3_finalize(stmt); - return 0; - } - } - - sqlite3_finalize(stmt); - return -1; -} - -int rua_init(void) -{ - if (_db) { - return 0; - } - - char defname[FILENAME_MAX]; - snprintf(defname, sizeof(defname), "%s/%s", RUA_DB_PATH, RUA_DB_NAME); - _db = __db_init(defname); - - if (_db == NULL) - return -1; - - return 0; -} - -int rua_fini(void) -{ - if (_db) { - db_util_close(_db); - _db = NULL; - } - - return 0; -} - -static int __exec(sqlite3 *db, char *query) -{ - int r; - char *errmsg = NULL; - - if (db == NULL) - return -1; - - r = sqlite3_exec(db, query, NULL, NULL, &errmsg); - - if (r != SQLITE_OK) { - sqlite3_free(errmsg); - return -1; - } - - return 0; -} - -static int __create_table(sqlite3 *db) -{ - int r; - - r = __exec(db, CREATE_RUA_HISTORY_TABLE); - if (r == -1) - return -1; - - return 0; -} - -static sqlite3 *__db_init(char *root) -{ - int r; - sqlite3 *db = NULL; - - r = db_util_open(root, &db, 0); - if (r) { - db_util_close(db); - return NULL; - } - - r = __create_table(db); - if (r) { - db_util_close(db); - return NULL; - } - - return db; -} diff --git a/src/perf-measure.c b/src/perf-measure.c new file mode 100644 index 0000000..5168852 --- /dev/null +++ b/src/perf-measure.c @@ -0,0 +1,63 @@ +/* + * RUA + * + * Copyright (c) 2000 - 2012 Samsung Electronics Co., Ltd. All rights reserved. + * + * Contact: Jayoun Lee + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + * + */ + + +#include +#include + +unsigned int _perf_measure_start(const char *tag, char *func_name, int line) +{ + struct timeval t; + unsigned int ts_start; + + if (!tag) + return 0; + + gettimeofday(&t, NULL); + ts_start = t.tv_sec * 1000000UL + t.tv_usec; + + printf("### START [%s:%d] timestamp(%u)\n", func_name, line, ts_start); + + return ts_start; +} + +unsigned int _perf_measure_end(const char *tag, unsigned int ts_start, + char *func_name, int line) +{ + struct timeval t; + unsigned int ts_end; + unsigned int elapsed_time = 0; + + gettimeofday(&t, NULL); + ts_end = t.tv_sec * 1000000UL + t.tv_usec; + + if (ts_start) + elapsed_time = ts_end - ts_start; + + printf("### END [%s:%d] timestamp(%u)\n", func_name, line, ts_end); + + if (elapsed_time) + printf("### ELAPSED [%s:%d] timestamp(%u)\n", func_name, line, + elapsed_time); + + return ts_end; +} + diff --git a/src/rua.c b/src/rua.c new file mode 100644 index 0000000..9b5ef8b --- /dev/null +++ b/src/rua.c @@ -0,0 +1,356 @@ +/* + * RUA + * + * Copyright (c) 2000 - 2012 Samsung Electronics Co., Ltd. All rights reserved. + * + * Contact: Jayoun Lee + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + * + */ + +/* + * @file rua.c + * @version 0.1 + */ + +#include +#include +#include + +#include + +#include "rua.h" +#include "db-schema.h" +#include "perf-measure.h" + +#define RUA_DB_PATH "/opt/dbspace" +#define RUA_DB_NAME ".rua.db" +#define RUA_HISTORY "rua_history" +#define QUERY_MAXLEN 4096 +#define Q_LATEST \ + "select pkg_name from rua_history " \ + "order by launch_time desc limit 1 " + +static sqlite3 *_db = NULL; + +static int __exec(sqlite3 *db, char *query); +static int __create_table(sqlite3 *db); +static sqlite3 *__db_init(char *root); + +int rua_clear_history(void) +{ + int r; + char query[QUERY_MAXLEN]; + + if (_db == NULL) + return -1; + + snprintf(query, QUERY_MAXLEN, "delete from %s;", RUA_HISTORY); + + r = __exec(_db, query); + + return r; +} + +int rua_delete_history_with_pkgname(char *pkg_name) +{ + int r; + char query[QUERY_MAXLEN]; + + if (_db == NULL) + return -1; + + if (pkg_name == NULL) + return -1; + + snprintf(query, QUERY_MAXLEN, "delete from %s where pkg_name = '%s';", + RUA_HISTORY, pkg_name); + + r = __exec(_db, query); + + return r; +} + +int rua_delete_history_with_apppath(char *app_path) +{ + int r; + char query[QUERY_MAXLEN]; + + if (_db == NULL) + return -1; + + if (app_path == NULL) + return -1; + + snprintf(query, QUERY_MAXLEN, "delete from %s where app_path = '%s';", + RUA_HISTORY, app_path); + + r = __exec(_db, query); + + return r; +} + +int rua_add_history(struct rua_rec *rec) +{ + int r; + int cnt = 0; + char query[QUERY_MAXLEN]; + sqlite3_stmt *stmt; + + unsigned int timestamp; + timestamp = PERF_MEASURE_START("RUA"); + + if (_db == NULL) + return -1; + + if (rec == NULL) + return -1; + + snprintf(query, QUERY_MAXLEN, + "select count(*) from %s where pkg_name = '%s';", RUA_HISTORY, + rec->pkg_name); + + r = sqlite3_prepare(_db, query, sizeof(query), &stmt, NULL); + if (r != SQLITE_OK) { + return -1; + } + + r = sqlite3_step(stmt); + if (r == SQLITE_ROW) { + cnt = sqlite3_column_int(stmt, 0); + } + sqlite3_finalize(stmt); + + if (cnt == 0) + /* insert */ + snprintf(query, QUERY_MAXLEN, + "insert into %s ( pkg_name, app_path, arg, launch_time ) " + " values ( \"%s\", \"%s\", \"%s\", %d ) ", + RUA_HISTORY, + rec->pkg_name ? rec->pkg_name : "", + rec->app_path ? rec->app_path : "", + rec->arg ? rec->arg : "", time(NULL)); + else + /* update */ + snprintf(query, QUERY_MAXLEN, + "update %s set arg='%s', launch_time='%d' where pkg_name = '%s';", + RUA_HISTORY, + rec->arg ? rec->arg : "", time(NULL), rec->pkg_name); + + r = __exec(_db, query); + if (r == -1) { + printf("[RUA ADD HISTORY ERROR] %s\n", query); + return -1; + } + + PERF_MEASURE_END("RUA", timestamp); + + return r; +} + +int rua_history_load_db(char ***table, int *nrows, int *ncols) +{ + int r; + char query[QUERY_MAXLEN]; + char *db_err = NULL; + char **db_result = NULL; + + if (table == NULL) + return -1; + if (nrows == NULL) + return -1; + if (ncols == NULL) + return -1; + + snprintf(query, QUERY_MAXLEN, + "select * from %s order by launch_time desc;", RUA_HISTORY); + + r = sqlite3_get_table(_db, query, &db_result, nrows, ncols, &db_err); + + if (r == SQLITE_OK) + *table = db_result; + else + sqlite3_free_table(db_result); + + return r; +} + +int rua_history_unload_db(char ***table) +{ + if (*table) { + sqlite3_free_table(*table); + *table = NULL; + return 0; + } + return -1; +} + +int rua_history_get_rec(struct rua_rec *rec, char **table, int nrows, int ncols, + int row) +{ + char **db_result = NULL; + char *tmp = NULL; + + if (rec == NULL) + return -1; + if (table == NULL) + return -1; + if (row >= nrows) + return -1; + + db_result = table + ((row + 1) * ncols); + + tmp = db_result[RUA_COL_ID]; + if (tmp) { + rec->id = atoi(tmp); + } + + tmp = db_result[RUA_COL_PKGNAME]; + if (tmp) { + rec->pkg_name = tmp; + } + + tmp = db_result[RUA_COL_APPPATH]; + if (tmp) { + rec->app_path = tmp; + } + + tmp = db_result[RUA_COL_ARG]; + if (tmp) { + rec->arg = tmp; + } + + tmp = db_result[RUA_COL_LAUNCHTIME]; + if (tmp) { + rec->launch_time = atoi(tmp); + } + + return 0; +} + +int rua_is_latest_app(const char *pkg_name) +{ + int r; + sqlite3_stmt *stmt; + const unsigned char *ct; + + if (!pkg_name || !_db) + return -1; + + r = sqlite3_prepare(_db, Q_LATEST, sizeof(Q_LATEST), &stmt, NULL); + if (r != SQLITE_OK) { + return -1; + } + + r = sqlite3_step(stmt); + if (r == SQLITE_ROW) { + ct = sqlite3_column_text(stmt, 0); + if (ct == NULL || ct[0] == '\0') { + sqlite3_finalize(stmt); + return -1; + } + + if (strncmp(pkg_name, ct, strlen(pkg_name)) == 0) { + sqlite3_finalize(stmt); + return 0; + } + } + + sqlite3_finalize(stmt); + return -1; +} + +int rua_init(void) +{ + unsigned int timestamp; + timestamp = PERF_MEASURE_START("RUA"); + + if (_db) { + return 0; + } + + char defname[FILENAME_MAX]; + snprintf(defname, sizeof(defname), "%s/%s", RUA_DB_PATH, RUA_DB_NAME); + _db = __db_init(defname); + + if (_db == NULL) + return -1; + + PERF_MEASURE_END("RUA", timestamp); + + return 0; +} + +int rua_fini(void) +{ + unsigned int timestamp; + timestamp = PERF_MEASURE_START("RUA"); + + if (_db) { + db_util_close(_db); + _db = NULL; + } + + PERF_MEASURE_END("RUA", timestamp); + return 0; +} + +static int __exec(sqlite3 *db, char *query) +{ + int r; + char *errmsg = NULL; + + if (db == NULL) + return -1; + + r = sqlite3_exec(db, query, NULL, NULL, &errmsg); + + if (r != SQLITE_OK) { + sqlite3_free(errmsg); + return -1; + } + + return 0; +} + +static int __create_table(sqlite3 *db) +{ + int r; + + r = __exec(db, CREATE_RUA_HISTORY_TABLE); + if (r == -1) + return -1; + + return 0; +} + +static sqlite3 *__db_init(char *root) +{ + int r; + sqlite3 *db = NULL; + + r = db_util_open(root, &db, 0); + if (r) { + db_util_close(db); + return NULL; + } + + r = __create_table(db); + if (r) { + db_util_close(db); + return NULL; + } + + return db; +} diff --git a/test/CMakeLists.txt b/test/CMakeLists.txt new file mode 100644 index 0000000..3f7d5c8 --- /dev/null +++ b/test/CMakeLists.txt @@ -0,0 +1,22 @@ +SET(RUATEST rua-test) +SET(RUATEST_SRCS rua-test.c) +SET(RUATEST_VENDOR samsung) +SET(RUATEST_DIR /usr/bin) +SET(RUATEST_LOCALEDIR /usr/share/locale) + +INCLUDE_DIRECTORIES(${CMAKE_CURRENT_SOURCE_DIR}) +PKG_CHECK_MODULES(RUATEST_PKGS REQUIRED + ) + +FOREACH(flag ${RUATEST_PKGS_CFLAGS}) + SET(RUATEST_CFLAGS "${RUATEST_CFLAGS} ${flag}") +ENDFOREACH(flag) + +SET(RUATEST_CFLAGS, "${RUATEST_CFLAGS} -DPREFIX=\"${CMAKE_INSTALL_PREFIX}\"") + +ADD_EXECUTABLE(${RUATEST} ${RUATEST_SRCS}) +SET_TARGET_PROPERTIES(${RUATEST} PROPERTIES COMPILE_FLAGS "${RUATEST_CFLAGS}") +TARGET_LINK_LIBRARIES(${RUATEST} ${PROJECT_NAME} ${RUATEST_PKGS_LDFLAGS}) + +INSTALL(TARGETS ${RUATEST} DESTINATION bin) + diff --git a/test/rua-test.c b/test/rua-test.c new file mode 100644 index 0000000..6fdd2e0 --- /dev/null +++ b/test/rua-test.c @@ -0,0 +1,65 @@ +/* + * RUA + * + * Copyright (c) 2000 - 2012 Samsung Electronics Co., Ltd. All rights reserved. + * + * Contact: Jayoun Lee + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + * + */ + +#include +#include +#include +#include +#include + +#include "rua.h" + +int __add_history(char *pkgname) +{ + int ret = 0; + struct rua_rec rec; + char apppath[FILENAME_MAX] = ""; + + snprintf(apppath, "/opt/apps/%s", pkgname, FILENAME_MAX); + memset(&rec, 0, sizeof(rec)); + rec.pkg_name = pkgname; + rec.app_path = apppath; + + ret = rua_init(); + if (ret) { + fprintf(stderr, "error rua_init()\n"); + return -1; + } + + ret = rua_add_history(&rec); + + rua_fini(); + + return ret; + +} + +int main(int argc, char* argv[]) +{ + int ret = 0; + + if (argc != 2) + return 0; + ret = __add_history(argv[1]); + return 0; +} + +