blob: 06ac5fa780628d5490d21864f0ab3c1c27d25f29 [file] [log] [blame]
Vishwanatha Subbannaac149a92017-07-11 18:16:50 +05301#pragma once
2
3#include <tuple>
4#include <queue>
5#include <sdbusplus/bus.hpp>
6#include <timer.hpp>
Vishwanatha Subbanna6e8979d2017-07-13 16:48:20 +05307#include <host-ipmid/ipmid-host-cmd-utils.hpp>
Vishwanatha Subbannaac149a92017-07-11 18:16:50 +05308
9namespace phosphor
10{
11namespace host
12{
13namespace command
14{
15
16/** @class
17 * @brief Manages commands that are to be sent to Host
18 */
19class Manager
20{
21 public:
22 Manager() = delete;
23 ~Manager() = default;
24 Manager(const Manager&) = delete;
25 Manager& operator=(const Manager&) = delete;
26 Manager(Manager&&) = delete;
27 Manager& operator=(Manager&&) = delete;
28
29 /** @brief Constructs Manager object
30 *
31 * @param[in] bus - dbus handler
32 * @param[in] event - pointer to sd_event
33 */
Vishwanatha Subbanna6e8979d2017-07-13 16:48:20 +053034 Manager(sdbusplus::bus::bus& bus, sd_event* event);
Vishwanatha Subbannaac149a92017-07-11 18:16:50 +053035
36 /** @brief Extracts the next entry in the queue and returns
37 * Command and data part of it.
38 *
39 * @detail Also calls into the registered handlers so that they can now
40 * send the CommandComplete signal since the interface contract
41 * is that we emit this signal once the message has been
42 * passed to the host (which is required when calling this)
43 *
44 * Also, if the queue has more commands, then it will alert the
45 * host
46 */
47 IpmiCmdData getNextCommand();
48
49 /** @brief Pushes the command onto the queue.
50 *
51 * @detail If the queue is empty, then it alerts the Host. If not,
52 * then it returns and the API documented above will handle
53 * the commands in Queue.
54 *
55 * @param[in] command - tuple of <IPMI command, data, callback>
56 */
57 void execute(CommandHandler command);
58
59 private:
60 /** @brief Check if anything in queue and alert host if so */
61 void checkQueueAndAlertHost();
62
63 /** @brief Call back interface on message timeouts to host.
64 *
65 * @detail When this happens, a failure message would be sent
66 * to all the commands that are in the Queue and queue
67 * will be purged
68 */
69 void hostTimeout();
70
71 /** @brief Reference to the dbus handler */
72 sdbusplus::bus::bus& bus;
73
74 /** @brief Queue to store the requested commands */
75 std::queue<CommandHandler> workQueue{};
76
77 /** @brief Timer for commands to host */
78 phosphor::ipmi::Timer timer;
79};
80
81} // namespace command
82} // namespace host
83} // namespace phosphor