diff options
Diffstat (limited to 'src/librbd/asio/Utils.h')
-rw-r--r-- | src/librbd/asio/Utils.h | 33 |
1 files changed, 33 insertions, 0 deletions
diff --git a/src/librbd/asio/Utils.h b/src/librbd/asio/Utils.h new file mode 100644 index 00000000000..2fbbb5846fd --- /dev/null +++ b/src/librbd/asio/Utils.h @@ -0,0 +1,33 @@ +// -*- mode:C++; tab-width:8; c-basic-offset:2; indent-tabs-mode:t -*- +// vim: ts=8 sw=2 smarttab + +#ifndef CEPH_LIBRBD_ASIO_UTILS_H +#define CEPH_LIBRBD_ASIO_UTILS_H + +#include "include/Context.h" +#include "include/rados/librados_fwd.hpp" +#include <boost/system/error_code.hpp> + +namespace librbd { +namespace asio { +namespace util { + +template <typename T> +auto get_context_adapter(T&& t) { + return [t = std::move(t)](boost::system::error_code ec) { + t->complete(-ec.value()); + }; +} + +template <typename T> +auto get_callback_adapter(T&& t) { + return [t = std::move(t)](boost::system::error_code ec, auto&& ... args) { + t(-ec.value(), std::forward<decltype(args)>(args)...); + }; +} + +} // namespace util +} // namespace asio +} // namespace librbd + +#endif // CEPH_LIBRBD_ASIO_UTILS_H |