blob: 070e3716200b5283b6cfb3e55ccac6305252adee [file] [log] [blame]
Deepak Kodihalli6b492fb2017-03-18 01:09:28 -05001#pragma once
2
3#include <string>
4#include <vector>
Vishwanatha Subbanna38b08d72017-04-14 18:12:14 +05305#include <unistd.h>
Deepak Kodihalli6b492fb2017-03-18 01:09:28 -05006#include <sdbusplus/bus.hpp>
7#include <sdbusplus/server/object.hpp>
Vishwanatha Subbanna9bb065b2017-04-18 14:25:26 +05308#include <org/open_power/OCC/PassThrough/server.hpp>
Deepak Kodihalli6b492fb2017-03-18 01:09:28 -05009#include "config.h"
Vishwanatha Subbanna38b08d72017-04-14 18:12:14 +053010#include "file.hpp"
Deepak Kodihalli6b492fb2017-03-18 01:09:28 -050011
12namespace open_power
13{
14namespace occ
15{
16namespace 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 */
23inline 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 */
32void run();
33
34using 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 */
40class PassThrough : public Iface
41{
42 public:
43 PassThrough() = delete;
Vishwanatha Subbanna38b08d72017-04-14 18:12:14 +053044 ~PassThrough() = default;
Deepak Kodihalli6b492fb2017-03-18 01:09:28 -050045 PassThrough(const PassThrough&) = delete;
46 PassThrough& operator=(const PassThrough&) = delete;
47 PassThrough(PassThrough&&) = default;
48 PassThrough& operator=(PassThrough&&) = default;
Deepak Kodihalli6b492fb2017-03-18 01:09:28 -050049
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;
Vishwanatha Subbannaafd21a62017-04-13 20:17:13 +053067
68 /** @brief OCC device path
69 * For now, here is the hard-coded mapping until
Vishwanatha Subbanna38b08d72017-04-14 18:12:14 +053070 * the udev rule is in.
Vishwanatha Subbannaafd21a62017-04-13 20:17:13 +053071 * occ0 --> /dev/occfifo1
72 * occ1 --> /dev/occfifo2
73 * ...
74 */
Vishwanatha Subbannad13694a2017-06-01 15:44:20 +053075 std::string devicePath = "/dev/occ";
Vishwanatha Subbanna38b08d72017-04-14 18:12:14 +053076
77 /** @brief File descriptor manager */
78 FileDescriptor fd;
79
80 /** Opens devicePath and returns file descritor */
81 int openDevice();
Deepak Kodihalli6b492fb2017-03-18 01:09:28 -050082};
83
84} // namespace pass_through
85} // namespace occ
86} // namespace open_power