blob: 8937e43416865bfee79b845f4f928fca8e2bec75 [file] [log] [blame]
Vishwanatha Subbannaac149a92017-07-11 18:16:50 +05301#pragma once
2
William A. Kennington III194375f2018-12-14 02:14:33 -08003#include <ipmid-host/cmd-utils.hpp>
Vishwanatha Subbannaac149a92017-07-11 18:16:50 +05304#include <sdbusplus/bus.hpp>
Matt Spinler15309ef2018-06-27 13:01:25 -05005#include <sdbusplus/bus/match.hpp>
Vernon Mauery1181af72018-10-08 12:05:00 -07006#include <sdbusplus/timer.hpp>
Patrick Williamsfbc6c9d2023-05-10 07:50:16 -05007
8#include <queue>
Patrick Venture0b02be92018-08-31 11:55:55 -07009#include <tuple>
Vishwanatha Subbannaac149a92017-07-11 18:16:50 +053010
11namespace phosphor
12{
13namespace host
14{
15namespace command
16{
17
18/** @class
19 * @brief Manages commands that are to be sent to Host
20 */
21class Manager
22{
Patrick Venture0b02be92018-08-31 11:55:55 -070023 public:
24 Manager() = delete;
25 ~Manager() = default;
26 Manager(const Manager&) = delete;
27 Manager& operator=(const Manager&) = delete;
28 Manager(Manager&&) = delete;
29 Manager& operator=(Manager&&) = delete;
Vishwanatha Subbannaac149a92017-07-11 18:16:50 +053030
Patrick Venture0b02be92018-08-31 11:55:55 -070031 /** @brief Constructs Manager object
32 *
33 * @param[in] bus - dbus handler
34 * @param[in] event - pointer to sd_event
35 */
Patrick Williams5d82f472022-07-22 19:26:53 -050036 explicit Manager(sdbusplus::bus_t& bus);
Vishwanatha Subbannaac149a92017-07-11 18:16:50 +053037
Patrick Venture0b02be92018-08-31 11:55:55 -070038 /** @brief Extracts the next entry in the queue and returns
39 * Command and data part of it.
40 *
41 * @detail Also calls into the registered handlers so that they can now
42 * send the CommandComplete signal since the interface contract
43 * is that we emit this signal once the message has been
44 * passed to the host (which is required when calling this)
45 *
46 * Also, if the queue has more commands, then it will alert the
47 * host
48 */
49 IpmiCmdData getNextCommand();
Vishwanatha Subbannaac149a92017-07-11 18:16:50 +053050
Patrick Venture0b02be92018-08-31 11:55:55 -070051 /** @brief Pushes the command onto the queue.
52 *
53 * @detail If the queue is empty, then it alerts the Host. If not,
54 * then it returns and the API documented above will handle
55 * the commands in Queue.
56 *
57 * @param[in] command - tuple of <IPMI command, data, callback>
58 */
59 void execute(CommandHandler command);
Vishwanatha Subbannaac149a92017-07-11 18:16:50 +053060
Patrick Venture0b02be92018-08-31 11:55:55 -070061 private:
62 /** @brief Check if anything in queue and alert host if so */
63 void checkQueueAndAlertHost();
Vishwanatha Subbannaac149a92017-07-11 18:16:50 +053064
Patrick Venture0b02be92018-08-31 11:55:55 -070065 /** @brief Call back interface on message timeouts to host.
66 *
67 * @detail When this happens, a failure message would be sent
68 * to all the commands that are in the Queue and queue
69 * will be purged
70 */
71 void hostTimeout();
Vishwanatha Subbannaac149a92017-07-11 18:16:50 +053072
Patrick Venture0b02be92018-08-31 11:55:55 -070073 /** @brief Clears the command queue
74 *
75 * @detail Clears the command queue and calls all callbacks
76 * specifying the command wasn't successful.
77 */
78 void clearQueue();
Matt Spinler15309ef2018-06-27 13:01:25 -050079
Patrick Venture0b02be92018-08-31 11:55:55 -070080 /** @brief Clears the command queue on a power on
81 *
82 * @detail The properties changed handler for the
83 * RequestedHostTransition property. When this property
84 * changes to 'On', this function will purge the command
85 * queue.
86 *
87 * This is done to avoid having commands that were issued
88 * before the host powers on from getting sent to the host,
89 * either due to race conditions around state transitions
90 * or from a user doing something like requesting an already
91 * powered off system to power off again and then immediately
92 * requesting a power on.
93 *
94 * @param[in] msg - the sdbusplus message containing the property
95 */
Patrick Williams5d82f472022-07-22 19:26:53 -050096 void clearQueueOnPowerOn(sdbusplus::message_t& msg);
Matt Spinler15309ef2018-06-27 13:01:25 -050097
Patrick Venture0b02be92018-08-31 11:55:55 -070098 /** @brief Reference to the dbus handler */
Patrick Williams5d82f472022-07-22 19:26:53 -050099 sdbusplus::bus_t& bus;
Vishwanatha Subbannaac149a92017-07-11 18:16:50 +0530100
Patrick Venture0b02be92018-08-31 11:55:55 -0700101 /** @brief Queue to store the requested commands */
102 std::queue<CommandHandler> workQueue{};
Vishwanatha Subbannaac149a92017-07-11 18:16:50 +0530103
Patrick Venture0b02be92018-08-31 11:55:55 -0700104 /** @brief Timer for commands to host */
Patrick Williams95655222023-12-05 12:45:02 -0600105 sdbusplus::Timer timer;
Matt Spinler15309ef2018-06-27 13:01:25 -0500106
Patrick Venture0b02be92018-08-31 11:55:55 -0700107 /** @brief Match handler for the requested host state */
108 sdbusplus::bus::match_t hostTransitionMatch;
Vishwanatha Subbannaac149a92017-07-11 18:16:50 +0530109};
110
111} // namespace command
112} // namespace host
113} // namespace phosphor