Austin Schuh | 812d0d1 | 2021-11-04 20:16:48 -0700 | [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/DsClient.h" |
| 9 | #include "wpi/EventLoopRunner.h" |
| 10 | #include "wpi/Logger.h" |
| 11 | #include "wpi/uv/Error.h" |
| 12 | |
| 13 | namespace uv = wpi::uv; |
| 14 | |
| 15 | static void logfunc(unsigned int level, const char* file, unsigned int line, |
| 16 | const char* msg) { |
| 17 | std::fprintf(stderr, "(%d) %s:%d: %s\n", level, file, line, msg); |
| 18 | } |
| 19 | |
| 20 | int main() { |
| 21 | wpi::Logger logger{logfunc, 0}; |
| 22 | |
| 23 | // Kick off the event loop on a separate thread |
| 24 | wpi::EventLoopRunner loop; |
| 25 | std::shared_ptr<wpi::DsClient> client; |
| 26 | loop.ExecAsync([&](uv::Loop& loop) { |
| 27 | client = wpi::DsClient::Create(loop, logger); |
| 28 | client->setIp.connect( |
| 29 | [](std::string_view ip) { fmt::print("got IP: {}\n", ip); }); |
| 30 | client->clearIp.connect([] { std::fputs("cleared IP\n", stdout); }); |
| 31 | }); |
| 32 | |
| 33 | // wait for a keypress to terminate |
| 34 | std::getchar(); |
| 35 | } |