blob: 363553b82e4a736fa98c9f704bb5233866f50cb0 [file] [log] [blame]
Deepak Kodihalli827b50f2017-02-24 00:00:08 -06001#include "config.h"
Saqib Khan2bb15192017-02-13 13:19:55 -06002#include <phosphor-logging/elog.hpp>
Deepak Kodihalli6fd9dc42018-04-03 02:08:42 -05003#include <stdexcept>
Adriana Kobylakc20dae82017-02-15 13:44:16 -06004
5namespace phosphor
6{
7namespace logging
8{
Marri Devender Rao7d0a07b2017-04-04 03:43:00 -05009namespace details
Adriana Kobylakc20dae82017-02-15 13:44:16 -060010{
Deepak Kodihalli6fd9dc42018-04-03 02:08:42 -050011using namespace sdbusplus::xyz::openbmc_project::Logging::server;
12
13auto _prepareMsg(const char* funcName)
Marri Devender Rao7d0a07b2017-04-04 03:43:00 -050014{
15 using phosphor::logging::log;
Adriana Kobylak205b1132017-02-06 20:15:29 -060016 constexpr auto MAPPER_BUSNAME = "xyz.openbmc_project.ObjectMapper";
Leonel Gonzalez3064a192017-03-16 13:47:40 -050017 constexpr auto MAPPER_PATH = "/xyz/openbmc_project/object_mapper";
Adriana Kobylak205b1132017-02-06 20:15:29 -060018 constexpr auto MAPPER_INTERFACE = "xyz.openbmc_project.ObjectMapper";
19
Adriana Kobylak205b1132017-02-06 20:15:29 -060020 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 Kodihalli6fd9dc42018-04-03 02:08:42 -050035 throw std::runtime_error("Error in mapper call");
Adriana Kobylak205b1132017-02-06 20:15:29 -060036 }
37
38 std::map<std::string, std::vector<std::string>> mapperResponse;
39 mapperResponseMsg.read(mapperResponse);
40 if (mapperResponse.empty())
41 {
Deepak Kodihalli6fd9dc42018-04-03 02:08:42 -050042 throw std::runtime_error("Error reading mapper response");
Adriana Kobylak205b1132017-02-06 20:15:29 -060043 }
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 Kodihalli6fd9dc42018-04-03 02:08:42 -050050 funcName);
51 return m;
52}
53
54void commit(const char* name)
55{
56 auto msg = _prepareMsg("Commit");
Adriana Kobylak205b1132017-02-06 20:15:29 -060057 uint64_t id = sdbusplus::server::transaction::get_id();
Deepak Kodihalli6fd9dc42018-04-03 02:08:42 -050058 msg.append(id, name);
59 auto bus = sdbusplus::bus::new_default();
60 bus.call_noreply(msg);
61}
62
63void 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 Kobylakc20dae82017-02-15 13:44:16 -060070}
Marri Devender Rao7d0a07b2017-04-04 03:43:00 -050071} // namespace details
72
73void 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 Kobylakc20dae82017-02-15 13:44:16 -060078
79} // namespace logging
80} // namespace phosphor
81