Deepak Kodihalli | 6b492fb | 2017-03-18 01:09:28 -0500 | [diff] [blame] | 1 | #pragma once |
| 2 | |
| 3 | #include <string> |
| 4 | #include <vector> |
Vishwanatha Subbanna | 38b08d7 | 2017-04-14 18:12:14 +0530 | [diff] [blame] | 5 | #include <unistd.h> |
Deepak Kodihalli | 6b492fb | 2017-03-18 01:09:28 -0500 | [diff] [blame] | 6 | #include <sdbusplus/bus.hpp> |
| 7 | #include <sdbusplus/server/object.hpp> |
Vishwanatha Subbanna | 9bb065b | 2017-04-18 14:25:26 +0530 | [diff] [blame] | 8 | #include <org/open_power/OCC/PassThrough/server.hpp> |
Deepak Kodihalli | 6b492fb | 2017-03-18 01:09:28 -0500 | [diff] [blame] | 9 | #include "config.h" |
Vishwanatha Subbanna | 38b08d7 | 2017-04-14 18:12:14 +0530 | [diff] [blame] | 10 | #include "file.hpp" |
Deepak Kodihalli | 6b492fb | 2017-03-18 01:09:28 -0500 | [diff] [blame] | 11 | |
| 12 | namespace open_power |
| 13 | { |
| 14 | namespace occ |
| 15 | { |
| 16 | namespace pass_through |
| 17 | { |
| 18 | |
| 19 | /** @brief Make occ pass-through d-bus object pathname |
| 20 | * @param[in] occ - occ name |
| 21 | * @returns occ pass-through path |
| 22 | */ |
| 23 | inline auto object(const std::string& occ) |
| 24 | { |
| 25 | return std::string(OCC_PASS_THROUGH_ROOT) + |
| 26 | '/' + |
| 27 | occ; |
| 28 | } |
| 29 | |
| 30 | /** @brief Put occ pass through objects on the bus |
| 31 | */ |
| 32 | void run(); |
| 33 | |
| 34 | using Iface = sdbusplus::server::object::object< |
| 35 | sdbusplus::org::open_power::OCC::server::PassThrough>; |
| 36 | |
| 37 | /** @class PassThrough |
| 38 | * @brief Implements org.open_power.OCC.PassThrough |
| 39 | */ |
| 40 | class PassThrough : public Iface |
| 41 | { |
| 42 | public: |
| 43 | PassThrough() = delete; |
Vishwanatha Subbanna | 38b08d7 | 2017-04-14 18:12:14 +0530 | [diff] [blame] | 44 | ~PassThrough() = default; |
Deepak Kodihalli | 6b492fb | 2017-03-18 01:09:28 -0500 | [diff] [blame] | 45 | PassThrough(const PassThrough&) = delete; |
| 46 | PassThrough& operator=(const PassThrough&) = delete; |
| 47 | PassThrough(PassThrough&&) = default; |
| 48 | PassThrough& operator=(PassThrough&&) = default; |
Deepak Kodihalli | 6b492fb | 2017-03-18 01:09:28 -0500 | [diff] [blame] | 49 | |
| 50 | /** @brief Ctor to put pass-through d-bus object on the bus |
| 51 | * @param[in] bus - Bus to attach to |
| 52 | * @param[in] path - Path to attach at |
| 53 | */ |
| 54 | PassThrough(sdbusplus::bus::bus& bus, |
| 55 | const char* path); |
| 56 | |
| 57 | /** @brief Pass through command to OCC |
| 58 | * @param[in] command - command to pass-through |
| 59 | * @returns OCC response as an array |
| 60 | */ |
| 61 | std::vector<std::int32_t> |
| 62 | send(std::vector<std::int32_t> command) override; |
| 63 | |
| 64 | private: |
| 65 | /** @brief Pass-through occ path on the bus */ |
| 66 | std::string path; |
Vishwanatha Subbanna | afd21a6 | 2017-04-13 20:17:13 +0530 | [diff] [blame] | 67 | |
| 68 | /** @brief OCC device path |
| 69 | * For now, here is the hard-coded mapping until |
Vishwanatha Subbanna | 38b08d7 | 2017-04-14 18:12:14 +0530 | [diff] [blame] | 70 | * the udev rule is in. |
Vishwanatha Subbanna | afd21a6 | 2017-04-13 20:17:13 +0530 | [diff] [blame] | 71 | * occ0 --> /dev/occfifo1 |
| 72 | * occ1 --> /dev/occfifo2 |
| 73 | * ... |
| 74 | */ |
Vishwanatha Subbanna | d13694a | 2017-06-01 15:44:20 +0530 | [diff] [blame^] | 75 | std::string devicePath = "/dev/occ"; |
Vishwanatha Subbanna | 38b08d7 | 2017-04-14 18:12:14 +0530 | [diff] [blame] | 76 | |
| 77 | /** @brief File descriptor manager */ |
| 78 | FileDescriptor fd; |
| 79 | |
| 80 | /** Opens devicePath and returns file descritor */ |
| 81 | int openDevice(); |
Deepak Kodihalli | 6b492fb | 2017-03-18 01:09:28 -0500 | [diff] [blame] | 82 | }; |
| 83 | |
| 84 | } // namespace pass_through |
| 85 | } // namespace occ |
| 86 | } // namespace open_power |