[feat] add minimal client and address-based init
All checks were successful
Verification / Is-Buildable (push) Successful in 3m40s

- add crpc_init_with_address for direct ip/port startup without yaml
- add minimal_client.cpp example using TCPConnector to send a ping
- set install_rpath '$ORIGIN' on shared libs so they find bundled deps
- ignore .worktrees/ for git worktree scratch directories
This commit is contained in:
Artur Mukhamadiev 2026-06-02 16:18:25 +03:00
parent e17eed40e4
commit 33dd44f454
5 changed files with 67 additions and 0 deletions

1
.gitignore vendored
View File

@ -8,3 +8,4 @@ subprojects/packagecache/
subprojects/yaml-cpp-0.8.0
subprojects/base64-0.5.2/
.venv/
.worktrees/

View File

@ -27,6 +27,7 @@ CRPC_EXPORT void crpc_str_destroy(rpc_string*);
typedef rpc_string*(*callback_t)(rpc_string*);
CRPC_EXPORT void crpc_init(const char* config_path);
CRPC_EXPORT void crpc_init_with_address(const char* ip, int port);
CRPC_EXPORT void crpc_deinit();
CRPC_EXPORT void crpc_add_method(callback_t cb, rpc_string* name);

View File

@ -13,6 +13,7 @@ libcloud_point_rpc = shared_library(
include_directories: inc,
dependencies: [json_dep, thread_dep, glog_dep, yaml_dep, asio_dep, base64_dep],
install: true,
install_rpath: '$ORIGIN',
)
cloud_point_rpc_dep = declare_dependency(
@ -27,6 +28,7 @@ libcloud_point_rpc_test = shared_library(
'test_api.cpp',
dependencies: cloud_point_rpc_dep,
install: true,
install_rpath: '$ORIGIN',
)
cloud_point_rpc_test_dep = declare_dependency(
@ -67,3 +69,11 @@ executable(
link_args: '-pthread',
install: true,
)
# Minimal client example
executable(
'minimal_client',
'minimal_client.cpp',
dependencies: cloud_point_rpc_dep,
install: true,
)

34
src/minimal_client.cpp Normal file
View File

@ -0,0 +1,34 @@
#include "cloud_point_rpc/config.hpp"
#include "cloud_point_rpc/tcp_connector.hpp"
#include <glog/logging.h>
#include <iostream>
#include <string>
int main(int argc, char *argv[]) {
google::InitGoogleLogging(argv[0]);
FLAGS_logtostderr = 1;
std::string config_path = "config.yml";
if (argc > 1) {
config_path = argv[1];
}
try {
auto config = score::ConfigLoader::load(config_path);
score::TCPConnector connector(config.server.ip,
static_cast<size_t>(config.server.port));
const std::string request =
R"({"jsonrpc":"2.0","method":"ping","params":{},"id":1})";
std::string response = connector.Send(request);
std::cout << response << std::endl;
} catch (const std::exception &e) {
std::cerr << "Error: " << e.what() << std::endl;
return 1;
}
return 0;
}

View File

@ -76,6 +76,27 @@ void crpc_init(const char *config_path) {
}
}
void crpc_init_with_address(const char *ip, int port) {
if (!google::IsGoogleLoggingInitialized())
google::InitGoogleLogging("CloudPointRPC");
if (!ip) {
LOG(ERROR) << "ip was not provided";
return;
}
try {
server = std::make_unique<score::TcpServer>(
std::string(ip), static_cast<size_t>(port),
[&](const std::string &request) {
std::lock_guard lock(server_mtx);
return rpc_server.process(request);
});
server->start();
LOG(INFO) << "Server started on " << ip << ":" << port;
} catch (const std::exception &e) {
LOG(ERROR) << "Fatal error: " << e.what();
}
}
void crpc_deinit() {
server.reset();
std::lock_guard lock(gc_mtx);