Cleanup db handlers and db handle provider
authorJunghyun Yeon <jungh.yeon@samsung.com>
Fri, 18 Jun 2021 10:19:49 +0000 (19:19 +0900)
committer연정현/Tizen Platform Lab(SR)/Staff Engineer/삼성전자 <jungh.yeon@samsung.com>
Wed, 23 Jun 2021 03:31:11 +0000 (12:31 +0900)
- Add empty lines for readability.
- Move initialization to initialization list for consistency.
- Fix minor coding rule.

Signed-off-by: Junghyun Yeon <jungh.yeon@samsung.com>
src/server/database/appinfo_db_handler.cc
src/server/database/appinfo_db_handler.hh
src/server/database/cert_get_db_handler.cc
src/server/database/cert_get_db_handler.hh
src/server/database/cert_set_db_handler.cc
src/server/database/cert_set_db_handler.hh
src/server/database/db_handle_provider.cc
src/server/database/db_handle_provider.hh

index ab40c6a..26ce9d1 100644 (file)
@@ -20,8 +20,8 @@
 #include <shared_mutex>
 
 #include "pkgmgrinfo_basic.h"
-#include "pkgmgrinfo_internal.h"
 #include "pkgmgrinfo_debug.h"
+#include "pkgmgrinfo_internal.h"
 
 namespace {
 
@@ -30,6 +30,7 @@ gboolean _move_func(gpointer key, gpointer value, gpointer user_data) {
   std::vector<application_x*>* app_list =
       static_cast<std::vector<application_x*>*>(user_data);
   app_list->emplace_back(appinfo);
+
   return true;
 }
 
@@ -43,7 +44,7 @@ namespace pkgmgr_server {
 namespace database {
 
 AppInfoDBHandler::AppInfoDBHandler(uid_t uid, int pid)
-    : AbstractDBHandler(uid, pid), uid_(uid) {}
+    : AbstractDBHandler(uid, pid), filter_(nullptr), uid_(uid) {}
 
 AppInfoDBHandler::~AppInfoDBHandler() {}
 
@@ -59,6 +60,7 @@ int AppInfoDBHandler::Execute() {
   std::shared_lock<std::shared_timed_mutex> s(lock_);
   SetOpType(pkgmgr_common::DBOperationType::OPERATION_TYPE_READ);
   SetDBType(pkgmgr_common::DBType::DB_TYPE_FILE_PKGDB);
+
   if (!Connect())
     return PMINFO_R_ERROR;
 
index 7e77c02..e239ef5 100644 (file)
@@ -41,7 +41,7 @@ class EXPORT_API AppInfoDBHandler : public AbstractDBHandler{
   int Execute() override;
 
  private:
-  pkgmgrinfo_filter_x* filter_ = nullptr;
+  pkgmgrinfo_filter_x* filter_;
   std::vector<application_x*> handle_list_;
   uid_t uid_;
 };
index 4a7b32b..d6daecb 100644 (file)
@@ -26,7 +26,7 @@ namespace pkgmgr_server {
 namespace database {
 
 CertGetDBHandler::CertGetDBHandler(uid_t uid, int pid)
-    : AbstractDBHandler(uid, pid), uid_(uid) {}
+    : AbstractDBHandler(uid, pid), uid_(uid), handle_(nullptr) {}
 
 CertGetDBHandler::~CertGetDBHandler() {}
 
@@ -40,8 +40,10 @@ void CertGetDBHandler::SetPkgID(std::string pkgid) {
 
 int CertGetDBHandler::Execute() {
   std::shared_lock<std::shared_timed_mutex> s(lock_);
+
   SetOpType(pkgmgr_common::DBOperationType::OPERATION_TYPE_READ);
   SetDBType(pkgmgr_common::DBType::DB_TYPE_FILE_CERTDB);
+
   if (!Connect()) {
     _LOGE("Failed to connect database");
     return PMINFO_R_ERROR;
@@ -52,11 +54,10 @@ int CertGetDBHandler::Execute() {
   if (ret != PMINFO_R_OK)
     return ret;
 
-  handle_ = static_cast<pkgmgr_certinfo_x*>(handle);
+  handle_ = reinterpret_cast<pkgmgr_certinfo_x*>(handle);
   sqlite3* conn = GetConnection().front().first;
-  ret = certinfo_internal_get(conn, pkgid_.c_str(), uid_, handle_);
 
-  return ret;
+  return certinfo_internal_get(conn, pkgid_.c_str(), uid_, handle_);
 }
 
 }  // namespace database
index 946dc79..f1ae3f0 100644 (file)
@@ -43,7 +43,7 @@ class EXPORT_API CertGetDBHandler : public AbstractDBHandler{
  private:
   uid_t uid_;
   std::string pkgid_;
-  pkgmgr_certinfo_x* handle_ = nullptr;
+  pkgmgr_certinfo_x* handle_;
 };
 
 }  // namespace database
index 68e7c99..9edc508 100644 (file)
@@ -26,7 +26,7 @@ namespace pkgmgr_server {
 namespace database {
 
 CertSetDBHandler::CertSetDBHandler(uid_t uid, int pid)
-    : AbstractDBHandler(uid, pid), uid_(uid) {}
+    : AbstractDBHandler(uid, pid), uid_(uid), handle_(nullptr) {}
 
 CertSetDBHandler::~CertSetDBHandler() {}
 
@@ -36,16 +36,17 @@ void CertSetDBHandler::SetCertHandle(pkgmgr_certinfo_x* cert_info) {
 
 int CertSetDBHandler::Execute() {
   std::unique_lock<std::shared_timed_mutex> u(lock_);
+
   SetOpType(pkgmgr_common::DBOperationType::OPERATION_TYPE_WRITE);
   SetDBType(pkgmgr_common::DBType::DB_TYPE_FILE_CERTDB);
+
   if (!Connect())
     return PMINFO_R_ERROR;
 
   DBHandleProvider::GetInst(uid_).SetMemoryMode(GetPID(), true);
-  sqlite3 *conn = GetConnection().front().first;
-  int ret = certinfo_internal_set(conn, handle_->pkgid, handle_, uid_);
+  sqlite3* conn = GetConnection().front().first;
 
-  return ret;
+  return certinfo_internal_set(conn, handle_->pkgid, handle_, uid_);
 }
 
 }  // namespace database
index 7ef50ff..51dcd9a 100644 (file)
@@ -41,7 +41,7 @@ class EXPORT_API CertSetDBHandler : public AbstractDBHandler{
 
  private:
   uid_t uid_;
-  pkgmgr_certinfo_x* handle_ = nullptr;
+  pkgmgr_certinfo_x* handle_;
 };
 
 }  // namespace database
index 7207f85..a2122b2 100644 (file)
@@ -14,6 +14,8 @@
  * limitations under the License.
  */
 
+#include "db_handle_provider.hh"
+
 #include <fcntl.h>
 #include <sys/types.h>
 
 #include <string>
 #include <vector>
 
-#include "db_handle_provider.hh"
 #include "pkgmgrinfo_debug.h"
 #include "pkgmgr-info.h"
 
-
 #ifdef LOG_TAG
 #undef LOG_TAG
 #endif
index df5e636..522bfe4 100644 (file)
@@ -42,7 +42,8 @@ class EXPORT_API DBHandleProvider {
   ~DBHandleProvider() = default;
   static DBHandleProvider& GetInst(uid_t uid);
   static bool IsCrashedWriteRequest();
-  std::vector<std::pair<std::string, uid_t>> GetParserDBPath(int pid, bool write);
+  std::vector<std::pair<std::string, uid_t>> GetParserDBPath(
+      int pid, bool write);
   std::string GetCertDBPath(int pid, bool write);
   void SetMemoryMode(pid_t pid, bool flag);
 
@@ -52,7 +53,8 @@ class EXPORT_API DBHandleProvider {
       const std::string& memorydb_path);
 
  private:
-  static std::unordered_map<uid_t, std::unique_ptr<DBHandleProvider>> provider_;
+  static std::unordered_map<uid_t,
+      std::unique_ptr<DBHandleProvider>> provider_;
   static bool is_memory_global_;
   static std::unique_ptr<sqlite3, decltype(sqlite3_close_v2)*>
       global_parser_memory_db_handle_;
@@ -67,7 +69,8 @@ class EXPORT_API DBHandleProvider {
 
   uid_t uid_;
   bool is_memory_;
-  std::unique_ptr<sqlite3, decltype(sqlite3_close_v2)*> parser_memory_db_handle_;
+  std::unique_ptr<sqlite3,
+      decltype(sqlite3_close_v2)*> parser_memory_db_handle_;
   std::string parser_memory_db_path_;
   std::string parser_file_db_path_;
 };