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);
82 rv = m_conn.connect();
85 m_rx_thread.reset(new std::thread(&HW::cmd_q::rx_run, this));
90 HW::cmd_q::disconnect()
98 if (m_rx_thread && m_rx_thread->joinable()) {
123 * The queue is enabled, Execute each command in the queue.
124 * If one execution fails, abort the rest
126 auto it = m_queue.begin();
128 while (it != m_queue.end()) {
129 std::shared_ptr<cmd> c = *it;
131 VOM_LOG(log_level_t::DEBUG) << *c;
135 * before we issue the command we must move it to the pending
137 * ince a async event can be recieved before the command
140 rc = c->issue(m_conn);
142 if (rc_t::OK == rc) {
148 * barf out without issuing the rest
150 VOM_LOG(log_level_t::ERROR) << "Failed to execute: " << c->to_string();
155 * The HW is disabled, so set each command as succeeded
164 * erase all objects in the queue
166 m_queue.erase(m_queue.begin(), m_queue.end());
172 * The single Command Queue
174 HW::cmd_q* HW::m_cmdQ;
175 HW::item<bool> HW::m_poll_state;
178 * Initialse the connection to VPP
181 HW::init(HW::cmd_q* f)
187 * Initialse the connection to VPP
192 m_cmdQ = new cmd_q();
196 HW::enqueue(cmd* cmd)
198 m_cmdQ->enqueue(cmd);
202 HW::enqueue(std::shared_ptr<cmd> cmd)
204 m_cmdQ->enqueue(cmd);
208 HW::enqueue(std::queue<cmd*>& cmds)
210 m_cmdQ->enqueue(cmds);
216 return m_cmdQ->connect();
222 m_cmdQ->disconnect();
240 return (m_cmdQ->write());
246 std::shared_ptr<cmd> poll(new hw_cmds::poll(m_poll_state));
251 return (m_poll_state);
256 HW::item<bool>::to_string() const
258 std::ostringstream os;
261 << "rc:" << item_rc.to_string() << " data:" << item_data << "]";
267 HW::item<unsigned int>::to_string() const
269 std::ostringstream os;
272 << "rc:" << item_rc.to_string() << " data:" << item_data << "]";
278 * fd.io coding-style-patch-verification: ON
281 * eval: (c-set-style "mozilla")