]>
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/assert.h" // boost clobbers this
11 #include "common/Formatter.h"
12 #include "common/BackTrace.h"
16 /* this is handy; can't believe it's not standard */
17 #define ARRAY_SIZE(a) (sizeof(a) / sizeof(*a))
19 typedef boost::variant
<std::string
,
23 std::vector
<std::string
>,
24 std::vector
<int64_t>> cmd_vartype
;
25 typedef std::map
<std::string
, cmd_vartype
> cmdmap_t
;
27 std::string
cmddesc_get_prefix(const std::string
&cmddesc
);
28 void dump_cmd_to_json(ceph::Formatter
*f
, const std::string
& cmd
);
29 void dump_cmd_and_help_to_json(ceph::Formatter
*f
,
30 const std::string
& secname
,
31 const std::string
& cmd
,
32 const std::string
& helptext
);
33 void dump_cmddesc_to_json(ceph::Formatter
*jf
,
34 const std::string
& secname
,
35 const std::string
& cmdsig
,
36 const std::string
& helptext
,
37 const std::string
& module
,
38 const std::string
& perm
,
39 const std::string
& avail
,
41 bool cmdmap_from_json(std::vector
<std::string
> cmd
, cmdmap_t
*mapp
,
42 std::stringstream
&ss
);
43 void cmdmap_dump(const cmdmap_t
&cmdmap
, ceph::Formatter
*f
);
44 void handle_bad_get(CephContext
*cct
, const std::string
& k
, const char *name
);
46 std::string
cmd_vartype_stringify(const cmd_vartype
& v
);
50 cmd_getval(CephContext
*cct
, const cmdmap_t
& cmdmap
, const std::string
& k
, T
& val
)
52 if (cmdmap
.count(k
)) {
54 val
= boost::get
<T
>(cmdmap
.find(k
)->second
);
56 } catch (boost::bad_get
) {
57 handle_bad_get(cct
, k
, typeid(T
).name());
67 cmd_getval(CephContext
*cct
, const cmdmap_t
& cmdmap
, const std::string
& k
, T
& val
, const T
& defval
)
69 if (!cmd_getval(cct
, cmdmap
, k
, val
))
75 cmd_putval(CephContext
*cct
, cmdmap_t
& cmdmap
, const std::string
& k
, const T
& val
)
80 extern int parse_osd_id(const char *s
, std::ostream
*pss
);
81 extern long parse_pos_long(const char *s
, std::ostream
*pss
= NULL
);