summaryrefslogtreecommitdiffstats
path: root/src/librbd/asio/Utils.h
diff options
context:
space:
mode:
Diffstat (limited to '')
-rw-r--r--src/librbd/asio/Utils.h33
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 000000000..2fbbb5846
--- /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