]> git.proxmox.com Git - ceph.git/blob - ceph/src/tools/rbd_mirror/CancelableRequest.h
update source to Ceph Pacific 16.2.2
[ceph.git] / ceph / src / tools / rbd_mirror / CancelableRequest.h
1 // -*- mode:C++; tab-width:8; c-basic-offset:2; indent-tabs-mode:t -*-
2 // vim: ts=8 sw=2 smarttab
3
4 #ifndef CEPH_RBD_MIRROR_CANCELABLE_REQUEST_H
5 #define CEPH_RBD_MIRROR_CANCELABLE_REQUEST_H
6
7 #include "common/RefCountedObj.h"
8 #include "include/Context.h"
9
10 namespace rbd {
11 namespace mirror {
12
13 class CancelableRequest : public RefCountedObject {
14 public:
15 CancelableRequest(const std::string& name, CephContext *cct,
16 Context *on_finish)
17 : RefCountedObject(cct), m_name(name), m_cct(cct),
18 m_on_finish(on_finish) {
19 }
20
21 virtual void send() = 0;
22 virtual void cancel() {}
23
24 protected:
25 virtual void finish(int r) {
26 if (m_cct) {
27 lsubdout(m_cct, rbd_mirror, 20) << m_name << "::finish: r=" << r << dendl;
28 }
29 if (m_on_finish) {
30 m_on_finish->complete(r);
31 }
32 put();
33 }
34
35 private:
36 const std::string m_name;
37 CephContext *m_cct;
38 Context *m_on_finish;
39 };
40
41 } // namespace mirror
42 } // namespace rbd
43
44 #endif // CEPH_RBD_MIRROR_CANCELABLE_REQUEST_H