}
}
-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);
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));
}
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;
}
}
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() {
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
}
void __free_applications(gpointer data) {
- pkgmgrinfo_basic_free_application((application_x*)data);
+ pkgmgrinfo_basic_free_application(reinterpret_cast<application_x*>(data));
}
} // namespace
* 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 {
* 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
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_ =
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;
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) {
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,
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_,
}
void __free_packages(gpointer data) {
- pkgmgrinfo_basic_free_package((package_x*)data);
+ pkgmgrinfo_basic_free_package(reinterpret_cast<package_x*>(data));
}
} // namespace
* 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"
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_);
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;
}
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;