1 #pragma once
2 
3 #include "occ_command.hpp"
4 
5 #include <fmt/core.h>
6 
7 #include <org/open_power/OCC/PassThrough/server.hpp>
8 #include <phosphor-logging/log.hpp>
9 #include <sdbusplus/bus.hpp>
10 #include <sdbusplus/server/object.hpp>
11 #include <string>
12 
13 namespace open_power
14 {
15 namespace occ
16 {
17 
18 using Iface = sdbusplus::server::object::object<
19     sdbusplus::org::open_power::OCC::server::PassThrough>;
20 
21 // For waiting on signals
22 namespace sdbusRule = sdbusplus::bus::match::rules;
23 
24 /** @class PassThrough
25  *  @brief Implements org.open_power.OCC.PassThrough
26  */
27 class PassThrough : public Iface
28 {
29   public:
30     PassThrough() = delete;
31     ~PassThrough() = default;
32     PassThrough(const PassThrough&) = delete;
33     PassThrough& operator=(const PassThrough&) = delete;
34     PassThrough(PassThrough&&) = default;
35     PassThrough& operator=(PassThrough&&) = default;
36 
37     /** @brief Ctor to put pass-through d-bus object on the bus
38      *  @param[in] bus - Bus to attach to
39      *  @param[in] path - Path to attach at
40      */
41     PassThrough(sdbusplus::bus::bus& bus, const char* path);
42 
43     /** @brief Pass through command to OCC from dbus
44      *  @param[in] command - command to pass-through
45      *  @returns OCC response as an array
46      */
47     std::vector<std::int32_t> send(std::vector<std::int32_t> command) override;
48 
49     /** @brief Pass through command to OCC from openpower-occ-control
50      *  @param[in] command - command to pass-through
51      *  @returns OCC response as an array
52      */
53     std::vector<std::uint8_t> send(std::vector<std::uint8_t> command);
54 
55   private:
56     /** @brief Pass-through occ path on the bus */
57     std::string path;
58 
59     /** @brief OCC device path
60      *  For now, here is the hard-coded mapping until
61      *  the udev rule is in.
62      *  occ0 --> /dev/occ1
63      *  occ1 --> /dev/occ2
64      *  ...
65      */
66     std::string devicePath;
67 
68     /** @brief OCC instance number */
69     int occInstance;
70 
71     /** @brief Indicates whether or not the OCC is currently active */
72     bool occActive = false;
73 
74     /** @brief Subscribe to OCC Status signal
75      *
76      *  Once the OCC status gets to active, only then we will get /dev/occ2
77      *  populated and hence need to wait on that before opening that
78      */
79     sdbusplus::bus::match_t activeStatusSignal;
80 
81     /** @brief Object to send commands to the OCC */
82     OccCommand occCmd;
83 
84     /** @brief Callback function on OCC Status change signals
85      *
86      *  @param[in]  msg - Data associated with subscribed signal
87      */
88     void activeStatusEvent(sdbusplus::message::message& msg);
89 };
90 
91 } // namespace occ
92 } // namespace open_power
93