diff --git a/AGENTS.md b/AGENTS.md index 2889a48..94c948b 100644 --- a/AGENTS.md +++ b/AGENTS.md @@ -66,12 +66,12 @@ Adhere strictly to **Modern C++20** standards. ### Naming Conventions - **Files:** `snake_case.cpp`, `snake_case.hpp`. - **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`. - **Private Members:** `snake_case_` (trailing underscore). -- **Constants:** `kPascalCase` or `ALL_CAPS` for macros (avoid macros). -- **Namespaces:** `snake_case`. -- **Interfaces:** `IPascalCase` (optional, but consistent if used). +- **Constants:** `kPascalCase` or `ALL_CAPS` for macros. +- **Namespaces:** `score` (primary project namespace). +- **Interfaces:** `IPascalCase`. ### Project Structure - `include/cloud_point_rpc/`: Public header files. @@ -92,7 +92,7 @@ Adhere strictly to **Modern C++20** standards. ### Example Class ```cpp -namespace cloud_point_rpc { +namespace score { /// @brief Manages camera parameters. class CameraController { @@ -114,7 +114,7 @@ class CameraController { std::vector cached_intrinsics_; }; -} // namespace cloud_point_rpc +} // namespace score ``` ### Implementation Details diff --git a/README.md b/README.md index 12593f3..094ee43 100644 --- a/README.md +++ b/README.md @@ -2,10 +2,19 @@ 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 -- [ ] Client correct implementation with OpenCV +- [x] Basic OpenCV image processing (Rectification, Image wrapper) +- [ ] Full OpenCV client implementation ## API Documentation @@ -17,20 +26,29 @@ The project uses **Meson** build system and **C++20**. ### Dependencies -- Meson, Ninja +- Meson (>= 1.1.0), Ninja - GCC/Clang (C++20 support) - 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 ```bash -git submodule init -git submodule update meson setup build meson compile -C build ./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 It's assumed that you have `GCC` and `make`/`ninja` installed on your system (and available in `PATH`) diff --git a/config.yaml.example b/config.yaml.example new file mode 100644 index 0000000..cdd9da7 --- /dev/null +++ b/config.yaml.example @@ -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] diff --git a/include/cloud_point_rpc/cli.hpp b/include/cloud_point_rpc/cli.hpp index 155478d..6e83ed2 100644 --- a/include/cloud_point_rpc/cli.hpp +++ b/include/cloud_point_rpc/cli.hpp @@ -1,8 +1,8 @@ #pragma once +#include "export.h" #include #include -#include "export.h" namespace score { /** @@ -14,7 +14,7 @@ namespace score { * @param port Server Port * @return int exit code */ -int CRPC_EXPORT run_cli(std::istream &input, std::ostream &output, const std::string &ip, - int port); +int CRPC_EXPORT run_cli(std::istream &input, std::ostream &output, + const std::string &ip, int port); -} // namespace cloud_point_rpc +} // namespace score diff --git a/include/cloud_point_rpc/config.hpp b/include/cloud_point_rpc/config.hpp index a1a172b..cd60cb2 100644 --- a/include/cloud_point_rpc/config.hpp +++ b/include/cloud_point_rpc/config.hpp @@ -69,4 +69,4 @@ class ConfigLoader { } }; -} // namespace cloud_point_rpc +} // namespace score diff --git a/include/cloud_point_rpc/rpc_client.hpp b/include/cloud_point_rpc/rpc_client.hpp index f7c8861..134c57a 100644 --- a/include/cloud_point_rpc/rpc_client.hpp +++ b/include/cloud_point_rpc/rpc_client.hpp @@ -36,4 +36,4 @@ class RpcClient : public jsonrpccxx::JsonRpcClient { int id{0}; }; -} // namespace cloud_point_rpc +} // namespace score diff --git a/include/cloud_point_rpc/rpc_server.hpp b/include/cloud_point_rpc/rpc_server.hpp index d5dc23b..698d9cb 100644 --- a/include/cloud_point_rpc/rpc_server.hpp +++ b/include/cloud_point_rpc/rpc_server.hpp @@ -1,15 +1,15 @@ #pragma once +#include "export.h" #include #include #include #include #include -#include "export.h" extern "C" { 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; std::string s; @@ -20,8 +20,8 @@ namespace score { class CRPC_EXPORT RpcServer { public: - using Handler = std::function; - using callback_t = rpc_string*(*)(rpc_string*); + using Handler = std::function; + using callback_t = rpc_string *(*)(rpc_string *); void register_method(const std::string &name, Handler handler); void register_method(const std::string &name, callback_t handler); @@ -32,4 +32,4 @@ class CRPC_EXPORT RpcServer { std::map handlers_; }; -} // namespace cloud_point_rpc +} // namespace score diff --git a/include/cloud_point_rpc/serialize.hpp b/include/cloud_point_rpc/serialize.hpp index 187307b..03d5dfc 100644 --- a/include/cloud_point_rpc/serialize.hpp +++ b/include/cloud_point_rpc/serialize.hpp @@ -34,4 +34,4 @@ template T deserialize(const std::vector &buffer) { return *reinterpret_cast(buffer.data()); } -} // namespace cloud_point_rpc \ No newline at end of file +} // namespace score \ No newline at end of file diff --git a/include/cloud_point_rpc/service.hpp b/include/cloud_point_rpc/service.hpp index efadc6c..2b20ed2 100644 --- a/include/cloud_point_rpc/service.hpp +++ b/include/cloud_point_rpc/service.hpp @@ -1,8 +1,8 @@ #pragma once #include "cloud_point_rpc/config.hpp" -#include #include "export.h" +#include namespace score { class CRPC_EXPORT Service { @@ -17,4 +17,4 @@ class CRPC_EXPORT Service { TestData data_; }; -} // namespace cloud_point_rpc +} // namespace score diff --git a/include/cloud_point_rpc/tcp_connector.hpp b/include/cloud_point_rpc/tcp_connector.hpp index a9d1ab0..6e041b1 100644 --- a/include/cloud_point_rpc/tcp_connector.hpp +++ b/include/cloud_point_rpc/tcp_connector.hpp @@ -1,11 +1,11 @@ #pragma once #include "cloud_point_rpc/serialize.hpp" +#include "export.h" #include "jsonrpccxx/iclientconnector.hpp" #include #include #include #include -#include "export.h" namespace score { /** * 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_; }; -} // namespace cloud_point_rpc \ No newline at end of file +} // namespace score \ No newline at end of file diff --git a/include/cloud_point_rpc/tcp_read.hpp b/include/cloud_point_rpc/tcp_read.hpp index 6c0b2f6..5f5cdbb 100644 --- a/include/cloud_point_rpc/tcp_read.hpp +++ b/include/cloud_point_rpc/tcp_read.hpp @@ -40,4 +40,4 @@ static inline std::string tcp_read(asio::ip::tcp::socket &socket, return result; } -} // namespace cloud_point_rpc \ No newline at end of file +} // namespace score \ No newline at end of file diff --git a/include/cloud_point_rpc/tcp_server.hpp b/include/cloud_point_rpc/tcp_server.hpp index 0cf73fd..1fa6287 100644 --- a/include/cloud_point_rpc/tcp_server.hpp +++ b/include/cloud_point_rpc/tcp_server.hpp @@ -1,15 +1,15 @@ #pragma once +#include "export.h" #include #include #include #include #include -#include -#include -#include "export.h" #include #include +#include +#include namespace score { class CRPC_EXPORT TcpServer { @@ -43,14 +43,17 @@ class CRPC_EXPORT TcpServer { accept_thread_ = std::jthread([this]() { LOG(INFO) << "Accept thread started"; while (running_) { - std::ranges::remove_if(client_threads.begin(), client_threads.end(), [](auto& client_info) { - bool result = false; - if (client_info.second.wait_for(0ms) == std::future_status::ready) { - client_info.first.join(); - result = true; - } - return result; - }); + std::ranges::remove_if( + client_threads.begin(), client_threads.end(), + [](auto &client_info) { + bool result = false; + if (client_info.second.wait_for(0ms) == + std::future_status::ready) { + client_info.first.join(); + result = true; + } + return result; + }); try { auto socket = std::make_shared( io_context_); @@ -60,10 +63,12 @@ class CRPC_EXPORT TcpServer { << "New connection from " << socket->remote_endpoint().address().to_string(); auto done = std::make_shared>(); - client_threads.push_back(std::make_pair(std::jthread([this, socket, done]() { - handle_client(socket); - done->set_value(true); - }),done->get_future())); + client_threads.push_back( + std::make_pair(std::jthread([this, socket, done]() { + handle_client(socket); + done->set_value(true); + }), + done->get_future())); } catch (const std::system_error &e) { LOG(INFO) << "Accept exception: " << e.what(); if (running_) { @@ -144,4 +149,4 @@ class CRPC_EXPORT TcpServer { std::jthread accept_thread_; }; -} // namespace cloud_point_rpc +} // namespace score diff --git a/src/cli.cpp b/src/cli.cpp index 8b4bd0c..75181a3 100644 --- a/src/cli.cpp +++ b/src/cli.cpp @@ -86,4 +86,4 @@ int run_cli(std::istream &input, std::ostream &output, const std::string &ip, return 0; } -} // namespace cloud_point_rpc +} // namespace score diff --git a/src/rpc_server.cpp b/src/rpc_server.cpp index 08d3012..98a1dee 100644 --- a/src/rpc_server.cpp +++ b/src/rpc_server.cpp @@ -21,11 +21,11 @@ void RpcServer::register_method(const std::string &name, Handler handler) { handlers_[name] = std::move(handler); } -void RpcServer::register_method(const std::string& name, callback_t handler) { - handlers_[name] = [handler](const nlohmann::json& j) -> nlohmann::json { +void RpcServer::register_method(const std::string &name, callback_t handler) { + handlers_[name] = [handler](const nlohmann::json &j) -> nlohmann::json { rpc_string tmp; - tmp.s = j.dump(); - rpc_string* res = handler(&tmp); + tmp.s = j.dump(); + rpc_string *res = handler(&tmp); return {res->s}; }; } @@ -66,4 +66,4 @@ std::string RpcServer::process(const std::string &request_str) { } } -} // namespace cloud_point_rpc +} // namespace score diff --git a/src/service.cpp b/src/service.cpp index 2745d5b..a77de00 100644 --- a/src/service.cpp +++ b/src/service.cpp @@ -27,4 +27,4 @@ std::vector> Service::get_cloud_point() const { return data_.cloud_point; } -} // namespace cloud_point_rpc +} // namespace score