Implement request handler
[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, std::string locale) {
19   auto abstract_parcel = ParcelableFactory::GetInst().CreateParcel(data, size);
20
21   if (abstract_parcel->GetType() != ParcelableType::PkgInfo)
22     return false;
23
24   auto* parcel = dynamic_cast<PkgInfoParcelable*>(abstract_parcel.get());
25
26   PkgSetDBHandler db(parcel->GetUid());
27   db.SetLocale(locale);
28
29   for (auto& i : parcel->GetPkgInfo()) {
30     db.SetPkgInfo(i);
31     if (db.Execute() == false)
32       return false;
33   }
34   return true;
35 }
36
37 std::vector<uint8_t> SetPkginfoRequestHandler::GetResult() {
38   return std::vector<uint8_t>('0');
39 }
40
41 }  // namespace request_handler
42 }  // namespace pkgmgr_server