summaryrefslogtreecommitdiffstats
path: root/src/librbd/asio/Utils.h
blob: 2fbbb5846fd6592116b9009e67c3473ec638975e (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
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