#include "table-statistics.h"
#include "table-restrictions.h"
#include "table-counters.h"
+#include "table-firewall.h"
#ifndef DATABASE_FULL_PATH
#define DATABASE_FULL_PATH "/opt/usr/dbspace/.stc-manager-datausage.db"
static sqlite3 *database;
+//LCOV_EXCL_START
static int __stc_db_busy(void *user, int attempts)
{
__STC_LOG_FUNC_ENTER__;
__STC_LOG_FUNC_EXIT__;
return 1;
}
+//LCOV_EXCL_STOP
stc_error_e stc_db_initialize_once(void)
{
int res = 0;
int retry_count = 0;
if (database != NULL) {
- __STC_LOG_FUNC_EXIT__;
- return STC_ERROR_NONE;
+ __STC_LOG_FUNC_EXIT__; //LCOV_EXCL_LINE
+ return STC_ERROR_NONE; //LCOV_EXCL_LINE
}
do {
res = sqlite3_open(DATABASE_FULL_PATH, &database);
if (res != SQLITE_OK) {
- STC_LOGD("Retry[%d] opening database %s: %s\n",
+ STC_LOGD("Retry[%d] opening database %s: %s\n", //LCOV_EXCL_LINE
++retry_count, DATABASE_FULL_PATH,
- sqlite3_errmsg(database));
+ sqlite3_errmsg(database)); //LCOV_EXCL_LINE
} else {
break;
}
} while (retry_count <= MAX_DB_RETRY_COUNT);
if (res != SQLITE_OK) {
- STC_LOGE("Can't open database %s: %s\n", DATABASE_FULL_PATH,
+ STC_LOGE("Can't open database %s: %s\n", DATABASE_FULL_PATH, //LCOV_EXCL_LINE
sqlite3_errmsg(database));
- __STC_LOG_FUNC_EXIT__;
- return STC_ERROR_DB_FAILED;
+ __STC_LOG_FUNC_EXIT__; //LCOV_EXCL_LINE
+ return STC_ERROR_DB_FAILED; //LCOV_EXCL_LINE
}
STC_LOGD("Successfully opened database");
res = sqlite3_exec(database, "PRAGMA locking_mode = NORMAL", 0, 0, 0);
if (res != SQLITE_OK) {
- STC_LOGE("Can't set locking mode %s, skip set busy handler.",
+ STC_LOGE("Can't set locking mode %s, skip set busy handler.", //LCOV_EXCL_LINE
sqlite3_errmsg(database));
- sqlite3_close(database);
- __STC_LOG_FUNC_EXIT__;
- return STC_ERROR_DB_FAILED;
+ sqlite3_close(database); //LCOV_EXCL_LINE
+ database = NULL; //LCOV_EXCL_LINE
+ __STC_LOG_FUNC_EXIT__; //LCOV_EXCL_LINE
+ return STC_ERROR_DB_FAILED; //LCOV_EXCL_LINE
}
/* Set how many times we'll repeat our attempts for sqlite_step */
if (sqlite3_busy_handler(database, __stc_db_busy, NULL)
!= SQLITE_OK)
- STC_LOGE("Couldn't set busy handler!");
+ STC_LOGE("Couldn't set busy handler!"); //LCOV_EXCL_LINE
__STC_LOG_FUNC_EXIT__;
return STC_ERROR_NONE;
}
+//LCOV_EXCL_START
sqlite3 *stc_db_get_database(void)
{
if (database == NULL)
return database;
}
+//LCOV_EXCL_STOP
stc_error_e stc_db_initialize(void)
{
stc_db_initialize_once();
+#ifndef TIZEN_TV_EXT
EXEC(STC_ERROR_NONE, table_statistics_prepare(database));
EXEC(STC_ERROR_NONE, table_restrictions_prepare(database));
EXEC(STC_ERROR_NONE, table_counters_prepare(database));
+#endif
+ EXEC(STC_ERROR_NONE, table_firewall_prepare(database));
EXEC(STC_ERROR_NONE, stc_init_db_guard());
__STC_LOG_FUNC_EXIT__;
return STC_ERROR_NONE;
handle_error:
- stc_db_deinitialize();
- __STC_LOG_FUNC_EXIT__;
- return STC_ERROR_DB_FAILED;
+ stc_db_deinitialize(); //LCOV_EXCL_LINE
+ __STC_LOG_FUNC_EXIT__; //LCOV_EXCL_LINE
+ return STC_ERROR_DB_FAILED; //LCOV_EXCL_LINE
}
gboolean stc_db_deinitialize(void)
{
__STC_LOG_FUNC_ENTER__;
if (database == NULL) {
- __STC_LOG_FUNC_EXIT__;
- return TRUE;
+ __STC_LOG_FUNC_EXIT__; //LCOV_EXCL_LINE
+ return TRUE; //LCOV_EXCL_LINE
}
+#ifndef TIZEN_TV_EXT
table_statistics_finalize();
table_restrictions_finalize();
table_counters_finalize();
+#endif
+ table_firewall_finalize();
sqlite3_close(database);
__STC_LOG_FUNC_EXIT__;