Skip to content

Commit 0b50d1b

Browse files
committed
Make Supervisor inherit from Debugger
1 parent 8122a8a commit 0b50d1b

File tree

3 files changed

+11
-33
lines changed

3 files changed

+11
-33
lines changed

src/Debug/debugger.h

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -12,7 +12,6 @@
1212
#include <vector>
1313

1414
#include "../Edward/proxy.h"
15-
#include "../Edward/proxy_supervisor.h"
1615
#include "../Threading/warduino-thread.h"
1716
#include "../Utils/sockets.h"
1817

@@ -109,6 +108,8 @@ enum class SnapshotPolicy : int {
109108
// points where primitives are used.
110109
};
111110

111+
class ProxySupervisor;
112+
112113
class Debugger {
113114
private:
114115
std::deque<uint8_t *> debugMessages = {};

src/Edward/proxy_supervisor.cpp

Lines changed: 7 additions & 30 deletions
Original file line numberDiff line numberDiff line change
@@ -53,9 +53,8 @@ Event *parseJSON(char *buff) {
5353
return new Event(*parsed.find("topic"), payload);
5454
}
5555

56-
ProxySupervisor::ProxySupervisor(Channel *duplex, warduino::mutex *mutex) {
56+
ProxySupervisor::ProxySupervisor(Channel *duplex, warduino::mutex *mutex) : Debugger(duplex) {
5757
debug("Starting supervisor.\n");
58-
this->channel = duplex;
5958
this->mutex = mutex;
6059
this->thread = warduino::thread(runSupervisor, this);
6160
this->proxyResult = nullptr;
@@ -70,39 +69,21 @@ bool isReply(nlohmann::basic_json<> parsed) {
7069
}
7170

7271
void ProxySupervisor::listenToSocket() {
73-
char _char;
74-
uint32_t buf_idx = 0;
75-
const uint32_t start_size = 1024;
76-
uint32_t current_size = start_size;
77-
char *buffer = (char *)malloc(start_size);
72+
uint8_t message[1024] = {0};
7873
ssize_t readAmount;
7974

8075
this->channel->open();
8176

8277
dbg_info("Proxy supervisor listening to remote device...\n");
8378
while (continuing(this->mutex)) {
84-
readAmount = this->channel->read(&_char, 1);
79+
readAmount = this->channel->read(message, 1024);
8580
if (readAmount == -1) {
8681
printf("Proxy supervisor shutting down.\n");
8782
exit(-1);
8883
}
8984
if (readAmount > 0) {
90-
// increase buffer size if needed
91-
if (current_size <= (buf_idx + 1)) {
92-
char *new_buff = (char *)malloc(current_size + start_size);
93-
memcpy((void *)new_buff, (void *)buffer, current_size);
94-
free(buffer);
95-
buffer = new_buff;
96-
current_size += start_size;
97-
printf("increasing PushClient's buffer size to %" PRId32 "\n",
98-
current_size);
99-
}
100-
buffer[buf_idx++] = _char;
101-
// manual null-termination is needed because parseJSON does not use
102-
// first len argument
103-
buffer[buf_idx] = '\0';
10485
try {
105-
nlohmann::basic_json<> parsed = nlohmann::json::parse(buffer);
86+
nlohmann::basic_json<> parsed = nlohmann::json::parse(message);
10687
debug("parseJSON: %s\n", parsed.dump().c_str());
10788

10889
if (isEvent(parsed)) {
@@ -115,13 +96,9 @@ void ProxySupervisor::listenToSocket() {
11596
this->hasReplied = true;
11697
this->proxyResult = parsed;
11798
}
118-
119-
buf_idx = 0;
12099
} catch (const nlohmann::detail::parse_error &e) {
121-
if (_char == '\n') {
122-
// discard buffer
123-
buf_idx = 0;
124-
}
100+
printf("Non RFC call: %s", message);
101+
WARDuino::instance()->handleInterrupt(readAmount, message);
125102
}
126103
}
127104
}
@@ -276,7 +253,7 @@ bool ProxySupervisor::call(RFC *callee) {
276253
char cmdBuffer[10] = "";
277254
int cmdBufferLen = 0;
278255
sprintf(cmdBuffer, "%x\n%n", interruptDUMPCallbackmapping, &cmdBufferLen);
279-
WARDuino::instance()->debugger->supervisor->send(cmdBuffer, cmdBufferLen);
256+
this->send(cmdBuffer, cmdBufferLen);
280257
this->deserializeRFCResult(callee);
281258
return true;
282259
}

src/Edward/proxy_supervisor.h

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -6,6 +6,7 @@
66
#include <set>
77
#include <thread>
88

9+
#include "../Debug/debugger.h"
910
#include "../Threading/warduino-thread.h"
1011
#include "../Utils/sockets.h"
1112
#include "RFC.h"
@@ -16,9 +17,8 @@
1617
#endif
1718
#include "sys/types.h"
1819

19-
class ProxySupervisor {
20+
class ProxySupervisor : public Debugger {
2021
private:
21-
Channel *channel;
2222
warduino::mutex *mutex;
2323
std::set<uint32_t> *proxied = new std::set<uint32_t>();
2424

0 commit comments

Comments
 (0)