blob: 1a077ca8cbbb376b80376711ba0f3778fce5acf9 [file] [log] [blame]
Andrew Geisslerc830e0f2016-10-18 12:51:29 -05001## 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 Williamsefcf7662021-09-09 06:25:29 -05007#include <phosphor-logging/elog.hpp>
8#include <phosphor-logging/log.hpp>
9#include <sdbusplus/exception.hpp>
Deepak Kodihalli99161192017-01-16 04:00:07 -060010#include <string>
Andrew Geisslerc830e0f2016-10-18 12:51:29 -050011#include <tuple>
12#include <type_traits>
Deepak Kodihalli15331102017-03-09 23:50:43 -060013
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
Patrick Williamsa9ee22b2021-09-09 06:35:09 -050025% for exception in sorted(set(exceptions)):
Deepak Kodihalli15331102017-03-09 23:50:43 -060026<%
27 ns = exception.split("::")
28 exception_name = ns[-1]
29 ns = ns[:-1]
30%>\
31 % for s in ns:
32namespace ${s}
33{
34 % endfor
Patrick Williamsefcf7662021-09-09 06:25:29 -050035struct ${exception_name};
Deepak Kodihalli15331102017-03-09 23:50:43 -060036 % for s in reversed(ns):
37} // namespace ${s}
38 % endfor
Deepak Kodihalli15331102017-03-09 23:50:43 -060039% endfor
Andrew Geisslerc830e0f2016-10-18 12:51:29 -050040
41namespace phosphor
42{
43
44namespace logging
45{
46
Deepak Kodihalli160d3e02017-01-17 04:25:22 -060047 % for index, name in enumerate(errors):
Andrew Geisslerdf048c12016-11-10 16:50:35 -060048<%
Adriana Kobylak465aaec2017-02-20 11:58:03 -060049 ## 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 Geisslerdf048c12016-11-10 16:50:35 -060055%>\
56 % for s in namespaces:
57namespace ${s}
58{
59 % endfor
Andrew Geisslerdf048c12016-11-10 16:50:35 -060060namespace _${classname}
Andrew Geisslerc830e0f2016-10-18 12:51:29 -050061{
Deepak Kodihalli7924b172017-03-08 00:04:33 -060062<%
63 meta_list = []
64 if(name in meta):
65 meta_list = meta[name]
66%>\
67
68 % for b in meta_list:
Andrew Geisslerc830e0f2016-10-18 12:51:29 -050069struct ${b}
70{
Andrew Jeffery14a8c8d2018-03-07 11:03:13 +103071 /*
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 Geisslerc830e0f2016-10-18 12:51:29 -050076 static constexpr auto str_short = "${meta_data[b]['str_short']}";
Andrew Jeffery14a8c8d2018-03-07 11:03:13 +103077 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 Geisslerc830e0f2016-10-18 12:51:29 -050079 type _entry;
80};
81 % endfor
82
Patrick Williamsefcf7662021-09-09 06:25:29 -050083} // namespace _${classname}
Deepak Kodihallif2462f02017-01-19 03:40:12 -060084<%
Marri Devender Rao99b33912017-05-14 08:33:39 -050085 example_yaml = False
86 if("example.xyz.openbmc_project" in name):
87 example_yaml = True
88%>\
89<%
Deepak Kodihalli7924b172017-03-08 00:04:33 -060090 meta_string = ""
91 if(meta_list):
92 meta_string = ', '.join(meta_list)
Deepak Kodihalli331ef902017-01-31 09:47:07 -060093 parent_meta = []
Deepak Kodihallif2462f02017-01-19 03:40:12 -060094
95 parent = parents[name]
96 while parent:
Adriana Kobylak465aaec2017-02-20 11:58:03 -060097 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 Kodihalli5221e1b2017-03-03 00:02:09 -0600102 parent_meta += [parent_namespace + "::" + parent_name + "::" +
Adriana Kobylak465aaec2017-02-20 11:58:03 -0600103 p for p in meta[parent]]
Deepak Kodihalli331ef902017-01-31 09:47:07 -0600104 parent_meta_short = ', '.join(meta[parent])
Lei YU80aa4762018-07-19 10:29:56 +0800105 # 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 Kodihallif2462f02017-01-19 03:40:12 -0600112 parent = parents[parent]
Deepak Kodihalli15331102017-03-09 23:50:43 -0600113
Marri Devender Rao99b33912017-05-14 08:33:39 -0500114 if example_yaml:
115 error_type = classname + " : public sdbusplus::exception_t"
116 else:
117 error_type = classname
Deepak Kodihallif2462f02017-01-19 03:40:12 -0600118%>
Deepak Kodihalli15331102017-03-09 23:50:43 -0600119struct ${error_type}
Andrew Geisslerc830e0f2016-10-18 12:51:29 -0500120{
Marri Devender Rao99b33912017-05-14 08:33:39 -0500121 % if example_yaml:
Marri Devender Rao7d0a07b2017-04-04 03:43:00 -0500122 static constexpr auto errName = "${name}";
123 static constexpr auto errDesc = "${error_msg[name]}";
Marri Devender Rao99b33912017-05-14 08:33:39 -0500124 % endif
Deepak Kodihalli160d3e02017-01-17 04:25:22 -0600125 static constexpr auto L = level::${error_lvl[name]};
Deepak Kodihalli7924b172017-03-08 00:04:33 -0600126 % for b in meta_list:
Andrew Geisslerdf048c12016-11-10 16:50:35 -0600127 using ${b} = _${classname}::${b};
Andrew Geisslerc830e0f2016-10-18 12:51:29 -0500128 % endfor
Deepak Kodihalli331ef902017-01-31 09:47:07 -0600129 % for b in parent_meta:
130 using ${b.split("::").pop()} = ${b};
131 % endfor
Andrew Geisslerc830e0f2016-10-18 12:51:29 -0500132 using metadata_types = std::tuple<${meta_string}>;
Marri Devender Rao99b33912017-05-14 08:33:39 -0500133 % if example_yaml:
Patrick Williamsefcf7662021-09-09 06:25:29 -0500134
Patrick Williams66580a92021-09-03 08:18:43 -0500135 const char* name() const noexcept override
Deepak Kodihalli15331102017-03-09 23:50:43 -0600136 {
Marri Devender Rao7d0a07b2017-04-04 03:43:00 -0500137 return errName;
Deepak Kodihalli15331102017-03-09 23:50:43 -0600138 }
139
Patrick Williams66580a92021-09-03 08:18:43 -0500140 const char* description() const noexcept override
Deepak Kodihalli15331102017-03-09 23:50:43 -0600141 {
Marri Devender Rao7d0a07b2017-04-04 03:43:00 -0500142 return errDesc;
Deepak Kodihalli15331102017-03-09 23:50:43 -0600143 }
144
Patrick Williams66580a92021-09-03 08:18:43 -0500145 const char* what() const noexcept override
Deepak Kodihalli15331102017-03-09 23:50:43 -0600146 {
Marri Devender Rao7d0a07b2017-04-04 03:43:00 -0500147 return errName;
Deepak Kodihalli15331102017-03-09 23:50:43 -0600148 }
Patrick Williams66580a92021-09-03 08:18:43 -0500149
150 int get_errno() const noexcept override
151 {
152 return EIO;
153 }
Marri Devender Rao99b33912017-05-14 08:33:39 -0500154 % endif
Andrew Geisslerc830e0f2016-10-18 12:51:29 -0500155};
Adriana Kobylak465aaec2017-02-20 11:58:03 -0600156
Andrew Geisslerdf048c12016-11-10 16:50:35 -0600157% for s in reversed(namespaces):
158} // namespace ${s}
159% endfor
160
Deepak Kodihalli15331102017-03-09 23:50:43 -0600161<%
162 sdbusplus_name = name
Marri Devender Rao99b33912017-05-14 08:33:39 -0500163 if not example_yaml :
Deepak Kodihalli15331102017-03-09 23:50:43 -0600164 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 Rao99b33912017-05-14 08:33:39 -0500170 if not example_yaml :
Deepak Kodihalli15331102017-03-09 23:50:43 -0600171 phosphor_type = sdbusplus_type.replace("sdbusplus::", "")
172 phosphor_type = phosphor_type.replace("Error::", "")
173%>\
Patrick Williamsefcf7662021-09-09 06:25:29 -0500174\
Deepak Kodihalli15331102017-03-09 23:50:43 -0600175% if sdbusplus_type != phosphor_type:
176namespace details
177{
178
179template <>
180struct map_exception_type<${sdbusplus_type}>
181{
182 using type = ${phosphor_type};
183};
184
Patrick Williamsefcf7662021-09-09 06:25:29 -0500185} // namespace details
Deepak Kodihalli15331102017-03-09 23:50:43 -0600186%endif
187
Andrew Geisslerc830e0f2016-10-18 12:51:29 -0500188 % endfor
189
190} // namespace logging
191
192} // namespace phosphor