Milestone 2

This commit is contained in:
Joey Yakimowich-Payne 2026-01-29 17:24:51 -07:00
commit 866f0419ad
19 changed files with 2006 additions and 23 deletions

95
examples/warppipe_cli.cpp Normal file
View file

@ -0,0 +1,95 @@
#include <cstdint>
#include <cstdlib>
#include <iostream>
#include <string>
#include <warppipe/warppipe.hpp>
namespace {
uint32_t ParseId(const char* value) {
if (!value) {
return 0;
}
char* end = nullptr;
unsigned long parsed = std::strtoul(value, &end, 10);
if (!end || end == value) {
return 0;
}
return static_cast<uint32_t>(parsed);
}
int Usage() {
std::cerr << "Usage:\n"
<< " warppipe_cli list-nodes\n"
<< " warppipe_cli list-ports <node-id>\n"
<< " warppipe_cli list-links\n";
return 2;
}
} // namespace
int main(int argc, char* argv[]) {
if (argc < 2) {
return Usage();
}
std::string command = argv[1];
warppipe::ConnectionOptions options;
options.application_name = "warppipe-cli";
auto client_result = warppipe::Client::Create(options);
if (!client_result.ok()) {
std::cerr << "warppipe: failed to connect: "
<< client_result.status.message << "\n";
return 1;
}
if (command == "list-nodes") {
auto nodes = client_result.value->ListNodes();
if (!nodes.ok()) {
std::cerr << "warppipe: list-nodes failed: " << nodes.status.message << "\n";
return 1;
}
for (const auto& node : nodes.value) {
std::cout << node.id.value << "\t" << node.name << "\t" << node.media_class << "\n";
}
return 0;
}
if (command == "list-ports") {
if (argc < 3) {
return Usage();
}
uint32_t node_id = ParseId(argv[2]);
if (node_id == 0) {
std::cerr << "warppipe: invalid node id\n";
return 1;
}
auto ports = client_result.value->ListPorts(warppipe::NodeId{node_id});
if (!ports.ok()) {
std::cerr << "warppipe: list-ports failed: " << ports.status.message << "\n";
return 1;
}
for (const auto& port : ports.value) {
std::cout << port.id.value << "\t" << port.name << "\t"
<< (port.is_input ? "in" : "out") << "\n";
}
return 0;
}
if (command == "list-links") {
auto links = client_result.value->ListLinks();
if (!links.ok()) {
std::cerr << "warppipe: list-links failed: " << links.status.message << "\n";
return 1;
}
for (const auto& link : links.value) {
std::cout << link.id.value << "\t" << link.output_port.value << "\t"
<< link.input_port.value << "\n";
}
return 0;
}
return Usage();
}