#include <aul.h>
#include <aul_svc.h>
#include <bundle.h>
-#include <db-util.h>
#include <vconf.h>
#include <vconf-keys.h>
#include <dlfcn.h>
#include <notification_ipc.h>
#include <notification_internal.h>
#include <system_info.h>
+#include <sqlite3.h>
#include <glib.h>
#if !GLIB_CHECK_VERSION(2, 31, 0)
void on_bus_name_owner_changed(GDBusConnection *connection, const gchar *sender_name, const gchar *object_path,
const gchar *interface_name, const gchar *signal_name, GVariant *parameters, gpointer user_data);
bool __get_caller_unique_name(int pid, char *unique_name, bool *is_app, uid_t uid);
+static int __db_busyhandler(void *pData, int count);
#ifdef _APPFW_FEATURE_ALARM_MANAGER_MODULE_LOG
static void __initialize_module_log(void);
current_tm.tm_year + 1900, current_tm.tm_mon + 1, current_tm.tm_mday, current_tm.tm_hour, current_tm.tm_min, current_tm.tm_sec);
db_path = strdup(db_path_tmp);
- if (db_util_open(db_path, &alarmmgr_tool_db, DB_UTIL_REGISTER_HOOK_METHOD) != SQLITE_OK) {
- ALARM_MGR_EXCEPTION_PRINT("Opening [%s] failed", db_path);
+ if (sqlite3_open(db_path, &alarmmgr_tool_db) != SQLITE_OK) {
+ ALARM_MGR_EXCEPTION_PRINT("Failed to open [%s]", db_path);
return_code = ERR_ALARM_SYSTEM_FAIL;
- g_dbus_method_invocation_return_value(invoc, g_variant_new("(si)", db_path, return_code));
- free(db_path);
- return true;
+ goto done;
+ }
+ /* Register busy handler */
+ if (sqlite3_busy_handler(alarmmgr_tool_db, __db_busyhandler, NULL) != SQLITE_OK) {
+ ALARM_MGR_EXCEPTION_PRINT("Failed to register the busy handler");
+ return_code = ERR_ALARM_SYSTEM_FAIL;
+ goto done;
}
/* Drop a table */
/* Create a table if it does not exist */
if (sqlite3_exec(alarmmgr_tool_db, query_for_creating_table, NULL, NULL, &error_message) != SQLITE_OK) {
ALARM_MGR_EXCEPTION_PRINT("Creating the table is failed. error message = %s", error_message);
- sqlite3_close(alarmmgr_tool_db);
return_code = ERR_ALARM_SYSTEM_FAIL;
- g_dbus_method_invocation_return_value(invoc, g_variant_new("(si)", db_path, return_code));
- free(db_path);
- return true;
+ goto done;
}
/* Get information of all alarms and save those into the DB. */
sqlite3_free(query);
}
-
- sqlite3_close(alarmmgr_tool_db);
-
return_code = ALARMMGR_RESULT_SUCCESS;
+
+done:
g_dbus_method_invocation_return_value(invoc, g_variant_new("(si)", db_path, return_code));
- free(db_path);
+ if (alarmmgr_tool_db)
+ sqlite3_close(alarmmgr_tool_db);
+ if (db_path)
+ free(db_path);
return true;
}
}
#define ALARMMGR_DB_FILE tzplatform_mkpath(TZ_SYS_DB, ".alarmmgr.db")
-#define QUERY_CREATE_TABLE_ALARMMGR "create table alarmmgr \
+#define QUERY_CREATE_TABLE_ALARMMGR "create table if not exists alarmmgr \
(alarm_id integer primary key,\
start integer,\
end integer,\
dst_service_name_mod text \
)"
+static int __db_busyhandler(void *pData, int count) {
+ if (5 - count > 0) {
+ struct timespec time = {
+ .tv_sec = 0,
+ .tv_nsec = (count + 1) * 100 * 1000 * 1000
+ };
+ nanosleep(&time, NULL);
+ ALARM_MGR_LOG_PRINT("alarmmgr_db: busy handler called. count: %d", count + 1);
+ return 1;
+ } else {
+ ALARM_MGR_LOG_PRINT("alarmmgr_db: busy handler will return SQLITE_BUSY error");
+ return 0;
+ }
+}
+
static bool __initialize_db()
{
char *error_message = NULL;
- int ret;
-
- if (access(ALARMMGR_DB_FILE, F_OK) == 0) {
- ret = db_util_open(ALARMMGR_DB_FILE, &alarmmgr_db, DB_UTIL_REGISTER_HOOK_METHOD);
- if (ret != SQLITE_OK) {
- ALARM_MGR_EXCEPTION_PRINT("====>>>> connect menu_db [%s] failed", ALARMMGR_DB_FILE);
- return false;
- }
-
- return true;
+ /* Create or Open the DB file */
+ if (sqlite3_open(ALARMMGR_DB_FILE, &alarmmgr_db) != SQLITE_OK) {
+ ALARM_MGR_EXCEPTION_PRINT("Failed to open [%s]. error: %s", ALARMMGR_DB_FILE, sqlite3_errmsg(alarmmgr_db));
+ return false;
}
-
- ret = db_util_open(ALARMMGR_DB_FILE, &alarmmgr_db, DB_UTIL_REGISTER_HOOK_METHOD);
-
- if (ret != SQLITE_OK) {
- ALARM_MGR_EXCEPTION_PRINT("====>>>> connect menu_db [%s] failed", ALARMMGR_DB_FILE);
+ /* Register busy handler */
+ if (sqlite3_busy_handler(alarmmgr_db, __db_busyhandler, NULL) != SQLITE_OK) {
+ ALARM_MGR_EXCEPTION_PRINT("Failed to register the busy handler");
+ sqlite3_close(alarmmgr_db);
return false;
}
-
- if (SQLITE_OK != sqlite3_exec(alarmmgr_db, QUERY_CREATE_TABLE_ALARMMGR, NULL, NULL, &error_message)) {
+ /* Create alarmmgr table */
+ if (sqlite3_exec(alarmmgr_db, QUERY_CREATE_TABLE_ALARMMGR, NULL, NULL, &error_message) != SQLITE_OK) {
ALARM_MGR_EXCEPTION_PRINT("Don't execute query = %s, error message = %s", QUERY_CREATE_TABLE_ALARMMGR, error_message);
+ sqlite3_close(alarmmgr_db);
+ sqlite3_free(error_message);
return false;
}