Fix coding rule for db handlers
authorJunghyun Yeon <jungh.yeon@samsung.com>
Mon, 15 Mar 2021 10:01:05 +0000 (19:01 +0900)
committer연정현/Tizen Platform Lab(SR)/Staff Engineer/삼성전자 <jungh.yeon@samsung.com>
Mon, 15 Mar 2021 22:56:22 +0000 (07:56 +0900)
Signed-off-by: Junghyun Yeon <jungh.yeon@samsung.com>
src/common/database/abstract_db_handler.cc
src/common/database/appinfo_db_handler.cc
src/common/database/cert_set_db_handler.cc
src/common/database/db_handle_provider.cc
src/common/database/pkg_get_db_handler.cc
src/common/database/pkg_set_db_handler.cc
src/common/database/query_handler.cc

index e47e9b4..5950513 100644 (file)
@@ -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<void*>(const_cast<char*>(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<std::pair<std::string, uid_t>> AbstractDBHandler::GetDBPath() {
   std::vector<std::pair<std::string, uid_t>> 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<std::pair<sqlite3*, uid_t>> 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
index 0aed7f9..d57da52 100644 (file)
@@ -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<application_x*>(data));
 }
 
 }  // namespace
index 1b41cc8..00f0252 100644 (file)
  * limitations under the License.
  */
 
-#include "db_handle_provider.hh"
 #include "cert_set_db_handler.hh"
 
 #include <vector>
 
+#include "db_handle_provider.hh"
+
 #include "pkgmgrinfo_internal.h"
 
 namespace pkgmgr_common {
index 0bdf0e1..3a989b5 100644 (file)
  * limitations under the License.
  */
 
+#include "db_handle_provider.hh"
+
 #include <sys/types.h>
 
 #include <tzplatform_config.h>
 
-#include "db_handle_provider.hh"
-#include "pkgmgr-info.h"
-#include "pkgmgrinfo_debug.h"
-
 #include <algorithm>
 #include <vector>
 
+#include "pkgmgrinfo_debug.h"
+#include "pkgmgr-info.h"
+
+
 #ifdef LOG_TAG
 #undef LOG_TAG
 #endif
@@ -53,7 +55,8 @@ std::unordered_map<uid_t, std::unique_ptr<DBHandleProvider>>
     DBHandleProvider::provider_;
 bool DBHandleProvider::is_memory_global_ = false;
 std::unique_ptr<sqlite3, decltype(sqlite3_close_v2)*>
-    DBHandleProvider::global_parser_memory_db_handle_(nullptr, sqlite3_close_v2);
+    DBHandleProvider::global_parser_memory_db_handle_(
+        nullptr, sqlite3_close_v2);
 std::unique_ptr<sqlite3, decltype(sqlite3_close_v2)*>
     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<std::mutex> 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<std::pair<std::string, uid_t>> DBHandleProvider::GetParserDBPath(pid_t pid) {
+std::vector<std::pair<std::string, uid_t>> DBHandleProvider::GetParserDBPath(
+    pid_t pid) {
   std::unique_lock<std::recursive_mutex> u(lock_);
   std::unique_lock<std::recursive_mutex> gu(global_lock_);
   std::vector<std::pair<std::string, uid_t>> db_path_list;
@@ -108,11 +111,13 @@ std::vector<std::pair<std::string, uid_t>> 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_,
index 81f4b48..6fc539d 100644 (file)
@@ -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<package_x*>(data));
 }
 
 }  // namespace
index 3909f32..51667d4 100644 (file)
  * limitations under the License.
  */
 
-#include "db_handle_provider.hh"
 #include "pkg_set_db_handler.hh"
 
 #include <vector>
 
+#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<std::vector<std::string>> PkgSetDBHandler::GetResult() {
   return std::move(result_);
@@ -41,35 +50,26 @@ std::vector<std::vector<std::string>> 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<std::pair<sqlite3*, uid_t>> 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;
 }
index da38fcd..a89c92e 100644 (file)
@@ -55,7 +55,7 @@ int QueryHandler::Execute() {
   std::vector<std::pair<sqlite3*, uid_t>> 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;