2 * Copyright (c) 2017 Cisco and/or its affiliates.
3 * Licensed under the Apache License, Version 2.0 (the "License");
4 * you may not use this file except in compliance with the License.
5 * You may obtain a copy of the License at:
7 * http://www.apache.org/licenses/LICENSE-2.0
9 * Unless required by applicable law or agreed to in writing, software
10 * distributed under the License is distributed on an "AS IS" BASIS,
11 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
12 * See the License for the specific language governing permissions and
13 * limitations under the License.
17 #include "vom/logger.hpp"
19 #include <vapi/vpe.api.vapi.hpp>
33 if (m_rx_thread && m_rx_thread->joinable()) {
39 HW::cmd_q::operator=(const HW::cmd_q& f)
45 * Run the connect/dispatch thread.
51 m_conn.ctx().dispatch();
56 HW::cmd_q::enqueue(cmd* c)
58 std::shared_ptr<cmd> sp(c);
60 m_queue.push_back(sp);
64 HW::cmd_q::enqueue(std::shared_ptr<cmd> c)
70 HW::cmd_q::enqueue(std::queue<cmd*>& cmds)
73 std::shared_ptr<cmd> sp(cmds.front());
75 m_queue.push_back(sp);
81 HW::cmd_q::dequeue(cmd* c)
88 HW::cmd_q::dequeue(std::shared_ptr<cmd> c)
91 m_pending.erase(c.get());
103 if (m_rx_thread && m_rx_thread->joinable()) {
110 m_rx_thread.reset(new std::thread(&HW::cmd_q::rx_run, this));
131 * The queue is enabled, Execute each command in the queue.
132 * If one execution fails, abort the rest
134 auto it = m_queue.begin();
136 while (it != m_queue.end()) {
137 std::shared_ptr<cmd> c = *it;
139 VOM_LOG(log_level_t::DEBUG) << *c;
143 * before we issue the command we must move it to the pending
145 * ince a async event can be recieved before the command
148 m_pending[c.get()] = c;
150 rc = c->issue(m_conn);
152 if (rc_t::INPROGRESS == rc) {
154 * this command completes asynchronously
155 * leave the command in the pending store
159 * the command completed, remove from the pending store
161 m_pending.erase(c.get());
163 if (rc_t::OK == rc) {
169 * barf out without issuing the rest
176 * The HW is disabled, so set each command as succeeded
185 * erase all objects in the queue
187 m_queue.erase(m_queue.begin(), m_queue.end());
193 * The single Command Queue
195 HW::cmd_q* HW::m_cmdQ;
196 HW::item<bool> HW::m_poll_state;
199 * Initialse the connection to VPP
202 HW::init(HW::cmd_q* f)
208 * Initialse the connection to VPP
213 m_cmdQ = new cmd_q();
217 HW::enqueue(cmd* cmd)
219 m_cmdQ->enqueue(cmd);
223 HW::enqueue(std::shared_ptr<cmd> cmd)
225 m_cmdQ->enqueue(cmd);
229 HW::enqueue(std::queue<cmd*>& cmds)
231 m_cmdQ->enqueue(cmds);
235 HW::dequeue(cmd* cmd)
237 m_cmdQ->dequeue(cmd);
241 HW::dequeue(std::shared_ptr<cmd> cmd)
243 m_cmdQ->dequeue(cmd);
267 return (m_cmdQ->write());
273 std::shared_ptr<cmd> poll(new Poll(m_poll_state));
278 return (m_poll_state);
283 HW::item<bool>::to_string() const
285 std::ostringstream os;
288 << "rc:" << item_rc.to_string() << " data:" << item_data << "]";
294 HW::item<unsigned int>::to_string() const
296 std::ostringstream os;
299 << "rc:" << item_rc.to_string() << " data:" << item_data << "]";
303 HW::Poll::Poll(HW::item<bool>& item)
309 HW::Poll::issue(connection& con)
311 msg_t req(con.ctx(), std::ref(*this));
313 VAPI_CALL(req.execute());
315 m_hw_item.set(wait());
321 HW::Poll::to_string() const
323 std::ostringstream s;
325 s << "poll: " << m_hw_item.to_string();
332 * fd.io coding-style-patch-verification: ON
335 * eval: (c-set-style "mozilla")