blob: 5cefe815daf2928a80bf99e6539864a861396623 [file] [log] [blame]
Deepak Kodihalli827b50f2017-02-24 00:00:08 -06001#include "config.h"
Patrick Venturef18bf832018-10-26 18:14:00 -07002
Saqib Khan2bb15192017-02-13 13:19:55 -06003#include <phosphor-logging/elog.hpp>
Deepak Kodihalli6fd9dc42018-04-03 02:08:42 -05004#include <stdexcept>
Adriana Kobylakc20dae82017-02-15 13:44:16 -06005
6namespace phosphor
7{
8namespace logging
9{
Marri Devender Rao7d0a07b2017-04-04 03:43:00 -050010namespace details
Adriana Kobylakc20dae82017-02-15 13:44:16 -060011{
Deepak Kodihalli6fd9dc42018-04-03 02:08:42 -050012using namespace sdbusplus::xyz::openbmc_project::Logging::server;
13
14auto _prepareMsg(const char* funcName)
Marri Devender Rao7d0a07b2017-04-04 03:43:00 -050015{
16 using phosphor::logging::log;
Adriana Kobylak205b1132017-02-06 20:15:29 -060017 constexpr auto MAPPER_BUSNAME = "xyz.openbmc_project.ObjectMapper";
Leonel Gonzalez3064a192017-03-16 13:47:40 -050018 constexpr auto MAPPER_PATH = "/xyz/openbmc_project/object_mapper";
Adriana Kobylak205b1132017-02-06 20:15:29 -060019 constexpr auto MAPPER_INTERFACE = "xyz.openbmc_project.ObjectMapper";
20
Patrick Venturef18bf832018-10-26 18:14:00 -070021 constexpr auto IFACE_INTERNAL(
22 "xyz.openbmc_project.Logging.Internal.Manager");
Adriana Kobylak205b1132017-02-06 20:15:29 -060023
24 // Transaction id is located at the end of the string separated by a period.
25
26 auto b = sdbusplus::bus::new_default();
Patrick Venturef18bf832018-10-26 18:14:00 -070027 auto mapper = b.new_method_call(MAPPER_BUSNAME, MAPPER_PATH,
28 MAPPER_INTERFACE, "GetObject");
Adriana Kobylak205b1132017-02-06 20:15:29 -060029 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 Kodihalli6fd9dc42018-04-03 02:08:42 -050034 throw std::runtime_error("Error in mapper call");
Adriana Kobylak205b1132017-02-06 20:15:29 -060035 }
36
37 std::map<std::string, std::vector<std::string>> mapperResponse;
38 mapperResponseMsg.read(mapperResponse);
39 if (mapperResponse.empty())
40 {
Deepak Kodihalli6fd9dc42018-04-03 02:08:42 -050041 throw std::runtime_error("Error reading mapper response");
Adriana Kobylak205b1132017-02-06 20:15:29 -060042 }
43
44 const auto& host = mapperResponse.cbegin()->first;
Patrick Venturef18bf832018-10-26 18:14:00 -070045 auto m =
46 b.new_method_call(host.c_str(), OBJ_INTERNAL, IFACE_INTERNAL, funcName);
47 return m;
Deepak Kodihalli6fd9dc42018-04-03 02:08:42 -050048}
49
50void commit(const char* name)
51{
52 auto msg = _prepareMsg("Commit");
Adriana Kobylak205b1132017-02-06 20:15:29 -060053 uint64_t id = sdbusplus::server::transaction::get_id();
Deepak Kodihalli6fd9dc42018-04-03 02:08:42 -050054 msg.append(id, name);
55 auto bus = sdbusplus::bus::new_default();
56 bus.call_noreply(msg);
57}
58
59void 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 Kobylakc20dae82017-02-15 13:44:16 -060066}
Marri Devender Rao7d0a07b2017-04-04 03:43:00 -050067} // namespace details
68
69void 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 Kobylakc20dae82017-02-15 13:44:16 -060074
75} // namespace logging
76} // namespace phosphor