2021-10-26 23:34:27 -07:00
|
|
|
// Copyright (c) FIRST and other WPILib contributors.
|
|
|
|
|
// Open Source Software; you can modify and/or share it under the terms of
|
|
|
|
|
// the WPILib BSD license file in the root directory of this project.
|
|
|
|
|
|
2025-11-11 18:05:12 -08:00
|
|
|
#include "wpi/net/DsClient.hpp"
|
|
|
|
|
|
2021-10-26 23:34:27 -07:00
|
|
|
#include <cstdio>
|
2024-09-20 17:43:39 -07:00
|
|
|
#include <memory>
|
2021-10-26 23:34:27 -07:00
|
|
|
|
2025-11-07 19:56:21 -05:00
|
|
|
#include "wpi/net/EventLoopRunner.hpp"
|
2025-11-07 19:57:55 -05:00
|
|
|
#include "wpi/util/Logger.hpp"
|
|
|
|
|
#include "wpi/util/print.hpp"
|
2021-10-26 23:34:27 -07:00
|
|
|
|
2025-11-07 20:00:05 -05:00
|
|
|
namespace uv = wpi::net::uv;
|
2021-10-26 23:34:27 -07:00
|
|
|
|
|
|
|
|
static void logfunc(unsigned int level, const char* file, unsigned int line,
|
|
|
|
|
const char* msg) {
|
|
|
|
|
std::fprintf(stderr, "(%d) %s:%d: %s\n", level, file, line, msg);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
int main() {
|
2025-11-07 20:00:05 -05:00
|
|
|
wpi::util::Logger logger{logfunc, 0};
|
2021-10-26 23:34:27 -07:00
|
|
|
|
|
|
|
|
// Kick off the event loop on a separate thread
|
2025-11-07 20:00:05 -05:00
|
|
|
wpi::net::EventLoopRunner loop;
|
|
|
|
|
std::shared_ptr<wpi::net::DsClient> client;
|
2021-10-26 23:34:27 -07:00
|
|
|
loop.ExecAsync([&](uv::Loop& loop) {
|
2025-11-07 20:00:05 -05:00
|
|
|
client = wpi::net::DsClient::Create(loop, logger);
|
2021-10-26 23:34:27 -07:00
|
|
|
client->setIp.connect(
|
2025-11-07 20:00:05 -05:00
|
|
|
[](std::string_view ip) { wpi::util::print("got IP: {}\n", ip); });
|
2021-10-26 23:34:27 -07:00
|
|
|
client->clearIp.connect([] { std::fputs("cleared IP\n", stdout); });
|
|
|
|
|
});
|
|
|
|
|
|
|
|
|
|
// wait for a keypress to terminate
|
2024-11-12 16:39:41 -08:00
|
|
|
static_cast<void>(std::getchar());
|
2021-10-26 23:34:27 -07:00
|
|
|
}
|