Sampa Misra | 032bd50 | 2019-03-06 05:03:22 -0600 | [diff] [blame] | 1 | #include "utils.hpp" |
| 2 | |
| 3 | #include "xyz/openbmc_project/Common/error.hpp" |
| 4 | |
| 5 | #include <array> |
| 6 | #include <ctime> |
| 7 | #include <iostream> |
| 8 | #include <map> |
Sampa Misra | 032bd50 | 2019-03-06 05:03:22 -0600 | [diff] [blame] | 9 | #include <stdexcept> |
| 10 | #include <string> |
| 11 | #include <vector> |
| 12 | |
| 13 | namespace pldm |
| 14 | { |
Sampa Misra | 032bd50 | 2019-03-06 05:03:22 -0600 | [diff] [blame] | 15 | |
| 16 | constexpr auto mapperBusName = "xyz.openbmc_project.ObjectMapper"; |
| 17 | constexpr auto mapperPath = "/xyz/openbmc_project/object_mapper"; |
| 18 | constexpr auto mapperInterface = "xyz.openbmc_project.ObjectMapper"; |
| 19 | |
| 20 | namespace responder |
| 21 | { |
| 22 | |
| 23 | std::string getService(sdbusplus::bus::bus& bus, const std::string& path, |
| 24 | const std::string& interface) |
| 25 | { |
| 26 | using DbusInterfaceList = std::vector<std::string>; |
| 27 | std::map<std::string, std::vector<std::string>> mapperResponse; |
| 28 | |
| 29 | try |
| 30 | { |
| 31 | auto mapper = bus.new_method_call(mapperBusName, mapperPath, |
| 32 | mapperInterface, "GetObject"); |
| 33 | mapper.append(path, DbusInterfaceList({interface})); |
| 34 | |
| 35 | auto mapperResponseMsg = bus.call(mapper); |
| 36 | mapperResponseMsg.read(mapperResponse); |
| 37 | } |
| 38 | catch (std::exception& e) |
| 39 | { |
Sampa Misra | aa8ae72 | 2019-12-12 03:20:40 -0600 | [diff] [blame] | 40 | std::cerr << "Error in mapper call, ERROR=" << e.what() |
| 41 | << " PATH=" << path.c_str() |
| 42 | << " INTERFACE=" << interface.c_str() << "\n"; |
Sampa Misra | 032bd50 | 2019-03-06 05:03:22 -0600 | [diff] [blame] | 43 | throw; |
| 44 | } |
| 45 | return mapperResponse.begin()->first; |
| 46 | } |
| 47 | |
Sampa Misra | aa8ae72 | 2019-12-12 03:20:40 -0600 | [diff] [blame] | 48 | void reportError(const char* errorMsg) |
| 49 | { |
| 50 | static constexpr auto logObjPath = "/xyz/openbmc_project/logging"; |
| 51 | static constexpr auto logInterface = "xyz.openbmc_project.Logging.Create"; |
| 52 | |
| 53 | static sdbusplus::bus::bus bus = sdbusplus::bus::new_default(); |
| 54 | |
| 55 | try |
| 56 | { |
| 57 | auto service = getService(bus, logObjPath, logInterface); |
| 58 | using namespace sdbusplus::xyz::openbmc_project::Logging::server; |
| 59 | auto severity = |
| 60 | sdbusplus::xyz::openbmc_project::Logging::server::convertForMessage( |
| 61 | sdbusplus::xyz::openbmc_project::Logging::server::Entry::Level:: |
| 62 | Error); |
| 63 | auto method = bus.new_method_call(service.c_str(), logObjPath, |
| 64 | logInterface, "Create"); |
| 65 | std::map<std::string, std::string> addlData{}; |
| 66 | method.append(errorMsg, severity, addlData); |
| 67 | bus.call_noreply(method); |
| 68 | } |
| 69 | catch (const std::exception& e) |
| 70 | { |
| 71 | std::cerr << "failed to make a d-bus call to create error log, ERROR=" |
| 72 | << e.what() << "\n"; |
| 73 | } |
| 74 | } |
| 75 | |
Sampa Misra | b37be31 | 2019-07-03 02:26:41 -0500 | [diff] [blame] | 76 | namespace utils |
| 77 | { |
| 78 | |
| 79 | uint8_t getNumPadBytes(uint32_t data) |
| 80 | { |
| 81 | uint8_t pad; |
| 82 | pad = ((data % 4) ? (4 - data % 4) : 0); |
| 83 | return pad; |
| 84 | } // end getNumPadBytes |
| 85 | |
| 86 | } // end namespace utils |
Sampa Misra | 032bd50 | 2019-03-06 05:03:22 -0600 | [diff] [blame] | 87 | } // namespace responder |
| 88 | } // namespace pldm |