[docs] consistency across impl and documentation
fully generated by gemini+opencode
This commit is contained in:
parent
2b12a0be9b
commit
e3b5be0f66
12
AGENTS.md
12
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<double> cached_intrinsics_;
|
||||
};
|
||||
|
||||
} // namespace cloud_point_rpc
|
||||
} // namespace score
|
||||
```
|
||||
|
||||
### Implementation Details
|
||||
|
||||
28
README.md
28
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`)
|
||||
|
||||
11
config.yaml.example
Normal file
11
config.yaml.example
Normal 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]
|
||||
@ -1,8 +1,8 @@
|
||||
#pragma once
|
||||
|
||||
#include "export.h"
|
||||
#include <iostream>
|
||||
#include <string>
|
||||
#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
|
||||
|
||||
@ -69,4 +69,4 @@ class ConfigLoader {
|
||||
}
|
||||
};
|
||||
|
||||
} // namespace cloud_point_rpc
|
||||
} // namespace score
|
||||
|
||||
@ -36,4 +36,4 @@ class RpcClient : public jsonrpccxx::JsonRpcClient {
|
||||
int id{0};
|
||||
};
|
||||
|
||||
} // namespace cloud_point_rpc
|
||||
} // namespace score
|
||||
|
||||
@ -1,15 +1,15 @@
|
||||
#pragma once
|
||||
|
||||
#include "export.h"
|
||||
#include <functional>
|
||||
#include <jsonrpccxx/server.hpp>
|
||||
#include <map>
|
||||
#include <nlohmann/json.hpp>
|
||||
#include <string>
|
||||
#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<nlohmann::json(const nlohmann::json &)>;
|
||||
using callback_t = rpc_string*(*)(rpc_string*);
|
||||
using Handler = std::function<nlohmann::json(const nlohmann::json &)>;
|
||||
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<std::string, Handler> handlers_;
|
||||
};
|
||||
|
||||
} // namespace cloud_point_rpc
|
||||
} // namespace score
|
||||
|
||||
@ -34,4 +34,4 @@ template <NumericType T> T deserialize(const std::vector<uint8_t> &buffer) {
|
||||
return *reinterpret_cast<const T *>(buffer.data());
|
||||
}
|
||||
|
||||
} // namespace cloud_point_rpc
|
||||
} // namespace score
|
||||
@ -1,8 +1,8 @@
|
||||
#pragma once
|
||||
|
||||
#include "cloud_point_rpc/config.hpp"
|
||||
#include <vector>
|
||||
#include "export.h"
|
||||
#include <vector>
|
||||
namespace score {
|
||||
|
||||
class CRPC_EXPORT Service {
|
||||
@ -17,4 +17,4 @@ class CRPC_EXPORT Service {
|
||||
TestData data_;
|
||||
};
|
||||
|
||||
} // namespace cloud_point_rpc
|
||||
} // namespace score
|
||||
|
||||
@ -1,11 +1,11 @@
|
||||
#pragma once
|
||||
#include "cloud_point_rpc/serialize.hpp"
|
||||
#include "export.h"
|
||||
#include "jsonrpccxx/iclientconnector.hpp"
|
||||
#include <asio.hpp>
|
||||
#include <cloud_point_rpc/tcp_read.hpp>
|
||||
#include <glog/logging.h>
|
||||
#include <string>
|
||||
#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
|
||||
} // namespace score
|
||||
@ -40,4 +40,4 @@ static inline std::string tcp_read(asio::ip::tcp::socket &socket,
|
||||
return result;
|
||||
}
|
||||
|
||||
} // namespace cloud_point_rpc
|
||||
} // namespace score
|
||||
@ -1,15 +1,15 @@
|
||||
#pragma once
|
||||
|
||||
#include "export.h"
|
||||
#include <asio.hpp>
|
||||
#include <atomic>
|
||||
#include <cloud_point_rpc/tcp_read.hpp>
|
||||
#include <functional>
|
||||
#include <glog/logging.h>
|
||||
#include <string>
|
||||
#include <thread>
|
||||
#include "export.h"
|
||||
#include <list>
|
||||
#include <ranges>
|
||||
#include <string>
|
||||
#include <thread>
|
||||
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<asio::ip::tcp::socket>(
|
||||
io_context_);
|
||||
@ -60,10 +63,12 @@ class CRPC_EXPORT TcpServer {
|
||||
<< "New connection from "
|
||||
<< socket->remote_endpoint().address().to_string();
|
||||
auto done = std::make_shared<std::promise<bool>>();
|
||||
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
|
||||
|
||||
@ -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
|
||||
|
||||
@ -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
|
||||
|
||||
@ -27,4 +27,4 @@ std::vector<std::vector<double>> Service::get_cloud_point() const {
|
||||
return data_.cloud_point;
|
||||
}
|
||||
|
||||
} // namespace cloud_point_rpc
|
||||
} // namespace score
|
||||
|
||||
Loading…
x
Reference in New Issue
Block a user