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"
9 #include "db_handle_provider.hh"
10 #include "parcelable_factory.hh"
11 #include "pkginfo_parcelable.hh"
12 #include "remove_cache_db_handler.hh"
13 #include "utils/logging.hh"
15 #include "pkgmgrinfo_debug.h"
16 #include "pkgmgrinfo_type.h"
18 namespace pcp = pkgmgr_common::parcel;
20 namespace pkgmgr_server {
21 namespace request_handler {
23 bool CommandRequestHandler::HandleRequest(unsigned char* data, size_t size,
24 const std::string& locale) {
25 auto abstract_parcel =
26 pcp::ParcelableFactory::GetInst().CreateParcel(data, size);
28 if (abstract_parcel == nullptr ||
29 abstract_parcel->GetType() != pcp::ParcelableType::Command) {
30 LOG(ERROR) << "Invalid parcel or type";
31 result_ = std::make_shared<pcp::ResultParcelable>(
32 PMINFO_R_ERROR, std::vector<pcp::StrArgs>{});
36 auto* parcel = dynamic_cast<pcp::CommandParcelable*>(abstract_parcel.get());
37 if (parcel == nullptr) {
38 LOG(ERROR) << "Parcel is empty";
39 result_ = std::make_shared<pcp::ResultParcelable>(
40 PMINFO_R_ERROR, std::vector<pcp::StrArgs>{});
44 if (parcel->GetCmd() == CommandType::RemoveCache) {
45 database::RemoveCacheDBHandler db(parcel->GetUid(), GetPID());
46 int ret = db.Execute();
47 result_ = std::make_shared<pcp::ResultParcelable>(
48 ret, std::vector<pcp::StrArgs>{});
55 } // namespace request_handler
56 } // namespace pkgmgr_server