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)
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)
+++ /dev/null
-librua (0.1.0-33) unstable; urgency=low
-
- * Initial Release.
- * Git: pkgs/l/librua
- * Tag: librua_0.1.0-33
-
- -- Jinwoo Nam <jwoo.nam@samsung.com> Sat, 17 Mar 2012 16:52:46 +0900
+++ /dev/null
-Source: librua
-Section: libs
-Priority: optional
-Maintainer: Jinwoo Nam <jwoo.nam@samsung.com>
-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)
+++ /dev/null
-usr/bin
-usr/sbin
+++ /dev/null
-CMakeLists.txt
+++ /dev/null
-@PREFIX@/lib/*.so.*
-/opt/share/*
+++ /dev/null
-#!/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
-
-
+++ /dev/null
-@PREFIX@/include/*
-@PREFIX@/lib/pkgconfig/*.pc
-@PREFIX@/lib/*.so
+++ /dev/null
-#!/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
--- /dev/null
+/*
+ * RUA
+ *
+ * Copyright (c) 2000 - 2012 Samsung Electronics Co., Ltd. All rights reserved.
+ *
+ * Contact: Jayoun Lee <airjany@samsung.com>
+ *
+ * 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 <time.h>
+
+
+//#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__*/
+++ /dev/null
-/*
- * RUA
- *
- * Copyright (c) 2000 - 2012 Samsung Electronics Co., Ltd. All rights reserved.
- *
- * Contact: Jayoun Lee <airjany@samsung.com>
- *
- * 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 <stdio.h>
-#include <stdlib.h>
-#include <string.h>
-
-#include <db-util.h>
-
-#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;
-}
--- /dev/null
+/*
+ * RUA
+ *
+ * Copyright (c) 2000 - 2012 Samsung Electronics Co., Ltd. All rights reserved.
+ *
+ * Contact: Jayoun Lee <airjany@samsung.com>
+ *
+ * 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 <stdio.h>
+#include <sys/time.h>
+
+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;
+}
+
--- /dev/null
+/*
+ * RUA
+ *
+ * Copyright (c) 2000 - 2012 Samsung Electronics Co., Ltd. All rights reserved.
+ *
+ * Contact: Jayoun Lee <airjany@samsung.com>
+ *
+ * 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 <stdio.h>
+#include <stdlib.h>
+#include <string.h>
+
+#include <db-util.h>
+
+#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;
+}
--- /dev/null
+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)
+
--- /dev/null
+/*
+ * RUA
+ *
+ * Copyright (c) 2000 - 2012 Samsung Electronics Co., Ltd. All rights reserved.
+ *
+ * Contact: Jayoun Lee <airjany@samsung.com>
+ *
+ * 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 <stdio.h>
+#include <getopt.h>
+#include <time.h>
+#include <stdlib.h>
+#include <string.h>
+
+#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;
+}
+
+