summaryrefslogtreecommitdiff
path: root/src
diff options
context:
space:
mode:
authorSangyoon Jang <s89.jang@samsung.com>2017-04-12 14:22:38 +0900
committerSangyoon Jang <s89.jang@samsung.com>2017-04-12 14:57:21 +0900
commitaebbb1ed7e0a832e90e20cb9053d2aedce75d422 (patch)
treed7784b13943f7c0678915717855e2aa9951baf85 /src
parent39d0815f8d35e313acd872d1828d9d9e2a6dd71e (diff)
downloadlibrua-aebbb1ed7e0a832e90e20cb9053d2aedce75d422.tar.gz
librua-aebbb1ed7e0a832e90e20cb9053d2aedce75d422.tar.bz2
librua-aebbb1ed7e0a832e90e20cb9053d2aedce75d422.zip
Clean up repository
- Don't export internal headers - Remove declares for internal purpose from public headers - Remove unnecessary includes - Remove explicit dependency of sqlite3 - Add explicit dependency of bundle - Add build dependency to glib-2.0 - Set api visibility at implementation part - Remove unnecessary excutable bits Change-Id: I180582538aad08cae70b29e5d713b86208b408e6 Signed-off-by: Sangyoon Jang <s89.jang@samsung.com>
Diffstat (limited to 'src')
-rw-r--r--src/db-schema.h63
-rw-r--r--src/rua.c77
-rw-r--r--src/rua_dbus.c3
-rw-r--r--src/rua_dbus.h31
-rw-r--r--src/rua_internal.c15
-rw-r--r--src/rua_private.h39
-rw-r--r--[-rwxr-xr-x]src/rua_stat.c22
-rw-r--r--src/rua_stat_internal.c18
-rw-r--r--src/rua_util.c5
-rw-r--r--src/rua_util.h36
10 files changed, 248 insertions, 61 deletions
diff --git a/src/db-schema.h b/src/db-schema.h
new file mode 100644
index 0000000..b2e322b
--- /dev/null
+++ b/src/db-schema.h
@@ -0,0 +1,63 @@
+/*
+ * Copyright (c) 2000 - 2016 Samsung Electronics Co., Ltd. All rights reserved.
+ *
+ * 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 __RUA_SCHEMA_H__
+#define __RUA_SCHEMA_H__
+
+#define CREATE_RUA_HISTORY_TABLE " \
+PRAGMA journal_mode = OFF; \
+\
+CREATE TABLE IF NOT EXISTS rua_history ( \
+ pkg_name TEXT, \
+ app_path TEXT, \
+ arg TEXT, \
+ launch_time INTEGER, \
+ instance_id TEXT, \
+ instance_name TEXT, \
+ icon TEXT, \
+ uri TEXT, \
+ PRIMARY KEY(pkg_name, instance_id) \
+);"
+
+#define CREATE_RUA_STAT_TABLE " \
+PRAGMA journal_mode = OFF; \
+\
+CREATE TABLE if not exists rua_panel_stat ( \
+ caller_panel TEXT NOT NULL, \
+ rua_stat_tag TEXT NOT NULL, \
+ score INTEGER DEFAULT 0, \
+ PRIMARY KEY(rua_stat_tag, caller_panel) \
+);"
+
+/* table index */
+enum {
+ RUA_COL_PKGNAME,
+ RUA_COL_APPPATH,
+ RUA_COL_ARG,
+ RUA_COL_LAUNCHTIME,
+ RUA_COL_INSTANCE_ID,
+ RUA_COL_INSTANCE_NAME,
+ RUA_COL_ICON,
+ RUA_COL_URI,
+};
+
+enum {
+ RUA_STAT_COL_CALLER_PANEL = 0x00,
+ RUA_STAT_COL_RUA_STAT_TAG,
+ RUA_SATA_COL_SCORE
+};
+
+#endif /* __RUA_SCHEMA_H__ */
diff --git a/src/rua.c b/src/rua.c
index 6381870..7fef47a 100644
--- a/src/rua.c
+++ b/src/rua.c
@@ -17,16 +17,19 @@
#include <stdio.h>
#include <stdlib.h>
#include <string.h>
+#include <unistd.h>
+
#include <db-util.h>
#include <aul.h>
+#include <dlog.h>
#include "rua_util.h"
-#include "rua_internal.h"
#include "rua.h"
#include "db-schema.h"
#include "rua_dbus.h"
+#include "rua_private.h"
-int rua_add_history_for_uid(char *pkg_name, char *app_path, char *arg, uid_t uid)
+API int rua_add_history_for_uid(char *pkg_name, char *app_path, char *arg, uid_t uid)
{
int r;
char time_str[32] = {0,};
@@ -58,12 +61,7 @@ int rua_add_history_for_uid(char *pkg_name, char *app_path, char *arg, uid_t uid
return r;
}
-int rua_delete_history_with_pkgname(char *pkg_name)
-{
- return rua_delete_history_with_pkgname_for_uid(pkg_name, getuid());
-}
-
-int rua_delete_history_with_pkgname_for_uid(char *pkg_name, uid_t uid)
+API int rua_delete_history_with_pkgname_for_uid(char *pkg_name, uid_t uid)
{
int r;
bundle *b;
@@ -84,12 +82,12 @@ int rua_delete_history_with_pkgname_for_uid(char *pkg_name, uid_t uid)
return r;
}
-int rua_delete_history_with_apppath(char *app_path)
+API int rua_delete_history_with_pkgname(char *pkg_name)
{
- return rua_delete_history_with_apppath_for_uid(app_path, getuid());
+ return rua_delete_history_with_pkgname_for_uid(pkg_name, getuid());
}
-int rua_delete_history_with_apppath_for_uid(char *app_path, uid_t uid)
+API int rua_delete_history_with_apppath_for_uid(char *app_path, uid_t uid)
{
int r;
bundle *b;
@@ -110,12 +108,12 @@ int rua_delete_history_with_apppath_for_uid(char *app_path, uid_t uid)
return r;
}
-int rua_clear_history(void)
+API int rua_delete_history_with_apppath(char *app_path)
{
- return rua_clear_history_for_uid(getuid());
+ return rua_delete_history_with_apppath_for_uid(app_path, getuid());
}
-int rua_clear_history_for_uid(uid_t uid)
+API int rua_clear_history_for_uid(uid_t uid)
{
int r;
@@ -128,12 +126,12 @@ int rua_clear_history_for_uid(uid_t uid)
return r;
}
-int rua_history_load_db(char ***table, int *nrows, int *ncols)
+API int rua_clear_history(void)
{
- return rua_history_load_db_for_uid(table, nrows, ncols, getuid());
+ return rua_clear_history_for_uid(getuid());
}
-int rua_history_load_db_for_uid(char ***table, int *nrows, int *ncols, uid_t uid)
+API int rua_history_load_db_for_uid(char ***table, int *nrows, int *ncols, uid_t uid)
{
int r;
char query[QUERY_MAXLEN];
@@ -173,12 +171,12 @@ int rua_history_load_db_for_uid(char ***table, int *nrows, int *ncols, uid_t uid
return r;
}
-int rua_register_update_cb(rua_history_update_cb callback, void *user_data, int *callback_id)
+API int rua_history_load_db(char ***table, int *nrows, int *ncols)
{
- return rua_register_update_cb_for_uid(callback, user_data, callback_id, getuid());
+ return rua_history_load_db_for_uid(table, nrows, ncols, getuid());
}
-int rua_register_update_cb_for_uid(rua_history_update_cb callback, void *user_data, int *callback_id, uid_t uid)
+API int rua_register_update_cb_for_uid(rua_history_update_cb callback, void *user_data, int *callback_id, uid_t uid)
{
int r;
@@ -194,12 +192,12 @@ int rua_register_update_cb_for_uid(rua_history_update_cb callback, void *user_da
return r;
}
-int rua_unregister_update_cb(int callback_id)
+API int rua_register_update_cb(rua_history_update_cb callback, void *user_data, int *callback_id)
{
- return rua_unregister_update_cb_for_uid(callback_id, getuid());
+ return rua_register_update_cb_for_uid(callback, user_data, callback_id, getuid());
}
-int rua_unregister_update_cb_for_uid(int callback_id, uid_t uid)
+API int rua_unregister_update_cb_for_uid(int callback_id, uid_t uid)
{
int r;
@@ -212,17 +210,12 @@ int rua_unregister_update_cb_for_uid(int callback_id, uid_t uid)
return r;
}
-int rua_history_unload_db(char ***table)
+API int rua_unregister_update_cb(int callback_id)
{
- if (*table) {
- sqlite3_free_table(*table);
- *table = NULL;
- return 0;
- }
- return -1;
+ return rua_unregister_update_cb_for_uid(callback_id, getuid());
}
-int rua_history_get_rec(struct rua_rec *rec, char **table, int nrows, int ncols,
+API int rua_history_get_rec(struct rua_rec *rec, char **table, int nrows, int ncols,
int row)
{
char **db_result = NULL;
@@ -281,12 +274,17 @@ int rua_history_get_rec(struct rua_rec *rec, char **table, int nrows, int ncols,
return 0;
}
-int rua_is_latest_app(const char *pkg_name)
+API int rua_history_unload_db(char ***table)
{
- return rua_is_latest_app_for_uid(pkg_name, getuid());
+ if (*table) {
+ sqlite3_free_table(*table);
+ *table = NULL;
+ return 0;
+ }
+ return -1;
}
-int rua_is_latest_app_for_uid(const char *pkg_name, uid_t uid)
+API int rua_is_latest_app_for_uid(const char *pkg_name, uid_t uid)
{
int r = -1;
sqlite3_stmt *stmt;
@@ -334,17 +332,22 @@ out:
return r;
}
-int rua_init(void)
+API int rua_is_latest_app(const char *pkg_name)
+{
+ return rua_is_latest_app_for_uid(pkg_name, getuid());
+}
+
+API int rua_init(void)
{
return 0;
}
-int rua_fini(void)
+API int rua_fini(void)
{
return 0;
}
-int rua_delete_history_with_instance_id(const char *app_id,
+API int rua_delete_history_with_instance_id(const char *app_id,
const char *instance_id)
{
int ret;
diff --git a/src/rua_dbus.c b/src/rua_dbus.c
index 132bb4a..1957e48 100644
--- a/src/rua_dbus.c
+++ b/src/rua_dbus.c
@@ -16,13 +16,14 @@
#include <stdio.h>
#include <stdlib.h>
-#include <string.h>
#include <glib.h>
#include <gio/gio.h>
+#include <dlog.h>
#include "rua.h"
#include "rua_dbus.h"
+#include "rua_private.h"
#define RUA_INTERFACE "org.tizen.rua"
#define RUA_PATH "/org/tizen/rua"
diff --git a/src/rua_dbus.h b/src/rua_dbus.h
new file mode 100644
index 0000000..1b53963
--- /dev/null
+++ b/src/rua_dbus.h
@@ -0,0 +1,31 @@
+/*
+ * Copyright (c) 2017 Samsung Electronics Co., Ltd. All rights reserved.
+ *
+ * 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 __RUA_DBUS_H__
+#define __RUA_DBUS_H__
+
+typedef enum
+{
+ ADD,
+ DELETE
+} update_type;
+
+int rua_dbus_send_update_signal(update_type type);
+int rua_dbus_signal_subscribe(rua_history_update_cb callback,
+ void *user_data, int *callback_id);
+int rua_dbus_signal_unsubscribe(int callback_id);
+
+#endif /*__RUA_DBUS_H__*/
diff --git a/src/rua_internal.c b/src/rua_internal.c
index bc17818..4aa2250 100644
--- a/src/rua_internal.c
+++ b/src/rua_internal.c
@@ -14,13 +14,20 @@
* limitations under the License.
*/
+#include <stdio.h>
+#include <sys/types.h>
+#include <unistd.h>
+
#include <db-util.h>
#include <aul.h>
+#include <dlog.h>
+#include <sqlite3.h>
#include "rua_internal.h"
#include "db-schema.h"
#include "rua_util.h"
#include "rua_dbus.h"
+#include "rua_private.h"
static int __exec(sqlite3 *db, char *query)
{
@@ -70,12 +77,12 @@ static sqlite3 *__db_init(uid_t uid)
return db;
}
-int rua_db_delete_history(bundle *b)
+API int rua_db_delete_history(bundle *b)
{
return rua_usr_db_delete_history(b, getuid());
}
-int rua_usr_db_delete_history(bundle *b, uid_t uid)
+API int rua_usr_db_delete_history(bundle *b, uid_t uid)
{
int r;
sqlite3 *db = NULL;
@@ -134,12 +141,12 @@ int rua_usr_db_delete_history(bundle *b, uid_t uid)
return result;
}
-int rua_db_add_history(struct rua_rec *rec)
+API int rua_db_add_history(struct rua_rec *rec)
{
return rua_usr_db_add_history(rec, getuid());
}
-int rua_usr_db_add_history(struct rua_rec *rec, uid_t uid)
+API int rua_usr_db_add_history(struct rua_rec *rec, uid_t uid)
{
int r;
char query[QUERY_MAXLEN];
diff --git a/src/rua_private.h b/src/rua_private.h
new file mode 100644
index 0000000..5dec197
--- /dev/null
+++ b/src/rua_private.h
@@ -0,0 +1,39 @@
+/*
+ * Copyright (c) 2017 Samsung Electronics Co., Ltd. All rights reserved.
+ *
+ * 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 __RUA_PRIVATE_H__
+#define __RUA_PRIVATE_H__
+
+#include <sqlite3.h>
+
+#ifdef LOG_TAG
+#undef LOG_TAG
+#endif
+
+#define LOG_TAG "RUA"
+
+#ifndef API
+#define API __attribute__ ((visibility("default")))
+#endif
+
+#define RUA_DB_NAME ".rua.db"
+#define RUA_HISTORY "rua_history"
+#define RUA_STAT_DB_NAME ".rua_stat.db"
+#define QUERY_MAXLEN 4096
+
+int _rua_stat_init(sqlite3 **db, char *db_name, int flags, uid_t uid);
+
+#endif /*__RUA_H__*/
diff --git a/src/rua_stat.c b/src/rua_stat.c
index f6304f4..1c5e8ed 100755..100644
--- a/src/rua_stat.c
+++ b/src/rua_stat.c
@@ -28,12 +28,12 @@
#include <db-util.h>
#include <aul.h>
+#include <dlog.h>
-#include "rua_stat_internal.h"
-#include "rua_stat.h"
#include "rua_util.h"
+#include "rua_private.h"
-int rua_stat_update_for_uid(char *caller, char *tag, uid_t uid)
+API int rua_stat_update_for_uid(char *caller, char *tag, uid_t uid)
{
int r;
bundle *b = NULL;
@@ -60,14 +60,7 @@ int rua_stat_update_for_uid(char *caller, char *tag, uid_t uid)
return r;
}
-int rua_stat_get_stat_tags(char *caller,
- int (*rua_stat_tag_iter_fn)(const char *rua_stat_tag, void *data),
- void *data)
-{
- return rua_stat_get_stat_tags_for_uid(caller, rua_stat_tag_iter_fn, data, getuid());
-}
-
-int rua_stat_get_stat_tags_for_uid(char *caller,
+API int rua_stat_get_stat_tags_for_uid(char *caller,
int (*rua_stat_tag_iter_fn)(const char *rua_stat_tag, void *data),
void *data, uid_t uid)
{
@@ -119,3 +112,10 @@ out:
return r;
}
+
+API int rua_stat_get_stat_tags(char *caller,
+ int (*rua_stat_tag_iter_fn)(const char *rua_stat_tag, void *data),
+ void *data)
+{
+ return rua_stat_get_stat_tags_for_uid(caller, rua_stat_tag_iter_fn, data, getuid());
+}
diff --git a/src/rua_stat_internal.c b/src/rua_stat_internal.c
index ee68dd1..438117b 100644
--- a/src/rua_stat_internal.c
+++ b/src/rua_stat_internal.c
@@ -20,10 +20,15 @@
#include <string.h>
#include <db-util.h>
+#include <dlog.h>
+#include <sqlite3.h>
#include "db-schema.h"
-#include "rua_stat_internal.h"
#include "rua_util.h"
+#include "rua_private.h"
+
+#define WIN_SCORE 100
+#define LOSE_SCORE_RATE 0.7f
int __rua_stat_insert(sqlite3 *db, char *caller, char *rua_stat_tag)
{
@@ -205,12 +210,7 @@ int _rua_stat_init(sqlite3 **db, char *db_name, int flags, uid_t uid)
return 0;
}
-int rua_stat_db_update(char *caller, char *rua_stat_tag)
-{
- return rua_stat_usr_db_update(caller, rua_stat_tag, getuid());
-}
-
-int rua_stat_usr_db_update(char *caller, char *rua_stat_tag, uid_t uid)
+API int rua_stat_usr_db_update(char *caller, char *rua_stat_tag, uid_t uid)
{
int r;
int affected_rows = 0;
@@ -263,3 +263,7 @@ int rua_stat_usr_db_update(char *caller, char *rua_stat_tag, uid_t uid)
return r;
}
+API int rua_stat_db_update(char *caller, char *rua_stat_tag)
+{
+ return rua_stat_usr_db_update(caller, rua_stat_tag, getuid());
+}
diff --git a/src/rua_util.c b/src/rua_util.c
index a5895b9..09dd080 100644
--- a/src/rua_util.c
+++ b/src/rua_util.c
@@ -25,9 +25,12 @@
#include <sys/stat.h>
#include <db-util.h>
#include <tzplatform_config.h>
+#include <dlog.h>
#include "rua_util.h"
-#include "rua_internal.h"
+#include "rua_private.h"
+
+#define BASE_UID 5000
char *_rua_util_get_db_path(uid_t uid, char *db_name)
{
diff --git a/src/rua_util.h b/src/rua_util.h
new file mode 100644
index 0000000..13efffe
--- /dev/null
+++ b/src/rua_util.h
@@ -0,0 +1,36 @@
+/*
+ * Copyright (c) 2016 Samsung Electronics Co., Ltd. All rights reserved.
+ *
+ * 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_util.h
+ * @brief RUA UTIL API declaration header file.
+ * @author Hyunho Kang (hhstark.kang@samsung.com)
+ * @version 0.1
+ * @history 0.1: RUA UTIL API Declarations, structure declaration
+ */
+
+#ifndef __RUA_UTIL_H__
+#define __RUA_UTIL_H__
+
+#include <sys/types.h>
+
+#include <sqlite3.h>
+
+char *_rua_util_get_db_path(uid_t uid, char *db_name);
+int _rua_util_open_db(sqlite3 **db, int flags, uid_t uid, char *db_name);
+int _rua_util_check_uid(uid_t target_uid);
+
+#endif /*__RUA_UTIL_H__*/