Skip to content

Commit a2c41e0

Browse files
committed
Update readReply to handle json
1 parent 79e91ca commit a2c41e0

File tree

2 files changed

+27
-52
lines changed

2 files changed

+27
-52
lines changed

src/Edward/proxy_supervisor.cpp

Lines changed: 25 additions & 51 deletions
Original file line numberDiff line numberDiff line change
@@ -108,6 +108,7 @@ void ProxySupervisor::startPushDebuggerSocket() {
108108
}
109109

110110
if (isReply(parsed)) {
111+
this->hasReplied = true;
111112
this->proxyResult = parsed;
112113
}
113114

@@ -124,9 +125,10 @@ bool ProxySupervisor::send(
124125
return n == size;
125126
}
126127

127-
char *ProxySupervisor::readReply() {
128-
// TODO use this->proxyResult
129-
return nullptr;
128+
nlohmann::basic_json<> ProxySupervisor::readReply() {
129+
while(!this->hasReplied);
130+
this->hasReplied = false;
131+
return this->proxyResult;
130132
}
131133

132134
pthread_t ProxySupervisor::getThreadID() { return this->threadid; }
@@ -209,54 +211,26 @@ struct SerializeData *ProxySupervisor::serializeRFC(RFC *callee) {
209211
}
210212

211213
void ProxySupervisor::deserializeRFCResult(RFC *rfc) {
212-
uint8_t *call_result = nullptr;
213-
while (call_result == nullptr) {
214-
call_result = (uint8_t *)this->readReply();
215-
}
216-
rfc->success = (uint8_t)call_result[0] == 1;
217-
218-
if (!rfc->success) {
219-
uint16_t msg_size = 0;
220-
memcpy(&msg_size, call_result + 1, sizeof(uint16_t));
221-
if (msg_size > rfc->exception_size) {
222-
delete[] rfc->exception;
223-
rfc->exception = new char[msg_size];
224-
rfc->exception_size = msg_size;
225-
}
226-
memcpy(rfc->exception, call_result + 1 + sizeof(uint16_t), msg_size);
227-
delete[] call_result;
228-
return;
229-
}
230-
231-
if (rfc->type->result_count == 0) {
232-
delete[] call_result;
233-
return;
234-
}
235-
236-
rfc->result->value.uint64 = 0;
237-
switch (rfc->result->value_type) {
238-
case I32:
239-
memcpy(&rfc->result->value.uint32, call_result + 1,
240-
sizeof(uint32_t));
241-
dbg_info("deserialized U32 %" PRIu32 "\n", result->value.uint32);
242-
break;
243-
case F32:
244-
memcpy(&rfc->result->value.f32, call_result + 1, sizeof(float));
245-
dbg_info("deserialized f32 %f \n", result->value.f32);
246-
break;
247-
case I64:
248-
memcpy(&rfc->result->value.uint64, call_result + 1,
249-
sizeof(uint64_t));
250-
dbg_info("deserialized I64 %" PRIu64 "\n", result->value.uint64);
251-
break;
252-
case F64:
253-
memcpy(&rfc->result->value.f64, call_result + 1, sizeof(double));
254-
dbg_info("deserialized f32 %f \n", result->value.f64);
255-
break;
256-
default:
257-
FATAL("Deserialization RFCResult\n");
258-
}
259-
delete[] call_result;
214+
nlohmann::basic_json<> call_result = this->readReply(); // blocking
215+
rfc->success = *call_result.find("success") == 1;
216+
217+
// if (!rfc->success) {
218+
// uint16_t msg_size = 0;
219+
// memcpy(&msg_size, call_result + 1, sizeof(uint16_t));
220+
// if (msg_size > rfc->exception_size) {
221+
// delete[] rfc->exception;
222+
// rfc->exception = new char[msg_size];
223+
// rfc->exception_size = msg_size;
224+
// }
225+
// memcpy(rfc->exception, call_result + 1 + sizeof(uint16_t), msg_size);
226+
// return;
227+
// }
228+
229+
uint8_t type = *call_result.find("type");
230+
auto *result = (StackValue *)malloc(sizeof (struct StackValue));
231+
result->value_type = type;
232+
result->value = {*call_result.find("value")};
233+
rfc->result = result;
260234
}
261235

262236
bool ProxySupervisor::call(RFC *callee) {

src/Edward/proxy_supervisor.h

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -21,6 +21,7 @@ class ProxySupervisor {
2121
pthread_mutex_t *mutex;
2222
std::set<uint32_t> *proxied = new std::set<uint32_t>();
2323

24+
bool hasReplied = false;
2425
nlohmann::basic_json<> proxyResult;
2526

2627
struct SerializeData *serializeRFC(RFC *callee);
@@ -32,7 +33,7 @@ class ProxySupervisor {
3233
void startPushDebuggerSocket();
3334

3435
bool send(void *t_buffer, int t_size);
35-
char *readReply();
36+
nlohmann::basic_json<>readReply();
3637

3738
pthread_t getThreadID();
3839

0 commit comments

Comments
 (0)