[Reform] Apply Coding Style
[platform/core/appfw/pkgmgr-info.git] / src / server / set_pkginfo_request_handler.cc
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.
4
5 #include "set_pkginfo_request_handler.hh"
6 #include "../common/parcel/parcelable_factory.hh"
7 #include "../common/parcel/pkginfo_parcelable.hh"
8 #include "../common/database/pkg_set_db_handler.hh"
9
10 #include <string>
11
12 using namespace pkgmgr_common::parcel;
13 using namespace pkgmgr_common::database;
14
15 namespace pkgmgr_server {
16 namespace request_handler {
17
18 bool SetPkginfoRequestHandler::HandleRequest(unsigned char* data, int size,
19                                              std::string locale) {
20   auto abstract_parcel = ParcelableFactory::GetInst().CreateParcel(data, size);
21
22   if (abstract_parcel == nullptr ||
23       abstract_parcel->GetType() != ParcelableType::PkgInfo)
24     return false;
25
26   auto* parcel = dynamic_cast<PkgInfoParcelable*>(abstract_parcel.get());
27   if (parcel == nullptr) return false;
28
29   PkgSetDBHandler db(parcel->GetUid());
30   db.SetLocale(locale);
31
32   for (auto& i : parcel->GetPkgInfo()) {
33     db.SetPkgInfo(i);
34     if (db.Execute() == false) return false;
35   }
36   return true;
37 }
38
39 std::vector<uint8_t> SetPkginfoRequestHandler::GetResult() {
40   return std::vector<uint8_t>('0');
41 }
42
43 }  // namespace request_handler
44 }  // namespace pkgmgr_server