BlinkenArea - GitList
Repositories
Blog
Wiki
libetherpix
Code
Commits
Branches
Tags
Search
Tree:
5c70d9d
Branches
Tags
master
libetherpix
simulator
main_window.cpp
implement receiving packets
Stefan Schuermans
commited
5c70d9d
at 2017-06-11 15:48:14
main_window.cpp
Blame
History
Raw
/* * EtherPix simulator * * Copyright 2017 Stefan Schuermans <stefan schuermans info> * * This program is free software: you can redistribute it and/or modify * it under the terms of the GNU General Public License as published by * the Free Software Foundation, version 3 of the License. * * * This program is distributed in the hope that it will be useful, * but WITHOUT ANY WARRANTY; without even the implied warranty of * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the * GNU General Public License for more details. * * You should have received a copy of the GNU Lesser General Public License * along with this program. If not, see <http://www.gnu.org/licenses/>. */ #include <gtkmm.h> #include "config.h" #include "draw.h" #include "main_window.h" #define TIMER_MS (40) /** * @brief constructor * @param[in] Gtk Window object (a C object) * @param[in] builder reference to GTK builder object */ MainWindow::MainWindow(BaseObjectType *cobject, const Glib::RefPtr<Gtk::Builder> &builder): Gtk::Window(cobject), m_builder(builder), m_config(NULL), m_packets(0), m_time_ms(0) { // get widgets builder->get_widget_derived("Draw", m_draw); builder->get_widget("Status", m_status); // connect callbacks signal_hide().connect(sigc::mem_fun(*this, &MainWindow::on_hide)); // start timer sigc::slot<bool> timer_slot = sigc::bind( sigc::mem_fun(*this, &MainWindow::on_timer), 0); m_timer = Glib::signal_timeout().connect(timer_slot, TIMER_MS); } /// virtual destructor MainWindow::~MainWindow() { // stop timer m_timer.disconnect(); } /// set configuration object void MainWindow::setConfig(Config &config) { m_config = &config; m_draw->setConfig(config); } /// window is being hidden void MainWindow::on_hide() { // leave main loop Gtk::Main::quit(); } /// set status bar text void MainWindow::set_status(std::string const &txt) { m_status->pop(); m_status->push(txt); } /// timer callback bool MainWindow::on_timer(int timerno) { // get packet counter unsigned long pack = 0; if (m_config) { pack = m_config->getPacketCounterAndReset(); } // request redraw if a packet has been received if (pack > 0) { m_draw->reqUpdate(); } // count packets per second and update status m_packets += pack; m_time_ms += TIMER_MS; if (m_time_ms >= 1000) { std::stringstream msg; msg << "receiving " << m_packets << " packets per second"; set_status(msg.str()); m_packets = 0; m_time_ms = 0; } // keep callback registered return true; (void)timerno; }