summaryrefslogtreecommitdiffstats
path: root/occ_pass_through.hpp
blob: a28eb6afedc283495940aca5e9f20fa9189d0e2d (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
#pragma once

#include <org/open_power/OCC/PassThrough/server.hpp>
#include <sdbusplus/bus.hpp>
#include <sdbusplus/server/object.hpp>
#include <string>

namespace open_power
{
namespace occ
{

using Iface = sdbusplus::server::object::object<
    sdbusplus::org::open_power::OCC::server::PassThrough>;

// For waiting on signals
namespace sdbusRule = sdbusplus::bus::match::rules;

/** @class PassThrough
 *  @brief Implements org.open_power.OCC.PassThrough
 */
class PassThrough : public Iface
{
  public:
    PassThrough() = delete;
    PassThrough(const PassThrough&) = delete;
    PassThrough& operator=(const PassThrough&) = delete;
    PassThrough(PassThrough&&) = default;
    PassThrough& operator=(PassThrough&&) = default;

    /** @brief Ctor to put pass-through d-bus object on the bus
     *  @param[in] bus - Bus to attach to
     *  @param[in] path - Path to attach at
     */
    PassThrough(sdbusplus::bus::bus& bus, const char* path);

    ~PassThrough()
    {
        closeDevice();
    }

    /** @brief Pass through command to OCC
     *  @param[in] command - command to pass-through
     *  @returns OCC response as an array
     */
    std::vector<std::int32_t> send(std::vector<std::int32_t> command) override;

  private:
    /** @brief Pass-through occ path on the bus */
    std::string path;

    /** @brief OCC device path
     *  For now, here is the hard-coded mapping until
     *  the udev rule is in.
     *  occ0 --> /dev/occ1
     *  occ1 --> /dev/occ2
     *  ...
     */
    std::string devicePath;

    /** @brief Indicates whether or not the OCC is currently active */
    bool occActive = false;

    /** brief file descriptor associated with occ device */
    int fd = -1;

    /** @brief Subscribe to OCC Status signal
     *
     *  Once the OCC status gets to active, only then we will get /dev/occ2
     *  populated and hence need to wait on that before opening that
     */
    sdbusplus::bus::match_t activeStatusSignal;

    /** Opens devicePath and populates file descritor */
    void openDevice();

    /** Closed the fd associated with opened device */
    void closeDevice();

    /** @brief Callback function on OCC Status change signals
     *
     *  @param[in]  msg - Data associated with subscribed signal
     */
    void activeStatusEvent(sdbusplus::message::message& msg);
};

} // namespace occ
} // namespace open_power
OpenPOWER on IntegriCloud