2 * Copyright (c) 2021 Samsung Electronics Co., Ltd.
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 "manager/pkginfo_manager.h"
19 #include <sys/types.h>
23 #include "pkgmgrinfo_private.h"
26 #include "common/parcel/appinfo_parcelable.hh"
27 #include "common/parcel/filter_parcelable.hh"
28 #include "common/parcel/pkginfo_parcelable.hh"
29 #include "common/parcel/result_parcelable.hh"
31 #include "client/pkginfo_client.hh"
38 #define LOG_TAG "PKGMGR_INFO"
43 #define EXPORT_API __attribute__((visibility("default")))
45 extern "C" EXPORT_API int _pkginfo_get_packages(uid_t uid,
46 pkgmgrinfo_filter_x *filter, int flag, GHashTable *packages) {
47 std::shared_ptr<pkgmgr_common::parcel::AbstractParcelable> parcelable(
48 new pkgmgr_common::parcel::FilterParcelable(uid,
49 static_cast<pkgmgrinfo_filter_x*>(filter), flag));
51 pkgmgr_client::PkgInfoClient client(parcelable, uid);
52 if (!client.SendRequest())
53 return PMINFO_R_ERROR;
55 std::shared_ptr<pkgmgr_common::parcel::PkgInfoParcelable> return_parcel(
56 std::static_pointer_cast<pkgmgr_common::parcel::PkgInfoParcelable>(
57 client.GetResultParcel()));
59 tizen_base::Parcel parcel;
60 parcel.ReadParcelable(return_parcel.get());
62 auto result_list = return_parcel->GetPkgInfo();
63 // TODO: check noentry error has returned if size of result_list is 0
64 for (auto& pkginfo : result_list) {
65 g_hash_table_insert(packages, (gpointer)pkginfo->package, (gpointer)pkginfo);
66 // TODO: remove element from list. is this work?
73 // TODO: Need to add target db uid to identify which database to be searched
74 extern "C" EXPORT_API int _appinfo_get_applications(uid_t db_uid, uid_t uid,
75 pkgmgrinfo_filter_x *filter, int flag, GHashTable *packages) {
76 std::shared_ptr<pkgmgr_common::parcel::AbstractParcelable> parcelable(
77 new pkgmgr_common::parcel::FilterParcelable(uid,
78 static_cast<pkgmgrinfo_filter_x*>(filter), flag));
80 pkgmgr_client::PkgInfoClient client(parcelable, uid);
81 if (!client.SendRequest())
82 return PMINFO_R_ERROR;
84 std::shared_ptr<pkgmgr_common::parcel::AppInfoParcelable> return_parcel(
85 std::static_pointer_cast<pkgmgr_common::parcel::AppInfoParcelable>(
86 client.GetResultParcel()));
88 tizen_base::Parcel parcel;
89 parcel.ReadParcelable(return_parcel.get());
90 auto result_list = return_parcel->GetAppInfo();
91 for (auto& appinfo : result_list) {
92 g_hash_table_insert(packages, (gpointer)appinfo->appid, (gpointer)appinfo);
93 // TODO: remove element from list. is this work?