diff options
author | Vishwanatha Subbanna <vishwa@linux.vnet.ibm.com> | 2017-04-14 18:12:14 +0530 |
---|---|---|
committer | Vishwanatha Subbanna <vishwa@linux.vnet.ibm.com> | 2017-04-26 16:15:07 +0530 |
commit | 38b08d791b159424c9c9f9a21876f73f6020062b (patch) | |
tree | 95b9007eff763921cdcd3e66436ffddd80a74516 /occ_pass_through.cpp | |
parent | afd21a650715bf7a0ecc9b71a93d60639706d980 (diff) | |
download | openpower-occ-control-38b08d791b159424c9c9f9a21876f73f6020062b.tar.gz openpower-occ-control-38b08d791b159424c9c9f9a21876f73f6020062b.zip |
Open device and populate file descriptor
Change-Id: I8159f71ff3dd087f10cdf3b013e1acb60d4758fb
Signed-off-by: Vishwanatha Subbanna <vishwa@linux.vnet.ibm.com>
Diffstat (limited to 'occ_pass_through.cpp')
-rw-r--r-- | occ_pass_through.cpp | 34 |
1 files changed, 16 insertions, 18 deletions
diff --git a/occ_pass_through.cpp b/occ_pass_through.cpp index 05864c1..88a0d29 100644 --- a/occ_pass_through.cpp +++ b/occ_pass_through.cpp @@ -1,5 +1,6 @@ #include <memory> #include <algorithm> +#include <fcntl.h> #include <phosphor-logging/log.hpp> #include "occ_pass_through.hpp" #include "occ_finder.hpp" @@ -38,32 +39,29 @@ PassThrough::PassThrough( sdbusplus::bus::bus& bus, const char* path) : Iface(bus, path), - path(path) + path(path), + fd(openDevice()) { - devicePath.append(std::to_string((this->path.back() - '0') + 1)); + // Nothing to do. } -std::vector<int32_t> PassThrough::send(std::vector<int32_t> command) +int PassThrough::openDevice() { - std::string msg = "Pass through to OCC "; - msg += path; + // Device instance number starts from 1. + devicePath.append(std::to_string((this->path.back() - '0') + 1)); - std::string cmd; - std::for_each(command.cbegin(), command.cend(), - [&cmd](const auto& c) - { - cmd += std::to_string(c); - cmd += ','; - }); - if (!cmd.empty()) + int fd = open(devicePath.c_str(), O_RDWR | O_NONBLOCK); + if (fd < 0) { - // Remove trailing ',' - cmd.pop_back(); + // This is for completion. This is getting replaced by elog + // in the next commit + throw std::runtime_error("Error opening " + devicePath); } + return fd; +} - using namespace phosphor::logging; - log<level::INFO>(msg.c_str(), entry("COMMAND=%s", cmd.c_str())); - +std::vector<int32_t> PassThrough::send(std::vector<int32_t> command) +{ return {}; } |