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   	#include "messages/MMgrCommand.h"
20   	
21   	class CommandOp
22   	{
23   	  public:
24   	  ConnectionRef con;
25   	  ceph_tid_t tid;
26   	
27   	  std::vector<std::string> cmd;
28   	  ceph::buffer::list    inbl;
29   	  Context      *on_finish;
30   	  ceph::buffer::list   *outbl;
31   	  std::string  *outs;
32   	
33   	  MessageRef get_message(const uuid_d &fsid,
34   				 bool mgr=false) const
35   	  {
36   	    if (mgr) {
37   	      auto m = make_message<MMgrCommand>(fsid);
38   	      m->cmd = cmd;
39   	      m->set_data(inbl);
40   	      m->set_tid(tid);
41   	      return m;
42   	    } else {
43   	      auto m = make_message<MCommand>(fsid);
44   	      m->cmd = cmd;
45   	      m->set_data(inbl);
46   	      m->set_tid(tid);
47   	      return m;
48   	    }
49   	  }
50   	
51   	  CommandOp(const ceph_tid_t t) : tid(t), on_finish(nullptr),
52   	                                  outbl(nullptr), outs(nullptr) {}
53   	  CommandOp() : tid(0), on_finish(nullptr), outbl(nullptr), outs(nullptr) {}
54   	};
55   	
56   	/**
57   	 * Hold client-side state for a collection of in-flight commands
58   	 * to a remote service.
59   	 */
60   	template<typename T>
61   	class CommandTable
62   	{
63   	protected:
64   	  ceph_tid_t last_tid;
65   	  std::map<ceph_tid_t, T> commands;
66   	
67   	public:
68   	
69   	  CommandTable()
70   	    : last_tid(0)
71   	  {}
72   	
(1) Event exn_spec_violation: An exception of type "_ZN5boost16exception_detail10clone_implINS0_19error_info_injectorINSt8ios_base7failureB5cxx11EEEEE" is thrown but the throw list "throw()" doesn't allow it to be thrown. This will cause a call to unexpected() which usually calls terminate().
Also see events: [fun_call_w_exception]
73   	  ~CommandTable()
74   	  {
(2) Event fun_call_w_exception: Called function throws an exception of type "_ZN5boost16exception_detail10clone_implINS0_19error_info_injectorINSt8ios_base7failureB5cxx11EEEEE". [details]
Also see events: [exn_spec_violation]
75   	    ceph_assert(commands.empty());
76   	  }
77   	
78   	  T& start_command()
79   	  {
80   	    ceph_tid_t tid = last_tid++;
81   	    commands.insert(std::make_pair(tid, T(tid)) );
82   	
83   	    return commands.at(tid);
84   	  }
85   	
86   	  const std::map<ceph_tid_t, T> &get_commands() const
87   	  {
88   	    return commands;
89   	  }
90   	
91   	  bool exists(ceph_tid_t tid) const
92   	  {
93   	    return commands.count(tid) > 0;
94   	  }
95   	
96   	  T& get_command(ceph_tid_t tid)
97   	  {
98   	    return commands.at(tid);
99   	  }
100  	
101  	  void erase(ceph_tid_t tid)
102  	  {
103  	    commands.erase(tid);
104  	  }
105  	
106  	  void clear() {
107  	    commands.clear();
108  	  }
109  	};
110  	
111  	#endif
112  	
113