summaryrefslogtreecommitdiffstats
path: root/src/tools/rbd_mirror/CancelableRequest.h
blob: 26e8dcb5b0835f6b8ac74b91c49cd86ff279750d (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
34
35
36
37
38
39
40
41
42
43
44
// -*- mode:C++; tab-width:8; c-basic-offset:2; indent-tabs-mode:t -*-
// vim: ts=8 sw=2 smarttab

#ifndef CEPH_RBD_MIRROR_CANCELABLE_REQUEST_H
#define CEPH_RBD_MIRROR_CANCELABLE_REQUEST_H

#include "common/RefCountedObj.h"
#include "include/Context.h"

namespace rbd {
namespace mirror {

class CancelableRequest : public RefCountedObject {
public:
  CancelableRequest(const std::string& name, CephContext *cct,
                    Context *on_finish)
    : RefCountedObject(cct), m_name(name), m_cct(cct),
      m_on_finish(on_finish) {
  }

  virtual void send() = 0;
  virtual void cancel() {}

protected:
  virtual void finish(int r) {
    if (m_cct) {
      lsubdout(m_cct, rbd_mirror, 20) << m_name << "::finish: r=" << r << dendl;
    }
    if (m_on_finish) {
      m_on_finish->complete(r);
    }
    put();
  }

private:
  const std::string m_name;
  CephContext *m_cct;
  Context *m_on_finish;
};

} // namespace mirror
} // namespace rbd

#endif // CEPH_RBD_MIRROR_CANCELABLE_REQUEST_H