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> |
Deepak Kodihalli | 6fd9dc4 | 2018-04-03 02:08:42 -0500 | [diff] [blame] | 4 | #include <stdexcept> |
Adriana Kobylak | c20dae8 | 2017-02-15 13:44:16 -0600 | [diff] [blame] | 5 | |
| 6 | namespace phosphor |
| 7 | { |
| 8 | namespace logging |
| 9 | { |
Marri Devender Rao | 7d0a07b | 2017-04-04 03:43:00 -0500 | [diff] [blame] | 10 | namespace details |
Adriana Kobylak | c20dae8 | 2017-02-15 13:44:16 -0600 | [diff] [blame] | 11 | { |
Deepak Kodihalli | 6fd9dc4 | 2018-04-03 02:08:42 -0500 | [diff] [blame] | 12 | using namespace sdbusplus::xyz::openbmc_project::Logging::server; |
| 13 | |
| 14 | auto _prepareMsg(const char* funcName) |
Marri Devender Rao | 7d0a07b | 2017-04-04 03:43:00 -0500 | [diff] [blame] | 15 | { |
| 16 | using phosphor::logging::log; |
Adriana Kobylak | 205b113 | 2017-02-06 20:15:29 -0600 | [diff] [blame] | 17 | constexpr auto MAPPER_BUSNAME = "xyz.openbmc_project.ObjectMapper"; |
Leonel Gonzalez | 3064a19 | 2017-03-16 13:47:40 -0500 | [diff] [blame] | 18 | constexpr auto MAPPER_PATH = "/xyz/openbmc_project/object_mapper"; |
Adriana Kobylak | 205b113 | 2017-02-06 20:15:29 -0600 | [diff] [blame] | 19 | constexpr auto MAPPER_INTERFACE = "xyz.openbmc_project.ObjectMapper"; |
| 20 | |
Patrick Venture | f18bf83 | 2018-10-26 18:14:00 -0700 | [diff] [blame] | 21 | constexpr auto IFACE_INTERNAL( |
| 22 | "xyz.openbmc_project.Logging.Internal.Manager"); |
Adriana Kobylak | 205b113 | 2017-02-06 20:15:29 -0600 | [diff] [blame] | 23 | |
| 24 | // Transaction id is located at the end of the string separated by a period. |
| 25 | |
| 26 | auto b = sdbusplus::bus::new_default(); |
Patrick Venture | f18bf83 | 2018-10-26 18:14:00 -0700 | [diff] [blame] | 27 | auto mapper = b.new_method_call(MAPPER_BUSNAME, MAPPER_PATH, |
| 28 | MAPPER_INTERFACE, "GetObject"); |
Adriana Kobylak | 205b113 | 2017-02-06 20:15:29 -0600 | [diff] [blame] | 29 | mapper.append(OBJ_INTERNAL, std::vector<std::string>({IFACE_INTERNAL})); |
| 30 | |
| 31 | auto mapperResponseMsg = b.call(mapper); |
| 32 | if (mapperResponseMsg.is_method_error()) |
| 33 | { |
Deepak Kodihalli | 6fd9dc4 | 2018-04-03 02:08:42 -0500 | [diff] [blame] | 34 | throw std::runtime_error("Error in mapper call"); |
Adriana Kobylak | 205b113 | 2017-02-06 20:15:29 -0600 | [diff] [blame] | 35 | } |
| 36 | |
| 37 | std::map<std::string, std::vector<std::string>> mapperResponse; |
| 38 | mapperResponseMsg.read(mapperResponse); |
| 39 | if (mapperResponse.empty()) |
| 40 | { |
Deepak Kodihalli | 6fd9dc4 | 2018-04-03 02:08:42 -0500 | [diff] [blame] | 41 | throw std::runtime_error("Error reading mapper response"); |
Adriana Kobylak | 205b113 | 2017-02-06 20:15:29 -0600 | [diff] [blame] | 42 | } |
| 43 | |
| 44 | const auto& host = mapperResponse.cbegin()->first; |
Patrick Venture | f18bf83 | 2018-10-26 18:14:00 -0700 | [diff] [blame] | 45 | auto m = |
| 46 | b.new_method_call(host.c_str(), OBJ_INTERNAL, IFACE_INTERNAL, funcName); |
| 47 | return m; |
Deepak Kodihalli | 6fd9dc4 | 2018-04-03 02:08:42 -0500 | [diff] [blame] | 48 | } |
| 49 | |
| 50 | void commit(const char* name) |
| 51 | { |
| 52 | auto msg = _prepareMsg("Commit"); |
Adriana Kobylak | 205b113 | 2017-02-06 20:15:29 -0600 | [diff] [blame] | 53 | uint64_t id = sdbusplus::server::transaction::get_id(); |
Deepak Kodihalli | 6fd9dc4 | 2018-04-03 02:08:42 -0500 | [diff] [blame] | 54 | msg.append(id, name); |
| 55 | auto bus = sdbusplus::bus::new_default(); |
| 56 | bus.call_noreply(msg); |
| 57 | } |
| 58 | |
| 59 | void commit(const char* name, Entry::Level level) |
| 60 | { |
| 61 | auto msg = _prepareMsg("CommitWithLvl"); |
| 62 | uint64_t id = sdbusplus::server::transaction::get_id(); |
| 63 | msg.append(id, name, static_cast<uint32_t>(level)); |
| 64 | auto bus = sdbusplus::bus::new_default(); |
| 65 | bus.call_noreply(msg); |
Adriana Kobylak | c20dae8 | 2017-02-15 13:44:16 -0600 | [diff] [blame] | 66 | } |
Marri Devender Rao | 7d0a07b | 2017-04-04 03:43:00 -0500 | [diff] [blame] | 67 | } // namespace details |
| 68 | |
| 69 | void commit(std::string&& name) |
| 70 | { |
| 71 | log<level::ERR>("method is deprecated, use commit() with exception type"); |
| 72 | phosphor::logging::details::commit(name.c_str()); |
| 73 | } |
Adriana Kobylak | c20dae8 | 2017-02-15 13:44:16 -0600 | [diff] [blame] | 74 | |
| 75 | } // namespace logging |
| 76 | } // namespace phosphor |