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"
33 HW::cmd_q::operator=(const HW::cmd_q& f)
39 * Run the connect/dispatch thread.
45 m_conn.ctx().dispatch();
50 HW::cmd_q::enqueue(cmd* c)
52 std::shared_ptr<cmd> sp(c);
54 m_queue.push_back(sp);
58 HW::cmd_q::enqueue(std::shared_ptr<cmd> c)
64 HW::cmd_q::enqueue(std::queue<cmd*>& cmds)
67 std::shared_ptr<cmd> sp(cmds.front());
69 m_queue.push_back(sp);
80 if (0 == m_conn.connect()) {
82 m_rx_thread.reset(new std::thread(&HW::cmd_q::rx_run, this));
88 HW::cmd_q::disconnect()
96 if (m_rx_thread && m_rx_thread->joinable()) {
121 * The queue is enabled, Execute each command in the queue.
122 * If one execution fails, abort the rest
124 auto it = m_queue.begin();
126 while (it != m_queue.end()) {
127 std::shared_ptr<cmd> c = *it;
129 VOM_LOG(log_level_t::DEBUG) << *c;
133 * before we issue the command we must move it to the pending
135 * ince a async event can be recieved before the command
138 rc = c->issue(m_conn);
140 if (rc_t::OK == rc) {
146 * barf out without issuing the rest
148 VOM_LOG(log_level_t::ERROR) << "Failed to execute: " << c->to_string();
153 * The HW is disabled, so set each command as succeeded
162 * erase all objects in the queue
164 m_queue.erase(m_queue.begin(), m_queue.end());
170 * The single Command Queue
172 HW::cmd_q* HW::m_cmdQ;
173 HW::item<bool> HW::m_poll_state;
176 * Initialse the connection to VPP
179 HW::init(HW::cmd_q* f)
185 * Initialse the connection to VPP
190 m_cmdQ = new cmd_q();
194 HW::enqueue(cmd* cmd)
196 m_cmdQ->enqueue(cmd);
200 HW::enqueue(std::shared_ptr<cmd> cmd)
202 m_cmdQ->enqueue(cmd);
206 HW::enqueue(std::queue<cmd*>& cmds)
208 m_cmdQ->enqueue(cmds);
214 return m_cmdQ->connect();
220 m_cmdQ->disconnect();
238 return (m_cmdQ->write());
244 std::shared_ptr<cmd> poll(new hw_cmds::poll(m_poll_state));
249 return (m_poll_state);
254 HW::item<bool>::to_string() const
256 std::ostringstream os;
259 << "rc:" << item_rc.to_string() << " data:" << item_data << "]";
265 HW::item<unsigned int>::to_string() const
267 std::ostringstream os;
270 << "rc:" << item_rc.to_string() << " data:" << item_data << "]";
276 * fd.io coding-style-patch-verification: ON
279 * eval: (c-set-style "mozilla")