James Kuszmaul | cf32412 | 2023-01-14 14:07:17 -0800 | [diff] [blame^] | 1 | // Copyright (c) FIRST and other WPILib contributors. |
| 2 | // Open Source Software; you can modify and/or share it under the terms of |
| 3 | // the WPILib BSD license file in the root directory of this project. |
| 4 | |
| 5 | #include <cstdio> |
| 6 | |
| 7 | #include <fmt/format.h> |
| 8 | #include <wpi/Logger.h> |
| 9 | |
| 10 | #include "wpinet/DsClient.h" |
| 11 | #include "wpinet/EventLoopRunner.h" |
| 12 | #include "wpinet/uv/Error.h" |
| 13 | |
| 14 | namespace uv = wpi::uv; |
| 15 | |
| 16 | static void logfunc(unsigned int level, const char* file, unsigned int line, |
| 17 | const char* msg) { |
| 18 | std::fprintf(stderr, "(%d) %s:%d: %s\n", level, file, line, msg); |
| 19 | } |
| 20 | |
| 21 | int main() { |
| 22 | wpi::Logger logger{logfunc, 0}; |
| 23 | |
| 24 | // Kick off the event loop on a separate thread |
| 25 | wpi::EventLoopRunner loop; |
| 26 | std::shared_ptr<wpi::DsClient> client; |
| 27 | loop.ExecAsync([&](uv::Loop& loop) { |
| 28 | client = wpi::DsClient::Create(loop, logger); |
| 29 | client->setIp.connect( |
| 30 | [](std::string_view ip) { fmt::print("got IP: {}\n", ip); }); |
| 31 | client->clearIp.connect([] { std::fputs("cleared IP\n", stdout); }); |
| 32 | }); |
| 33 | |
| 34 | // wait for a keypress to terminate |
| 35 | std::getchar(); |
| 36 | } |