Andrew Geissler | c830e0f | 2016-10-18 12:51:29 -0500 | [diff] [blame] | 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 | |
Patrick Williams | efcf766 | 2021-09-09 06:25:29 -0500 | [diff] [blame^] | 7 | #include <phosphor-logging/elog.hpp> |
| 8 | #include <phosphor-logging/log.hpp> |
| 9 | #include <sdbusplus/exception.hpp> |
Deepak Kodihalli | 9916119 | 2017-01-16 04:00:07 -0600 | [diff] [blame] | 10 | #include <string> |
Andrew Geissler | c830e0f | 2016-10-18 12:51:29 -0500 | [diff] [blame] | 11 | #include <tuple> |
| 12 | #include <type_traits> |
Deepak Kodihalli | 1533110 | 2017-03-09 23:50:43 -0600 | [diff] [blame] | 13 | |
| 14 | <% exceptions = [] %>\ |
| 15 | % for name in errors: |
| 16 | <% |
| 17 | if("example.xyz.openbmc_project" not in name): |
| 18 | exception = name.replace(".", "::") |
| 19 | exception = "sdbusplus::" + exception |
| 20 | index = exception.rfind("::") |
| 21 | exception = exception[:index] + "::Error::" + exception[index+2:] |
| 22 | exceptions.append(exception) |
| 23 | %>\ |
| 24 | % endfor |
| 25 | % for exception in set(exceptions): |
| 26 | <% |
| 27 | ns = exception.split("::") |
| 28 | exception_name = ns[-1] |
| 29 | ns = ns[:-1] |
| 30 | %>\ |
| 31 | % for s in ns: |
| 32 | namespace ${s} |
| 33 | { |
| 34 | % endfor |
Patrick Williams | efcf766 | 2021-09-09 06:25:29 -0500 | [diff] [blame^] | 35 | struct ${exception_name}; |
Deepak Kodihalli | 1533110 | 2017-03-09 23:50:43 -0600 | [diff] [blame] | 36 | % for s in reversed(ns): |
| 37 | } // namespace ${s} |
| 38 | % endfor |
Deepak Kodihalli | 1533110 | 2017-03-09 23:50:43 -0600 | [diff] [blame] | 39 | % endfor |
Andrew Geissler | c830e0f | 2016-10-18 12:51:29 -0500 | [diff] [blame] | 40 | |
| 41 | namespace phosphor |
| 42 | { |
| 43 | |
| 44 | namespace logging |
| 45 | { |
| 46 | |
Deepak Kodihalli | 160d3e0 | 2017-01-17 04:25:22 -0600 | [diff] [blame] | 47 | % for index, name in enumerate(errors): |
Andrew Geissler | df048c1 | 2016-11-10 16:50:35 -0600 | [diff] [blame] | 48 | <% |
Adriana Kobylak | 465aaec | 2017-02-20 11:58:03 -0600 | [diff] [blame] | 49 | ## Ex: name: xyz.openbmc_project.Error.Callout.Device |
| 50 | namespaces = name.split('.') |
| 51 | ## classname is the last name item (Device) |
| 52 | classname = namespaces[-1] |
| 53 | ## namespaces are all the name items except the last one |
| 54 | namespaces = namespaces[:-1] |
Andrew Geissler | df048c1 | 2016-11-10 16:50:35 -0600 | [diff] [blame] | 55 | %>\ |
| 56 | % for s in namespaces: |
| 57 | namespace ${s} |
| 58 | { |
| 59 | % endfor |
Andrew Geissler | df048c1 | 2016-11-10 16:50:35 -0600 | [diff] [blame] | 60 | namespace _${classname} |
Andrew Geissler | c830e0f | 2016-10-18 12:51:29 -0500 | [diff] [blame] | 61 | { |
Deepak Kodihalli | 7924b17 | 2017-03-08 00:04:33 -0600 | [diff] [blame] | 62 | <% |
| 63 | meta_list = [] |
| 64 | if(name in meta): |
| 65 | meta_list = meta[name] |
| 66 | %>\ |
| 67 | |
| 68 | % for b in meta_list: |
Andrew Geissler | c830e0f | 2016-10-18 12:51:29 -0500 | [diff] [blame] | 69 | struct ${b} |
| 70 | { |
Andrew Jeffery | 14a8c8d | 2018-03-07 11:03:13 +1030 | [diff] [blame] | 71 | /* |
| 72 | * We can't use -fsanitize=undefined if we declare a |
| 73 | * 'static constexpr auto str' member, so don't. Instead, open-code the |
| 74 | * mako template lookups. |
| 75 | */ |
Andrew Geissler | c830e0f | 2016-10-18 12:51:29 -0500 | [diff] [blame] | 76 | static constexpr auto str_short = "${meta_data[b]['str_short']}"; |
Andrew Jeffery | 14a8c8d | 2018-03-07 11:03:13 +1030 | [diff] [blame] | 77 | using type = std::tuple<std::decay_t<decltype("${meta_data[b]['str']}")>,${meta_data[b]['type']}>; |
| 78 | explicit constexpr ${b}(${meta_data[b]['type']} a) : _entry(entry("${meta_data[b]['str']}", a)) {}; |
Andrew Geissler | c830e0f | 2016-10-18 12:51:29 -0500 | [diff] [blame] | 79 | type _entry; |
| 80 | }; |
| 81 | % endfor |
| 82 | |
Patrick Williams | efcf766 | 2021-09-09 06:25:29 -0500 | [diff] [blame^] | 83 | } // namespace _${classname} |
Deepak Kodihalli | f2462f0 | 2017-01-19 03:40:12 -0600 | [diff] [blame] | 84 | <% |
Marri Devender Rao | 99b3391 | 2017-05-14 08:33:39 -0500 | [diff] [blame] | 85 | example_yaml = False |
| 86 | if("example.xyz.openbmc_project" in name): |
| 87 | example_yaml = True |
| 88 | %>\ |
| 89 | <% |
Deepak Kodihalli | 7924b17 | 2017-03-08 00:04:33 -0600 | [diff] [blame] | 90 | meta_string = "" |
| 91 | if(meta_list): |
| 92 | meta_string = ', '.join(meta_list) |
Deepak Kodihalli | 331ef90 | 2017-01-31 09:47:07 -0600 | [diff] [blame] | 93 | parent_meta = [] |
Deepak Kodihalli | f2462f0 | 2017-01-19 03:40:12 -0600 | [diff] [blame] | 94 | |
| 95 | parent = parents[name] |
| 96 | while parent: |
Adriana Kobylak | 465aaec | 2017-02-20 11:58:03 -0600 | [diff] [blame] | 97 | tmpparent = parent.split('.') |
| 98 | ## Name is the last item |
| 99 | parent_name = tmpparent[-1] |
| 100 | ## namespaces are all the name items except the last one |
| 101 | parent_namespace = '::'.join(tmpparent[:-1]) |
Deepak Kodihalli | 5221e1b | 2017-03-03 00:02:09 -0600 | [diff] [blame] | 102 | parent_meta += [parent_namespace + "::" + parent_name + "::" + |
Adriana Kobylak | 465aaec | 2017-02-20 11:58:03 -0600 | [diff] [blame] | 103 | p for p in meta[parent]] |
Deepak Kodihalli | 331ef90 | 2017-01-31 09:47:07 -0600 | [diff] [blame] | 104 | parent_meta_short = ', '.join(meta[parent]) |
Lei YU | 80aa476 | 2018-07-19 10:29:56 +0800 | [diff] [blame] | 105 | # The parent may have empty meta, |
| 106 | # so only add parent meta when it exists |
| 107 | if (parent_meta_short): |
| 108 | if(meta_string): |
| 109 | meta_string = meta_string + ", " + parent_meta_short |
| 110 | else: |
| 111 | meta_string = parent_meta_short |
Deepak Kodihalli | f2462f0 | 2017-01-19 03:40:12 -0600 | [diff] [blame] | 112 | parent = parents[parent] |
Deepak Kodihalli | 1533110 | 2017-03-09 23:50:43 -0600 | [diff] [blame] | 113 | |
Marri Devender Rao | 99b3391 | 2017-05-14 08:33:39 -0500 | [diff] [blame] | 114 | if example_yaml: |
| 115 | error_type = classname + " : public sdbusplus::exception_t" |
| 116 | else: |
| 117 | error_type = classname |
Deepak Kodihalli | f2462f0 | 2017-01-19 03:40:12 -0600 | [diff] [blame] | 118 | %> |
Deepak Kodihalli | 1533110 | 2017-03-09 23:50:43 -0600 | [diff] [blame] | 119 | struct ${error_type} |
Andrew Geissler | c830e0f | 2016-10-18 12:51:29 -0500 | [diff] [blame] | 120 | { |
Marri Devender Rao | 99b3391 | 2017-05-14 08:33:39 -0500 | [diff] [blame] | 121 | % if example_yaml: |
Marri Devender Rao | 7d0a07b | 2017-04-04 03:43:00 -0500 | [diff] [blame] | 122 | static constexpr auto errName = "${name}"; |
| 123 | static constexpr auto errDesc = "${error_msg[name]}"; |
Marri Devender Rao | 99b3391 | 2017-05-14 08:33:39 -0500 | [diff] [blame] | 124 | % endif |
Deepak Kodihalli | 160d3e0 | 2017-01-17 04:25:22 -0600 | [diff] [blame] | 125 | static constexpr auto L = level::${error_lvl[name]}; |
Deepak Kodihalli | 7924b17 | 2017-03-08 00:04:33 -0600 | [diff] [blame] | 126 | % for b in meta_list: |
Andrew Geissler | df048c1 | 2016-11-10 16:50:35 -0600 | [diff] [blame] | 127 | using ${b} = _${classname}::${b}; |
Andrew Geissler | c830e0f | 2016-10-18 12:51:29 -0500 | [diff] [blame] | 128 | % endfor |
Deepak Kodihalli | 331ef90 | 2017-01-31 09:47:07 -0600 | [diff] [blame] | 129 | % for b in parent_meta: |
| 130 | using ${b.split("::").pop()} = ${b}; |
| 131 | % endfor |
Andrew Geissler | c830e0f | 2016-10-18 12:51:29 -0500 | [diff] [blame] | 132 | using metadata_types = std::tuple<${meta_string}>; |
Marri Devender Rao | 99b3391 | 2017-05-14 08:33:39 -0500 | [diff] [blame] | 133 | % if example_yaml: |
Patrick Williams | efcf766 | 2021-09-09 06:25:29 -0500 | [diff] [blame^] | 134 | |
Patrick Williams | 66580a9 | 2021-09-03 08:18:43 -0500 | [diff] [blame] | 135 | const char* name() const noexcept override |
Deepak Kodihalli | 1533110 | 2017-03-09 23:50:43 -0600 | [diff] [blame] | 136 | { |
Marri Devender Rao | 7d0a07b | 2017-04-04 03:43:00 -0500 | [diff] [blame] | 137 | return errName; |
Deepak Kodihalli | 1533110 | 2017-03-09 23:50:43 -0600 | [diff] [blame] | 138 | } |
| 139 | |
Patrick Williams | 66580a9 | 2021-09-03 08:18:43 -0500 | [diff] [blame] | 140 | const char* description() const noexcept override |
Deepak Kodihalli | 1533110 | 2017-03-09 23:50:43 -0600 | [diff] [blame] | 141 | { |
Marri Devender Rao | 7d0a07b | 2017-04-04 03:43:00 -0500 | [diff] [blame] | 142 | return errDesc; |
Deepak Kodihalli | 1533110 | 2017-03-09 23:50:43 -0600 | [diff] [blame] | 143 | } |
| 144 | |
Patrick Williams | 66580a9 | 2021-09-03 08:18:43 -0500 | [diff] [blame] | 145 | const char* what() const noexcept override |
Deepak Kodihalli | 1533110 | 2017-03-09 23:50:43 -0600 | [diff] [blame] | 146 | { |
Marri Devender Rao | 7d0a07b | 2017-04-04 03:43:00 -0500 | [diff] [blame] | 147 | return errName; |
Deepak Kodihalli | 1533110 | 2017-03-09 23:50:43 -0600 | [diff] [blame] | 148 | } |
Patrick Williams | 66580a9 | 2021-09-03 08:18:43 -0500 | [diff] [blame] | 149 | |
| 150 | int get_errno() const noexcept override |
| 151 | { |
| 152 | return EIO; |
| 153 | } |
Marri Devender Rao | 99b3391 | 2017-05-14 08:33:39 -0500 | [diff] [blame] | 154 | % endif |
Andrew Geissler | c830e0f | 2016-10-18 12:51:29 -0500 | [diff] [blame] | 155 | }; |
Adriana Kobylak | 465aaec | 2017-02-20 11:58:03 -0600 | [diff] [blame] | 156 | |
Andrew Geissler | df048c1 | 2016-11-10 16:50:35 -0600 | [diff] [blame] | 157 | % for s in reversed(namespaces): |
| 158 | } // namespace ${s} |
| 159 | % endfor |
| 160 | |
Deepak Kodihalli | 1533110 | 2017-03-09 23:50:43 -0600 | [diff] [blame] | 161 | <% |
| 162 | sdbusplus_name = name |
Marri Devender Rao | 99b3391 | 2017-05-14 08:33:39 -0500 | [diff] [blame] | 163 | if not example_yaml : |
Deepak Kodihalli | 1533110 | 2017-03-09 23:50:43 -0600 | [diff] [blame] | 164 | sdbusplus_name = "sdbusplus." + sdbusplus_name |
| 165 | pos = sdbusplus_name.rfind(".") |
| 166 | sdbusplus_name = (sdbusplus_name[:pos] + ".Error." + |
| 167 | sdbusplus_name[pos+1:]) |
| 168 | sdbusplus_type = sdbusplus_name.replace(".", "::") |
| 169 | phosphor_type = sdbusplus_type |
Marri Devender Rao | 99b3391 | 2017-05-14 08:33:39 -0500 | [diff] [blame] | 170 | if not example_yaml : |
Deepak Kodihalli | 1533110 | 2017-03-09 23:50:43 -0600 | [diff] [blame] | 171 | phosphor_type = sdbusplus_type.replace("sdbusplus::", "") |
| 172 | phosphor_type = phosphor_type.replace("Error::", "") |
| 173 | %>\ |
Patrick Williams | efcf766 | 2021-09-09 06:25:29 -0500 | [diff] [blame^] | 174 | \ |
Deepak Kodihalli | 1533110 | 2017-03-09 23:50:43 -0600 | [diff] [blame] | 175 | % if sdbusplus_type != phosphor_type: |
| 176 | namespace details |
| 177 | { |
| 178 | |
| 179 | template <> |
| 180 | struct map_exception_type<${sdbusplus_type}> |
| 181 | { |
| 182 | using type = ${phosphor_type}; |
| 183 | }; |
| 184 | |
Patrick Williams | efcf766 | 2021-09-09 06:25:29 -0500 | [diff] [blame^] | 185 | } // namespace details |
Deepak Kodihalli | 1533110 | 2017-03-09 23:50:43 -0600 | [diff] [blame] | 186 | %endif |
| 187 | |
Andrew Geissler | c830e0f | 2016-10-18 12:51:29 -0500 | [diff] [blame] | 188 | % endfor |
| 189 | |
| 190 | } // namespace logging |
| 191 | |
| 192 | } // namespace phosphor |