From: 김일호/Tizen Platform Lab(SR)/Engineer/삼성전자 Date: Wed, 24 Feb 2021 00:07:03 +0000 (+0900) Subject: Implement PkgInfoClient (#79) X-Git-Tag: submit/tizen/20210317.082331~115 X-Git-Url: http://review.tizen.org/git/?a=commitdiff_plain;h=3e32c7da3aa8eb795fd843f374120ad1364372b4;p=platform%2Fcore%2Fappfw%2Fpkgmgr-info.git Implement PkgInfoClient (#79) * Implement PkgInfoClient Signed-off-by: Ilho Kim --- diff --git a/src/client/pkginfo_client.cc b/src/client/pkginfo_client.cc index f509bd3..91575c4 100644 --- a/src/client/pkginfo_client.cc +++ b/src/client/pkginfo_client.cc @@ -4,21 +4,84 @@ #include "pkginfo_client.hh" -#include "../common/parcel/abstract_parcelable.hh" +#include "parcelable_factory.hh" + +#include + +#include "pkgmgrinfo_debug.h" #include namespace pkgmgr_client { + +static const char SOCK_PATH[] = "/run/pkgmgr-info-server"; + PkgInfoClient::PkgInfoClient( std::shared_ptr parcel, uid_t uid, pkgmgr_common::ReqType req_type) - : parcel_(parcel), uid_(uid), req_type_(req_type) {} + : parcel_(parcel), uid_(uid), req_type_(req_type) { + socket_ = std::make_unique(SOCK_PATH); +} + +bool PkgInfoClient::SendRequest() { + if (socket_ == nullptr) + return false; + + if (!socket_->Connect()) { + LOGE("Failed to connect client socket"); + return false; + } + + if (socket_->SendData(&req_type_, sizeof(req_type_)) != 0) { + LOGE("fail to send data"); + return false; + } + + tizen_base::Parcel p; + p.WriteParcelable(*parcel_.get()); + const auto& raw = p.GetRaw(); + int len = raw.size(); -bool PkgInfoClient::SendRequest() { return true; } + if (socket_->SendData(&len, sizeof(len)) != 0) { + LOGE("fail to send data"); + return false; + } + + if (socket_->SendData(&raw[0], len) != 0) { + LOGE("Fail to send data"); + return false; + } + + return true; +} std::shared_ptr PkgInfoClient::GetResultParcel() { - return nullptr; + if (socket_ == nullptr) + return nullptr; + + int len = 0; + if (socket_->ReceiveData(&len, sizeof(len)) != 0) { + LOGE("Fail to receive data"); + return nullptr; + } + + unsigned char* raw = new (std::nothrow) unsigned char[len]; + if (raw == nullptr) { + LOGE("Out of memory"); + return nullptr; + } + + if (socket_->ReceiveData(raw, len) != 0) { + LOGE("Fail to receive data"); + return nullptr; + } + + auto res = pkgmgr_common::parcel::ParcelableFactory::GetInst() + .CreateParcel(raw, len); + delete[] raw; + + return res; } } // namespace pkgmgr_client diff --git a/src/client/pkginfo_client.hh b/src/client/pkginfo_client.hh index bcb93f1..e838d38 100644 --- a/src/client/pkginfo_client.hh +++ b/src/client/pkginfo_client.hh @@ -5,8 +5,8 @@ #ifndef CLIENT_PKGINFO_CLIENT_HH_ #define CLIENT_PKGINFO_CLIENT_HH_ -#include "../common/parcel/abstract_parcelable.hh" - +#include "abstract_parcelable.hh" +#include "client_socket.hh" #include "request_type.hh" #include @@ -22,6 +22,7 @@ class PkgInfoClient { private: std::shared_ptr parcel_; + std::unique_ptr socket_; uid_t uid_; pkgmgr_common::ReqType req_type_; }; diff --git a/src/server/get_appinfo_request_handler.cc b/src/server/get_appinfo_request_handler.cc index fa309b9..068f20b 100644 --- a/src/server/get_appinfo_request_handler.cc +++ b/src/server/get_appinfo_request_handler.cc @@ -39,7 +39,7 @@ bool GetAppinfoRequestHandler::HandleRequest(unsigned char* data, int size, std::vector GetAppinfoRequestHandler::GetResult() { tizen_base::Parcel parcel; - result_->WriteToParcel(&parcel); + parcel.WriteParcelable(*result_.get()); std::vector raw = parcel.GetRaw(); return raw; diff --git a/src/server/get_cert_request_handler.cc b/src/server/get_cert_request_handler.cc index 4075685..03ba3d1 100644 --- a/src/server/get_cert_request_handler.cc +++ b/src/server/get_cert_request_handler.cc @@ -40,7 +40,7 @@ bool GetCertRequestHandler::HandleRequest(unsigned char* data, int size, std::vector GetCertRequestHandler::GetResult() { tizen_base::Parcel parcel; - result_->WriteToParcel(&parcel); + parcel.WriteParcelable(*result_.get()); std::vector raw = parcel.GetRaw(); return raw; diff --git a/src/server/get_pkginfo_request_handler.cc b/src/server/get_pkginfo_request_handler.cc index 479bfaf..ed5e91e 100644 --- a/src/server/get_pkginfo_request_handler.cc +++ b/src/server/get_pkginfo_request_handler.cc @@ -39,7 +39,7 @@ bool GetPkginfoRequestHandler::HandleRequest(unsigned char* data, int size, std::vector GetPkginfoRequestHandler::GetResult() { tizen_base::Parcel parcel; - result_->WriteToParcel(&parcel); + parcel.WriteParcelable(*result_.get()); std::vector raw = parcel.GetRaw(); return raw; diff --git a/src/server/pkg_request.cc b/src/server/pkg_request.cc index e08d12c..0ae4438 100644 --- a/src/server/pkg_request.cc +++ b/src/server/pkg_request.cc @@ -73,6 +73,9 @@ bool PkgRequest::ReceiveData() { } bool PkgRequest::SendData(unsigned char* data, int size) { + if (socket_->SendData(&size, sizeof(size)) < 0) + return false; + return (socket_->SendData(data, size) < 0); } diff --git a/src/server/query_request_handler.cc b/src/server/query_request_handler.cc index 5b29552..8aae6f1 100644 --- a/src/server/query_request_handler.cc +++ b/src/server/query_request_handler.cc @@ -39,7 +39,7 @@ bool QueryRequestHandler::HandleRequest(unsigned char* data, int size, std::vector QueryRequestHandler::GetResult() { tizen_base::Parcel parcel; - result_->WriteToParcel(&parcel); + parcel.WriteParcelable(*result_.get()); std::vector raw = parcel.GetRaw(); return raw;