diff options
author | Deepak Kodihalli <dkodihal@in.ibm.com> | 2017-03-09 23:50:43 -0600 |
---|---|---|
committer | Patrick Williams <patrick@stwcx.xyz> | 2017-03-15 21:11:40 +0000 |
commit | 153311005f6c4f0de710adebaf93a98cc2ca8ebc (patch) | |
tree | 2032a8d03490b8a7c4dd56691188385d5fcf5676 /tools/phosphor-logging | |
parent | 682326a19c45b68299cb295b69754a9eb3154f48 (diff) | |
download | phosphor-logging-153311005f6c4f0de710adebaf93a98cc2ca8ebc.tar.gz phosphor-logging-153311005f6c4f0de710adebaf93a98cc2ca8ebc.zip |
Map sdbusplus exception to phosphor exception
Errors will be created by using the sdbusplus error types, which results
in an sdbusplus exception being thrown.
Error metadata can be verified at compile-time by checking the error
against phosphor-logging error types. This commit maps the sdbusplus
error type to the phosphor type, for this purpose, via template
specializations.
Change-Id: Iee37e2a3846cc3acf3a62270a520ff0c395fd36d
Signed-off-by: Deepak Kodihalli <dkodihal@in.ibm.com>
Diffstat (limited to 'tools/phosphor-logging')
-rw-r--r-- | tools/phosphor-logging/templates/elog-gen-template.mako.hpp | 76 |
1 files changed, 75 insertions, 1 deletions
diff --git a/tools/phosphor-logging/templates/elog-gen-template.mako.hpp b/tools/phosphor-logging/templates/elog-gen-template.mako.hpp index 9728d44..7ee4268 100644 --- a/tools/phosphor-logging/templates/elog-gen-template.mako.hpp +++ b/tools/phosphor-logging/templates/elog-gen-template.mako.hpp @@ -7,7 +7,37 @@ #include <string> #include <tuple> #include <type_traits> +#include <sdbusplus/exception.hpp> #include <phosphor-logging/log.hpp> +#include <phosphor-logging/elog.hpp> + +<% exceptions = [] %>\ +% for name in errors: +<% + if("example.xyz.openbmc_project" not in name): + exception = name.replace(".", "::") + exception = "sdbusplus::" + exception + index = exception.rfind("::") + exception = exception[:index] + "::Error::" + exception[index+2:] + exceptions.append(exception) +%>\ +% endfor +% for exception in set(exceptions): +<% + ns = exception.split("::") + exception_name = ns[-1] + ns = ns[:-1] +%>\ + % for s in ns: +namespace ${s} +{ + % endfor + struct ${exception_name}; + % for s in reversed(ns): +} // namespace ${s} + % endfor + +% endfor namespace phosphor { @@ -69,8 +99,10 @@ struct ${b} else: meta_string = parent_meta_short parent = parents[parent] + + error_type = classname + " : public sdbusplus::exception_t" %> -struct ${classname} +struct ${error_type} { static constexpr auto err_code = "${name}"; static constexpr auto err_msg = "${error_msg[name]}"; @@ -82,12 +114,54 @@ struct ${classname} using ${b.split("::").pop()} = ${b}; % endfor using metadata_types = std::tuple<${meta_string}>; + + const char* name() const noexcept + { + return err_code; + } + + const char* description() const noexcept + { + return err_msg; + } + + const char* what() const noexcept + { + return err_code; + } }; % for s in reversed(namespaces): } // namespace ${s} % endfor +<% + sdbusplus_name = name + if("example.xyz.openbmc_project" not in name): + sdbusplus_name = "sdbusplus." + sdbusplus_name + pos = sdbusplus_name.rfind(".") + sdbusplus_name = (sdbusplus_name[:pos] + ".Error." + + sdbusplus_name[pos+1:]) + sdbusplus_type = sdbusplus_name.replace(".", "::") + phosphor_type = sdbusplus_type + if("example.xyz.openbmc_project" not in name): + phosphor_type = sdbusplus_type.replace("sdbusplus::", "") + phosphor_type = phosphor_type.replace("Error::", "") +%>\ + +% if sdbusplus_type != phosphor_type: +namespace details +{ + +template <> +struct map_exception_type<${sdbusplus_type}> +{ + using type = ${phosphor_type}; +}; + +} +%endif + % endfor } // namespace logging |