1 #pragma once
2 
3 #include <string>
4 #include <vector>
5 #include <unistd.h>
6 #include <sdbusplus/bus.hpp>
7 #include <sdbusplus/server/object.hpp>
8 #include <org/open_power/OCC/PassThrough/server.hpp>
9 #include "config.h"
10 #include "file.hpp"
11 
12 namespace open_power
13 {
14 namespace occ
15 {
16 namespace pass_through
17 {
18 
19 /** @brief Make occ pass-through d-bus object pathname
20  *  @param[in] occ - occ name
21  *  @returns occ pass-through path
22  */
23 inline auto object(const std::string& occ)
24 {
25     return std::string(OCC_PASS_THROUGH_ROOT) +
26            '/' +
27            occ;
28 }
29 
30 /** @brief Put occ pass through objects on the bus
31  */
32 void run();
33 
34 using Iface = sdbusplus::server::object::object<
35     sdbusplus::org::open_power::OCC::server::PassThrough>;
36 
37 /** @class PassThrough
38  *  @brief Implements org.open_power.OCC.PassThrough
39  */
40 class PassThrough : public Iface
41 {
42     public:
43         PassThrough() = delete;
44         ~PassThrough() = default;
45         PassThrough(const PassThrough&) = delete;
46         PassThrough& operator=(const PassThrough&) = delete;
47         PassThrough(PassThrough&&) = default;
48         PassThrough& operator=(PassThrough&&) = default;
49 
50         /** @brief Ctor to put pass-through d-bus object on the bus
51          *  @param[in] bus - Bus to attach to
52          *  @param[in] path - Path to attach at
53          */
54         PassThrough(sdbusplus::bus::bus& bus,
55                     const char* path);
56 
57         /** @brief Pass through command to OCC
58          *  @param[in] command - command to pass-through
59          *  @returns OCC response as an array
60          */
61         std::vector<std::int32_t>
62             send(std::vector<std::int32_t> command) override;
63 
64     private:
65         /** @brief Pass-through occ path on the bus */
66         std::string path;
67 
68         /** @brief OCC device path
69          *  For now, here is the hard-coded mapping until
70          *  the udev rule is in.
71          *  occ0 --> /dev/occfifo1
72          *  occ1 --> /dev/occfifo2
73          *  ...
74          */
75         std::string devicePath = "/dev/occfifo";
76 
77         /** @brief File descriptor manager */
78         FileDescriptor fd;
79 
80         /** Opens devicePath and returns file descritor */
81         int openDevice();
82 };
83 
84 } // namespace pass_through
85 } // namespace occ
86 } // namespace open_power
87