blob: 88a0d296a3915575f8e094f6581d14a38c207fdb [file] [log] [blame]
Deepak Kodihalli6b492fb2017-03-18 01:09:28 -05001#include <memory>
Deepak Kodihalli02ba9ec2017-03-18 02:57:43 -05002#include <algorithm>
Vishwanatha Subbanna38b08d72017-04-14 18:12:14 +05303#include <fcntl.h>
Deepak Kodihalli02ba9ec2017-03-18 02:57:43 -05004#include <phosphor-logging/log.hpp>
Deepak Kodihalli6b492fb2017-03-18 01:09:28 -05005#include "occ_pass_through.hpp"
6#include "occ_finder.hpp"
Deepak Kodihalli6b492fb2017-03-18 01:09:28 -05007namespace 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),
Vishwanatha Subbanna38b08d72017-04-14 18:12:14 +053042 path(path),
43 fd(openDevice())
Deepak Kodihalli6b492fb2017-03-18 01:09:28 -050044{
Vishwanatha Subbanna38b08d72017-04-14 18:12:14 +053045 // Nothing to do.
46}
47
48int PassThrough::openDevice()
49{
50 // Device instance number starts from 1.
Vishwanatha Subbannaafd21a62017-04-13 20:17:13 +053051 devicePath.append(std::to_string((this->path.back() - '0') + 1));
Vishwanatha Subbanna38b08d72017-04-14 18:12:14 +053052
53 int fd = open(devicePath.c_str(), O_RDWR | O_NONBLOCK);
54 if (fd < 0)
55 {
56 // This is for completion. This is getting replaced by elog
57 // in the next commit
58 throw std::runtime_error("Error opening " + devicePath);
59 }
60 return fd;
Deepak Kodihalli6b492fb2017-03-18 01:09:28 -050061}
62
63std::vector<int32_t> PassThrough::send(std::vector<int32_t> command)
64{
Deepak Kodihalli6b492fb2017-03-18 01:09:28 -050065 return {};
66}
67
68} // namespace pass_through
69} // namespace occ
70} // namespace open_power