// -*- mode:C++; tab-width:8; c-basic-offset:2; indent-tabs-mode:t -*- // vim: ts=8 sw=2 smarttab #ifndef CEPH_LIBRBD_ASIO_ENGINE_H #define CEPH_LIBRBD_ASIO_ENGINE_H #include "include/common_fwd.h" #include "include/rados/librados_fwd.hpp" #include #include #include #include #include struct Context; namespace neorados { struct RADOS; } namespace librbd { namespace asio { struct ContextWQ; } class AsioEngine { public: explicit AsioEngine(std::shared_ptr rados); explicit AsioEngine(librados::IoCtx& io_ctx); ~AsioEngine(); AsioEngine(AsioEngine&&) = delete; AsioEngine(const AsioEngine&) = delete; AsioEngine& operator=(const AsioEngine&) = delete; inline neorados::RADOS& get_rados_api() { return *m_rados_api; } inline boost::asio::io_context& get_io_context() { return m_io_context; } inline operator boost::asio::io_context&() { return m_io_context; } using executor_type = boost::asio::io_context::executor_type; inline executor_type get_executor() { return m_io_context.get_executor(); } inline boost::asio::io_context::strand& get_api_strand() { // API client callbacks should never fire concurrently return *m_api_strand; } inline asio::ContextWQ* get_work_queue() { return m_context_wq.get(); } template void dispatch(T&& t) { boost::asio::dispatch(m_io_context, std::forward(t)); } void dispatch(Context* ctx, int r); template void post(T&& t) { boost::asio::post(m_io_context, std::forward(t)); } void post(Context* ctx, int r); private: std::shared_ptr m_rados_api; CephContext* m_cct; boost::asio::io_context& m_io_context; std::unique_ptr m_api_strand; std::unique_ptr m_context_wq; }; } // namespace librbd #endif // CEPH_LIBRBD_ASIO_ENGINE_H