2 * Copyright (c) 2021 Samsung Electronics Co., Ltd All Rights Reserved
4 * Licensed under the Apache License, Version 2.0 (the "License");
5 * you may not use this file except in compliance with the License.
6 * You may obtain a copy of the License at
8 * http://www.apache.org/licenses/LICENSE-2.0
10 * Unless required by applicable law or agreed to in writing, software
11 * distributed under the License is distributed on an "AS IS" BASIS,
12 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13 * See the License for the specific language governing permissions and
14 * limitations under the License.
17 #include "pkg_get_db_handler.hh"
21 #include "pkgmgrinfo_debug.h"
22 #include "pkgmgrinfo_internal.h"
26 gboolean _move_func(gpointer key, gpointer value, gpointer user_data) {
27 package_x* appinfo = static_cast<package_x*>(value);
28 std::vector<package_x*>* app_list =
29 static_cast<std::vector<package_x*>*>(user_data);
30 app_list->emplace_back(appinfo);
35 void __free_packages(gpointer data) {
36 pkgmgrinfo_basic_free_package((package_x*)data);
41 namespace pkgmgr_common {
44 PkgGetDBHandler::PkgGetDBHandler(uid_t uid, int pid)
45 : AbstractDBHandler(uid, pid), uid_(uid) {}
47 PkgGetDBHandler::~PkgGetDBHandler() {}
49 std::vector<package_x*> PkgGetDBHandler::GetPkgHandle() {
50 return std::move(handle_list_);
53 void PkgGetDBHandler::SetFilter(pkgmgrinfo_filter_x* filter) {
57 int PkgGetDBHandler::Execute() {
58 SetOpType(OPERATION_TYPE_READ);
59 SetDBType(DB_TYPE_FILE_PKGDB);
61 _LOGE("Failed to connect database");
62 return PMINFO_R_ERROR;
65 GHashTable* list = g_hash_table_new_full(g_str_hash, g_str_equal,
66 NULL, __free_packages);
67 std::vector<sqlite3*> conn_list = GetConnection();
68 int ret = PMINFO_R_OK;
69 for (auto& conn : conn_list) {
70 ret = pkginfo_internal_filter_get_list(conn, filter_, uid_,
71 GetLocale().c_str(), list);
72 if (ret == PMINFO_R_ERROR)
73 _LOGE("Failed to pkginfo_internal_filter_get_list (%d)", ret);
77 if (ret == PMINFO_R_OK)
78 g_hash_table_foreach_steal(list, _move_func, &handle_list_);
80 g_hash_table_destroy(list);
84 } // namespace database
85 } // namespace pkgmgr_common