blob: 5135d70a913ff2ee3de8b2a922f1e20c49bd2d1f [file] [log] [blame]
James Kuszmaulcf324122023-01-14 14:07:17 -08001// 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
14namespace uv = wpi::uv;
15
16static 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
21int 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}