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);
88 if (m_rx_thread && m_rx_thread->joinable()) {
95 m_rx_thread.reset(new std::thread(&HW::cmd_q::rx_run, this));
116 * The queue is enabled, Execute each command in the queue.
117 * If one execution fails, abort the rest
119 auto it = m_queue.begin();
121 while (it != m_queue.end()) {
122 std::shared_ptr<cmd> c = *it;
124 VOM_LOG(log_level_t::DEBUG) << *c;
128 * before we issue the command we must move it to the pending
130 * ince a async event can be recieved before the command
133 rc = c->issue(m_conn);
135 if (rc_t::OK == rc) {
141 * barf out without issuing the rest
143 VOM_LOG(log_level_t::ERROR) << "Failed to execute: " << c->to_string();
148 * The HW is disabled, so set each command as succeeded
157 * erase all objects in the queue
159 m_queue.erase(m_queue.begin(), m_queue.end());
165 * The single Command Queue
167 HW::cmd_q* HW::m_cmdQ;
168 HW::item<bool> HW::m_poll_state;
171 * Initialse the connection to VPP
174 HW::init(HW::cmd_q* f)
180 * Initialse the connection to VPP
185 m_cmdQ = new cmd_q();
189 HW::enqueue(cmd* cmd)
191 m_cmdQ->enqueue(cmd);
195 HW::enqueue(std::shared_ptr<cmd> cmd)
197 m_cmdQ->enqueue(cmd);
201 HW::enqueue(std::queue<cmd*>& cmds)
203 m_cmdQ->enqueue(cmds);
227 return (m_cmdQ->write());
233 std::shared_ptr<cmd> poll(new hw_cmds::poll(m_poll_state));
238 return (m_poll_state);
244 HW::item<bool>::to_string() const
246 std::ostringstream os;
249 << "rc:" << item_rc.to_string() << " data:" << item_data << "]";
255 HW::item<unsigned int>::to_string() const
257 std::ostringstream os;
260 << "rc:" << item_rc.to_string() << " data:" << item_data << "]";
266 * fd.io coding-style-patch-verification: ON
269 * eval: (c-set-style "mozilla")