blob: e07ca619c78c10a89cfd7bad73ebb56421dc5aed [file] [log] [blame]
Vishwanatha Subbanna307d80b2017-06-28 15:56:09 +05301#pragma once
2
3#include <sdbusplus/bus.hpp>
4#include <sdbusplus/server/object.hpp>
5#include <org/open_power/OCC/Status/server.hpp>
Vishwanatha Subbanna30e329a2017-07-24 23:13:14 +05306#include <org/open_power/Control/Host/server.hpp>
Vishwanatha Subbannaee4d83d2017-06-29 18:35:00 +05307#include "occ_events.hpp"
Vishwanatha Subbanna32e84e92017-06-28 19:17:28 +05308#include "occ_device.hpp"
Vishwanatha Subbanna307d80b2017-06-28 15:56:09 +05309namespace open_power
10{
11namespace occ
12{
13
14namespace Base = sdbusplus::org::open_power::OCC::server;
15using Interface = sdbusplus::server::object::object<Base::Status>;
16
Vishwanatha Subbanna30e329a2017-07-24 23:13:14 +053017// IPMID's host control application
18namespace Control = sdbusplus::org::open_power::Control::server;
19
20// For waiting on signals
21namespace sdbusRule = sdbusplus::bus::match::rules;
22
Vishwanatha Subbanna6add0b82017-07-21 19:02:37 +053023// OCC status instance. Ex. for "occ0", the instance is 0
24using instanceID = int;
25
26// IPMI sensor ID for a given OCC instance
27using sensorID = uint8_t;
28
Vishwanatha Subbanna307d80b2017-06-28 15:56:09 +053029/** @class Status
30 * @brief Implementation of OCC Active Status
31 */
32class Status : public Interface
33{
34 public:
35 Status() = delete;
36 ~Status() = default;
37 Status(const Status&) = delete;
38 Status& operator=(const Status&) = delete;
39 Status(Status&&) = default;
40 Status& operator=(Status&&) = default;
41
Vishwanatha Subbannaee4d83d2017-06-29 18:35:00 +053042 /** @brief Constructs the Status object and
43 * the underlying device object
Vishwanatha Subbanna307d80b2017-06-28 15:56:09 +053044 *
45 * @param[in] bus - DBus bus to attach to
46 * @param[in] path - DBus object path
47 */
Vishwanatha Subbannaee4d83d2017-06-29 18:35:00 +053048 Status(sdbusplus::bus::bus& bus, EventPtr& event, const char* path)
Vishwanatha Subbanna32e84e92017-06-28 19:17:28 +053049 : Interface(bus, path),
Vishwanatha Subbanna30e329a2017-07-24 23:13:14 +053050 bus(bus),
Vishwanatha Subbanna32e84e92017-06-28 19:17:28 +053051 path(path),
Vishwanatha Subbanna6add0b82017-07-21 19:02:37 +053052 instance(((this->path.back() - '0'))),
Vishwanatha Subbannaee4d83d2017-06-29 18:35:00 +053053 device(event,
Vishwanatha Subbanna6add0b82017-07-21 19:02:37 +053054 name + std::to_string(instance + 1),
Vishwanatha Subbanna30e329a2017-07-24 23:13:14 +053055 std::bind(&Status::deviceErrorHandler, this)),
56 hostControlSignal(
57 bus,
58 sdbusRule::type::signal() +
59 sdbusRule::member("CommandComplete") +
60 sdbusRule::path("/org/open_power/control/host0") +
61 sdbusRule::interface("org.open_power.Control.Host") +
62 sdbusRule::argN(0, Control::convertForMessage(
63 Control::Host::Command::OCCReset)),
64 std::bind(std::mem_fn(&Status::hostControlEvent),
65 this, std::placeholders::_1))
Vishwanatha Subbanna307d80b2017-06-28 15:56:09 +053066 {
67 // Nothing to do here
68 }
69
Vishwanatha Subbanna32e84e92017-06-28 19:17:28 +053070 /** @brief Since we are overriding the setter-occActive but not the
71 * getter-occActive, we need to have this using in order to
72 * allow passthrough usage of the getter-occActive
73 */
74 using Base::Status::occActive;
75
Vishwanatha Subbanna307d80b2017-06-28 15:56:09 +053076 /** @brief SET OccActive to True or False
77 *
78 * @param[in] value - Intended value
79 *
80 * @return - Updated value of the property
81 */
82 bool occActive(bool value) override;
Vishwanatha Subbanna32e84e92017-06-28 19:17:28 +053083
84 private:
Vishwanatha Subbanna30e329a2017-07-24 23:13:14 +053085
86 /** @brief sdbus handle */
87 sdbusplus::bus::bus& bus;
88
Vishwanatha Subbanna32e84e92017-06-28 19:17:28 +053089 /** @brief OCC dbus object path */
90 std::string path;
91
92 /** @brief occ name prefix */
93 std::string name = OCC_NAME;
94
Vishwanatha Subbanna6add0b82017-07-21 19:02:37 +053095 /** @brief OCC instance number. Ex, 0,1, etc */
96 int instance;
97
98 /** @brief OCC instance to Sensor ID mapping */
99 static const std::map<instanceID, sensorID> sensorMap;
100
Vishwanatha Subbanna32e84e92017-06-28 19:17:28 +0530101 /** @brief OCC device object to do bind and unbind */
102 Device device;
Vishwanatha Subbannaee4d83d2017-06-29 18:35:00 +0530103
Vishwanatha Subbanna30e329a2017-07-24 23:13:14 +0530104 /** @brief Subscribe to host control signal
105 *
106 * Once the OCC reset is requested, BMC sends that message to host.
107 * If the host does not ack the message, then there would be a timeout
108 * and we need to catch that to log an error
109 **/
110 sdbusplus::bus::match_t hostControlSignal;
111
Vishwanatha Subbannaee4d83d2017-06-29 18:35:00 +0530112 /** @brief Callback handler when device errors are detected */
113 void deviceErrorHandler();
Vishwanatha Subbanna30e329a2017-07-24 23:13:14 +0530114
115 /** @brief Callback function on host control signals
116 *
117 * @param[in] msg - Data associated with subscribed signal
118 */
119 void hostControlEvent(sdbusplus::message::message& msg);
120
121 /** @brief Sends a message to host control command handler to reset OCC
122 */
123 void resetOCC();
Vishwanatha Subbanna307d80b2017-06-28 15:56:09 +0530124};
125
126} // namespace occ
127} // namespace open_power