#include "cloud_point_rpc/cli.hpp" #include "cloud_point_rpc/rpc_client.hpp" #include #include namespace cloud_point_rpc { void print_menu(std::ostream &output) { output << "\n=== Cloud Point RPC CLI ===" << std::endl; output << "1. get-intrinsic-params" << std::endl; output << "2. get-extrinsic-params" << std::endl; output << "3. get-cloud-point" << std::endl; output << "0. Exit" << std::endl; output << "Select an option: "; } template std::string vector_to_string(const std::vector &v) { std::string result; for (auto &el : v) { result += std::to_string(el) + " "; } return result; } template std::string vector_to_string(const std::vector> &v) { std::string result; for (auto &el : v) { result += vector_to_string(el) + "\n"; } return result; } int run_cli(std::istream &input, std::ostream &output, const std::string &ip, int port) { try { TCPConnector connector(ip, port); RpcClient client(connector); output << "Connected to " << ip << ":" << port << std::endl; std::string choice; while (true) { print_menu(output); if (!(input >> choice)) break; if (choice == "0") break; std::string method; if (choice == "1") { method = "get-intrinsic-params"; } else if (choice == "2") { method = "get-extrinsic-params"; } else if (choice == "3") { method = "get-cloud-point"; } else { output << "Invalid option: " << choice << std::endl; continue; } try { if (method == "get-intrinsic-params") { auto response = client.get_intrinsic_params(); output << vector_to_string(response); } if (method == "get-extrinsic-params") { auto response = client.get_extrinsic_params(); output << vector_to_string(response); } if (method == "get-cloud-point") { auto response = client.get_cloud_point(); output << vector_to_string(response); } } catch (const std::exception &e) { output << "\nRPC Error: " << e.what() << std::endl; } } } catch (const std::exception &e) { LOG(ERROR) << "CLI Error: " << e.what(); output << "Error: " << e.what() << std::endl; return 1; } return 0; } } // namespace cloud_point_rpc