2020-08-22 22:30:12 -04:00
|
|
|
/*!
|
|
|
|
* @file Listener.h
|
|
|
|
* The Listener can connect to a Deci2Server for debugging.
|
|
|
|
*/
|
|
|
|
|
|
|
|
#ifndef JAK1_LISTENER_H
|
|
|
|
#define JAK1_LISTENER_H
|
|
|
|
|
|
|
|
#include <string>
|
|
|
|
#include <vector>
|
|
|
|
#include <thread>
|
|
|
|
#include <mutex>
|
|
|
|
#include "common/common_types.h"
|
|
|
|
#include "common/listener_common.h"
|
|
|
|
|
|
|
|
namespace listener {
|
|
|
|
class Listener {
|
|
|
|
public:
|
|
|
|
static constexpr int BUFFER_SIZE = 32 * 1024 * 1024;
|
|
|
|
Listener();
|
|
|
|
~Listener();
|
2020-09-07 13:28:16 -04:00
|
|
|
bool connect_to_target(int n_tries = 1,
|
|
|
|
const std::string& ip = "127.0.0.1",
|
|
|
|
int port = DECI2_PORT);
|
2020-08-22 22:30:12 -04:00
|
|
|
void record_messages(ListenerMessageKind kind);
|
2020-09-06 16:58:25 -04:00
|
|
|
std::vector<std::string> stop_recording_messages();
|
2020-08-22 22:30:12 -04:00
|
|
|
bool is_connected() const;
|
2020-09-06 16:58:25 -04:00
|
|
|
void send_reset(bool shutdown);
|
2020-09-07 13:28:16 -04:00
|
|
|
void send_poke();
|
2020-08-22 22:30:12 -04:00
|
|
|
void disconnect();
|
2020-09-06 16:58:25 -04:00
|
|
|
void send_code(std::vector<uint8_t>& code);
|
|
|
|
bool most_recent_send_was_acked() { return got_ack; }
|
2020-08-22 22:30:12 -04:00
|
|
|
|
|
|
|
private:
|
2020-09-06 12:45:31 -04:00
|
|
|
void send_buffer(int sz);
|
|
|
|
bool wait_for_ack();
|
|
|
|
|
2020-08-26 01:21:33 -04:00
|
|
|
char* m_buffer = nullptr; //! buffer for incoming messages
|
|
|
|
bool m_connected = false; //! do we think we are connected?
|
|
|
|
bool receive_thread_running = false; //! is the receive thread unjoined?
|
2020-09-08 19:15:14 -04:00
|
|
|
int listen_socket = -1; //! socket
|
2020-08-22 22:30:12 -04:00
|
|
|
bool got_ack = false;
|
|
|
|
bool waiting_for_ack = false;
|
|
|
|
|
|
|
|
std::thread rcv_thread;
|
|
|
|
std::mutex rcv_mtx;
|
|
|
|
void receive_func();
|
|
|
|
ListenerMessageKind filter = ListenerMessageKind::MSG_INVALID;
|
|
|
|
std::vector<std::string> message_record;
|
|
|
|
char ack_recv_buff[512];
|
|
|
|
};
|
2020-08-26 01:21:33 -04:00
|
|
|
} // namespace listener
|
2020-08-22 22:30:12 -04:00
|
|
|
|
|
|
|
#endif // JAK1_LISTENER_H
|