VOM: Fix connection state
[vpp.git] / src / vpp-api / vom / hw.cpp
index 4150d5f..0952b60 100644 (file)
@@ -27,11 +27,6 @@ HW::cmd_q::cmd_q()
 
 HW::cmd_q::~cmd_q()
 {
-  m_connected = false;
-
-  if (m_rx_thread && m_rx_thread->joinable()) {
-    m_rx_thread->join();
-  }
 }
 
 HW::cmd_q&
@@ -76,26 +71,25 @@ HW::cmd_q::enqueue(std::queue<cmd*>& cmds)
   }
 }
 
-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;
 
@@ -103,10 +97,7 @@ HW::cmd_q::connect()
     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
@@ -144,33 +135,18 @@ HW::cmd_q::write()
        * ince a async event can be recieved before the command
        * completes
        */
-      m_pending[c.get()] = c;
-
       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
+         * barf out without issuing the rest
          */
-        m_pending.erase(c.get());
-
-        if (rc_t::OK == rc) {
-          /*
-           * move to the next
-           */
-        } else {
-          /*
-           * barf out without issuing the rest
-           */
-          VOM_LOG(log_level_t::ERROR) << "Failed to execute: "
-                                      << c->to_string();
-          break;
-        }
+        VOM_LOG(log_level_t::ERROR) << "Failed to execute: " << c->to_string();
+        break;
       }
     } else {
       /*
@@ -232,22 +208,16 @@ HW::enqueue(std::queue<cmd*>& cmds)
   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
@@ -277,7 +247,6 @@ HW::poll()
   HW::write();
 
   return (m_poll_state);
-  return (true);
 }
 
 template <>