1 ## Note that this file is not auto generated, it is what generates the 2 ## elog-gen.hpp file 3 // This file was autogenerated. Do not edit! 4 // See elog-gen.py for more details 5 #pragma once 6 7 #include <phosphor-logging/elog.hpp> 8 #include <phosphor-logging/log.hpp> 9 #include <sdbusplus/exception.hpp> 10 #include <string> 11 #include <tuple> 12 #include <type_traits> 13 14 <% 15 import inflection 16 17 def sdbusplus_name(name): 18 if "example.xyz.openbmc_project" in name: 19 names = name.split(".") 20 else: 21 names = ["sdbusplus", "error" ] + name.split(".") 22 23 classname = inflection.camelize(names[-1]) 24 namespace_name = "::".join([inflection.underscore(x) for x in names[:-1]]) 25 26 return (namespace_name, classname) 27 28 def phosphor_name(name): 29 namespace_name, classname = sdbusplus_name(name) 30 namespace_name = namespace_name.replace("sdbusplus::error::", "") 31 32 return (namespace_name, classname) 33 34 def old_phosphor_name(name): 35 names = name.split(".") 36 return ("::".join(names[:-1]), names[-1]) 37 38 exceptions = sorted( 39 set([x for x in errors if "example.xyz.openbmc_project" not in x])) 40 %>\ 41 % for error in exceptions: 42 <% 43 ns, exception_name = sdbusplus_name(error) 44 %>\ 45 namespace ${ns} 46 { 47 struct ${exception_name}; 48 } // namespace ${ns} 49 % endfor 50 51 namespace phosphor::logging 52 { 53 54 % for name in errors: 55 <% 56 namespaces, classname = phosphor_name(name) 57 meta_list = meta.get(name, []) 58 %>\ 59 namespace ${namespaces} 60 { 61 % if len(meta_list) != 0: 62 namespace _${classname} 63 { 64 % for b in meta_list: 65 struct ${b} 66 { 67 /* 68 * We can't use -fsanitize=undefined if we declare a 69 * 'static constexpr auto str' member, so don't. Instead, open-code the 70 * mako template lookups. 71 */ 72 static constexpr auto str_short = "${meta_data[b]['str_short']}"; 73 using type = std::tuple<std::decay_t<decltype("${meta_data[b]['str']}")>,${meta_data[b]['type']}>; 74 explicit constexpr ${b}(${meta_data[b]['type']} a) : _entry(entry("${meta_data[b]['str']}", a)) {}; 75 type _entry; 76 }; 77 % endfor 78 } // namespace _${classname} 79 % endif 80 <% 81 example_yaml = "example.xyz.openbmc_project" in name 82 83 meta_string = "" 84 if(meta_list): 85 meta_string = ', '.join(meta_list) 86 parent_meta = [] 87 88 parent = parents[name] 89 while parent: 90 parent_ns, parent_class = phosphor_name(parent) 91 92 parent_meta += [parent_ns + "::" + parent_class + "::" + 93 p for p in meta[parent]] 94 parent_meta_short = ', '.join(meta[parent]) 95 96 # The parent may have empty meta, 97 # so only add parent meta when it exists 98 if (parent_meta_short): 99 if(meta_string): 100 meta_string = meta_string + ", " + parent_meta_short 101 else: 102 meta_string = parent_meta_short 103 parent = parents[parent] 104 105 if example_yaml: 106 error_type = classname + " : public sdbusplus::exception_t" 107 else: 108 error_type = classname 109 %> 110 struct ${error_type} 111 { 112 % if example_yaml: 113 static constexpr auto errName = "${name}"; 114 static constexpr auto errDesc = "${error_msg[name]}"; 115 % endif 116 static constexpr auto L = level::${error_lvl[name]}; 117 % for b in meta_list: 118 using ${b} = _${classname}::${b}; 119 % endfor 120 % for b in parent_meta: 121 using ${b.split("::")[-1]} = 122 phosphor::logging::${b}; 123 % endfor 124 using metadata_types = std::tuple<${meta_string}>; 125 % if example_yaml: 126 127 const char* name() const noexcept override 128 { 129 return errName; 130 } 131 132 const char* description() const noexcept override 133 { 134 return errDesc; 135 } 136 137 const char* what() const noexcept override 138 { 139 return errName; 140 } 141 142 int get_errno() const noexcept override 143 { 144 return EIO; 145 } 146 % endif 147 }; 148 149 } // namespace ${namespaces} 150 <% 151 old_ns, old_class = old_phosphor_name(name) 152 %> 153 % if old_ns != namespaces or old_class != classname: 154 #ifndef SDBUSPP_REMOVE_DEPRECATED_NAMESPACE 155 namespace ${old_ns} 156 { 157 using ${old_class} = 158 phosphor::logging::${namespaces}::${classname}; 159 } 160 #endif 161 % endif 162 163 % if not example_yaml: 164 <% 165 sdbusplus_ns, sdbusplus_class = sdbusplus_name(name) 166 %>\ 167 namespace details 168 { 169 170 template <> 171 struct map_exception_type<${sdbusplus_ns}::${sdbusplus_class}> 172 { 173 using type = 174 phosphor::logging::${namespaces}::${classname}; 175 }; 176 177 } // namespace details 178 %endif 179 % endfor 180 } // namespace phosphor::logging 181