From 915a14bf31d5a06a8f76b555641bbe2903c06a89 Mon Sep 17 00:00:00 2001 From: Junghyun Yeon Date: Mon, 15 Mar 2021 19:01:05 +0900 Subject: [PATCH] Fix coding rule for db handlers Signed-off-by: Junghyun Yeon --- src/common/database/abstract_db_handler.cc | 34 ++++++++++---------------- src/common/database/appinfo_db_handler.cc | 2 +- src/common/database/cert_set_db_handler.cc | 3 ++- src/common/database/db_handle_provider.cc | 38 +++++++++++++++++------------- src/common/database/pkg_get_db_handler.cc | 2 +- src/common/database/pkg_set_db_handler.cc | 38 +++++++++++++++--------------- src/common/database/query_handler.cc | 2 +- 7 files changed, 57 insertions(+), 62 deletions(-) diff --git a/src/common/database/abstract_db_handler.cc b/src/common/database/abstract_db_handler.cc index e47e9b4..5950513 100644 --- a/src/common/database/abstract_db_handler.cc +++ b/src/common/database/abstract_db_handler.cc @@ -183,7 +183,8 @@ static int __writedb_busy_handler(void *data, int count) { } } -static int __open_write_db(uid_t uid, const char *path, sqlite3 **db, int flags) { +static int __open_write_db(uid_t uid, const char* path, + sqlite3** db, int flags) { int ret; ret = sqlite3_open_v2(path, db, flags, NULL); @@ -192,7 +193,8 @@ static int __open_write_db(uid_t uid, const char *path, sqlite3 **db, int flags) return ret; } - ret = sqlite3_busy_handler(*db, __writedb_busy_handler, (void *)path); + ret = sqlite3_busy_handler(*db, __writedb_busy_handler, + reinterpret_cast(const_cast(path))); if (ret != SQLITE_OK) { _LOGE("failed to register busy handler: %s", sqlite3_errmsg(*db)); @@ -229,18 +231,18 @@ AbstractDBHandler::AbstractDBHandler(uid_t uid, int pid) { } AbstractDBHandler::~AbstractDBHandler() { - // Is this necessary? for (auto db_handle : db_handle_list_) sqlite3_close(db_handle.first); } std::vector> AbstractDBHandler::GetDBPath() { std::vector> db_path; - if (db_type_ == DB_TYPE_FILE_PKGDB) { + if (db_type_ == DB_TYPE_FILE_PKGDB) db_path = DBHandleProvider::GetInst(uid_).GetParserDBPath(pid_); - } else if (db_type_ == DB_TYPE_FILE_CERTDB) { - db_path.emplace_back(std::make_pair(DBHandleProvider::GetInst(uid_).GetCertDBPath(pid_), uid_)); - } + else if (db_type_ == DB_TYPE_FILE_CERTDB) + db_path.emplace_back( + std::make_pair( + DBHandleProvider::GetInst(uid_).GetCertDBPath(pid_), uid_)); return db_path; } @@ -271,20 +273,6 @@ bool AbstractDBHandler::Connect() { } return true; -/* - if (op_type_ == OPERATION_TYPE_READ) - ret = __open_read_db(db_path.c_str(), &db_, SQLITE_OPEN_READONLY | - SQLITE_OPEN_URI); - else - ret = __open_write_db(uid_, db_path.c_str(), &db_, - SQLITE_OPEN_READWRITE | SQLITE_OPEN_CREATE); - - if (ret != SQLITE_OK) { - // error log - return false; - } - return true; -*/ } std::vector> AbstractDBHandler::GetConnection() { @@ -305,7 +293,9 @@ void AbstractDBHandler::SetLocale(const std::string& locale) { void AbstractDBHandler::SetDBType(DBType type) { db_type_ = type; } -AbstractDBHandler::OperationType AbstractDBHandler::GetOpType() { return op_type_; } +AbstractDBHandler::OperationType AbstractDBHandler::GetOpType() { + return op_type_; +} } // namespace database } // namespace pkgmgr_common diff --git a/src/common/database/appinfo_db_handler.cc b/src/common/database/appinfo_db_handler.cc index 0aed7f9..d57da52 100644 --- a/src/common/database/appinfo_db_handler.cc +++ b/src/common/database/appinfo_db_handler.cc @@ -33,7 +33,7 @@ gboolean _move_func(gpointer key, gpointer value, gpointer user_data) { } void __free_applications(gpointer data) { - pkgmgrinfo_basic_free_application((application_x*)data); + pkgmgrinfo_basic_free_application(reinterpret_cast(data)); } } // namespace diff --git a/src/common/database/cert_set_db_handler.cc b/src/common/database/cert_set_db_handler.cc index 1b41cc8..00f0252 100644 --- a/src/common/database/cert_set_db_handler.cc +++ b/src/common/database/cert_set_db_handler.cc @@ -14,11 +14,12 @@ * limitations under the License. */ -#include "db_handle_provider.hh" #include "cert_set_db_handler.hh" #include +#include "db_handle_provider.hh" + #include "pkgmgrinfo_internal.h" namespace pkgmgr_common { diff --git a/src/common/database/db_handle_provider.cc b/src/common/database/db_handle_provider.cc index 0bdf0e1..3a989b5 100644 --- a/src/common/database/db_handle_provider.cc +++ b/src/common/database/db_handle_provider.cc @@ -14,17 +14,19 @@ * limitations under the License. */ +#include "db_handle_provider.hh" + #include #include -#include "db_handle_provider.hh" -#include "pkgmgr-info.h" -#include "pkgmgrinfo_debug.h" - #include #include +#include "pkgmgrinfo_debug.h" +#include "pkgmgr-info.h" + + #ifdef LOG_TAG #undef LOG_TAG #endif @@ -53,7 +55,8 @@ std::unordered_map> DBHandleProvider::provider_; bool DBHandleProvider::is_memory_global_ = false; std::unique_ptr - DBHandleProvider::global_parser_memory_db_handle_(nullptr, sqlite3_close_v2); + DBHandleProvider::global_parser_memory_db_handle_( + nullptr, sqlite3_close_v2); std::unique_ptr DBHandleProvider::cert_memory_db_handle_(nullptr, sqlite3_close_v2); std::string DBHandleProvider::global_parser_memory_db_path_ = @@ -91,14 +94,14 @@ DBHandleProvider& DBHandleProvider::GetInst(uid_t uid) { std::unique_lock u(singleton_lock); uid = ConvertUID(uid); auto& prov = provider_[uid]; - if (prov == nullptr) { + if (prov == nullptr) prov.reset(new DBHandleProvider(uid)); - } return *prov; } -std::vector> DBHandleProvider::GetParserDBPath(pid_t pid) { +std::vector> DBHandleProvider::GetParserDBPath( + pid_t pid) { std::unique_lock u(lock_); std::unique_lock gu(global_lock_); std::vector> db_path_list; @@ -108,11 +111,13 @@ std::vector> DBHandleProvider::GetParserDBPath(pid if (is_memory_ && pid_list_.find(pid) == pid_list_.end()) { if (uid_ > REGULAR_USER) db_path_list.emplace_back(std::make_pair(parser_memory_db_path_, uid_)); - db_path_list.emplace_back(std::make_pair(global_parser_memory_db_path_, GetGlobalUID())); + db_path_list.emplace_back( + std::make_pair(global_parser_memory_db_path_, GetGlobalUID())); } else { if (uid_ > REGULAR_USER) db_path_list.emplace_back(std::make_pair(parser_file_db_path_, uid_)); - db_path_list.emplace_back(std::make_pair(global_parser_file_db_path_, GetGlobalUID())); + db_path_list.emplace_back( + std::make_pair(global_parser_file_db_path_, GetGlobalUID())); } if (db_path_list.size() == 1) { @@ -131,11 +136,10 @@ std::string DBHandleProvider::GetCertDBPath(pid_t pid) { if (is_memory_ != is_memory_global_) SetMemoryMode(pid, is_memory_global_); - if (is_memory_ && pid_list_.find(pid) == pid_list_.end()) { - return cert_memory_db_path_; - } else { - return cert_file_db_path_; - } + if (is_memory_ && pid_list_.find(pid) == pid_list_.end()) + return cert_memory_db_path_; + else + return cert_file_db_path_; } sqlite3* DBHandleProvider::GetMemoryDBHandle(const std::string& filedb_path, @@ -185,8 +189,8 @@ void DBHandleProvider::SetMemoryMode(pid_t pid, bool flag) { parser_memory_db_handle_.reset(parser_db); if (is_memory_ == is_memory_global_) { /* first call */ - sqlite3* global_parser_file_db = GetMemoryDBHandle(global_parser_file_db_path_, - global_parser_memory_db_path_); + sqlite3* global_parser_file_db = GetMemoryDBHandle( + global_parser_file_db_path_, global_parser_memory_db_path_); if (global_parser_file_db) global_parser_memory_db_handle_.reset(global_parser_file_db); sqlite3* cert_db = GetMemoryDBHandle(cert_file_db_path_, diff --git a/src/common/database/pkg_get_db_handler.cc b/src/common/database/pkg_get_db_handler.cc index 81f4b48..6fc539d 100644 --- a/src/common/database/pkg_get_db_handler.cc +++ b/src/common/database/pkg_get_db_handler.cc @@ -33,7 +33,7 @@ gboolean _move_func(gpointer key, gpointer value, gpointer user_data) { } void __free_packages(gpointer data) { - pkgmgrinfo_basic_free_package((package_x*)data); + pkgmgrinfo_basic_free_package(reinterpret_cast(data)); } } // namespace diff --git a/src/common/database/pkg_set_db_handler.cc b/src/common/database/pkg_set_db_handler.cc index 3909f32..51667d4 100644 --- a/src/common/database/pkg_set_db_handler.cc +++ b/src/common/database/pkg_set_db_handler.cc @@ -14,11 +14,12 @@ * limitations under the License. */ -#include "db_handle_provider.hh" #include "pkg_set_db_handler.hh" #include +#include "db_handle_provider.hh" + #include "pkgmgrinfo_debug.h" #include "pkgmgrinfo_internal.h" @@ -30,9 +31,17 @@ PkgSetDBHandler::PkgSetDBHandler(uid_t uid, int pid) PkgSetDBHandler::~PkgSetDBHandler() {} -void PkgSetDBHandler::SetPkgInfo(package_x* package) { package_ = package; } -void PkgSetDBHandler::SetPkgID(std::string pkgid) { pkgid = std::move(pkgid); } -void PkgSetDBHandler::SetWriteType(WriteType write_type) { write_type_ = write_type; } +void PkgSetDBHandler::SetPkgInfo(package_x* package) { + package_ = package; +} + +void PkgSetDBHandler::SetPkgID(std::string pkgid) { + pkgid = std::move(pkgid); +} + +void PkgSetDBHandler::SetWriteType(WriteType write_type) { + write_type_ = write_type; +} std::vector> PkgSetDBHandler::GetResult() { return std::move(result_); @@ -41,35 +50,26 @@ std::vector> PkgSetDBHandler::GetResult() { int PkgSetDBHandler::Execute() { SetOpType(OPERATION_TYPE_WRITE); SetDBType(DB_TYPE_FILE_PKGDB); - //result_.clear(); - //result_.resize(1); - if (!Connect()) { - //result_[0].emplace_back("FAIL"); + if (!Connect()) return PMINFO_R_ERROR; - } int ret = 0; DBHandleProvider::GetInst(uid_).SetMemoryMode(GetPID(), true); std::vector> conn_list = GetConnection(); sqlite3* conn = conn_list.front().first; - if (write_type_ == Insert) { + if (write_type_ == Insert) ret = pkgmgr_parser_insert_pkg_info(conn, package_, uid_); - } else if (write_type_ == Update) { + else if (write_type_ == Update) ret = pkgmgr_parser_update_pkg_info(conn, package_, uid_); - } else if (write_type_ == Delete) { + else if (write_type_ == Delete) ret = pkgmgr_parser_delete_pkg_info(conn, package_->package, uid_); - } else { + else _LOGE("Unknown db write type"); - } - if (ret != PM_PARSER_R_OK) { - //result_[0].emplace_back("FAIL"); + if (ret != PM_PARSER_R_OK) return ret; - } - - //result_[0].emplace_back("SUCCESS"); return ret; } diff --git a/src/common/database/query_handler.cc b/src/common/database/query_handler.cc index da38fcd..a89c92e 100644 --- a/src/common/database/query_handler.cc +++ b/src/common/database/query_handler.cc @@ -55,7 +55,7 @@ int QueryHandler::Execute() { std::vector> conn_list = GetConnection(); if (GetOpType() == OPERATION_TYPE_READ) { for (auto& conn : conn_list) { - GList* list =nullptr; + GList* list = nullptr; int row = 0; int col = 0; -- 2.7.4