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/hw_cmds.hpp"
18 #include "vom/logger.hpp"
32 if (m_rx_thread && m_rx_thread->joinable()) {
38 HW::cmd_q::operator=(const HW::cmd_q& f)
44 * Run the connect/dispatch thread.
50 m_conn.ctx().dispatch();
55 HW::cmd_q::enqueue(cmd* c)
57 std::shared_ptr<cmd> sp(c);
59 m_queue.push_back(sp);
63 HW::cmd_q::enqueue(std::shared_ptr<cmd> c)
69 HW::cmd_q::enqueue(std::queue<cmd*>& cmds)
72 std::shared_ptr<cmd> sp(cmds.front());
74 m_queue.push_back(sp);
80 HW::cmd_q::dequeue(cmd* c)
87 HW::cmd_q::dequeue(std::shared_ptr<cmd> c)
90 m_pending.erase(c.get());
102 if (m_rx_thread && m_rx_thread->joinable()) {
109 m_rx_thread.reset(new std::thread(&HW::cmd_q::rx_run, this));
130 * The queue is enabled, Execute each command in the queue.
131 * If one execution fails, abort the rest
133 auto it = m_queue.begin();
135 while (it != m_queue.end()) {
136 std::shared_ptr<cmd> c = *it;
138 VOM_LOG(log_level_t::DEBUG) << *c;
142 * before we issue the command we must move it to the pending
144 * ince a async event can be recieved before the command
147 m_pending[c.get()] = c;
149 rc = c->issue(m_conn);
151 if (rc_t::INPROGRESS == rc) {
153 * this command completes asynchronously
154 * leave the command in the pending store
158 * the command completed, remove from the pending store
160 m_pending.erase(c.get());
162 if (rc_t::OK == rc) {
168 * barf out without issuing the rest
170 VOM_LOG(log_level_t::ERROR) << "Failed to execute: "
177 * The HW is disabled, so set each command as succeeded
186 * erase all objects in the queue
188 m_queue.erase(m_queue.begin(), m_queue.end());
194 * The single Command Queue
196 HW::cmd_q* HW::m_cmdQ;
197 HW::item<bool> HW::m_poll_state;
200 * Initialse the connection to VPP
203 HW::init(HW::cmd_q* f)
209 * Initialse the connection to VPP
214 m_cmdQ = new cmd_q();
218 HW::enqueue(cmd* cmd)
220 m_cmdQ->enqueue(cmd);
224 HW::enqueue(std::shared_ptr<cmd> cmd)
226 m_cmdQ->enqueue(cmd);
230 HW::enqueue(std::queue<cmd*>& cmds)
232 m_cmdQ->enqueue(cmds);
236 HW::dequeue(cmd* cmd)
238 m_cmdQ->dequeue(cmd);
242 HW::dequeue(std::shared_ptr<cmd> cmd)
244 m_cmdQ->dequeue(cmd);
268 return (m_cmdQ->write());
274 std::shared_ptr<cmd> poll(new hw_cmds::poll(m_poll_state));
279 return (m_poll_state);
285 HW::item<bool>::to_string() const
287 std::ostringstream os;
290 << "rc:" << item_rc.to_string() << " data:" << item_data << "]";
296 HW::item<unsigned int>::to_string() const
298 std::ostringstream os;
301 << "rc:" << item_rc.to_string() << " data:" << item_data << "]";
307 * fd.io coding-style-patch-verification: ON
310 * eval: (c-set-style "mozilla")