1 #pragma once
2 
3 #include <org/open_power/OCC/PassThrough/server.hpp>
4 #include <sdbusplus/bus.hpp>
5 #include <sdbusplus/server/object.hpp>
6 #include <string>
7 
8 namespace open_power
9 {
10 namespace occ
11 {
12 
13 using Iface = sdbusplus::server::object::object<
14     sdbusplus::org::open_power::OCC::server::PassThrough>;
15 
16 // For waiting on signals
17 namespace sdbusRule = sdbusplus::bus::match::rules;
18 
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;
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, const char* path);
36 
37     ~PassThrough()
38     {
39         closeDevice();
40     }
41 
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;
47 
48   private:
49     /** @brief Pass-through occ path on the bus */
50     std::string path;
51 
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;
60 
61     /** @brief Indicates whether or not the OCC is currently active */
62     bool occActive = false;
63 
64     /** brief file descriptor associated with occ device */
65     int fd = -1;
66 
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;
73 
74     /** Opens devicePath and populates file descritor */
75     void openDevice();
76 
77     /** Closed the fd associated with opened device */
78     void closeDevice();
79 
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);
85 };
86 
87 } // namespace occ
88 } // namespace open_power
89