1 #include <memory>
2 #include <algorithm>
3 #include <fcntl.h>
4 #include <phosphor-logging/log.hpp>
5 #include "occ_pass_through.hpp"
6 #include "occ_finder.hpp"
7 namespace open_power
8 {
9 namespace occ
10 {
11 namespace pass_through
12 {
13 
14 void 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 
38 PassThrough::PassThrough(
39     sdbusplus::bus::bus& bus,
40     const char* path) :
41     Iface(bus, path),
42     path(path),
43     fd(openDevice())
44 {
45     // Nothing to do.
46 }
47 
48 int PassThrough::openDevice()
49 {
50     // Device instance number starts from 1.
51     devicePath.append(std::to_string((this->path.back() - '0') + 1));
52 
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;
61 }
62 
63 std::vector<int32_t> PassThrough::send(std::vector<int32_t> command)
64 {
65     return {};
66 }
67 
68 } // namespace pass_through
69 } // namespace occ
70 } // namespace open_power
71