From: Dan Mick Date: Tue, 4 Jun 2013 04:05:12 +0000 (-0700) Subject: cmdparse: add handle_bad_get(), ceph:: qualifiers, cmdmap_t X-Git-Tag: v0.65~136^2^2~35 X-Git-Url: http://git-server-git.apps.pok.os.sepia.ceph.com/?a=commitdiff_plain;h=f1021c9b353f5065768c745e914ef8b5b0d6aced;p=ceph.git cmdparse: add handle_bad_get(), ceph:: qualifiers, cmdmap_t Signed-off-by: Dan Mick --- diff --git a/src/common/cmdparse.cc b/src/common/cmdparse.cc index f516017842c..0fd5d438aae 100644 --- a/src/common/cmdparse.cc +++ b/src/common/cmdparse.cc @@ -12,9 +12,11 @@ * */ +#include #include "common/cmdparse.h" #include "include/str_list.h" #include "json_spirit/json_spirit.h" +#include "common/debug.h" using namespace std; @@ -170,3 +172,19 @@ cmdmap_from_json(vector cmd, map *mapp, stringstrea } } +void +handle_bad_get(CephContext *cct, string k, const char *tname) +{ + ostringstream errstr; + int status; + const char *typestr = abi::__cxa_demangle(tname, 0, 0, &status); + if (status != 0) + typestr = tname; + errstr << "bad boost::get: key " << k << " is not type " << typestr; + lderr(cct) << errstr.str() << dendl; + + BackTrace bt(1); + ostringstream oss; + bt.print(oss); + lderr(cct) << oss << dendl; +} diff --git a/src/common/cmdparse.h b/src/common/cmdparse.h index d6920656e98..8a65d24ac78 100644 --- a/src/common/cmdparse.h +++ b/src/common/cmdparse.h @@ -9,65 +9,46 @@ #include #include #include -#ifdef __GNUC__ -#include -#endif -#include "common/dout.h" #include "common/Formatter.h" #include "common/BackTrace.h" +#include "common/ceph_context.h" /* this is handy; can't believe it's not standard */ #define ARRAY_SIZE(a) (sizeof(a) / sizeof(*a)) typedef boost::variant > cmd_vartype; +typedef std::map cmdmap_t; + +void dump_cmd_to_json(ceph::JSONFormatter *f, const std::string& cmd); +void dump_cmd_and_help_to_json(ceph::JSONFormatter *f, + const std::string& secname, + const std::string& cmd, + const std::string& helptext); +bool cmdmap_from_json(std::vector cmd, cmdmap_t *mapp, + std::stringstream &ss); +void handle_bad_get(CephContext *cct, std::string k, const char *name); -void dump_cmd_to_json(JSONFormatter *f, const string& cmd); -void dump_cmd_and_help_to_json(JSONFormatter *f, const string& secname, - const string& cmd, const string& helptext); -bool cmdmap_from_json(std::vector cmd, std::map *mapp, std::stringstream &ss); template bool -cmd_getval(CephContext *cct, std::map& cmdmap, std::string k, T& val) +cmd_getval(CephContext *cct, cmdmap_t& cmdmap, std::string k, T& val) { - // referencing a nonexistent key creates it, even as an rvalue; - // we don't want that behavior for get. if (cmdmap.count(k)) { try { val = boost::get(cmdmap[k]); return true; } catch (boost::bad_get) { - std::ostringstream errstr; - errstr << "bad boost::get: key " << k << ", which value " << cmdmap[k].which() << ", is not type "; -#ifdef __GNUC__ - int status; - char *tname = abi::__cxa_demangle(typeid(T).name(), 0, 0, &status); - if (status == 0) { - errstr << tname; - free(tname); - } else { - errstr << typeid(T).name(); - } -#else - errstr << typeid(T).name(); -#endif - lderr(cct) << errstr.str() << dendl; - BackTrace bt(1); - ostringstream oss; - bt.print(oss); - lderr(cct) << oss << dendl; + handle_bad_get(cct, k, typeid(T).name()); } } - // either not found or bad type, return false return false; } // with default + template void -cmd_getval(CephContext *cct, std::map& cmdmap, std::string k, T& val, - T defval) +cmd_getval(CephContext *cct, cmdmap_t& cmdmap, std::string k, T& val, T defval) { if (!cmd_getval(cct, cmdmap, k, val)) val = defval; @@ -75,9 +56,8 @@ cmd_getval(CephContext *cct, std::map& cmdmap, std::st template void -cmd_putval(CephContext *cct, std::map& cmdmap, std::string k, T val) +cmd_putval(CephContext *cct, cmdmap_t& cmdmap, std::string k, T val) { cmdmap[k] = val; } - #endif