| Deepak Kodihalli | 6b492fb | 2017-03-18 01:09:28 -0500 | [diff] [blame] | 1 | #pragma once | 
|  | 2 |  | 
|  | 3 | #include <string> | 
| Deepak Kodihalli | 6b492fb | 2017-03-18 01:09:28 -0500 | [diff] [blame] | 4 | #include <sdbusplus/bus.hpp> | 
|  | 5 | #include <sdbusplus/server/object.hpp> | 
| Vishwanatha Subbanna | 9bb065b | 2017-04-18 14:25:26 +0530 | [diff] [blame] | 6 | #include <org/open_power/OCC/PassThrough/server.hpp> | 
| 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 | { | 
|  | 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 |  | 
|  | 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, | 
|  | 36 | const char* path); | 
|  | 37 |  | 
| Vishwanatha Subbanna | 3e5422e | 2017-08-10 18:25:26 +0530 | [diff] [blame] | 38 | ~PassThrough() | 
|  | 39 | { | 
|  | 40 | closeDevice(); | 
|  | 41 | } | 
|  | 42 |  | 
| Deepak Kodihalli | 6b492fb | 2017-03-18 01:09:28 -0500 | [diff] [blame] | 43 | /** @brief Pass through command to OCC | 
|  | 44 | *  @param[in] command - command to pass-through | 
|  | 45 | *  @returns OCC response as an array | 
|  | 46 | */ | 
|  | 47 | std::vector<std::int32_t> | 
|  | 48 | send(std::vector<std::int32_t> command) override; | 
|  | 49 |  | 
|  | 50 | private: | 
|  | 51 | /** @brief Pass-through occ path on the bus */ | 
|  | 52 | std::string path; | 
| Vishwanatha Subbanna | afd21a6 | 2017-04-13 20:17:13 +0530 | [diff] [blame] | 53 |  | 
|  | 54 | /** @brief OCC device path | 
|  | 55 | *  For now, here is the hard-coded mapping until | 
| Vishwanatha Subbanna | 38b08d7 | 2017-04-14 18:12:14 +0530 | [diff] [blame] | 56 | *  the udev rule is in. | 
| Vishwanatha Subbanna | 3e5422e | 2017-08-10 18:25:26 +0530 | [diff] [blame] | 57 | *  occ0 --> /dev/occ1 | 
|  | 58 | *  occ1 --> /dev/occ2 | 
| Vishwanatha Subbanna | afd21a6 | 2017-04-13 20:17:13 +0530 | [diff] [blame] | 59 | *  ... | 
|  | 60 | */ | 
| Vishwanatha Subbanna | 3e5422e | 2017-08-10 18:25:26 +0530 | [diff] [blame] | 61 | std::string devicePath; | 
| Vishwanatha Subbanna | 38b08d7 | 2017-04-14 18:12:14 +0530 | [diff] [blame] | 62 |  | 
| Vishwanatha Subbanna | 3e5422e | 2017-08-10 18:25:26 +0530 | [diff] [blame] | 63 | /** brief file descriptor associated with occ device */ | 
|  | 64 | int fd = -1; | 
| Vishwanatha Subbanna | 38b08d7 | 2017-04-14 18:12:14 +0530 | [diff] [blame] | 65 |  | 
| Vishwanatha Subbanna | 3e5422e | 2017-08-10 18:25:26 +0530 | [diff] [blame] | 66 | /** @brief Subscribe to OCC Status signal | 
|  | 67 | * | 
|  | 68 | *  Once the OCC status gets to active, only then we will get /dev/occ2 | 
|  | 69 | *  populated and hence need to wait on that before opening that | 
|  | 70 | */ | 
|  | 71 | sdbusplus::bus::match_t activeStatusSignal; | 
|  | 72 |  | 
|  | 73 | /** Opens devicePath and populates file descritor */ | 
|  | 74 | void openDevice(); | 
|  | 75 |  | 
|  | 76 | /** Closed the fd associated with opened device */ | 
|  | 77 | void closeDevice(); | 
|  | 78 |  | 
|  | 79 | /** @brief Callback function on OCC Status change signals | 
|  | 80 | * | 
|  | 81 | *  @param[in]  msg - Data associated with subscribed signal | 
|  | 82 | */ | 
|  | 83 | void activeStatusEvent(sdbusplus::message::message& msg); | 
| Deepak Kodihalli | 6b492fb | 2017-03-18 01:09:28 -0500 | [diff] [blame] | 84 | }; | 
|  | 85 |  | 
| Deepak Kodihalli | 6b492fb | 2017-03-18 01:09:28 -0500 | [diff] [blame] | 86 | } // namespace occ | 
|  | 87 | } // namespace open_power |