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"
19 #include "vom/stat_reader.hpp"
34 HW::cmd_q::operator=(const HW::cmd_q& f)
40 * Run the connect/dispatch thread.
46 m_conn.ctx().dispatch();
51 HW::cmd_q::enqueue(cmd* c)
53 std::shared_ptr<cmd> sp(c);
55 m_queue.push_back(sp);
59 HW::cmd_q::enqueue(std::shared_ptr<cmd> c)
65 HW::cmd_q::enqueue(std::queue<cmd*>& cmds)
68 std::shared_ptr<cmd> sp(cmds.front());
70 m_queue.push_back(sp);
81 if (0 == m_conn.connect()) {
83 m_rx_thread.reset(new std::thread(&HW::cmd_q::rx_run, this));
89 HW::cmd_q::disconnect()
97 if (m_rx_thread && m_rx_thread->joinable()) {
122 * The queue is enabled, Execute each command in the queue.
123 * If one execution fails, abort the rest
125 auto it = m_queue.begin();
127 while (it != m_queue.end()) {
128 std::shared_ptr<cmd> c = *it;
130 VOM_LOG(log_level_t::DEBUG) << *c;
134 * before we issue the command we must move it to the pending
136 * ince a async event can be recieved before the command
139 rc = c->issue(m_conn);
141 if (rc_t::OK == rc) {
147 * barf out without issuing the rest
149 VOM_LOG(log_level_t::ERROR) << "Failed to execute: " << c->to_string();
154 * The HW is disabled, so set each command as succeeded
163 * erase all objects in the queue
165 m_queue.erase(m_queue.begin(), m_queue.end());
171 * The single Command Queue
173 HW::cmd_q* HW::m_cmdQ;
178 stat_reader* HW::m_statReader;
179 HW::item<bool> HW::m_poll_state;
182 * Initialse the connection to VPP
185 HW::init(HW::cmd_q* f)
188 m_statReader = new stat_reader();
192 * Initialse the connection to VPP
195 HW::init(HW::cmd_q* f, stat_reader* s)
202 * Initialse the connection to VPP
207 m_cmdQ = new cmd_q();
208 m_statReader = new stat_reader();
212 HW::enqueue(cmd* cmd)
214 m_cmdQ->enqueue(cmd);
218 HW::enqueue(std::shared_ptr<cmd> cmd)
220 m_cmdQ->enqueue(cmd);
224 HW::enqueue(std::queue<cmd*>& cmds)
226 m_cmdQ->enqueue(cmds);
232 return (m_cmdQ->connect() && m_statReader->connect());
238 m_statReader->disconnect();
239 m_cmdQ->disconnect();
257 return (m_cmdQ->write());
263 std::shared_ptr<cmd> poll(new hw_cmds::poll(m_poll_state));
268 return (m_poll_state);
274 m_statReader->read();
279 HW::item<bool>::to_string() const
281 std::ostringstream os;
284 << "rc:" << item_rc.to_string() << " data:" << item_data << "]";
290 HW::item<unsigned int>::to_string() const
292 std::ostringstream os;
295 << "rc:" << item_rc.to_string() << " data:" << item_data << "]";
301 * fd.io coding-style-patch-verification: ON
304 * eval: (c-set-style "mozilla")