Deepak Kodihalli | 827b50f | 2017-02-24 00:00:08 -0600 | [diff] [blame] | 1 | #include "config.h" |
Patrick Venture | f18bf83 | 2018-10-26 18:14:00 -0700 | [diff] [blame] | 2 | |
Saqib Khan | 2bb1519 | 2017-02-13 13:19:55 -0600 | [diff] [blame] | 3 | #include <phosphor-logging/elog.hpp> |
Arya K Padman | 5bc2653 | 2024-04-10 06:19:25 -0500 | [diff] [blame] | 4 | #include <phosphor-logging/lg2.hpp> |
Patrick Williams | 2544b41 | 2022-10-04 08:41:06 -0500 | [diff] [blame] | 5 | |
Deepak Kodihalli | 6fd9dc4 | 2018-04-03 02:08:42 -0500 | [diff] [blame] | 6 | #include <stdexcept> |
Adriana Kobylak | c20dae8 | 2017-02-15 13:44:16 -0600 | [diff] [blame] | 7 | |
| 8 | namespace phosphor |
| 9 | { |
| 10 | namespace logging |
| 11 | { |
Marri Devender Rao | 7d0a07b | 2017-04-04 03:43:00 -0500 | [diff] [blame] | 12 | namespace details |
Adriana Kobylak | c20dae8 | 2017-02-15 13:44:16 -0600 | [diff] [blame] | 13 | { |
Willy Tu | 6ddbf69 | 2023-09-05 10:54:16 -0700 | [diff] [blame] | 14 | using namespace sdbusplus::server::xyz::openbmc_project::logging; |
Deepak Kodihalli | 6fd9dc4 | 2018-04-03 02:08:42 -0500 | [diff] [blame] | 15 | |
| 16 | auto _prepareMsg(const char* funcName) |
Marri Devender Rao | 7d0a07b | 2017-04-04 03:43:00 -0500 | [diff] [blame] | 17 | { |
| 18 | using phosphor::logging::log; |
Patrick Venture | f18bf83 | 2018-10-26 18:14:00 -0700 | [diff] [blame] | 19 | constexpr auto IFACE_INTERNAL( |
| 20 | "xyz.openbmc_project.Logging.Internal.Manager"); |
Adriana Kobylak | 205b113 | 2017-02-06 20:15:29 -0600 | [diff] [blame] | 21 | |
| 22 | // Transaction id is located at the end of the string separated by a period. |
| 23 | |
| 24 | auto b = sdbusplus::bus::new_default(); |
Adriana Kobylak | 205b113 | 2017-02-06 20:15:29 -0600 | [diff] [blame] | 25 | |
Matt Spinler | 6b300d2 | 2020-07-15 13:20:44 -0500 | [diff] [blame] | 26 | auto m = b.new_method_call(BUSNAME_LOGGING, OBJ_INTERNAL, IFACE_INTERNAL, |
| 27 | funcName); |
Patrick Venture | f18bf83 | 2018-10-26 18:14:00 -0700 | [diff] [blame] | 28 | return m; |
Deepak Kodihalli | 6fd9dc4 | 2018-04-03 02:08:42 -0500 | [diff] [blame] | 29 | } |
| 30 | |
Lei YU | b50c705 | 2021-01-21 16:02:26 +0800 | [diff] [blame] | 31 | uint32_t commit(const char* name) |
Deepak Kodihalli | 6fd9dc4 | 2018-04-03 02:08:42 -0500 | [diff] [blame] | 32 | { |
| 33 | auto msg = _prepareMsg("Commit"); |
Adriana Kobylak | 205b113 | 2017-02-06 20:15:29 -0600 | [diff] [blame] | 34 | uint64_t id = sdbusplus::server::transaction::get_id(); |
Deepak Kodihalli | 6fd9dc4 | 2018-04-03 02:08:42 -0500 | [diff] [blame] | 35 | msg.append(id, name); |
| 36 | auto bus = sdbusplus::bus::new_default(); |
Lei YU | b50c705 | 2021-01-21 16:02:26 +0800 | [diff] [blame] | 37 | auto reply = bus.call(msg); |
| 38 | uint32_t entryID; |
| 39 | reply.read(entryID); |
| 40 | return entryID; |
Deepak Kodihalli | 6fd9dc4 | 2018-04-03 02:08:42 -0500 | [diff] [blame] | 41 | } |
| 42 | |
Lei YU | b50c705 | 2021-01-21 16:02:26 +0800 | [diff] [blame] | 43 | uint32_t commit(const char* name, Entry::Level level) |
Deepak Kodihalli | 6fd9dc4 | 2018-04-03 02:08:42 -0500 | [diff] [blame] | 44 | { |
| 45 | auto msg = _prepareMsg("CommitWithLvl"); |
| 46 | uint64_t id = sdbusplus::server::transaction::get_id(); |
| 47 | msg.append(id, name, static_cast<uint32_t>(level)); |
| 48 | auto bus = sdbusplus::bus::new_default(); |
Lei YU | b50c705 | 2021-01-21 16:02:26 +0800 | [diff] [blame] | 49 | auto reply = bus.call(msg); |
| 50 | uint32_t entryID; |
| 51 | reply.read(entryID); |
| 52 | return entryID; |
Adriana Kobylak | c20dae8 | 2017-02-15 13:44:16 -0600 | [diff] [blame] | 53 | } |
Marri Devender Rao | 7d0a07b | 2017-04-04 03:43:00 -0500 | [diff] [blame] | 54 | } // namespace details |
| 55 | |
Lei YU | b50c705 | 2021-01-21 16:02:26 +0800 | [diff] [blame] | 56 | uint32_t commit(std::string&& name) |
Marri Devender Rao | 7d0a07b | 2017-04-04 03:43:00 -0500 | [diff] [blame] | 57 | { |
Arya K Padman | 5bc2653 | 2024-04-10 06:19:25 -0500 | [diff] [blame] | 58 | lg2::error("method is deprecated, use commit() with exception type"); |
Lei YU | b50c705 | 2021-01-21 16:02:26 +0800 | [diff] [blame] | 59 | return phosphor::logging::details::commit(name.c_str()); |
Marri Devender Rao | 7d0a07b | 2017-04-04 03:43:00 -0500 | [diff] [blame] | 60 | } |
Adriana Kobylak | c20dae8 | 2017-02-15 13:44:16 -0600 | [diff] [blame] | 61 | |
| 62 | } // namespace logging |
| 63 | } // namespace phosphor |