mirror of
https://github.com/wpilibsuite/allwpilib
synced 2026-06-19 00:41:43 +00:00
[sim] WebSockets: don't override HAL_Main
Also clean up some other implementation aspects for cleaner shutdown and reduce peak memory allocation.
This commit is contained in:
@@ -19,8 +19,6 @@
|
||||
#include <wpi/uv/Tcp.h>
|
||||
#include <wpi/uv/Timer.h>
|
||||
|
||||
namespace uv = wpi::uv;
|
||||
|
||||
namespace wpilibws {
|
||||
|
||||
class WebServerClientTest {
|
||||
@@ -29,36 +27,25 @@ class WebServerClientTest {
|
||||
using LoopFunc = std::function<void(void)>;
|
||||
using UvExecFunc = wpi::uv::AsyncFunction<void(LoopFunc)>;
|
||||
|
||||
static std::shared_ptr<WebServerClientTest> GetInstance() {
|
||||
return g_instance;
|
||||
}
|
||||
static void SetInstance(std::shared_ptr<WebServerClientTest> inst) {
|
||||
g_instance = inst;
|
||||
}
|
||||
|
||||
WebServerClientTest() {}
|
||||
explicit WebServerClientTest(wpi::uv::Loop& loop) : m_loop(loop) {}
|
||||
WebServerClientTest(const WebServerClientTest&) = delete;
|
||||
WebServerClientTest& operator=(const WebServerClientTest&) = delete;
|
||||
|
||||
bool Initialize(std::shared_ptr<uv::Loop>& loop);
|
||||
bool Initialize();
|
||||
void AttemptConnect();
|
||||
void Exit();
|
||||
|
||||
void SendMessage(const wpi::json& msg);
|
||||
const wpi::json& GetLastMessage();
|
||||
bool IsConnectedWS() { return m_ws_connected; }
|
||||
void SetTerminateFlag(bool flag) { m_terminateFlag = flag; }
|
||||
|
||||
private:
|
||||
void InitializeWebSocket(const std::string& host, int port,
|
||||
const std::string& uri);
|
||||
|
||||
bool m_terminateFlag = false;
|
||||
static std::shared_ptr<WebServerClientTest> g_instance;
|
||||
bool m_tcp_connected = false;
|
||||
std::shared_ptr<wpi::uv::Timer> m_connect_timer;
|
||||
int m_connect_attempts = 0;
|
||||
std::shared_ptr<wpi::uv::Loop> m_loop;
|
||||
wpi::uv::Loop& m_loop;
|
||||
std::shared_ptr<wpi::uv::Tcp> m_tcp_client;
|
||||
wpi::json m_json;
|
||||
|
||||
|
||||
Reference in New Issue
Block a user