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