| Deepak Kodihalli | 6b492fb | 2017-03-18 01:09:28 -0500 | [diff] [blame] | 1 | #pragma once | 
 | 2 |  | 
| Gunnar Mills | 94df8c9 | 2018-09-14 14:50:03 -0500 | [diff] [blame] | 3 | #include <org/open_power/OCC/PassThrough/server.hpp> | 
| Deepak Kodihalli | 6b492fb | 2017-03-18 01:09:28 -0500 | [diff] [blame] | 4 | #include <sdbusplus/bus.hpp> | 
 | 5 | #include <sdbusplus/server/object.hpp> | 
| Gunnar Mills | 94df8c9 | 2018-09-14 14:50:03 -0500 | [diff] [blame] | 6 | #include <string> | 
| Deepak Kodihalli | 6b492fb | 2017-03-18 01:09:28 -0500 | [diff] [blame] | 7 |  | 
 | 8 | namespace open_power | 
 | 9 | { | 
 | 10 | namespace occ | 
 | 11 | { | 
| Deepak Kodihalli | 6b492fb | 2017-03-18 01:09:28 -0500 | [diff] [blame] | 12 |  | 
 | 13 | using Iface = sdbusplus::server::object::object< | 
 | 14 |     sdbusplus::org::open_power::OCC::server::PassThrough>; | 
 | 15 |  | 
| Vishwanatha Subbanna | 3e5422e | 2017-08-10 18:25:26 +0530 | [diff] [blame] | 16 | // For waiting on signals | 
 | 17 | namespace sdbusRule = sdbusplus::bus::match::rules; | 
 | 18 |  | 
| Deepak Kodihalli | 6b492fb | 2017-03-18 01:09:28 -0500 | [diff] [blame] | 19 | /** @class PassThrough | 
 | 20 |  *  @brief Implements org.open_power.OCC.PassThrough | 
 | 21 |  */ | 
 | 22 | class PassThrough : public Iface | 
 | 23 | { | 
| Gunnar Mills | 94df8c9 | 2018-09-14 14:50:03 -0500 | [diff] [blame] | 24 |   public: | 
 | 25 |     PassThrough() = delete; | 
 | 26 |     PassThrough(const PassThrough&) = delete; | 
 | 27 |     PassThrough& operator=(const PassThrough&) = delete; | 
 | 28 |     PassThrough(PassThrough&&) = default; | 
 | 29 |     PassThrough& operator=(PassThrough&&) = default; | 
| Deepak Kodihalli | 6b492fb | 2017-03-18 01:09:28 -0500 | [diff] [blame] | 30 |  | 
| Gunnar Mills | 94df8c9 | 2018-09-14 14:50:03 -0500 | [diff] [blame] | 31 |     /** @brief Ctor to put pass-through d-bus object on the bus | 
 | 32 |      *  @param[in] bus - Bus to attach to | 
 | 33 |      *  @param[in] path - Path to attach at | 
 | 34 |      */ | 
 | 35 |     PassThrough(sdbusplus::bus::bus& bus, const char* path); | 
| Deepak Kodihalli | 6b492fb | 2017-03-18 01:09:28 -0500 | [diff] [blame] | 36 |  | 
| Gunnar Mills | 94df8c9 | 2018-09-14 14:50:03 -0500 | [diff] [blame] | 37 |     ~PassThrough() | 
 | 38 |     { | 
 | 39 |         closeDevice(); | 
 | 40 |     } | 
| Vishwanatha Subbanna | 3e5422e | 2017-08-10 18:25:26 +0530 | [diff] [blame] | 41 |  | 
| Gunnar Mills | 94df8c9 | 2018-09-14 14:50:03 -0500 | [diff] [blame] | 42 |     /** @brief Pass through command to OCC | 
 | 43 |      *  @param[in] command - command to pass-through | 
 | 44 |      *  @returns OCC response as an array | 
 | 45 |      */ | 
 | 46 |     std::vector<std::int32_t> send(std::vector<std::int32_t> command) override; | 
| Deepak Kodihalli | 6b492fb | 2017-03-18 01:09:28 -0500 | [diff] [blame] | 47 |  | 
| Gunnar Mills | 94df8c9 | 2018-09-14 14:50:03 -0500 | [diff] [blame] | 48 |   private: | 
 | 49 |     /** @brief Pass-through occ path on the bus */ | 
 | 50 |     std::string path; | 
| Vishwanatha Subbanna | afd21a6 | 2017-04-13 20:17:13 +0530 | [diff] [blame] | 51 |  | 
| Gunnar Mills | 94df8c9 | 2018-09-14 14:50:03 -0500 | [diff] [blame] | 52 |     /** @brief OCC device path | 
 | 53 |      *  For now, here is the hard-coded mapping until | 
 | 54 |      *  the udev rule is in. | 
 | 55 |      *  occ0 --> /dev/occ1 | 
 | 56 |      *  occ1 --> /dev/occ2 | 
 | 57 |      *  ... | 
 | 58 |      */ | 
 | 59 |     std::string devicePath; | 
| Vishwanatha Subbanna | 38b08d7 | 2017-04-14 18:12:14 +0530 | [diff] [blame] | 60 |  | 
| Gunnar Mills | 94df8c9 | 2018-09-14 14:50:03 -0500 | [diff] [blame] | 61 |     /** @brief Indicates whether or not the OCC is currently active */ | 
 | 62 |     bool occActive = false; | 
| Eddie James | 4f4712d | 2018-06-21 15:57:02 -0500 | [diff] [blame] | 63 |  | 
| Gunnar Mills | 94df8c9 | 2018-09-14 14:50:03 -0500 | [diff] [blame] | 64 |     /** brief file descriptor associated with occ device */ | 
 | 65 |     int fd = -1; | 
| Vishwanatha Subbanna | 38b08d7 | 2017-04-14 18:12:14 +0530 | [diff] [blame] | 66 |  | 
| Gunnar Mills | 94df8c9 | 2018-09-14 14:50:03 -0500 | [diff] [blame] | 67 |     /** @brief Subscribe to OCC Status signal | 
 | 68 |      * | 
 | 69 |      *  Once the OCC status gets to active, only then we will get /dev/occ2 | 
 | 70 |      *  populated and hence need to wait on that before opening that | 
 | 71 |      */ | 
 | 72 |     sdbusplus::bus::match_t activeStatusSignal; | 
| Vishwanatha Subbanna | 3e5422e | 2017-08-10 18:25:26 +0530 | [diff] [blame] | 73 |  | 
| Gunnar Mills | 94df8c9 | 2018-09-14 14:50:03 -0500 | [diff] [blame] | 74 |     /** Opens devicePath and populates file descritor */ | 
 | 75 |     void openDevice(); | 
| Vishwanatha Subbanna | 3e5422e | 2017-08-10 18:25:26 +0530 | [diff] [blame] | 76 |  | 
| Gunnar Mills | 94df8c9 | 2018-09-14 14:50:03 -0500 | [diff] [blame] | 77 |     /** Closed the fd associated with opened device */ | 
 | 78 |     void closeDevice(); | 
| Vishwanatha Subbanna | 3e5422e | 2017-08-10 18:25:26 +0530 | [diff] [blame] | 79 |  | 
| Gunnar Mills | 94df8c9 | 2018-09-14 14:50:03 -0500 | [diff] [blame] | 80 |     /** @brief Callback function on OCC Status change signals | 
 | 81 |      * | 
 | 82 |      *  @param[in]  msg - Data associated with subscribed signal | 
 | 83 |      */ | 
 | 84 |     void activeStatusEvent(sdbusplus::message::message& msg); | 
| Deepak Kodihalli | 6b492fb | 2017-03-18 01:09:28 -0500 | [diff] [blame] | 85 | }; | 
 | 86 |  | 
| Deepak Kodihalli | 6b492fb | 2017-03-18 01:09:28 -0500 | [diff] [blame] | 87 | } // namespace occ | 
 | 88 | } // namespace open_power |