blob: 766a183a3b71ba066f1dcb36488e8c0a7e090500 [file] [log] [blame]
Sampa Misra032bd502019-03-06 05:03:22 -06001#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>
Deepak Kodihallic2feac92019-04-30 17:21:19 +05309#include <phosphor-logging/log.hpp>
Sampa Misra032bd502019-03-06 05:03:22 -060010#include <stdexcept>
11#include <string>
12#include <vector>
13
14namespace pldm
15{
16using namespace phosphor::logging;
17
18constexpr auto mapperBusName = "xyz.openbmc_project.ObjectMapper";
19constexpr auto mapperPath = "/xyz/openbmc_project/object_mapper";
20constexpr auto mapperInterface = "xyz.openbmc_project.ObjectMapper";
21
22namespace responder
23{
24
25std::string getService(sdbusplus::bus::bus& bus, const std::string& path,
26 const std::string& interface)
27{
28 using DbusInterfaceList = std::vector<std::string>;
29 std::map<std::string, std::vector<std::string>> mapperResponse;
30
31 try
32 {
33 auto mapper = bus.new_method_call(mapperBusName, mapperPath,
34 mapperInterface, "GetObject");
35 mapper.append(path, DbusInterfaceList({interface}));
36
37 auto mapperResponseMsg = bus.call(mapper);
38 mapperResponseMsg.read(mapperResponse);
39 }
40 catch (std::exception& e)
41 {
42 log<level::ERR>("Error in mapper call", entry("ERROR=%s", e.what()),
43 entry("PATH=%s", path.c_str()),
44 entry("INTERFACE=%s", interface.c_str()));
45 throw;
46 }
47 return mapperResponse.begin()->first;
48}
49
Sampa Misrab37be312019-07-03 02:26:41 -050050namespace utils
51{
52
53uint8_t getNumPadBytes(uint32_t data)
54{
55 uint8_t pad;
56 pad = ((data % 4) ? (4 - data % 4) : 0);
57 return pad;
58} // end getNumPadBytes
59
60} // end namespace utils
Sampa Misra032bd502019-03-06 05:03:22 -060061} // namespace responder
62} // namespace pldm