[Reform] Apply Coding Style
[platform/core/appfw/pkgmgr-info.git] / src / common / database / appinfo_db_handler.cc
1 /*
2  * Copyright (c) 2021 Samsung Electronics Co., Ltd All Rights Reserved
3  *
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
7  *
8  * http://www.apache.org/licenses/LICENSE-2.0
9  *
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.
15  */
16
17 #include "appinfo_db_handler.hh"
18
19 #include "pkgmgrinfo_internal.h"
20
21 namespace {
22
23 void _move(gpointer key, gpointer value, gpointer user_data) {
24   application_x* appinfo = static_cast<application_x*>(value);
25   std::vector<application_x*>* app_list =
26       static_cast<std::vector<application_x*>*>(user_data);
27   app_list->emplace_back(appinfo);
28 }
29
30 }  // namespace
31
32 namespace pkgmgr_common {
33 namespace database {
34
35 AppInfoDBHandler::AppInfoDBHandler(uid_t uid)
36     : AbstractDBHandler(uid), uid_(uid) {}
37
38 AppInfoDBHandler::~AppInfoDBHandler() {}
39
40 std::vector<application_x*> AppInfoDBHandler::GetAppHandle() {
41   return std::move(handle_list_);
42 }
43
44 void AppInfoDBHandler::SetFilter(pkgmgrinfo_filter_x* filter) {
45   filter_ = filter;
46 }
47
48 bool AppInfoDBHandler::Execute() {
49   SetOpType(OPERATION_TYPE_READ);
50   SetDBType(DB_TYPE_FILE_PKGDB);
51   if (!Connect()) return false;
52
53   GHashTable* list;
54   int ret = appinfo_internal_filter_get_list(GetConnection(), filter_, uid_,
55                                              GetLocale().c_str(), &list);
56   if (ret != PMINFO_R_OK) {
57     // TODO: error log
58     return false;
59   }
60
61   g_hash_table_foreach(list, _move, &handle_list_);
62   g_hash_table_destroy(list);
63   return true;
64 }
65
66 }  // namespace database
67 }  // namespace pkgmgr_common