blob: a533067066f2c21d7520bbd7374888bc7e104d2d [file] [log] [blame]
Deepak Kodihalli5f031f32017-07-26 08:25:59 -05001#include <algorithm>
2#include <iterator>
3#include <experimental/filesystem>
4#include <sdbusplus/server.hpp>
5#include <phosphor-logging/elog-errors.hpp>
6#include <phosphor-logging/log.hpp>
7#include <xyz/openbmc_project/Common/error.hpp>
8#include "occ_finder.hpp"
9#include "config.h"
10
11namespace open_power
12{
13namespace occ
14{
15namespace finder
16{
17
18using namespace phosphor::logging;
19
20constexpr auto toChar(size_t c)
21{
22 constexpr auto map = "0123456789abcdef";
23 return map[c];
24}
25
26std::vector<std::string> get()
27{
28 namespace fs = std::experimental::filesystem;
29 using Path = std::string;
30 using Service = std::string;
31 using Interface = std::string;
32 using Interfaces = std::vector<Interface>;
33
34 auto bus = sdbusplus::bus::new_default();
35 auto mapper =
36 bus.new_method_call(
37 "xyz.openbmc_project.ObjectMapper",
38 "/xyz/openbmc_project/object_mapper",
39 "xyz.openbmc_project.ObjectMapper",
40 "GetSubTree");
41
42 auto depth = 0;
43 Path path = CPU_SUBPATH;
44 Interfaces interfaces{INVENTORY_ITEM_INTERFACE};
45 mapper.append(path);
46 mapper.append(depth);
47 mapper.append(interfaces);
48
49 auto result = bus.call(mapper);
50 if (result.is_method_error())
51 {
52 // It's okay to not have inventory, for example at BMC standby
53 return {};
54 }
55
56 using MapperResponse = std::map<Path, std::map<Service, Interfaces>>;
57 MapperResponse response;
58 result.read(response);
59 if (response.empty())
60 {
61 // It's okay to not have inventory, for example at BMC standby
62 return {};
63 }
64
65 std::vector<std::string> occs;
66 for (auto count = 0; count < MAX_CPUS; ++count)
67 {
68 fs::path p(path);
69 p /= std::string(CPU_NAME) + toChar(count);
70 if (response.end() != response.find(p.string()))
71 {
72 occs.emplace_back(std::string(OCC_NAME) +
73 toChar(count));
74 }
75 }
76
77 return occs;
78}
79
80} // namespace finder
81} // namespace occ
82} // namespace open_power