blob: 8d6391d08358d32892a9ce866048e85d8a41fa53 [file] [log] [blame]
Deepak Kodihalli47795312017-03-17 07:12:08 -05001#include <algorithm>
2#include <sdbusplus/server.hpp>
3#include "occ_finder.hpp"
4#include "config.h"
5
6namespace open_power
7{
8namespace occ
9{
10namespace finder
11{
12
13constexpr auto toChar(size_t c)
14{
15 constexpr auto map = "0123";
16 return map[c];
17}
18
19std::vector<std::string> get()
20{
21 auto bus = sdbusplus::bus::new_default();
22 auto mapper =
23 bus.new_method_call(
24 "xyz.openbmc_project.ObjectMapper",
25 "/xyz/openbmc_project/object_mapper",
26 "xyz.openbmc_project.ObjectMapper",
27 "GetSubTreePaths");
28
29 auto depth = 0;
30 mapper.append(std::string(INVENTORY_ROOT));
31 mapper.append(depth);
32 mapper.append(std::vector<std::string>(
33 {std::string(INVENTORY_ITEM_INTERFACE)}));
34
35 auto result = bus.call(mapper);
36 if (result.is_method_error())
37 {
38 throw std::runtime_error("ObjectMapper GetSubTreePaths failed");
39 }
40
41 std::vector<std::string> response;
42 result.read(response);
43 if (response.empty())
44 {
45 throw std::runtime_error("ObjectMapper GetSubTreePaths : bad response");
46 }
47
48 std::vector<std::string> occs;
49 size_t count = 0;
50 std::string cpu = std::string(CPU_NAME) + toChar(count);
51 auto constexpr MAX_PROCS = 4; // Revisit for multi-node systems
52 for (const auto& path: response)
53 {
54 if (std::equal(cpu.crbegin(), cpu.crend(), path.crbegin()))
55 {
56 if(count == MAX_PROCS)
57 {
58 break;
59 }
60 occs.emplace_back(std::string(OCC_NAME) +
61 toChar(count++));
62 }
63 cpu.back() = toChar(count);
64 }
65
66 return occs;
67}
68
69} // namespace finder
70} // namespace occ
71} // namespace open_power