mirror of
https://github.com/wpilibsuite/allwpilib
synced 2026-07-05 03:21:42 +00:00
SCRIPT namespace replacements
This commit is contained in:
committed by
Peter Johnson
parent
ae6c043632
commit
9aca8e0fd6
@@ -24,7 +24,7 @@ int main() {
|
||||
while (cycleCount < 1000) {
|
||||
std::this_thread::sleep_for(std::chrono::milliseconds(100));
|
||||
cycleCount++;
|
||||
wpi::print("Count: {}\n", cycleCount);
|
||||
wpi::util::print("Count: {}\n", cycleCount);
|
||||
}
|
||||
|
||||
std::puts("DONE");
|
||||
|
||||
@@ -20,7 +20,7 @@
|
||||
#include "wpi/util/fs.hpp"
|
||||
#include "wpi/util/print.hpp"
|
||||
|
||||
namespace uv = wpi::uv;
|
||||
namespace uv = wpi::net::uv;
|
||||
|
||||
using namespace wpilibws;
|
||||
|
||||
@@ -54,10 +54,10 @@ void HALSimHttpConnection::ProcessWsUpgrade() {
|
||||
return;
|
||||
}
|
||||
|
||||
wpi::json j;
|
||||
wpi::util::json j;
|
||||
try {
|
||||
j = wpi::json::parse(msg);
|
||||
} catch (const wpi::json::parse_error& e) {
|
||||
j = wpi::util::json::parse(msg);
|
||||
} catch (const wpi::util::json::parse_error& e) {
|
||||
std::string err("JSON parse failed: ");
|
||||
err += e.what();
|
||||
m_websocket->Fail(400, err);
|
||||
@@ -77,20 +77,20 @@ void HALSimHttpConnection::ProcessWsUpgrade() {
|
||||
});
|
||||
}
|
||||
|
||||
void HALSimHttpConnection::OnSimValueChanged(const wpi::json& msg) {
|
||||
void HALSimHttpConnection::OnSimValueChanged(const wpi::util::json& msg) {
|
||||
// Skip sending if this message is not in the allowed filter list
|
||||
try {
|
||||
auto& type = msg.at("type").get_ref<const std::string&>();
|
||||
if (!m_server->CanSendMessage(type)) {
|
||||
return;
|
||||
}
|
||||
} catch (wpi::json::exception& e) {
|
||||
wpi::print(stderr, "Error with message: {}\n", e.what());
|
||||
} catch (wpi::util::json::exception& e) {
|
||||
wpi::util::print(stderr, "Error with message: {}\n", e.what());
|
||||
}
|
||||
|
||||
// render json to buffers
|
||||
wpi::SmallVector<uv::Buffer, 4> sendBufs;
|
||||
wpi::raw_uv_ostream os{sendBufs, [this]() -> uv::Buffer {
|
||||
wpi::util::SmallVector<uv::Buffer, 4> sendBufs;
|
||||
wpi::net::raw_uv_ostream os{sendBufs, [this]() -> uv::Buffer {
|
||||
std::lock_guard lock(m_buffers_mutex);
|
||||
return m_buffers.Allocate();
|
||||
}};
|
||||
@@ -99,14 +99,14 @@ void HALSimHttpConnection::OnSimValueChanged(const wpi::json& msg) {
|
||||
// call the websocket send function on the uv loop
|
||||
m_server->GetExec().Send([self = shared_from_this(), sendBufs] {
|
||||
self->m_websocket->SendText(sendBufs,
|
||||
[self](auto bufs, wpi::uv::Error err) {
|
||||
[self](auto bufs, wpi::net::uv::Error err) {
|
||||
{
|
||||
std::lock_guard lock(self->m_buffers_mutex);
|
||||
self->m_buffers.Release(bufs);
|
||||
}
|
||||
|
||||
if (err) {
|
||||
wpi::print(stderr, "{}\n", err.str());
|
||||
wpi::util::print(stderr, "{}\n", err.str());
|
||||
std::fflush(stderr);
|
||||
}
|
||||
});
|
||||
@@ -127,22 +127,22 @@ void HALSimHttpConnection::SendFileResponse(int code, std::string_view codeText,
|
||||
}
|
||||
|
||||
// open file
|
||||
auto fileBuffer = wpi::MemoryBuffer::GetFile(filename);
|
||||
auto fileBuffer = wpi::util::MemoryBuffer::GetFile(filename);
|
||||
if (!fileBuffer) {
|
||||
MySendError(404, "error opening file");
|
||||
return;
|
||||
}
|
||||
|
||||
wpi::SmallVector<uv::Buffer, 4> toSend;
|
||||
wpi::raw_uv_ostream os{toSend, 4096};
|
||||
wpi::util::SmallVector<uv::Buffer, 4> toSend;
|
||||
wpi::net::raw_uv_ostream os{toSend, 4096};
|
||||
BuildHeader(os, code, codeText, contentType, size, extraHeader);
|
||||
SendData(os.bufs(), false);
|
||||
|
||||
Log(code);
|
||||
|
||||
// Read the file byte by byte
|
||||
wpi::SmallVector<uv::Buffer, 4> bodyData;
|
||||
wpi::raw_uv_ostream bodyOs{bodyData, 4096};
|
||||
wpi::util::SmallVector<uv::Buffer, 4> bodyData;
|
||||
wpi::net::raw_uv_ostream bodyOs{bodyData, 4096};
|
||||
|
||||
bodyOs << fileBuffer.value()->GetBuffer();
|
||||
|
||||
@@ -153,8 +153,8 @@ void HALSimHttpConnection::SendFileResponse(int code, std::string_view codeText,
|
||||
}
|
||||
|
||||
void HALSimHttpConnection::ProcessRequest() {
|
||||
wpi::UrlParser url{m_request.GetUrl(),
|
||||
m_request.GetMethod() == wpi::HTTP_CONNECT};
|
||||
wpi::net::UrlParser url{m_request.GetUrl(),
|
||||
m_request.GetMethod() == wpi::net::HTTP_CONNECT};
|
||||
if (!url.IsValid()) {
|
||||
// failed to parse URL
|
||||
MySendError(400, "Invalid URL");
|
||||
@@ -166,17 +166,17 @@ void HALSimHttpConnection::ProcessRequest() {
|
||||
path = url.GetPath();
|
||||
}
|
||||
|
||||
if (m_request.GetMethod() == wpi::HTTP_GET && wpi::starts_with(path, '/') &&
|
||||
!wpi::contains(path, "..") && !wpi::contains(path, "//")) {
|
||||
if (m_request.GetMethod() == wpi::net::HTTP_GET && wpi::util::starts_with(path, '/') &&
|
||||
!wpi::util::contains(path, "..") && !wpi::util::contains(path, "//")) {
|
||||
// convert to fs native representation
|
||||
fs::path nativePath;
|
||||
if (auto userPath = wpi::remove_prefix(path, "/user/")) {
|
||||
if (auto userPath = wpi::util::remove_prefix(path, "/user/")) {
|
||||
nativePath = fs::path{m_server->GetWebrootSys()} /
|
||||
fs::path{*userPath, fs::path::format::generic_format};
|
||||
} else {
|
||||
nativePath =
|
||||
fs::path{m_server->GetWebrootSys()} /
|
||||
fs::path{wpi::drop_front(path), fs::path::format::generic_format};
|
||||
fs::path{wpi::util::drop_front(path), fs::path::format::generic_format};
|
||||
}
|
||||
|
||||
if (fs::is_directory(nativePath)) {
|
||||
@@ -186,7 +186,7 @@ void HALSimHttpConnection::ProcessRequest() {
|
||||
if (!fs::exists(nativePath) || fs::is_directory(nativePath)) {
|
||||
MySendError(404, fmt::format("Resource '{}' not found", path));
|
||||
} else {
|
||||
auto contentType = wpi::MimeTypeFromPath(nativePath.string());
|
||||
auto contentType = wpi::net::MimeTypeFromPath(nativePath.string());
|
||||
SendFileResponse(200, "OK", contentType, nativePath.string());
|
||||
}
|
||||
} else {
|
||||
@@ -200,7 +200,7 @@ void HALSimHttpConnection::MySendError(int code, std::string_view message) {
|
||||
}
|
||||
|
||||
void HALSimHttpConnection::Log(int code) {
|
||||
auto method = wpi::http_method_str(m_request.GetMethod());
|
||||
wpi::print(stderr, "{} {} HTTP/{}.{} {}\n", method, m_request.GetUrl(),
|
||||
auto method = wpi::net::http_method_str(m_request.GetMethod());
|
||||
wpi::util::print(stderr, "{} {} HTTP/{}.{} {}\n", method, m_request.GetUrl(),
|
||||
m_request.GetMajor(), m_request.GetMinor(), code);
|
||||
}
|
||||
|
||||
@@ -24,7 +24,7 @@ using namespace wpilibws;
|
||||
|
||||
bool HALSimWSServer::Initialize() {
|
||||
bool result = true;
|
||||
runner.ExecSync([&](wpi::uv::Loop& loop) {
|
||||
runner.ExecSync([&](wpi::net::uv::Loop& loop) {
|
||||
simWeb = std::make_shared<HALSimWeb>(loop, providers, simDevices);
|
||||
|
||||
if (!simWeb->Initialize()) {
|
||||
|
||||
@@ -17,17 +17,17 @@
|
||||
#include "wpi/util/fs.hpp"
|
||||
#include "wpi/util/print.hpp"
|
||||
|
||||
namespace uv = wpi::uv;
|
||||
namespace uv = wpi::net::uv;
|
||||
|
||||
using namespace wpilibws;
|
||||
|
||||
HALSimWeb::HALSimWeb(wpi::uv::Loop& loop, ProviderContainer& providers,
|
||||
HALSimWeb::HALSimWeb(wpi::net::uv::Loop& loop, ProviderContainer& providers,
|
||||
HALSimWSProviderSimDevices& simDevicesProvider)
|
||||
: m_loop(loop),
|
||||
m_providers(providers),
|
||||
m_simDevicesProvider(simDevicesProvider) {
|
||||
m_loop.error.connect([](uv::Error err) {
|
||||
wpi::print(stderr, "HALSim WS Server libuv ERROR: {}\n", err.str());
|
||||
wpi::util::print(stderr, "HALSim WS Server libuv ERROR: {}\n", err.str());
|
||||
});
|
||||
|
||||
m_server = uv::Tcp::Create(m_loop);
|
||||
@@ -72,7 +72,7 @@ bool HALSimWeb::Initialize() {
|
||||
try {
|
||||
m_port = std::stoi(port);
|
||||
} catch (const std::invalid_argument& err) {
|
||||
wpi::print(stderr, "Error decoding HALSIMWS_PORT ({})\n", err.what());
|
||||
wpi::util::print(stderr, "Error decoding HALSIMWS_PORT ({})\n", err.what());
|
||||
return false;
|
||||
}
|
||||
} else {
|
||||
@@ -82,8 +82,8 @@ bool HALSimWeb::Initialize() {
|
||||
const char* msgFilters = std::getenv("HALSIMWS_FILTERS");
|
||||
if (msgFilters != nullptr) {
|
||||
m_useMsgFiltering = true;
|
||||
wpi::split(wpi::trim(msgFilters), ',', -1, false,
|
||||
[&](auto val) { m_msgFilters[wpi::trim(val)] = true; });
|
||||
wpi::util::split(wpi::util::trim(msgFilters), ',', -1, false,
|
||||
[&](auto val) { m_msgFilters[wpi::util::trim(val)] = true; });
|
||||
} else {
|
||||
m_useMsgFiltering = false;
|
||||
}
|
||||
@@ -109,17 +109,17 @@ void HALSimWeb::Start() {
|
||||
|
||||
// start listening for incoming connections
|
||||
m_server->Listen();
|
||||
wpi::print("Listening at http://localhost:{}\n", m_port);
|
||||
wpi::print("WebSocket URI: {}\n", m_uri);
|
||||
wpi::util::print("Listening at http://localhost:{}\n", m_port);
|
||||
wpi::util::print("WebSocket URI: {}\n", m_uri);
|
||||
|
||||
// Print any filters we are using
|
||||
if (m_useMsgFiltering) {
|
||||
wpi::print("WS Message Filters:");
|
||||
wpi::util::print("WS Message Filters:");
|
||||
for (auto&& filter : m_msgFilters) {
|
||||
wpi::print("* \"{}\"\n", filter.first);
|
||||
wpi::util::print("* \"{}\"\n", filter.first);
|
||||
}
|
||||
} else {
|
||||
wpi::print("No WS Message Filters specified");
|
||||
wpi::util::print("No WS Message Filters specified");
|
||||
}
|
||||
}
|
||||
|
||||
@@ -155,7 +155,7 @@ void HALSimWeb::CloseWebsocket(
|
||||
}
|
||||
}
|
||||
|
||||
void HALSimWeb::OnNetValueChanged(const wpi::json& msg) {
|
||||
void HALSimWeb::OnNetValueChanged(const wpi::util::json& msg) {
|
||||
// Look for "type" and "device" fields so that we can
|
||||
// generate the key
|
||||
|
||||
@@ -163,7 +163,7 @@ void HALSimWeb::OnNetValueChanged(const wpi::json& msg) {
|
||||
auto& type = msg.at("type").get_ref<const std::string&>();
|
||||
auto& device = msg.at("device").get_ref<const std::string&>();
|
||||
|
||||
wpi::SmallString<64> key;
|
||||
wpi::util::SmallString<64> key;
|
||||
key.append(type);
|
||||
if (!device.empty()) {
|
||||
key.append("/");
|
||||
@@ -174,8 +174,8 @@ void HALSimWeb::OnNetValueChanged(const wpi::json& msg) {
|
||||
if (provider) {
|
||||
provider->OnNetValueChanged(msg.at("data"));
|
||||
}
|
||||
} catch (wpi::json::exception& e) {
|
||||
wpi::print(stderr, "Error with incoming message: {}\n", e.what());
|
||||
} catch (wpi::util::json::exception& e) {
|
||||
wpi::util::print(stderr, "Error with incoming message: {}\n", e.what());
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
@@ -20,18 +20,18 @@
|
||||
namespace wpilibws {
|
||||
|
||||
class HALSimHttpConnection
|
||||
: public wpi::HttpWebSocketServerConnection<HALSimHttpConnection>,
|
||||
: public wpi::net::HttpWebSocketServerConnection<HALSimHttpConnection>,
|
||||
public HALSimBaseWebSocketConnection {
|
||||
public:
|
||||
HALSimHttpConnection(std::shared_ptr<HALSimWeb> server,
|
||||
std::shared_ptr<wpi::uv::Stream> stream)
|
||||
: wpi::HttpWebSocketServerConnection<HALSimHttpConnection>(stream, {}),
|
||||
std::shared_ptr<wpi::net::uv::Stream> stream)
|
||||
: wpi::net::HttpWebSocketServerConnection<HALSimHttpConnection>(stream, {}),
|
||||
m_server(std::move(server)),
|
||||
m_buffers(128) {}
|
||||
|
||||
public:
|
||||
// callable from any thread
|
||||
void OnSimValueChanged(const wpi::json& msg) override;
|
||||
void OnSimValueChanged(const wpi::util::json& msg) override;
|
||||
|
||||
protected:
|
||||
void ProcessRequest() override;
|
||||
@@ -51,7 +51,7 @@ class HALSimHttpConnection
|
||||
bool m_isWsConnected = false;
|
||||
|
||||
// these are only valid if the websocket is connected
|
||||
wpi::uv::SimpleBufferPool<4> m_buffers;
|
||||
wpi::net::uv::SimpleBufferPool<4> m_buffers;
|
||||
std::mutex m_buffers_mutex;
|
||||
};
|
||||
|
||||
|
||||
@@ -23,7 +23,7 @@ class HALSimWSServer {
|
||||
|
||||
ProviderContainer providers;
|
||||
HALSimWSProviderSimDevices simDevices{providers};
|
||||
wpi::EventLoopRunner runner;
|
||||
wpi::net::EventLoopRunner runner;
|
||||
std::shared_ptr<HALSimWeb> simWeb;
|
||||
};
|
||||
|
||||
|
||||
@@ -23,9 +23,9 @@ namespace wpilibws {
|
||||
class HALSimWeb : public std::enable_shared_from_this<HALSimWeb> {
|
||||
public:
|
||||
using LoopFunc = std::function<void()>;
|
||||
using UvExecFunc = wpi::uv::Async<LoopFunc>;
|
||||
using UvExecFunc = wpi::net::uv::Async<LoopFunc>;
|
||||
|
||||
HALSimWeb(wpi::uv::Loop& loop, ProviderContainer& providers,
|
||||
HALSimWeb(wpi::net::uv::Loop& loop, ProviderContainer& providers,
|
||||
HALSimWSProviderSimDevices& simDevicesProvider);
|
||||
|
||||
HALSimWeb(const HALSimWeb&) = delete;
|
||||
@@ -38,7 +38,7 @@ class HALSimWeb : public std::enable_shared_from_this<HALSimWeb> {
|
||||
void CloseWebsocket(std::shared_ptr<HALSimBaseWebSocketConnection> hws);
|
||||
|
||||
// network -> sim
|
||||
void OnNetValueChanged(const wpi::json& msg);
|
||||
void OnNetValueChanged(const wpi::util::json& msg);
|
||||
|
||||
bool CanSendMessage(std::string_view type);
|
||||
|
||||
@@ -46,7 +46,7 @@ class HALSimWeb : public std::enable_shared_from_this<HALSimWeb> {
|
||||
const std::string& GetWebrootUser() const { return m_webroot_user; }
|
||||
const std::string& GetServerUri() const { return m_uri; }
|
||||
int GetServerPort() const { return m_port; }
|
||||
wpi::uv::Loop& GetLoop() { return m_loop; }
|
||||
wpi::net::uv::Loop& GetLoop() { return m_loop; }
|
||||
|
||||
UvExecFunc& GetExec() { return *m_exec; }
|
||||
|
||||
@@ -54,8 +54,8 @@ class HALSimWeb : public std::enable_shared_from_this<HALSimWeb> {
|
||||
// connected http connection that contains active websocket
|
||||
std::weak_ptr<HALSimBaseWebSocketConnection> m_hws;
|
||||
|
||||
wpi::uv::Loop& m_loop;
|
||||
std::shared_ptr<wpi::uv::Tcp> m_server;
|
||||
wpi::net::uv::Loop& m_loop;
|
||||
std::shared_ptr<wpi::net::uv::Tcp> m_server;
|
||||
std::shared_ptr<UvExecFunc> m_exec;
|
||||
|
||||
// list of providers
|
||||
@@ -72,7 +72,7 @@ class HALSimWeb : public std::enable_shared_from_this<HALSimWeb> {
|
||||
int m_port;
|
||||
|
||||
bool m_useMsgFiltering;
|
||||
wpi::StringMap<bool> m_msgFilters;
|
||||
wpi::util::StringMap<bool> m_msgFilters;
|
||||
};
|
||||
|
||||
} // namespace wpilibws
|
||||
|
||||
@@ -17,15 +17,15 @@
|
||||
|
||||
static constexpr int kTcpConnectAttemptTimeout = 1000;
|
||||
|
||||
namespace uv = wpi::uv;
|
||||
namespace uv = wpi::net::uv;
|
||||
|
||||
namespace wpilibws {
|
||||
|
||||
// Create Web Socket and specify event callbacks
|
||||
void WebServerClientTest::InitializeWebSocket(const std::string& host, int port,
|
||||
const std::string& uri) {
|
||||
wpi::print("Will attempt to connect to: {}:{}{}\n", host, port, uri);
|
||||
m_websocket = wpi::WebSocket::CreateClient(*m_tcp_client.get(), uri,
|
||||
wpi::util::print("Will attempt to connect to: {}:{}{}\n", host, port, uri);
|
||||
m_websocket = wpi::net::WebSocket::CreateClient(*m_tcp_client.get(), uri,
|
||||
fmt::format("{}:{}", host, port));
|
||||
|
||||
// Hook up events
|
||||
@@ -44,13 +44,13 @@ void WebServerClientTest::InitializeWebSocket(const std::string& host, int port,
|
||||
});
|
||||
|
||||
m_websocket->text.connect([this](auto msg, bool) {
|
||||
wpi::json j;
|
||||
wpi::util::json j;
|
||||
try {
|
||||
j = wpi::json::parse(msg);
|
||||
} catch (const wpi::json::parse_error& e) {
|
||||
j = wpi::util::json::parse(msg);
|
||||
} catch (const wpi::util::json::parse_error& e) {
|
||||
std::string err("JSON parse failed: ");
|
||||
err += e.what();
|
||||
wpi::print(stderr, "{}\n", err);
|
||||
wpi::util::print(stderr, "{}\n", err);
|
||||
m_websocket->Fail(1003, err);
|
||||
return;
|
||||
}
|
||||
@@ -69,7 +69,7 @@ void WebServerClientTest::InitializeWebSocket(const std::string& host, int port,
|
||||
// Create tcp client, specify callbacks, and create timers for loop
|
||||
bool WebServerClientTest::Initialize() {
|
||||
m_loop.error.connect(
|
||||
[](uv::Error err) { wpi::print(stderr, "uv Error: {}\n", err.str()); });
|
||||
[](uv::Error err) { wpi::util::print(stderr, "uv Error: {}\n", err.str()); });
|
||||
|
||||
m_tcp_client = uv::Tcp::Create(m_loop);
|
||||
if (!m_tcp_client) {
|
||||
@@ -79,7 +79,7 @@ bool WebServerClientTest::Initialize() {
|
||||
|
||||
// Hook up TCP client events
|
||||
m_tcp_client->error.connect(
|
||||
[this, socket = m_tcp_client.get()](wpi::uv::Error err) {
|
||||
[this, socket = m_tcp_client.get()](wpi::net::uv::Error err) {
|
||||
if (m_tcp_connected) {
|
||||
m_tcp_connected = false;
|
||||
m_connect_attempts = 0;
|
||||
@@ -110,7 +110,7 @@ bool WebServerClientTest::Initialize() {
|
||||
|
||||
void WebServerClientTest::AttemptConnect() {
|
||||
m_connect_attempts++;
|
||||
wpi::print("Test Client Connection Attempt {}\n", m_connect_attempts);
|
||||
wpi::util::print("Test Client Connection Attempt {}\n", m_connect_attempts);
|
||||
|
||||
if (m_connect_attempts >= 5) {
|
||||
std::fputs("Test Client Timeout. Unable to connect\n", stderr);
|
||||
@@ -126,15 +126,15 @@ void WebServerClientTest::AttemptConnect() {
|
||||
});
|
||||
}
|
||||
|
||||
void WebServerClientTest::SendMessage(const wpi::json& msg) {
|
||||
void WebServerClientTest::SendMessage(const wpi::util::json& msg) {
|
||||
if (msg.empty()) {
|
||||
std::fputs("Message to send is empty\n", stderr);
|
||||
return;
|
||||
}
|
||||
|
||||
wpi::SmallVector<uv::Buffer, 4> sendBufs;
|
||||
wpi::util::SmallVector<uv::Buffer, 4> sendBufs;
|
||||
|
||||
wpi::raw_uv_ostream os{sendBufs, [this]() -> uv::Buffer {
|
||||
wpi::net::raw_uv_ostream os{sendBufs, [this]() -> uv::Buffer {
|
||||
std::lock_guard lock(m_buffers_mutex);
|
||||
return m_buffers->Allocate();
|
||||
}};
|
||||
@@ -142,20 +142,20 @@ void WebServerClientTest::SendMessage(const wpi::json& msg) {
|
||||
|
||||
// Call the websocket send function on the uv loop
|
||||
m_exec->Call([this, sendBufs]() mutable {
|
||||
m_websocket->SendText(sendBufs, [this](auto bufs, wpi::uv::Error err) {
|
||||
m_websocket->SendText(sendBufs, [this](auto bufs, wpi::net::uv::Error err) {
|
||||
{
|
||||
std::lock_guard lock(m_buffers_mutex);
|
||||
m_buffers->Release(bufs);
|
||||
}
|
||||
if (err) {
|
||||
wpi::print(stderr, "{}\n", err.str());
|
||||
wpi::util::print(stderr, "{}\n", err.str());
|
||||
std::fflush(stderr);
|
||||
}
|
||||
});
|
||||
});
|
||||
}
|
||||
|
||||
const wpi::json& WebServerClientTest::GetLastMessage() {
|
||||
const wpi::util::json& WebServerClientTest::GetLastMessage() {
|
||||
return m_json;
|
||||
}
|
||||
|
||||
|
||||
@@ -17,7 +17,7 @@
|
||||
#include "wpi/net/uv/Loop.hpp"
|
||||
#include "wpi/util/print.hpp"
|
||||
|
||||
namespace uv = wpi::uv;
|
||||
namespace uv = wpi::net::uv;
|
||||
|
||||
using namespace wpilibws;
|
||||
|
||||
@@ -51,13 +51,13 @@ TEST_F(WebServerIntegrationTest, DISABLED_DigitalOutput) {
|
||||
|
||||
// Attach timer to loop for test function
|
||||
m_server.runner.ExecSync([&](auto& loop) {
|
||||
auto timer = wpi::uv::Timer::Create(loop);
|
||||
auto timer = wpi::net::uv::Timer::Create(loop);
|
||||
timer->timeout.connect([&] {
|
||||
if (done) {
|
||||
return;
|
||||
}
|
||||
if (IsConnectedClientWS()) {
|
||||
wpi::print("***** Setting DIO value for pin {} to {}\n", PIN,
|
||||
wpi::util::print("***** Setting DIO value for pin {} to {}\n", PIN,
|
||||
(EXPECTED_VALUE ? "true" : "false"));
|
||||
HALSIM_SetDIOValue(PIN, EXPECTED_VALUE);
|
||||
done = true;
|
||||
@@ -80,12 +80,12 @@ TEST_F(WebServerIntegrationTest, DISABLED_DigitalOutput) {
|
||||
test_type = msg.at("type").get_ref<const std::string&>();
|
||||
test_device = msg.at("device").get_ref<const std::string&>();
|
||||
auto& data = msg.at("data");
|
||||
wpi::json::const_iterator it = data.find("<>value");
|
||||
wpi::util::json::const_iterator it = data.find("<>value");
|
||||
if (it != data.end()) {
|
||||
test_value = it.value();
|
||||
}
|
||||
} catch (wpi::json::exception& e) {
|
||||
wpi::print(stderr, "Error with incoming message: {}\n", e.what());
|
||||
} catch (wpi::util::json::exception& e) {
|
||||
wpi::util::print(stderr, "Error with incoming message: {}\n", e.what());
|
||||
}
|
||||
|
||||
// Compare results
|
||||
@@ -102,16 +102,16 @@ TEST_F(WebServerIntegrationTest, DISABLED_DigitalInput) {
|
||||
|
||||
// Attach timer to loop for test function
|
||||
m_server.runner.ExecSync([&](auto& loop) {
|
||||
auto timer = wpi::uv::Timer::Create(loop);
|
||||
auto timer = wpi::net::uv::Timer::Create(loop);
|
||||
timer->timeout.connect([&] {
|
||||
if (done) {
|
||||
return;
|
||||
}
|
||||
if (IsConnectedClientWS()) {
|
||||
wpi::json msg = {{"type", "DIO"},
|
||||
wpi::util::json msg = {{"type", "DIO"},
|
||||
{"device", std::to_string(PIN)},
|
||||
{"data", {{"<>value", EXPECTED_VALUE}}}};
|
||||
wpi::print("***** Input JSON: {}\n", msg.dump());
|
||||
wpi::util::print("***** Input JSON: {}\n", msg.dump());
|
||||
m_webserverClient->SendMessage(msg);
|
||||
done = true;
|
||||
}
|
||||
@@ -136,17 +136,17 @@ TEST_F(WebServerIntegrationTest, DriverStation) {
|
||||
|
||||
// Attach timer to loop for test function
|
||||
m_server.runner.ExecSync([&](auto& loop) {
|
||||
auto timer = wpi::uv::Timer::Create(loop);
|
||||
auto timer = wpi::net::uv::Timer::Create(loop);
|
||||
timer->timeout.connect([&] {
|
||||
if (done) {
|
||||
return;
|
||||
}
|
||||
if (IsConnectedClientWS()) {
|
||||
wpi::json msg = {
|
||||
wpi::util::json msg = {
|
||||
{"type", "DriverStation"},
|
||||
{"device", ""},
|
||||
{"data", {{">enabled", EXPECTED_VALUE}, {">new_data", true}}}};
|
||||
wpi::print("***** Input JSON: {}\n", msg.dump());
|
||||
wpi::util::print("***** Input JSON: {}\n", msg.dump());
|
||||
m_webserverClient->SendMessage(msg);
|
||||
done = true;
|
||||
}
|
||||
|
||||
@@ -21,19 +21,19 @@ namespace wpilibws {
|
||||
|
||||
class WebServerClientTest {
|
||||
public:
|
||||
using BufferPool = wpi::uv::SimpleBufferPool<4>;
|
||||
using BufferPool = wpi::net::uv::SimpleBufferPool<4>;
|
||||
using LoopFunc = std::function<void()>;
|
||||
using UvExecFunc = wpi::uv::AsyncFunction<void(LoopFunc)>;
|
||||
using UvExecFunc = wpi::net::uv::AsyncFunction<void(LoopFunc)>;
|
||||
|
||||
explicit WebServerClientTest(wpi::uv::Loop& loop) : m_loop(loop) {}
|
||||
explicit WebServerClientTest(wpi::net::uv::Loop& loop) : m_loop(loop) {}
|
||||
WebServerClientTest(const WebServerClientTest&) = delete;
|
||||
WebServerClientTest& operator=(const WebServerClientTest&) = delete;
|
||||
|
||||
bool Initialize();
|
||||
void AttemptConnect();
|
||||
|
||||
void SendMessage(const wpi::json& msg);
|
||||
const wpi::json& GetLastMessage();
|
||||
void SendMessage(const wpi::util::json& msg);
|
||||
const wpi::util::json& GetLastMessage();
|
||||
bool IsConnectedWS() { return m_ws_connected; }
|
||||
|
||||
private:
|
||||
@@ -41,14 +41,14 @@ class WebServerClientTest {
|
||||
const std::string& uri);
|
||||
|
||||
bool m_tcp_connected = false;
|
||||
std::shared_ptr<wpi::uv::Timer> m_connect_timer;
|
||||
std::shared_ptr<wpi::net::uv::Timer> m_connect_timer;
|
||||
int m_connect_attempts = 0;
|
||||
wpi::uv::Loop& m_loop;
|
||||
std::shared_ptr<wpi::uv::Tcp> m_tcp_client;
|
||||
wpi::json m_json;
|
||||
wpi::net::uv::Loop& m_loop;
|
||||
std::shared_ptr<wpi::net::uv::Tcp> m_tcp_client;
|
||||
wpi::util::json m_json;
|
||||
|
||||
bool m_ws_connected = false;
|
||||
std::shared_ptr<wpi::WebSocket> m_websocket;
|
||||
std::shared_ptr<wpi::net::WebSocket> m_websocket;
|
||||
std::shared_ptr<UvExecFunc> m_exec;
|
||||
std::unique_ptr<BufferPool> m_buffers;
|
||||
std::mutex m_buffers_mutex;
|
||||
|
||||
Reference in New Issue
Block a user