zmq_client.h 1.3 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859
  1. #ifndef DEPTHGUIDE_ZMQ_CLIENT_H
  2. #define DEPTHGUIDE_ZMQ_CLIENT_H
  3. #include "core/cuda_helper.hpp"
  4. #include "core/image_utility_v2.h"
  5. #include <boost/container/static_vector.hpp>
  6. #include <nlohmann/json.hpp>
  7. #include <memory>
  8. class zmq_client {
  9. public:
  10. static constexpr auto max_img_cnt = 2;
  11. using img_list_type =
  12. boost::container::static_vector<image_ptr, max_img_cnt>;
  13. struct request_type {
  14. img_list_type img_list;
  15. std::string model_name;
  16. nlohmann::json extra;
  17. };
  18. struct reply_type {
  19. img_list_type img_list;
  20. nlohmann::json extra;
  21. };
  22. // reply will be call in another thread
  23. using reply_cb_type = std::function<void(reply_type)>;
  24. struct create_config {
  25. std::string python_interpreter;
  26. std::string server_working_dir;
  27. std::string server_script_path;
  28. std::string serv_addr; // like "ipc://fast_sam_v1"
  29. reply_cb_type reply_cb;
  30. CUcontext *cuda_ctx = nullptr;
  31. };
  32. explicit zmq_client(const create_config &conf);
  33. ~zmq_client();
  34. // requests will be dropped if the previous request has not been finished.
  35. void request(const request_type &req);
  36. bool is_ideal() const;
  37. bool is_running() const;
  38. private:
  39. struct impl;
  40. std::unique_ptr<impl> pimpl;
  41. };
  42. #endif //DEPTHGUIDE_ZMQ_CLIENT_H