blob: 68e5f8d379adc591e018ecd82a6370ed05d608c6 [file] [log] [blame]
Jayanth Othayothd31be2c2020-02-04 02:56:45 -06001#include "dump_utils.hpp"
2
Dhruvaraj Subhashchandran6f2f0982023-06-29 03:46:25 -05003#include "dump_types.hpp"
4
Dhruvaraj Subhashchandrand1f670f2023-06-05 22:19:25 -05005#include <phosphor-logging/lg2.hpp>
Jayanth Othayothd31be2c2020-02-04 02:56:45 -06006
7namespace phosphor
8{
9namespace dump
10{
11
Patrick Williams9b18bf22022-07-22 19:26:55 -050012std::string getService(sdbusplus::bus_t& bus, const std::string& path,
Jayanth Othayothd31be2c2020-02-04 02:56:45 -060013 const std::string& interface)
14{
15 constexpr auto objectMapperName = "xyz.openbmc_project.ObjectMapper";
16 constexpr auto objectMapperPath = "/xyz/openbmc_project/object_mapper";
Jayanth Othayothd31be2c2020-02-04 02:56:45 -060017
18 auto method = bus.new_method_call(objectMapperName, objectMapperPath,
19 objectMapperName, "GetObject");
20
21 method.append(path);
22 method.append(std::vector<std::string>({interface}));
23
24 std::vector<std::pair<std::string, std::vector<std::string>>> response;
25
26 try
27 {
28 auto reply = bus.call(method);
29 reply.read(response);
30 if (response.empty())
31 {
Dhruvaraj Subhashchandrand1f670f2023-06-05 22:19:25 -050032 lg2::error(
33 "Error in mapper response for getting service name, PATH: "
34 "{PATH}, INTERFACE: {INTERFACE}",
35 "PATH", path, "INTERFACE", interface);
Jayanth Othayothd31be2c2020-02-04 02:56:45 -060036 return std::string{};
37 }
38 }
Patrick Williams9b18bf22022-07-22 19:26:55 -050039 catch (const sdbusplus::exception_t& e)
Jayanth Othayothd31be2c2020-02-04 02:56:45 -060040 {
Dhruvaraj Subhashchandrand1f670f2023-06-05 22:19:25 -050041 lg2::error("Error in mapper method call, errormsg: {ERROR}, "
42 "PATH: {PATH}, INTERFACE: {INTERFACE}",
43 "ERROR", e, "PATH", path, "INTERFACE", interface);
Dhruvaraj Subhashchandran3a25e5b2022-03-22 08:06:20 -050044 throw;
Jayanth Othayothd31be2c2020-02-04 02:56:45 -060045 }
46 return response[0].first;
47}
48
Dhruvaraj Subhashchandran6f2f0982023-06-29 03:46:25 -050049DumpTypes validateDumpType(const std::string& type, const std::string& category)
50{
51 using InvalidArgument =
52 sdbusplus::xyz::openbmc_project::Common::Error::InvalidArgument;
53 using Argument = xyz::openbmc_project::Common::InvalidArgument;
54 // Dump type user will be return if type is empty
55 DumpTypes dumpType = DumpTypes::USER;
56 if (type.empty())
57 {
58 return dumpType;
59 }
60
61 // Find any matching dump collection type for the category
62 auto it = std::find_if(dumpTypeTable.begin(), dumpTypeTable.end(),
63 [&](const auto& pair) {
64 return pair.first == type && pair.second.second == category;
65 });
66
67 if (it != dumpTypeTable.end())
68 {
69 dumpType = it->second.first;
70 }
71 else
72 {
73 lg2::error("An invalid dump type: {TYPE} passed", "TYPE", type);
74 elog<InvalidArgument>(Argument::ARGUMENT_NAME("BMC_DUMP_TYPE"),
75 Argument::ARGUMENT_VALUE(type.c_str()));
76 }
77 return dumpType;
78}
79
Jayanth Othayothd31be2c2020-02-04 02:56:45 -060080} // namespace dump
81} // namespace phosphor