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