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 "parcelable_factory.hh"
21 #include "abstract_parcelable.hh"
22 #include "appinfo_parcelable.hh"
23 #include "certinfo_parcelable.hh"
24 #include "depinfo_parcelable.hh"
25 #include "filter_parcelable.hh"
26 #include "create_db_parcelable.hh"
27 #include "pkginfo_parcelable.hh"
28 #include "query_parcelable.hh"
29 #include "result_parcelable.hh"
30 #include "command_parcelable.hh"
32 namespace pkgmgr_common {
35 ParcelableFactory::ParcelableFactory() {}
36 ParcelableFactory::~ParcelableFactory() {}
38 ParcelableFactory& ParcelableFactory::GetInst() {
39 static ParcelableFactory instance;
43 std::unique_ptr<AbstractParcelable> ParcelableFactory::CreateParcel(
44 const unsigned char* data, int size) {
46 std::unique_ptr<AbstractParcelable> res = nullptr;
47 tizen_base::Parcel parcel(data, size);
49 parcel.ReadInt32(&tmp);
51 ParcelableType type = static_cast<ParcelableType>(tmp);
54 case ParcelableType::AppInfo:
55 res = std::make_unique<AppInfoParcelable>();
56 parcel.ReadParcelable(res.get());
58 case ParcelableType::CertInfo:
59 res = std::make_unique<CertInfoParcelable>();
60 parcel.ReadParcelable(res.get());
62 case ParcelableType::Filter:
63 res = std::make_unique<FilterParcelable>();
64 parcel.ReadParcelable(res.get());
66 case ParcelableType::PkgInfo:
67 res = std::make_unique<PkgInfoParcelable>();
68 parcel.ReadParcelable(res.get());
70 case ParcelableType::DepInfo:
71 res = std::make_unique<DepInfoParcelable>();
72 parcel.ReadParcelable(res.get());
74 case ParcelableType::Query:
75 res = std::make_unique<QueryParcelable>();
76 parcel.ReadParcelable(res.get());
78 case ParcelableType::Result:
79 res = std::make_unique<ResultParcelable>();
80 parcel.ReadParcelable(res.get());
82 case ParcelableType::Command:
83 res = std::make_unique<CommandParcelable>();
84 parcel.ReadParcelable(res.get());
86 case ParcelableType::CreateDB:
87 res = std::make_unique<CreateDBParcelable>();
88 parcel.ReadParcelable(res.get());
90 case ParcelableType::Unknown:
91 res = std::make_unique<AbstractParcelable>();
92 parcel.ReadParcelable(res.get());
100 } // namespace parcel
101 } // namespace pkgmgr_common