Files
allwpilib/wpinet/examples/dsclient/dsclient.cpp
Tyler Veness d88c71ffdc [wpiutil] Upgrade to fmt 10.2.1, add wpi::print (#6161)
We now use a wrapper (wpi::print) to catch exceptions since we can't patch
std::print() to not throw when we ultimately migrate to it.

fmtlib and std format/print throw the same exceptions and always have. We previously patched fmt::print() to not throw a write failure exception, but we can't do that for std::print(); wpi::print() is the migration plan.
2024-05-12 06:25:42 -07:00

37 lines
1.0 KiB
C++

// 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 <cstdio>
#include <wpi/Logger.h>
#include <wpi/print.h>
#include "wpinet/DsClient.h"
#include "wpinet/EventLoopRunner.h"
#include "wpinet/uv/Error.h"
namespace uv = wpi::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() {
wpi::Logger logger{logfunc, 0};
// Kick off the event loop on a separate thread
wpi::EventLoopRunner loop;
std::shared_ptr<wpi::DsClient> client;
loop.ExecAsync([&](uv::Loop& loop) {
client = wpi::DsClient::Create(loop, logger);
client->setIp.connect(
[](std::string_view ip) { wpi::print("got IP: {}\n", ip); });
client->clearIp.connect([] { std::fputs("cleared IP\n", stdout); });
});
// wait for a keypress to terminate
std::getchar();
}