1 // Copyright (c) 2021 Samsung Electronics Co., Ltd All Rights Reserved
2 // Use of this source code is governed by an apache-2.0 license that can be
3 // found in the LICENSE file.
5 #include "command_request_handler.hh"
6 #include "parcelable_factory.hh"
7 #include "pkginfo_parcelable.hh"
8 #include "db_handle_provider.hh"
10 #include "pkgmgrinfo_debug.h"
14 using namespace pkgmgr_common::parcel;
15 using namespace pkgmgr_common::database;
17 namespace pkgmgr_server {
18 namespace request_handler {
20 bool CommandRequestHandler::HandleRequest(unsigned char* data, int size,
22 auto abstract_parcel = ParcelableFactory::GetInst().CreateParcel(data, size);
24 if (abstract_parcel == nullptr ||
25 abstract_parcel->GetType() != ParcelableType::Command) {
26 _LOGE("Invalid parcel or type");
27 result_ = std::make_shared<ResultParcelable>(PMINFO_R_ERROR, std::vector<std::vector<std::string>>{});
31 auto* parcel = dynamic_cast<CommandParcelable*>(abstract_parcel.get());
32 if (parcel == nullptr) {
33 _LOGE("Parcel is empty");
34 result_ = std::make_shared<ResultParcelable>(PMINFO_R_ERROR, std::vector<std::vector<std::string>>{});
38 if (parcel->GetCmd() == CommandType::RemoveCache) {
39 pkgmgr_common::DBHandleProvider::GetInst(parcel->GetUid()).SetMemoryMode(GetPID(), false);
40 result_ = std::make_shared<ResultParcelable>(PMINFO_R_OK, std::vector<std::vector<std::string>>{});
47 std::vector<uint8_t> CommandRequestHandler::ExtractResult() {
48 tizen_base::Parcel parcel;
50 parcel.WriteParcelable(*result_.get());
51 std::vector<uint8_t> raw = parcel.GetRaw();
57 } // namespace request_handler
58 } // namespace pkgmgr_server