score-back/src/cli.cpp
amukhamadiev ece26e7b1f [jsonrpccxx] moved to external rpc impl
Detailed:
      As base used jsonrpccxx implementation paired with TCP socket
      TCP socket updated to handle dynamic sized buffers
      TCP communication protocol changed to serialized packet size after
      which json string is presented
2026-02-20 17:51:14 +03:00

90 lines
2.7 KiB
C++

#include "cloud_point_rpc/cli.hpp"
#include "cloud_point_rpc/rpc_client.hpp"
#include <glog/logging.h>
#include <string>
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 <typename T> std::string vector_to_string(const std::vector<T> &v) {
std::string result;
for (auto &el : v) {
result += std::to_string(el) + " ";
}
return result;
}
template <typename T>
std::string vector_to_string(const std::vector<std::vector<T>> &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