1 #include <memory>
2 #include <algorithm>
3 #include <phosphor-logging/log.hpp>
4 #include "occ_pass_through.hpp"
5 #include "occ_finder.hpp"
6 namespace open_power
7 {
8 namespace occ
9 {
10 namespace pass_through
11 {
12 
13 void run()
14 {
15     auto bus = sdbusplus::bus::new_default();
16     sdbusplus::server::manager::manager objManager(bus,
17                                                    OCC_PASS_THROUGH_ROOT);
18 
19     std::vector<std::unique_ptr<PassThrough>> objects;
20     auto occs = open_power::occ::finder::get();
21 
22     for (const auto& occ : occs)
23     {
24         auto occPassThrough = object(occ);
25         objects.emplace_back(
26             std::make_unique<PassThrough>(bus, occPassThrough.c_str()));
27     }
28     bus.request_name(OCC_PASS_THROUGH_BUSNAME);
29 
30     while (true)
31     {
32         bus.process_discard();
33         bus.wait();
34     }
35 }
36 
37 PassThrough::PassThrough(
38     sdbusplus::bus::bus& bus,
39     const char* path) :
40     Iface(bus, path),
41     path(path)
42 {
43     devicePath.append(std::to_string((this->path.back() - '0') + 1));
44 }
45 
46 std::vector<int32_t> PassThrough::send(std::vector<int32_t> command)
47 {
48     std::string msg = "Pass through to OCC ";
49     msg += path;
50 
51     std::string cmd;
52     std::for_each(command.cbegin(), command.cend(),
53                   [&cmd](const auto& c)
54                   {
55                       cmd += std::to_string(c);
56                       cmd += ',';
57                   });
58     if (!cmd.empty())
59     {
60         // Remove trailing ','
61         cmd.pop_back();
62     }
63 
64     using namespace phosphor::logging;
65     log<level::INFO>(msg.c_str(), entry("COMMAND=%s", cmd.c_str()));
66 
67     return {};
68 }
69 
70 } // namespace pass_through
71 } // namespace occ
72 } // namespace open_power
73