]> git.proxmox.com Git - ceph.git/blob - ceph/src/mgr/MgrContext.h
update source to Ceph Pacific 16.2.2
[ceph.git] / ceph / src / mgr / MgrContext.h
1 // -*- mode:C++; tab-width:8; c-basic-offset:2; indent-tabs-mode:t -*-
2 // vim: ts=8 sw=2 smarttab
3 /*
4 * Ceph - scalable distributed file system
5 *
6 * Copyright (C) 2016 John Spray <john.spray@redhat.com>
7 *
8 * This is free software; you can redistribute it and/or
9 * modify it under the terms of the GNU Lesser General Public
10 * License version 2.1, as published by the Free Software
11 * Foundation. See file COPYING.
12 */
13
14 #ifndef MGR_CONTEXT_H_
15 #define MGR_CONTEXT_H_
16
17 #include <memory>
18
19 #include "common/ceph_json.h"
20 #include "common/Cond.h"
21 #include "mon/MonClient.h"
22
23 class Command
24 {
25 protected:
26 C_SaferCond cond;
27 public:
28 ceph::buffer::list outbl;
29 std::string outs;
30 int r;
31
32 void run(MonClient *monc, const std::string &command)
33 {
34 monc->start_mon_command({command}, {},
35 &outbl, &outs, &cond);
36 }
37
38 void run(MonClient *monc, const std::string &command, const ceph::buffer::list &inbl)
39 {
40 monc->start_mon_command({command}, inbl,
41 &outbl, &outs, &cond);
42 }
43
44 virtual void wait()
45 {
46 r = cond.wait();
47 }
48
49 virtual ~Command() {}
50 };
51
52
53 class JSONCommand : public Command
54 {
55 public:
56 json_spirit::mValue json_result;
57
58 void wait() override
59 {
60 Command::wait();
61
62 if (r == 0) {
63 bool read_ok = json_spirit::read(
64 outbl.to_str(), json_result);
65 if (!read_ok) {
66 r = -EINVAL;
67 }
68 }
69 }
70 };
71
72 #endif
73