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.
16 #include "depinfo_parcelable.hh"
20 #include "pkgmgrinfo_private.h"
22 namespace pkgmgr_common {
25 DepInfoParcelable::DepInfoParcelable()
26 : AbstractParcelable(0, ParcelableType::DepInfo),
27 pkgid_(""), auto_release_(true) {}
29 DepInfoParcelable::DepInfoParcelable(int ret,
30 std::vector<dependency_x *>&& dependency_list, bool auto_release)
31 : AbstractParcelable(0, ParcelableType::DepInfo, ret),
33 dependency_list_(std::move(dependency_list)),
34 auto_release_(auto_release) {}
36 DepInfoParcelable::DepInfoParcelable(const std::string& pkgid)
37 : AbstractParcelable(0, ParcelableType::DepInfo),
38 pkgid_(pkgid), auto_release_(true) {}
40 DepInfoParcelable::~DepInfoParcelable() {
44 for (auto dep : dependency_list_) {
45 pkgmgrinfo_basic_free_dependency(dep);
50 const std::vector<dependency_x *>& DepInfoParcelable::GetDependencyInfo() {
51 return dependency_list_;
54 std::vector<dependency_x *> DepInfoParcelable::ExtractDependencyInfo() {
55 return std::move(dependency_list_);
58 const std::string& DepInfoParcelable::GetPkgID() {
62 void DepInfoParcelable::WriteToParcel(tizen_base::Parcel* parcel) const {
63 AbstractParcelable::WriteToParcel(parcel);
64 parcel->WriteString(pkgid_);
65 WriteInt(parcel, dependency_list_.size());
67 for (auto dependency : dependency_list_) {
68 WriteDependency(parcel, dependency);
72 void DepInfoParcelable::ReadFromParcel(tizen_base::Parcel* parcel) {
75 AbstractParcelable::ReadFromParcel(parcel);
76 pkgid_ = parcel->ReadString();
77 ReadInt(parcel, &len);
79 for (int i = 0; i < len ; ++i) {
80 dependency_list_.emplace_back(ReadDependency(parcel));
84 void DepInfoParcelable::WriteDependency(tizen_base::Parcel* parcel,
85 dependency_x *dependency) const {
86 WriteString(parcel, dependency->pkgid);
87 WriteString(parcel, dependency->depends_on);
88 WriteString(parcel, dependency->type);
89 WriteString(parcel, dependency->required_version);
92 dependency_x *DepInfoParcelable::ReadDependency(tizen_base::Parcel* parcel) {
94 reinterpret_cast<dependency_x*>(calloc(1, sizeof(dependency_x)));
95 ReadString(parcel, &dep->pkgid);
96 ReadString(parcel, &dep->depends_on);
97 ReadString(parcel, &dep->type);
98 ReadString(parcel, &dep->required_version);
103 } // namespace parcel
104 } // namespace pkgmgr_common