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/filter_parcelable.hh"
27 #include "common/parcel/pkginfo_parcelable.hh"
28 #include "common/parcel/result_parcelable.hh"
30 #include "client/pkginfo_client.hh"
37 #define LOG_TAG "PKGMGR_INFO"
42 #define EXPORT_API __attribute__((visibility("default")))
44 extern "C" EXPORT_API int _pkginfo_get_packages(uid_t uid,
45 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 if (result_list.size() == 0)
64 return PMINFO_R_ENOENT;
65 for (auto& pkginfo : result_list) {
66 g_hash_table_insert(packages, (gpointer)pkginfo->package, (gpointer)pkginfo);
67 // TODO: remove element from list. is this work?