2 * Copyright (c) 2021 Samsung Electronics Co., Ltd.
4 * Licensed under the Apache License, Version 2.0 (the "License");
5 * you may not use this file except in compliance with the License.
6 * You may obtain a copy of the License at
8 * http://www.apache.org/licenses/LICENSE-2.0
10 * Unless required by applicable law or agreed to in writing, software
11 * distributed under the License is distributed on an "AS IS" BASIS,
12 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13 * See the License for the specific language governing permissions and
14 * limitations under the License.
17 #include "request_handler_direct_access.h"
19 #include "pkgmgrinfo_debug.h"
21 #include "common/parcel/parcelable_factory.hh"
22 #include "command_request_handler.hh"
23 #include "create_db_request_handler.hh"
24 #include "get_appinfo_request_handler.hh"
25 #include "get_cert_request_handler.hh"
26 #include "get_depinfo_request_handler.hh"
27 #include "get_pkginfo_request_handler.hh"
28 #include "query_request_handler.hh"
29 #include "set_cert_request_handler.hh"
30 #include "set_pkginfo_request_handler.hh"
31 #include "utils/logging.hh"
36 #define EXPORT_API __attribute__((visibility("default")))
38 extern "C" EXPORT_API void* _request_handler_direct_access(int req_type,
39 unsigned char* data, int size, const char *locale) {
40 if (data == nullptr || size < 0 || locale == nullptr) {
41 LOG(ERROR) << "Invalid parameter";
45 std::unique_ptr<pkgmgr_server::request_handler::AbstractRequestHandler>
48 case pkgmgr_common::ReqType::GET_PKG_INFO:
50 new pkgmgr_server::request_handler::GetPkginfoRequestHandler());
52 case pkgmgr_common::ReqType::GET_APP_INFO:
54 new pkgmgr_server::request_handler::GetAppinfoRequestHandler());
56 case pkgmgr_common::ReqType::SET_PKG_INFO:
58 new pkgmgr_server::request_handler::SetPkginfoRequestHandler(true));
60 case pkgmgr_common::ReqType::SET_CERT_INFO:
62 new pkgmgr_server::request_handler::SetCertRequestHandler(true));
64 case pkgmgr_common::ReqType::GET_CERT_INFO:
66 new pkgmgr_server::request_handler::GetCertRequestHandler());
68 case pkgmgr_common::ReqType::GET_PKG_DEP_INFO:
70 new pkgmgr_server::request_handler::GetDepinfoRequestHandler());
72 case pkgmgr_common::ReqType::READ_QUERY:
73 handler.reset(new pkgmgr_server::request_handler::QueryRequestHandler());
75 case pkgmgr_common::ReqType::WRITE_QUERY:
76 handler.reset(new pkgmgr_server::request_handler::QueryRequestHandler());
78 case pkgmgr_common::ReqType::COMMAND:
80 new pkgmgr_server::request_handler::CommandRequestHandler());
82 case pkgmgr_common::ReqType::CREATE_DB:
84 new pkgmgr_server::request_handler::CreateDBRequestHandler());
87 handler.reset(nullptr);
91 if (handler == nullptr) {
92 LOG(ERROR) << "Can't reset handler with type : " << req_type;
97 if (!handler->HandleRequest(data, size, locale)) {
98 LOG(ERROR) << "Failed to handle request";
101 tizen_base::Parcel parcel = handler->ExtractResult();
102 if (parcel.GetDataSize() == 0) {
103 LOG(ERROR) << "Fail to extract result";
107 return pkgmgr_common::parcel::ParcelableFactory::GetInst()
108 .CreateParcel(parcel.GetData(), parcel.GetDataSize(), true)