|
|
@@ -9,8 +9,6 @@ using boost::system::error_code;
|
|
|
|
|
|
namespace zmq_client_impl {
|
|
|
|
|
|
-// zmq::context_t zmq_ctx;
|
|
|
-
|
|
|
const char *cv_type_to_dtype(int type) {
|
|
|
static constexpr bool le =
|
|
|
boost::endian::order::native == boost::endian::order::little;
|
|
|
@@ -134,6 +132,16 @@ namespace zmq_client_impl {
|
|
|
}
|
|
|
|
|
|
zmq_client::impl::impl(const create_config &conf) {
|
|
|
+ // create python process
|
|
|
+ static constexpr auto zmq_server_path =
|
|
|
+ "/home/tpx/project/DepthGuide/src/ai/impl/python";
|
|
|
+ bp::environment aux_env =
|
|
|
+ boost::this_process::environment();
|
|
|
+ aux_env["PYTHONPATH"] += zmq_server_path;
|
|
|
+ aux_proc = std::make_unique<bp::child>(
|
|
|
+ conf.python_interpreter, conf.server_script_path,
|
|
|
+ aux_env, bp::start_dir(conf.server_working_dir));
|
|
|
+
|
|
|
aux_ctx = std::make_unique<io_context>();
|
|
|
aux_thread = std::make_unique<std::thread>([=, this]() {
|
|
|
aux_thread_work(conf);
|
|
|
@@ -143,6 +151,7 @@ zmq_client::impl::impl(const create_config &conf) {
|
|
|
zmq_client::impl::~impl() {
|
|
|
aux_ctx->stop();
|
|
|
aux_thread->join();
|
|
|
+ aux_proc->terminate();
|
|
|
}
|
|
|
|
|
|
void zmq_client::impl::aux_thread_work(const create_config &conf) {
|
|
|
@@ -188,8 +197,12 @@ void zmq_client::impl::on_reply(const data_type &data) {
|
|
|
socket_busy.clear();
|
|
|
}
|
|
|
|
|
|
+bool zmq_client::impl::is_running() const {
|
|
|
+ return aux_proc->running();
|
|
|
+}
|
|
|
+
|
|
|
void zmq_client::impl::on_request(const request_type &req) {
|
|
|
- if (socket_busy.test()) return;
|
|
|
+ if (socket_busy.test() || !is_running()) return;
|
|
|
post(*aux_ctx, [req = req, this]() { aux_on_request(req); });
|
|
|
}
|
|
|
|