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 "appinfo_db_handler.hh"
21 #include "pkgmgrinfo_basic.h"
22 #include "pkgmgrinfo_internal.h"
23 #include "pkgmgrinfo_debug.h"
27 gboolean _move_func(gpointer key, gpointer value, gpointer user_data) {
28 application_x* appinfo = static_cast<application_x*>(value);
29 std::vector<application_x*>* app_list =
30 static_cast<std::vector<application_x*>*>(user_data);
31 app_list->emplace_back(appinfo);
35 void __free_applications(gpointer data) {
36 pkgmgrinfo_basic_free_application((application_x*)data);
41 namespace pkgmgr_common {
44 AppInfoDBHandler::AppInfoDBHandler(uid_t uid, int pid)
45 : AbstractDBHandler(uid, pid), uid_(uid) {}
47 AppInfoDBHandler::~AppInfoDBHandler() {}
49 std::vector<application_x*> AppInfoDBHandler::GetAppHandle() {
50 return std::move(handle_list_);
53 void AppInfoDBHandler::SetFilter(pkgmgrinfo_filter_x* filter) {
57 int AppInfoDBHandler::Execute() {
58 SetOpType(OPERATION_TYPE_READ);
59 SetDBType(DB_TYPE_FILE_PKGDB);
60 if (!Connect()) return PMINFO_R_ERROR;
62 GHashTable* list = g_hash_table_new_full(g_str_hash, g_str_equal,
63 NULL, __free_applications);
64 std::vector<std::pair<sqlite3*, uid_t>> conn_list = GetConnection();
65 int ret = PMINFO_R_OK;
66 for (auto conn : conn_list) {
67 ret = appinfo_internal_filter_get_list(conn.first, filter_, conn.second,
68 GetLocale().c_str(), list);
69 if (ret == PMINFO_R_ERROR) {
70 _LOGE("Failed to appinfo_internal_filter_get_list (%d)", ret);
75 if (g_hash_table_size(list) == 0)
76 ret = PMINFO_R_ENOENT;
78 if (ret == PMINFO_R_OK)
79 g_hash_table_foreach_steal(list, _move_func, &handle_list_);
81 g_hash_table_destroy(list);
85 } // namespace database
86 } // namespace pkgmgr_common