Files
allwpilib/wpinet/examples/dsclient/dsclient.cpp

37 lines
1.1 KiB
C++
Raw Normal View History

// 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.
#include "wpi/net/DsClient.hpp"
#include <cstdio>
2024-09-20 17:43:39 -07:00
#include <memory>
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"
2025-11-07 20:00:05 -05:00
namespace uv = wpi::net::uv;
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};
// 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;
loop.ExecAsync([&](uv::Loop& loop) {
2025-11-07 20:00:05 -05:00
client = wpi::net::DsClient::Create(loop, logger);
client->setIp.connect(
2025-11-07 20:00:05 -05:00
[](std::string_view ip) { wpi::util::print("got IP: {}\n", ip); });
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());
}