]>
git.proxmox.com Git - ceph.git/blob - ceph/src/common/cmdparse.h
1 // -*- mode:C++; tab-width:8; c-basic-offset:2; indent-tabs-mode:t -*-
2 // vim: ts=8 sw=2 smarttab
3 #ifndef CEPH_COMMON_CMDPARSE_H
4 #define CEPH_COMMON_CMDPARSE_H
9 #include <boost/variant.hpp>
10 #include "include/ceph_assert.h" // boost clobbers this
11 #include "include/common_fwd.h"
12 #include "common/Formatter.h"
13 #include "common/BackTrace.h"
15 typedef boost::variant
<std::string
,
19 std::vector
<std::string
>,
21 std::vector
<double>> cmd_vartype
;
22 typedef std::map
<std::string
, cmd_vartype
, std::less
<>> cmdmap_t
;
24 namespace TOPNSPC::common
{
25 std::string
cmddesc_get_prefix(const std::string_view
&cmddesc
);
26 std::string
cmddesc_get_prenautilus_compat(const std::string
&cmddesc
);
27 void dump_cmd_to_json(ceph::Formatter
*f
, uint64_t features
,
28 const std::string
& cmd
);
29 void dump_cmd_and_help_to_json(ceph::Formatter
*f
,
31 const std::string
& secname
,
32 const std::string
& cmd
,
33 const std::string
& helptext
);
34 void dump_cmddesc_to_json(ceph::Formatter
*jf
,
36 const std::string
& secname
,
37 const std::string
& cmdsig
,
38 const std::string
& helptext
,
39 const std::string
& module
,
40 const std::string
& perm
,
42 bool cmdmap_from_json(const std::vector
<std::string
>& cmd
, cmdmap_t
*mapp
,
44 void cmdmap_dump(const cmdmap_t
&cmdmap
, ceph::Formatter
*f
);
45 void handle_bad_get(CephContext
*cct
, const std::string
& k
, const char *name
);
47 std::string
cmd_vartype_stringify(const cmd_vartype
& v
);
49 struct bad_cmd_get
: public std::exception
{
51 bad_cmd_get(const std::string
& f
, const cmdmap_t
& cmdmap
) {
52 desc
= "bad or missing field '" + f
+ "'";
54 const char *what() const throw() override
{
59 bool cmd_getval(const cmdmap_t
& cmdmap
,
60 const std::string
& k
, bool& val
);
63 bool cmd_getval(const cmdmap_t
& cmdmap
,
64 const std::string
& k
, T
& val
)
66 if (cmdmap
.count(k
)) {
68 val
= boost::get
<T
>(cmdmap
.find(k
)->second
);
70 } catch (boost::bad_get
&) {
71 throw bad_cmd_get(k
, cmdmap
);
81 const cmdmap_t
& cmdmap
, const std::string
& k
,
82 T
& val
, const T
& defval
)
84 if (cmdmap
.count(k
)) {
86 val
= boost::get
<T
>(cmdmap
.find(k
)->second
);
88 } catch (boost::bad_get
&) {
89 throw bad_cmd_get(k
, cmdmap
);
99 cmd_putval(CephContext
*cct
, cmdmap_t
& cmdmap
, const std::string
& k
, const T
& val
)
104 bool validate_cmd(CephContext
* cct
,
105 const std::string
& desc
,
106 const cmdmap_t
& cmdmap
,
108 extern int parse_osd_id(const char *s
, std::ostream
*pss
);
109 extern long parse_pos_long(const char *s
, std::ostream
*pss
= NULL
);