1 #pragma once 2 3 #include <tuple> 4 #include <queue> 5 #include <sdbusplus/bus.hpp> 6 #include <timer.hpp> 7 #include <host-ipmid/ipmid-host-cmd-utils.hpp> 8 9 namespace phosphor 10 { 11 namespace host 12 { 13 namespace command 14 { 15 16 /** @class 17 * @brief Manages commands that are to be sent to Host 18 */ 19 class 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 */ 34 Manager(sdbusplus::bus::bus& bus, sd_event* event); 35 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 84