]> git.proxmox.com Git - ceph.git/blob - ceph/src/mgr/MgrContext.h
import ceph 14.2.5
[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 "mon/MonClient.h"
21
22 class Command
23 {
24 protected:
25 C_SaferCond cond;
26 public:
27 bufferlist outbl;
28 std::string outs;
29 int r;
30
31 void run(MonClient *monc, const std::string &command)
32 {
33 monc->start_mon_command({command}, {},
34 &outbl, &outs, &cond);
35 }
36
37 virtual void wait()
38 {
39 r = cond.wait();
40 }
41
42 virtual ~Command() {}
43 };
44
45
46 class JSONCommand : public Command
47 {
48 public:
49 json_spirit::mValue json_result;
50
51 void wait() override
52 {
53 Command::wait();
54
55 if (r == 0) {
56 bool read_ok = json_spirit::read(
57 outbl.to_str(), json_result);
58 if (!read_ok) {
59 r = -EINVAL;
60 }
61 }
62 }
63 };
64
65 #endif
66