Deepak Kodihalli | 6b492fb | 2017-03-18 01:09:28 -0500 | [diff] [blame] | 1 | #include <memory> |
Deepak Kodihalli | 02ba9ec | 2017-03-18 02:57:43 -0500 | [diff] [blame] | 2 | #include <algorithm> |
Vishwanatha Subbanna | 38b08d7 | 2017-04-14 18:12:14 +0530 | [diff] [blame^] | 3 | #include <fcntl.h> |
Deepak Kodihalli | 02ba9ec | 2017-03-18 02:57:43 -0500 | [diff] [blame] | 4 | #include <phosphor-logging/log.hpp> |
Deepak Kodihalli | 6b492fb | 2017-03-18 01:09:28 -0500 | [diff] [blame] | 5 | #include "occ_pass_through.hpp" |
| 6 | #include "occ_finder.hpp" |
Deepak Kodihalli | 6b492fb | 2017-03-18 01:09:28 -0500 | [diff] [blame] | 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), |
Vishwanatha Subbanna | 38b08d7 | 2017-04-14 18:12:14 +0530 | [diff] [blame^] | 42 | path(path), |
| 43 | fd(openDevice()) |
Deepak Kodihalli | 6b492fb | 2017-03-18 01:09:28 -0500 | [diff] [blame] | 44 | { |
Vishwanatha Subbanna | 38b08d7 | 2017-04-14 18:12:14 +0530 | [diff] [blame^] | 45 | // Nothing to do. |
| 46 | } |
| 47 | |
| 48 | int PassThrough::openDevice() |
| 49 | { |
| 50 | // Device instance number starts from 1. |
Vishwanatha Subbanna | afd21a6 | 2017-04-13 20:17:13 +0530 | [diff] [blame] | 51 | devicePath.append(std::to_string((this->path.back() - '0') + 1)); |
Vishwanatha Subbanna | 38b08d7 | 2017-04-14 18:12:14 +0530 | [diff] [blame^] | 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; |
Deepak Kodihalli | 6b492fb | 2017-03-18 01:09:28 -0500 | [diff] [blame] | 61 | } |
| 62 | |
| 63 | std::vector<int32_t> PassThrough::send(std::vector<int32_t> command) |
| 64 | { |
Deepak Kodihalli | 6b492fb | 2017-03-18 01:09:28 -0500 | [diff] [blame] | 65 | return {}; |
| 66 | } |
| 67 | |
| 68 | } // namespace pass_through |
| 69 | } // namespace occ |
| 70 | } // namespace open_power |