Adriana Kobylak | f855c3e | 2016-09-29 20:48:08 -0500 | [diff] [blame^] | 1 | #pragma once |
| 2 | |
| 3 | #include <tuple> |
| 4 | #include <utility> |
| 5 | #include "elog-gen.hpp" |
| 6 | |
| 7 | namespace phosphor |
| 8 | { |
| 9 | |
| 10 | namespace logging |
| 11 | { |
| 12 | |
| 13 | /** |
| 14 | * @brief Structure used by callers to indicate they want to use the last value |
| 15 | * put in the journal for input parameter. |
| 16 | */ |
| 17 | template <typename T> |
| 18 | struct prev_entry |
| 19 | { |
| 20 | using type = T; |
| 21 | }; |
| 22 | |
| 23 | |
| 24 | |
| 25 | namespace details |
| 26 | { |
| 27 | /** |
| 28 | * @brief Used to return the generated tuple for the error code meta data |
| 29 | * |
| 30 | * The prev_entry (above) and deduce_entry_type structures below are used |
| 31 | * to verify at compile time the required parameters have been passed to |
| 32 | * the elog interface and then to forward on the appropriate tuple to the |
| 33 | * log interface. |
| 34 | */ |
| 35 | template <typename T> |
| 36 | struct deduce_entry_type |
| 37 | { |
| 38 | |
| 39 | using type = T; |
| 40 | auto get() { return value._entry; } |
| 41 | |
| 42 | T value; |
| 43 | }; |
| 44 | |
| 45 | /** |
| 46 | * @brief Used to return an empty tuple for prev_entry parameters |
| 47 | * |
| 48 | * This is done so we can still call the log() interface with the variable |
| 49 | * arg parameters to elog. The log() interface will simply ignore the empty |
| 50 | * tuples which is what we want for prev_entry parameters. |
| 51 | */ |
| 52 | template <typename T> |
| 53 | struct deduce_entry_type<prev_entry<T>> |
| 54 | { |
| 55 | using type = T; |
| 56 | auto get() { return std::make_tuple(); } |
| 57 | |
| 58 | prev_entry<T> value; |
| 59 | }; |
| 60 | |
| 61 | /** |
| 62 | * @brief Typedef for above structure usage |
| 63 | */ |
| 64 | template <typename T> using deduce_entry_type_t = |
| 65 | typename deduce_entry_type<T>::type; |
| 66 | |
| 67 | } // namespace details |
| 68 | |
| 69 | /** @fn commit() |
| 70 | * @brief Create an error log entry based on journal |
| 71 | * entry with a specified MSG_ID |
| 72 | * @tparam E - Error log struct |
| 73 | */ |
| 74 | template <typename E> |
| 75 | void commit() |
| 76 | { |
| 77 | // TODO placeholder function call |
| 78 | // to call the new error log server to create |
| 79 | // an error log on the BMC flash |
| 80 | // dbus_commit(E.msgid); // call server |
| 81 | } |
| 82 | |
| 83 | /** @fn elog() |
| 84 | * @brief Create a journal log entry based on predefined |
| 85 | * error log information |
| 86 | * @tparam T - Error log type |
| 87 | * @param[in] i_args - Metadata fields to be added to the journal entry |
| 88 | */ |
| 89 | template <typename T, typename ...Args> |
| 90 | void elog(Args... i_args) |
| 91 | { |
| 92 | // Validate the caller passed in the required parameters |
| 93 | static_assert(std::is_same<typename T::metadata_types, |
| 94 | std::tuple< |
| 95 | details::deduce_entry_type_t<Args>...>> |
| 96 | ::value, |
| 97 | "You are not passing in required arguments for this error"); |
| 98 | |
| 99 | log<T::L>(T::err_msg, |
| 100 | details::deduce_entry_type<Args>{i_args}.get()...); |
| 101 | } |
| 102 | |
| 103 | } // namespace logging |
| 104 | |
| 105 | } // namespace phosphor |
| 106 | |