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);
49 const std::vector<dependency_x*>& DepInfoParcelable::GetDependencyInfo() {
50 return dependency_list_;
53 std::vector<dependency_x*> DepInfoParcelable::ExtractDependencyInfo() {
54 return std::move(dependency_list_);
57 const std::string& DepInfoParcelable::GetPkgID() {
61 void DepInfoParcelable::WriteToParcel(tizen_base::Parcel* parcel) const {
62 AbstractParcelable::WriteToParcel(parcel);
63 parcel->WriteString(pkgid_);
64 WriteInt(parcel, dependency_list_.size());
66 for (auto dependency : dependency_list_)
67 WriteDependency(parcel, dependency);
70 void DepInfoParcelable::ReadFromParcel(tizen_base::Parcel* parcel) {
72 AbstractParcelable::ReadFromParcel(parcel);
73 pkgid_ = parcel->ReadString();
74 ReadInt(parcel, &len);
76 for (int i = 0; i < len ; ++i)
77 dependency_list_.emplace_back(ReadDependency(parcel));
80 void DepInfoParcelable::WriteDependency(tizen_base::Parcel* parcel,
81 dependency_x *dependency) const {
82 WriteString(parcel, dependency->pkgid);
83 WriteString(parcel, dependency->depends_on);
84 WriteString(parcel, dependency->type);
85 WriteString(parcel, dependency->required_version);
88 dependency_x *DepInfoParcelable::ReadDependency(tizen_base::Parcel* parcel) {
90 reinterpret_cast<dependency_x*>(calloc(1, sizeof(dependency_x)));
91 ReadString(parcel, &dep->pkgid);
92 ReadString(parcel, &dep->depends_on);
93 ReadString(parcel, &dep->type);
94 ReadString(parcel, &dep->required_version);
100 } // namespace pkgmgr_common