Implement pkgmgrinfo_pkginfo_set_installed_storage
[platform/core/appfw/pkgmgr-info.git] / src / common / parcel / query_parcelable.cc
1 /*
2  * Copyright (c) 2021 Samsung Electronics Co., Ltd All Rights Reserved
3  *
4  * Licensed under the Apache License, Version 2.0 (the License) {
5  * }
6  *
7  *  you may not use this file except in compliance with the License.
8  * You may obtain a copy of the License at
9  *
10  * http://www.apache.org/licenses/LICENSE-2.0
11  *
12  * Unless required by applicable law or agreed to in writing, software
13  * distributed under the License is distributed on an AS IS BASIS,
14  * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
15  * See the License for the specific language governing permissions and
16  * limitations under the License.
17  */
18 #include "query_parcelable.hh"
19
20 #include <vector>
21
22 #include "pkgmgrinfo_private.h"
23
24 namespace pkgmgr_common {
25 namespace parcel {
26
27 QueryParcelable::QueryParcelable()
28     : AbstractParcelable(0, ParcelableType::Query), db_type_(AbstractDBHandler::DBType::DB_TYPE_NONE), op_type_(AbstractDBHandler::OperationType::OPERATION_TYPE_NONE) {}
29
30
31 QueryParcelable::QueryParcelable(uid_t uid, std::string query,
32     AbstractDBHandler::DBType db_type, AbstractDBHandler::OperationType op_type)
33     : AbstractParcelable(0, ParcelableType::Query), queries_(std::vector<std::string>{query}), db_type_(db_type), op_type_(op_type) {}
34
35 QueryParcelable::QueryParcelable(uid_t uid, std::vector<std::string> queries, AbstractDBHandler::DBType db_type, AbstractDBHandler::OperationType op_type)
36     : AbstractParcelable(uid, ParcelableType::Query), queries_(queries), db_type_(db_type), op_type_(op_type) {}
37
38 void QueryParcelable::WriteToParcel(tizen_base::Parcel* parcel) const {
39   AbstractParcelable::WriteToParcel(parcel);
40   WriteInt(parcel, queries_.size());
41   for (const auto& query : queries_)
42     parcel->WriteString(query);
43   WriteInt(parcel, db_type_);
44   WriteInt(parcel, op_type_);
45 }
46
47 void QueryParcelable::ReadFromParcel(tizen_base::Parcel* parcel) {
48   int query_size = 0;
49   int op_type = 0;
50   int db_type = 0;
51
52   AbstractParcelable::ReadFromParcel(parcel);
53   ReadInt(parcel, &query_size);
54   for (int i = 0; i < query_size; ++i) {
55     queries_.emplace_back(parcel->ReadString());
56   }
57   ReadInt(parcel, &db_type);
58   db_type_ = static_cast<AbstractDBHandler::DBType>(db_type);
59   ReadInt(parcel, &op_type);
60   op_type_ = static_cast<AbstractDBHandler::OperationType>(op_type);
61 }
62
63 const std::vector<std::string>& QueryParcelable::GetQueries() {
64   return queries_;
65 }
66
67 AbstractDBHandler::DBType QueryParcelable::GetDBType() {
68   return db_type_;
69 }
70
71 AbstractDBHandler::OperationType QueryParcelable::GetOpType() {
72   return op_type_;
73 }
74
75 std::unique_ptr<AbstractParcelable> QueryParcelable::Factory::CreateParcel() {
76   return nullptr;
77 }
78
79 }  // namespace parcel
80 }  // namespace pkgmgr_common