blob: a28eb6afedc283495940aca5e9f20fa9189d0e2d [file] [log] [blame]
Deepak Kodihalli6b492fb2017-03-18 01:09:28 -05001#pragma once
2
Gunnar Mills94df8c92018-09-14 14:50:03 -05003#include <org/open_power/OCC/PassThrough/server.hpp>
Deepak Kodihalli6b492fb2017-03-18 01:09:28 -05004#include <sdbusplus/bus.hpp>
5#include <sdbusplus/server/object.hpp>
Gunnar Mills94df8c92018-09-14 14:50:03 -05006#include <string>
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{
Gunnar Mills94df8c92018-09-14 14:50:03 -050024 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
Gunnar Mills94df8c92018-09-14 14:50:03 -050031 /** @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 Kodihalli6b492fb2017-03-18 01:09:28 -050036
Gunnar Mills94df8c92018-09-14 14:50:03 -050037 ~PassThrough()
38 {
39 closeDevice();
40 }
Vishwanatha Subbanna3e5422e2017-08-10 18:25:26 +053041
Gunnar Mills94df8c92018-09-14 14:50:03 -050042 /** @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 Kodihalli6b492fb2017-03-18 01:09:28 -050047
Gunnar Mills94df8c92018-09-14 14:50:03 -050048 private:
49 /** @brief Pass-through occ path on the bus */
50 std::string path;
Vishwanatha Subbannaafd21a62017-04-13 20:17:13 +053051
Gunnar Mills94df8c92018-09-14 14:50:03 -050052 /** @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 Subbanna38b08d72017-04-14 18:12:14 +053060
Gunnar Mills94df8c92018-09-14 14:50:03 -050061 /** @brief Indicates whether or not the OCC is currently active */
62 bool occActive = false;
Eddie James4f4712d2018-06-21 15:57:02 -050063
Gunnar Mills94df8c92018-09-14 14:50:03 -050064 /** brief file descriptor associated with occ device */
65 int fd = -1;
Vishwanatha Subbanna38b08d72017-04-14 18:12:14 +053066
Gunnar Mills94df8c92018-09-14 14:50:03 -050067 /** @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 Subbanna3e5422e2017-08-10 18:25:26 +053073
Gunnar Mills94df8c92018-09-14 14:50:03 -050074 /** Opens devicePath and populates file descritor */
75 void openDevice();
Vishwanatha Subbanna3e5422e2017-08-10 18:25:26 +053076
Gunnar Mills94df8c92018-09-14 14:50:03 -050077 /** Closed the fd associated with opened device */
78 void closeDevice();
Vishwanatha Subbanna3e5422e2017-08-10 18:25:26 +053079
Gunnar Mills94df8c92018-09-14 14:50:03 -050080 /** @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 Kodihalli6b492fb2017-03-18 01:09:28 -050085};
86
Deepak Kodihalli6b492fb2017-03-18 01:09:28 -050087} // namespace occ
88} // namespace open_power