*/
#include "vom/hw.hpp"
+#include "vom/hw_cmds.hpp"
#include "vom/logger.hpp"
-#include <vapi/vpe.api.vapi.hpp>
-
namespace VOM {
HW::cmd_q::cmd_q()
: m_enabled(true)
HW::cmd_q::~cmd_q()
{
- m_connected = false;
-
- if (m_rx_thread && m_rx_thread->joinable()) {
- m_rx_thread->join();
- }
}
HW::cmd_q&
}
}
-void
-HW::cmd_q::dequeue(cmd* c)
+bool
+HW::cmd_q::connect()
{
- c->retire(m_conn);
- m_pending.erase(c);
-}
+ if (m_connected)
+ return m_connected;
-void
-HW::cmd_q::dequeue(std::shared_ptr<cmd> c)
-{
- c->retire(m_conn);
- m_pending.erase(c.get());
+ if (0 == m_conn.connect()) {
+ m_connected = true;
+ m_rx_thread.reset(new std::thread(&HW::cmd_q::rx_run, this));
+ }
+ return (m_connected);
}
void
-HW::cmd_q::connect()
+HW::cmd_q::disconnect()
{
- if (m_connected) {
- m_conn.disconnect();
- }
+
+ if (!m_connected)
+ return;
m_connected = false;
m_rx_thread->join();
}
- m_conn.connect();
-
- m_connected = true;
- m_rx_thread.reset(new std::thread(&HW::cmd_q::rx_run, this));
+ m_conn.disconnect();
}
void
rc_t rc = rc_t::OK;
/*
- * The queue is enabled, Execute each command in the queue.
- * If one execution fails, abort the rest
- */
+ * The queue is enabled, Execute each command in the queue.
+ * If one execution fails, abort the rest
+ */
auto it = m_queue.begin();
while (it != m_queue.end()) {
if (m_enabled) {
/*
- * before we issue the command we must move it to the pending
- * store
- * ince a async event can be recieved before the command
- * completes
- */
- m_pending[c.get()] = c;
-
+ * before we issue the command we must move it to the pending
+ * store
+ * ince a async event can be recieved before the command
+ * completes
+ */
rc = c->issue(m_conn);
- if (rc_t::INPROGRESS == rc) {
+ if (rc_t::OK == rc) {
/*
- * this command completes asynchronously
- * leave the command in the pending store
- */
+ * move to the next
+ */
} else {
/*
- * the command completed, remove from the pending store
- */
- m_pending.erase(c.get());
-
- if (rc_t::OK == rc) {
- /*
- * move to the next
- */
- } else {
- /*
- * barf out without issuing the rest
- */
- break;
- }
+ * barf out without issuing the rest
+ */
+ VOM_LOG(log_level_t::ERROR) << "Failed to execute: " << c->to_string();
+ break;
}
} else {
/*
- * The HW is disabled, so set each command as succeeded
- */
+ * The HW is disabled, so set each command as succeeded
+ */
c->succeeded();
}
}
/*
- * erase all objects in the queue
- */
+ * erase all objects in the queue
+ */
m_queue.erase(m_queue.begin(), m_queue.end());
return (rc);
m_cmdQ->enqueue(cmds);
}
-void
-HW::dequeue(cmd* cmd)
-{
- m_cmdQ->dequeue(cmd);
-}
-
-void
-HW::dequeue(std::shared_ptr<cmd> cmd)
+bool
+HW::connect()
{
- m_cmdQ->dequeue(cmd);
+ return m_cmdQ->connect();
}
void
-HW::connect()
+HW::disconnect()
{
- m_cmdQ->connect();
+ m_cmdQ->disconnect();
}
void
bool
HW::poll()
{
- std::shared_ptr<cmd> poll(new Poll(m_poll_state));
+ std::shared_ptr<cmd> poll(new hw_cmds::poll(m_poll_state));
HW::enqueue(poll);
HW::write();
<< "rc:" << item_rc.to_string() << " data:" << item_data << "]";
return (os.str());
}
-
-HW::Poll::Poll(HW::item<bool>& item)
- : rpc_cmd(item)
-{
-}
-
-rc_t
-HW::Poll::issue(connection& con)
-{
- msg_t req(con.ctx(), std::ref(*this));
-
- VAPI_CALL(req.execute());
-
- m_hw_item.set(wait());
-
- return (rc_t::OK);
-}
-
-std::string
-HW::Poll::to_string() const
-{
- std::ostringstream s;
-
- s << "poll: " << m_hw_item.to_string();
-
- return (s.str());
-}
}
/*