Advertisement
Guest User

Untitled

a guest
Nov 13th, 2019
123
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 1.51 KB | None | 0 0
  1. class ws_impl
  2. : public std::enable_shared_from_this<ws_impl>
  3. {
  4. ALLOW_MAKE_SHARED(ws_impl)
  5.  
  6. public:
  7. static std::shared_ptr<ws_impl> create(std::shared_ptr<websocket_client> client, uint32_t archive_idx, qt::qthread_executor& exec, std::shared_ptr<source_model> model, std::shared_ptr<archive_proxy_concurrent> archive)
  8. {
  9. auto object = std::make_shared<ws_impl>(client, archive_idx, exec, model, archive);
  10. object->run();
  11. return object;
  12. }
  13. void shutdown()
  14. {
  15. client_->unsubscribe_from_websocket(sources_token_);
  16. }
  17. ~ws_impl()
  18. {
  19. shutdown();
  20. }
  21. private:
  22. ws_impl(std::shared_ptr<websocket_client> client, uint32_t archive_idx, qt::qthread_executor& exec, std::shared_ptr<source_model> model, std::shared_ptr<archive_proxy_concurrent> archive)
  23. : client_(client)
  24. , archive_idx_(archive_idx_)
  25. , exec_(exec)
  26. , model_(*model)
  27. , archive_(archive)
  28. {
  29. }
  30. void run()
  31. {
  32. std::string resource = "/sources/";
  33. sources_token_ = fmt::format("{:x}_{}", ao::bit_cast<uint64_t>(this), resource);
  34. client_->subscribe_to_websocket(resource, sources_token_, 0,
  35. boost::asio::bind_post(exec_,
  36. [this /*, self = shared_from_this() */ , resource](const nlohmann::json& js, boost::system::error_code e)
  37. {
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement