summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorHwankyu Jhun <h.jhun@samsung.com>2021-04-08 10:17:32 +0900
committerHwankyu Jhun <h.jhun@samsung.com>2021-04-08 10:34:45 +0900
commit08a0d5a428be7412e0ee064fdbcacee1667ff0cb (patch)
tree1c52d9c429433ac607dda95501fb7df001d5208e
parent1e442c95a4a40917e4c62993c5e23c85cd590be6 (diff)
downloadaul-1-08a0d5a428be7412e0ee064fdbcacee1667ff0cb.tar.gz
aul-1-08a0d5a428be7412e0ee064fdbcacee1667ff0cb.tar.bz2
aul-1-08a0d5a428be7412e0ee064fdbcacee1667ff0cb.zip
Fix an argument of Client::Recv()
The type of an argument is changed to Packet**. Change-Id: I6a429014988308755c17b4d81dce42bc8f070dbc Signed-off-by: Hwankyu Jhun <h.jhun@samsung.com>
-rw-r--r--aul/app_manager/app_manager.cc11
-rw-r--r--aul/component/component_port.cc9
-rw-r--r--aul/socket/client.cc10
-rw-r--r--aul/socket/client.hh2
4 files changed, 18 insertions, 14 deletions
diff --git a/aul/app_manager/app_manager.cc b/aul/app_manager/app_manager.cc
index 28329990..2362fc85 100644
--- a/aul/app_manager/app_manager.cc
+++ b/aul/app_manager/app_manager.cc
@@ -76,7 +76,7 @@ std::unique_ptr<AppContext> AppManager::GetAppContext(int pid) {
}
std::unique_ptr<AppContext> AppManager::GetAppContext(const Packet& packet) {
- Packet recv_pkt;
+ Packet* recv_pkt = nullptr;
try {
Client client(PATH_AMD_SOCK);
int ret = client.Send(packet);
@@ -85,7 +85,7 @@ std::unique_ptr<AppContext> AppManager::GetAppContext(const Packet& packet) {
return {};
}
- ret = client.Recv(recv_pkt);
+ ret = client.Recv(&recv_pkt);
if (ret < 0) {
set_last_result(aul_error_convert(ret));
return {};
@@ -96,14 +96,15 @@ std::unique_ptr<AppContext> AppManager::GetAppContext(const Packet& packet) {
return {};
}
- if (recv_pkt.GetCmd() != APP_GET_INFO_OK) {
+ std::unique_ptr<Packet> ptr(recv_pkt);
+ if (recv_pkt->GetCmd() != APP_GET_INFO_OK) {
_E("Failed to find app context");
- set_last_result(aul_error_convert(recv_pkt.GetCmd()));
+ set_last_result(aul_error_convert(recv_pkt->GetCmd()));
return {};
}
set_last_result(AUL_R_OK);
- tizen_base::Bundle b = recv_pkt.DataToBundle();
+ tizen_base::Bundle b = recv_pkt->DataToBundle();
return std::unique_ptr<AppContext>(new (std::nothrow) AppContext(b));
}
diff --git a/aul/component/component_port.cc b/aul/component/component_port.cc
index 6b7fa5c9..dfa3a903 100644
--- a/aul/component/component_port.cc
+++ b/aul/component/component_port.cc
@@ -81,7 +81,7 @@ int ComponentPort::SendRequest(int cmd, int opt) {
tizen_base::Bundle b;
b.Add(AUL_K_COMPONENT_PORT, name_);
Packet pkt(cmd, opt | AUL_SOCK_BUNDLE, b);
- Packet recv_pkt;
+ Packet* recv_pkt = nullptr;
try {
Client client(PATH_AMD_SOCK);
int ret = client.Send(pkt);
@@ -91,7 +91,7 @@ int ComponentPort::SendRequest(int cmd, int opt) {
if (opt & AUL_SOCK_NOREPLY)
return ret;
- ret = client.Recv(recv_pkt);
+ ret = client.Recv(&recv_pkt);
if (ret < 0)
return aul_error_convert(ret);
} catch (Exception& e) {
@@ -99,12 +99,13 @@ int ComponentPort::SendRequest(int cmd, int opt) {
return aul_error_convert(e.GetErrorCode());
}
- if (recv_pkt.GetCmd() != cmd) {
+ std::unique_ptr<Packet> ptr(recv_pkt);
+ if (recv_pkt->GetCmd() != cmd) {
_E("Invalid protocol");
return AUL_R_ECOMM;
}
- b = recv_pkt.DataToBundle();
+ b = recv_pkt->DataToBundle();
auto str = b.GetString(AUL_K_RESULT);
int ret = std::stoi(str);
if (ret < 0)
diff --git a/aul/socket/client.cc b/aul/socket/client.cc
index 879dc8df..82fa292a 100644
--- a/aul/socket/client.cc
+++ b/aul/socket/client.cc
@@ -54,7 +54,7 @@ int Client::Send(const Packet& packet) {
return Socket::Send(reinterpret_cast<void*>(&raw[0]), raw.size());
}
-int Client::Recv(Packet& packet) {
+int Client::Recv(Packet** packet) {
int cmd = -1;
void* p = reinterpret_cast<void*>(&cmd);
int ret = Socket::Recv(p, sizeof(cmd));
@@ -93,9 +93,11 @@ int Client::Recv(Packet& packet) {
std::vector<unsigned char> data(buf, buf + size);
delete[] buf;
- packet.SetCmd(cmd);
- packet.SetOpt(opt);
- packet.SetData(data);
+ *packet = new (std::nothrow) Packet(cmd, opt, data);
+ if (*packet == nullptr) {
+ _E("Out of memory");
+ return -ENOMEM;
+ }
return 0;
}
diff --git a/aul/socket/client.hh b/aul/socket/client.hh
index c54bb059..ca6a5cf0 100644
--- a/aul/socket/client.hh
+++ b/aul/socket/client.hh
@@ -26,7 +26,7 @@ class Client : public Socket {
public:
Client(std::string path, int timeout_msec = 5000);
int Send(const Packet& packet);
- int Recv(Packet& packet);
+ int Recv(Packet** packet);
};
} // namespace aul