]> git.proxmox.com Git - ceph.git/blame - ceph/src/common/CommandTable.h
update sources to ceph Nautilus 14.2.1
[ceph.git] / ceph / src / common / CommandTable.h
CommitLineData
7c673cae
FG
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 Red Hat Inc
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
15#ifndef COMMAND_TABLE_H_
16#define COMMAND_TABLE_H_
17
18#include "messages/MCommand.h"
19
20class CommandOp
21{
22 public:
23 ConnectionRef con;
24 ceph_tid_t tid;
25
26 std::vector<std::string> cmd;
27 bufferlist inbl;
28 Context *on_finish;
29 bufferlist *outbl;
30 std::string *outs;
31
11fdf7f2 32 MCommand::ref get_message(const uuid_d &fsid) const
7c673cae 33 {
11fdf7f2 34 auto m = MCommand::create(fsid);
7c673cae
FG
35 m->cmd = cmd;
36 m->set_data(inbl);
37 m->set_tid(tid);
38
39 return m;
40 }
41
42 CommandOp(const ceph_tid_t t) : tid(t), on_finish(nullptr),
43 outbl(nullptr), outs(nullptr) {}
44 CommandOp() : tid(0), on_finish(nullptr), outbl(nullptr), outs(nullptr) {}
45};
46
47/**
48 * Hold client-side state for a collection of in-flight commands
49 * to a remote service.
50 */
51template<typename T>
52class CommandTable
53{
54protected:
55 ceph_tid_t last_tid;
56 std::map<ceph_tid_t, T> commands;
57
58public:
59
60 CommandTable()
61 : last_tid(0)
62 {}
63
64 ~CommandTable()
65 {
11fdf7f2 66 ceph_assert(commands.empty());
7c673cae
FG
67 }
68
69 T& start_command()
70 {
71 ceph_tid_t tid = last_tid++;
72 commands.insert(std::make_pair(tid, T(tid)) );
73
74 return commands.at(tid);
75 }
76
77 const std::map<ceph_tid_t, T> &get_commands() const
78 {
79 return commands;
80 }
81
82 bool exists(ceph_tid_t tid) const
83 {
84 return commands.count(tid) > 0;
85 }
86
87 T& get_command(ceph_tid_t tid)
88 {
89 return commands.at(tid);
90 }
91
92 void erase(ceph_tid_t tid)
93 {
94 commands.erase(tid);
95 }
96
97 void clear() {
98 commands.clear();
99 }
100};
101
102#endif
103