@@ -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
7271void 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}
0 commit comments