blob: b47cc8f8ebfa110206bd5e2c8342bebca2ad24a0 [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
Vishwanatha Subbanna1ec291f2017-08-21 17:07:29 +053026std::vector<std::string> get(sdbusplus::bus::bus& bus)
Deepak Kodihalli5f031f32017-07-26 08:25:59 -050027{
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
Deepak Kodihalli5f031f32017-07-26 08:25:59 -050034 auto mapper =
35 bus.new_method_call(
36 "xyz.openbmc_project.ObjectMapper",
37 "/xyz/openbmc_project/object_mapper",
38 "xyz.openbmc_project.ObjectMapper",
39 "GetSubTree");
40
41 auto depth = 0;
42 Path path = CPU_SUBPATH;
43 Interfaces interfaces{INVENTORY_ITEM_INTERFACE};
44 mapper.append(path);
45 mapper.append(depth);
46 mapper.append(interfaces);
47
48 auto result = bus.call(mapper);
49 if (result.is_method_error())
50 {
51 // It's okay to not have inventory, for example at BMC standby
52 return {};
53 }
54
55 using MapperResponse = std::map<Path, std::map<Service, Interfaces>>;
56 MapperResponse response;
57 result.read(response);
58 if (response.empty())
59 {
60 // It's okay to not have inventory, for example at BMC standby
61 return {};
62 }
63
64 std::vector<std::string> occs;
65 for (auto count = 0; count < MAX_CPUS; ++count)
66 {
67 fs::path p(path);
68 p /= std::string(CPU_NAME) + toChar(count);
69 if (response.end() != response.find(p.string()))
70 {
71 occs.emplace_back(std::string(OCC_NAME) +
72 toChar(count));
73 }
74 }
75
76 return occs;
77}
78
79} // namespace finder
80} // namespace occ
81} // namespace open_power