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"
13 #include "pkgmgrinfo_debug.h"
14 #include "pkgmgrinfo_type.h"
16 namespace pcp = pkgmgr_common::parcel;
18 namespace pkgmgr_server {
19 namespace request_handler {
21 bool CommandRequestHandler::HandleRequest(unsigned char* data, int size,
22 const std::string& locale) {
23 auto abstract_parcel =
24 pcp::ParcelableFactory::GetInst().CreateParcel(data, size);
26 if (abstract_parcel == nullptr ||
27 abstract_parcel->GetType() != pcp::ParcelableType::Command) {
28 _LOGE("Invalid parcel or type");
29 result_ = std::make_shared<pcp::ResultParcelable>(
30 PMINFO_R_ERROR, std::vector<std::vector<std::string>>{});
34 auto* parcel = dynamic_cast<pcp::CommandParcelable*>(abstract_parcel.get());
35 if (parcel == nullptr) {
36 _LOGE("Parcel is empty");
37 result_ = std::make_shared<pcp::ResultParcelable>(
38 PMINFO_R_ERROR, std::vector<std::vector<std::string>>{});
42 if (parcel->GetCmd() == CommandType::RemoveCache) {
43 database::DBHandleProvider::GetInst(
44 parcel->GetUid()).SetMemoryMode(GetPID(), false);
45 result_ = std::make_shared<pcp::ResultParcelable>(
46 PMINFO_R_OK, std::vector<std::vector<std::string>>{});
53 std::vector<uint8_t> CommandRequestHandler::ExtractResult() {
54 tizen_base::Parcel parcel;
56 parcel.WriteParcelable(*result_);
57 std::vector<uint8_t> raw = parcel.GetRaw();
63 } // namespace request_handler
64 } // namespace pkgmgr_server