blob: 384a0659dd68cff99826e3517bdad5a4cb331bae [file] [log] [blame]
Deepak Kodihalli6b492fb2017-03-18 01:09:28 -05001#pragma once
2
3#include <string>
Deepak Kodihalli6b492fb2017-03-18 01:09:28 -05004#include <sdbusplus/bus.hpp>
5#include <sdbusplus/server/object.hpp>
Vishwanatha Subbanna9bb065b2017-04-18 14:25:26 +05306#include <org/open_power/OCC/PassThrough/server.hpp>
Deepak Kodihalli6b492fb2017-03-18 01:09:28 -05007
8namespace open_power
9{
10namespace occ
11{
Deepak Kodihalli6b492fb2017-03-18 01:09:28 -050012
13using Iface = sdbusplus::server::object::object<
14 sdbusplus::org::open_power::OCC::server::PassThrough>;
15
Vishwanatha Subbanna3e5422e2017-08-10 18:25:26 +053016// For waiting on signals
17namespace sdbusRule = sdbusplus::bus::match::rules;
18
Deepak Kodihalli6b492fb2017-03-18 01:09:28 -050019/** @class PassThrough
20 * @brief Implements org.open_power.OCC.PassThrough
21 */
22class 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 Kodihalli6b492fb2017-03-18 01:09:28 -050030
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 Subbanna3e5422e2017-08-10 18:25:26 +053038 ~PassThrough()
39 {
40 closeDevice();
41 }
42
Deepak Kodihalli6b492fb2017-03-18 01:09:28 -050043 /** @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 Subbannaafd21a62017-04-13 20:17:13 +053053
54 /** @brief OCC device path
55 * For now, here is the hard-coded mapping until
Vishwanatha Subbanna38b08d72017-04-14 18:12:14 +053056 * the udev rule is in.
Vishwanatha Subbanna3e5422e2017-08-10 18:25:26 +053057 * occ0 --> /dev/occ1
58 * occ1 --> /dev/occ2
Vishwanatha Subbannaafd21a62017-04-13 20:17:13 +053059 * ...
60 */
Vishwanatha Subbanna3e5422e2017-08-10 18:25:26 +053061 std::string devicePath;
Vishwanatha Subbanna38b08d72017-04-14 18:12:14 +053062
Eddie James4f4712d2018-06-21 15:57:02 -050063 /** @brief Indicates whether or not the OCC is currently active */
64 bool occActive = false;
65
Vishwanatha Subbanna3e5422e2017-08-10 18:25:26 +053066 /** brief file descriptor associated with occ device */
67 int fd = -1;
Vishwanatha Subbanna38b08d72017-04-14 18:12:14 +053068
Vishwanatha Subbanna3e5422e2017-08-10 18:25:26 +053069 /** @brief Subscribe to OCC Status signal
70 *
71 * Once the OCC status gets to active, only then we will get /dev/occ2
72 * populated and hence need to wait on that before opening that
73 */
74 sdbusplus::bus::match_t activeStatusSignal;
75
76 /** Opens devicePath and populates file descritor */
77 void openDevice();
78
79 /** Closed the fd associated with opened device */
80 void closeDevice();
81
82 /** @brief Callback function on OCC Status change signals
83 *
84 * @param[in] msg - Data associated with subscribed signal
85 */
86 void activeStatusEvent(sdbusplus::message::message& msg);
Deepak Kodihalli6b492fb2017-03-18 01:09:28 -050087};
88
Deepak Kodihalli6b492fb2017-03-18 01:09:28 -050089} // namespace occ
90} // namespace open_power