#include "pkginfo_client.hh"
-#include "../common/parcel/abstract_parcelable.hh"
+#include "parcelable_factory.hh"
+
+#include <parcel.hh>
+
+#include "pkgmgrinfo_debug.h"
#include <string>
namespace pkgmgr_client {
+
+static const char SOCK_PATH[] = "/run/pkgmgr-info-server";
+
PkgInfoClient::PkgInfoClient(
std::shared_ptr<pkgmgr_common::parcel::AbstractParcelable> 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<pkgmgr_common::socket::ClientSocket>(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<pkgmgr_common::parcel::AbstractParcelable>
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
#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 <string>
private:
std::shared_ptr<pkgmgr_common::parcel::AbstractParcelable> parcel_;
+ std::unique_ptr<pkgmgr_common::socket::ClientSocket> socket_;
uid_t uid_;
pkgmgr_common::ReqType req_type_;
};