[docs] consistency across impl and documentation

fully generated by gemini+opencode
This commit is contained in:
Artur Mukhamadiev 2026-03-12 23:23:36 +03:00
parent 2b12a0be9b
commit e3b5be0f66
15 changed files with 85 additions and 51 deletions

View File

@ -66,12 +66,12 @@ Adhere strictly to **Modern C++20** standards.
### Naming Conventions ### Naming Conventions
- **Files:** `snake_case.cpp`, `snake_case.hpp`. - **Files:** `snake_case.cpp`, `snake_case.hpp`.
- **Classes/Structs:** `PascalCase`. - **Classes/Structs:** `PascalCase`.
- **Functions/Methods:** `snake_case` (or `camelCase` if adhering strictly to a specific external library style, but default to snake_case). - **Functions/Methods:** `snake_case`.
- **Variables:** `snake_case`. - **Variables:** `snake_case`.
- **Private Members:** `snake_case_` (trailing underscore). - **Private Members:** `snake_case_` (trailing underscore).
- **Constants:** `kPascalCase` or `ALL_CAPS` for macros (avoid macros). - **Constants:** `kPascalCase` or `ALL_CAPS` for macros.
- **Namespaces:** `snake_case`. - **Namespaces:** `score` (primary project namespace).
- **Interfaces:** `IPascalCase` (optional, but consistent if used). - **Interfaces:** `IPascalCase`.
### Project Structure ### Project Structure
- `include/cloud_point_rpc/`: Public header files. - `include/cloud_point_rpc/`: Public header files.
@ -92,7 +92,7 @@ Adhere strictly to **Modern C++20** standards.
### Example Class ### Example Class
```cpp ```cpp
namespace cloud_point_rpc { namespace score {
/// @brief Manages camera parameters. /// @brief Manages camera parameters.
class CameraController { class CameraController {
@ -114,7 +114,7 @@ class CameraController {
std::vector<double> cached_intrinsics_; std::vector<double> cached_intrinsics_;
}; };
} // namespace cloud_point_rpc } // namespace score
``` ```
### Implementation Details ### Implementation Details

View File

@ -2,10 +2,19 @@
Communication JSON RPC protocol and implementation with Unity Scene. Communication JSON RPC protocol and implementation with Unity Scene.
## TODO ## Project Structure
- `include/`: Header files for the RPC server, TCP server, and C-API.
- `src/`: Implementation of the RPC logic, networking, and C-API.
- `src/cloud_point/`: OpenCV-based image processing and rectification logic.
- `docs/`: Documentation diagrams and models.
- `subprojects/`: Dependencies managed by Meson.
## Status
- [x] Server implementation with C-API for Unity - [x] Server implementation with C-API for Unity
- [ ] Client correct implementation with OpenCV - [x] Basic OpenCV image processing (Rectification, Image wrapper)
- [ ] Full OpenCV client implementation
## API Documentation ## API Documentation
@ -17,20 +26,29 @@ The project uses **Meson** build system and **C++20**.
### Dependencies ### Dependencies
- Meson, Ninja - Meson (>= 1.1.0), Ninja
- GCC/Clang (C++20 support) - GCC/Clang (C++20 support)
- Git (for subprojects) - Git (for subprojects)
- OpenCV (for cloud point compute)
The following dependencies are managed via Meson subprojects:
- [ASIO](https://think-async.com/Asio/) (Networking)
- [nlohmann/json](https://github.com/nlohmann/json) (JSON serialization)
- [yaml-cpp](https://github.com/jbeder/yaml-cpp) (Configuration loading)
- [glog](https://github.com/google/glog) (Logging)
- [jsonrpccxx](https://github.com/uS-S/jsonrpccxx) (JSON-RPC 2.0 implementation)
- [stdexec](https://github.com/NVIDIA/stdexec) (P2300 Senders/Receivers)
### Build & Run ### Build & Run
```bash ```bash
git submodule init
git submodule update
meson setup build meson setup build
meson compile -C build meson compile -C build
./build/src/cloud_point_rpc_server config.yaml ./build/src/cloud_point_rpc_server config.yaml
``` ```
*Note: You need a `config.yaml` file. See `config.yaml.example` for the required format.*
#### Build on windows #### Build on windows
It's assumed that you have `GCC` and `make`/`ninja` installed on your system (and available in `PATH`) It's assumed that you have `GCC` and `make`/`ninja` installed on your system (and available in `PATH`)

11
config.yaml.example Normal file
View File

@ -0,0 +1,11 @@
server:
ip: "127.0.0.1"
port: 8080
test_data:
intrinsic_params: [1.0, 0.0, 0.0, 0.0, 1.0, 0.0, 0.0, 0.0, 1.0]
extrinsic_params: [1.0, 0.0, 0.0, 0.0, 0.0, 1.0, 0.0, 0.0, 0.0, 0.0, 1.0, 0.0, 0.0, 0.0, 0.0, 1.0]
cloud_point:
- [0.1, 0.2, 0.3]
- [1.1, 1.2, 1.3]
- [5.5, 6.6, 7.7]

View File

@ -1,8 +1,8 @@
#pragma once #pragma once
#include "export.h"
#include <iostream> #include <iostream>
#include <string> #include <string>
#include "export.h"
namespace score { namespace score {
/** /**
@ -14,7 +14,7 @@ namespace score {
* @param port Server Port * @param port Server Port
* @return int exit code * @return int exit code
*/ */
int CRPC_EXPORT run_cli(std::istream &input, std::ostream &output, const std::string &ip, int CRPC_EXPORT run_cli(std::istream &input, std::ostream &output,
int port); const std::string &ip, int port);
} // namespace cloud_point_rpc } // namespace score

View File

@ -69,4 +69,4 @@ class ConfigLoader {
} }
}; };
} // namespace cloud_point_rpc } // namespace score

View File

@ -36,4 +36,4 @@ class RpcClient : public jsonrpccxx::JsonRpcClient {
int id{0}; int id{0};
}; };
} // namespace cloud_point_rpc } // namespace score

View File

@ -1,15 +1,15 @@
#pragma once #pragma once
#include "export.h"
#include <functional> #include <functional>
#include <jsonrpccxx/server.hpp> #include <jsonrpccxx/server.hpp>
#include <map> #include <map>
#include <nlohmann/json.hpp> #include <nlohmann/json.hpp>
#include <string> #include <string>
#include "export.h"
extern "C" { extern "C" {
struct rpc_string { struct rpc_string {
rpc_string(const char* data, uint64_t size) : s(data,size) {} rpc_string(const char *data, uint64_t size) : s(data, size) {}
rpc_string() = default; rpc_string() = default;
std::string s; std::string s;
@ -20,8 +20,8 @@ namespace score {
class CRPC_EXPORT RpcServer { class CRPC_EXPORT RpcServer {
public: public:
using Handler = std::function<nlohmann::json(const nlohmann::json &)>; using Handler = std::function<nlohmann::json(const nlohmann::json &)>;
using callback_t = rpc_string*(*)(rpc_string*); using callback_t = rpc_string *(*)(rpc_string *);
void register_method(const std::string &name, Handler handler); void register_method(const std::string &name, Handler handler);
void register_method(const std::string &name, callback_t handler); void register_method(const std::string &name, callback_t handler);
@ -32,4 +32,4 @@ class CRPC_EXPORT RpcServer {
std::map<std::string, Handler> handlers_; std::map<std::string, Handler> handlers_;
}; };
} // namespace cloud_point_rpc } // namespace score

View File

@ -34,4 +34,4 @@ template <NumericType T> T deserialize(const std::vector<uint8_t> &buffer) {
return *reinterpret_cast<const T *>(buffer.data()); return *reinterpret_cast<const T *>(buffer.data());
} }
} // namespace cloud_point_rpc } // namespace score

View File

@ -1,8 +1,8 @@
#pragma once #pragma once
#include "cloud_point_rpc/config.hpp" #include "cloud_point_rpc/config.hpp"
#include <vector>
#include "export.h" #include "export.h"
#include <vector>
namespace score { namespace score {
class CRPC_EXPORT Service { class CRPC_EXPORT Service {
@ -17,4 +17,4 @@ class CRPC_EXPORT Service {
TestData data_; TestData data_;
}; };
} // namespace cloud_point_rpc } // namespace score

View File

@ -1,11 +1,11 @@
#pragma once #pragma once
#include "cloud_point_rpc/serialize.hpp" #include "cloud_point_rpc/serialize.hpp"
#include "export.h"
#include "jsonrpccxx/iclientconnector.hpp" #include "jsonrpccxx/iclientconnector.hpp"
#include <asio.hpp> #include <asio.hpp>
#include <cloud_point_rpc/tcp_read.hpp> #include <cloud_point_rpc/tcp_read.hpp>
#include <glog/logging.h> #include <glog/logging.h>
#include <string> #include <string>
#include "export.h"
namespace score { namespace score {
/** /**
* TCPConnector main purpose is to implement jsonrpccxx::IClientConnector Send * TCPConnector main purpose is to implement jsonrpccxx::IClientConnector Send
@ -43,4 +43,4 @@ class CRPC_EXPORT TCPConnector : public jsonrpccxx::IClientConnector {
asio::ip::tcp::socket socket_; asio::ip::tcp::socket socket_;
}; };
} // namespace cloud_point_rpc } // namespace score

View File

@ -40,4 +40,4 @@ static inline std::string tcp_read(asio::ip::tcp::socket &socket,
return result; return result;
} }
} // namespace cloud_point_rpc } // namespace score

View File

@ -1,15 +1,15 @@
#pragma once #pragma once
#include "export.h"
#include <asio.hpp> #include <asio.hpp>
#include <atomic> #include <atomic>
#include <cloud_point_rpc/tcp_read.hpp> #include <cloud_point_rpc/tcp_read.hpp>
#include <functional> #include <functional>
#include <glog/logging.h> #include <glog/logging.h>
#include <string>
#include <thread>
#include "export.h"
#include <list> #include <list>
#include <ranges> #include <ranges>
#include <string>
#include <thread>
namespace score { namespace score {
class CRPC_EXPORT TcpServer { class CRPC_EXPORT TcpServer {
@ -43,14 +43,17 @@ class CRPC_EXPORT TcpServer {
accept_thread_ = std::jthread([this]() { accept_thread_ = std::jthread([this]() {
LOG(INFO) << "Accept thread started"; LOG(INFO) << "Accept thread started";
while (running_) { while (running_) {
std::ranges::remove_if(client_threads.begin(), client_threads.end(), [](auto& client_info) { std::ranges::remove_if(
bool result = false; client_threads.begin(), client_threads.end(),
if (client_info.second.wait_for(0ms) == std::future_status::ready) { [](auto &client_info) {
client_info.first.join(); bool result = false;
result = true; if (client_info.second.wait_for(0ms) ==
} std::future_status::ready) {
return result; client_info.first.join();
}); result = true;
}
return result;
});
try { try {
auto socket = std::make_shared<asio::ip::tcp::socket>( auto socket = std::make_shared<asio::ip::tcp::socket>(
io_context_); io_context_);
@ -60,10 +63,12 @@ class CRPC_EXPORT TcpServer {
<< "New connection from " << "New connection from "
<< socket->remote_endpoint().address().to_string(); << socket->remote_endpoint().address().to_string();
auto done = std::make_shared<std::promise<bool>>(); auto done = std::make_shared<std::promise<bool>>();
client_threads.push_back(std::make_pair(std::jthread([this, socket, done]() { client_threads.push_back(
handle_client(socket); std::make_pair(std::jthread([this, socket, done]() {
done->set_value(true); handle_client(socket);
}),done->get_future())); done->set_value(true);
}),
done->get_future()));
} catch (const std::system_error &e) { } catch (const std::system_error &e) {
LOG(INFO) << "Accept exception: " << e.what(); LOG(INFO) << "Accept exception: " << e.what();
if (running_) { if (running_) {
@ -144,4 +149,4 @@ class CRPC_EXPORT TcpServer {
std::jthread accept_thread_; std::jthread accept_thread_;
}; };
} // namespace cloud_point_rpc } // namespace score

View File

@ -86,4 +86,4 @@ int run_cli(std::istream &input, std::ostream &output, const std::string &ip,
return 0; return 0;
} }
} // namespace cloud_point_rpc } // namespace score

View File

@ -21,11 +21,11 @@ void RpcServer::register_method(const std::string &name, Handler handler) {
handlers_[name] = std::move(handler); handlers_[name] = std::move(handler);
} }
void RpcServer::register_method(const std::string& name, callback_t handler) { void RpcServer::register_method(const std::string &name, callback_t handler) {
handlers_[name] = [handler](const nlohmann::json& j) -> nlohmann::json { handlers_[name] = [handler](const nlohmann::json &j) -> nlohmann::json {
rpc_string tmp; rpc_string tmp;
tmp.s = j.dump(); tmp.s = j.dump();
rpc_string* res = handler(&tmp); rpc_string *res = handler(&tmp);
return {res->s}; return {res->s};
}; };
} }
@ -66,4 +66,4 @@ std::string RpcServer::process(const std::string &request_str) {
} }
} }
} // namespace cloud_point_rpc } // namespace score

View File

@ -27,4 +27,4 @@ std::vector<std::vector<double>> Service::get_cloud_point() const {
return data_.cloud_point; return data_.cloud_point;
} }
} // namespace cloud_point_rpc } // namespace score