2 * Copyright (c) 2021 Samsung Electronics Co., Ltd All Rights Reserved
4 * Licensed under the Apache License, Version 2.0 (the License) {
7 * you may not use this file except in compliance with the License.
8 * You may obtain a copy of the License at
10 * http://www.apache.org/licenses/LICENSE-2.0
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.
19 #include "query_parcelable.hh"
23 #include "pkgmgrinfo_private.h"
25 namespace pkgmgr_common {
28 QueryParcelable::QueryParcelable()
29 : AbstractParcelable(0, ParcelableType::Query),
30 db_type_(AbstractDBHandler::DBType::DB_TYPE_NONE),
31 op_type_(AbstractDBHandler::OperationType::OPERATION_TYPE_NONE) {}
34 QueryParcelable::QueryParcelable(uid_t uid,
35 std::pair<int, std::vector<std::string>> query_args,
36 AbstractDBHandler::DBType db_type,
37 AbstractDBHandler::OperationType op_type)
38 : AbstractParcelable(0, ParcelableType::Query),
39 query_args_(std::vector<std::pair<int, std::vector<std::string>>>{query_args}),
40 db_type_(db_type), op_type_(op_type) {}
42 QueryParcelable::QueryParcelable(uid_t uid,
43 std::vector<std::pair<int, std::vector<std::string>>> query_args,
44 AbstractDBHandler::DBType db_type,
45 AbstractDBHandler::OperationType op_type)
46 : AbstractParcelable(uid, ParcelableType::Query),
47 query_args_(std::move(query_args)), db_type_(db_type), op_type_(op_type) {}
49 void QueryParcelable::WriteToParcel(tizen_base::Parcel* parcel) const {
50 AbstractParcelable::WriteToParcel(parcel);
51 WriteInt(parcel, query_args_.size());
52 for (const auto& query_info : query_args_) {
53 WriteInt(parcel, query_info.first);
54 WriteInt(parcel, query_info.second.size());
55 for (const auto& args : query_info.second)
56 parcel->WriteString(args);
58 WriteInt(parcel, db_type_);
59 WriteInt(parcel, op_type_);
62 void QueryParcelable::ReadFromParcel(tizen_base::Parcel* parcel) {
67 AbstractParcelable::ReadFromParcel(parcel);
68 ReadInt(parcel, &query_size);
69 for (int i = 0; i < query_size; ++i) {
70 std::vector<std::string> args;
73 ReadInt(parcel, &index);
74 ReadInt(parcel, &arg_cnt);
76 for (int j = 0; j < arg_cnt; ++j) {
77 args.push_back(parcel->ReadString());
79 query_args_.push_back(std::pair<int, std::vector<std::string>>(index, std::move(args)));
81 ReadInt(parcel, &db_type);
82 db_type_ = static_cast<AbstractDBHandler::DBType>(db_type);
83 ReadInt(parcel, &op_type);
84 op_type_ = static_cast<AbstractDBHandler::OperationType>(op_type);
87 const std::vector<std::pair<int, std::vector<std::string>>>& QueryParcelable::GetQueryArgs() {
91 AbstractDBHandler::DBType QueryParcelable::GetDBType() {
95 AbstractDBHandler::OperationType QueryParcelable::GetOpType() {
100 } // namespace pkgmgr_common