void UserGUI::run()

in analyzers/src/watch/user_gui.cpp [43:149]


void UserGUI::run()
{
    try
    {
        // prepare for select
        fd_set rfds;

        MainWindow       mainWindow;
        HeaderWindow     headerWindow(mainWindow);
        StatisticsWindow statisticsWindow(mainWindow, _statisticsContainers);

        /* Watch stdin (fd 0) to see when it has input. */
        FD_ZERO(&rfds);
        FD_SET(STDIN_FILENO, &rfds);

        /* Set wait time. */
        struct timeval tv = getTimeval();

        uint16_t key = 0;

        std::vector<std::size_t> tmp;

        statisticsWindow.updateProtocol(_activeProtocol);

        while(_running.test_and_set())
        {
            if(_shouldResize)
            {
                mainWindow.resize();
                headerWindow.resize(mainWindow);
                statisticsWindow.resize(mainWindow);
                statisticsWindow.updateProtocol(_activeProtocol);

                _shouldResize = false;
            }
            if(_running.test_and_set())
            {
                std::unique_lock<std::mutex> lck(_statisticsDeltaMutex);
                tmp = _statisticsContainers.at(_activeProtocol);
            }
            headerWindow.update();
            statisticsWindow.update(tmp);
            mainWindow.update();

            if(select(STDIN_FILENO + 1, &rfds, nullptr, nullptr, &tv) == -1)
            {
                break;
            }
            else
            {
                key = mainWindow.inputKeys();
                if(key == KEY_LEFT || key == KEY_RIGHT)
                {
                    auto it = find_if(_allProtocols.begin(), _allProtocols.end(), [&](std::string s) {
                        return !(s.compare(_activeProtocol->getProtocolName()));
                    });
                    if(it != _allProtocols.end())
                    {
                        if(key == KEY_LEFT)
                        {
                            if(it + 1 == _allProtocols.end())
                                it = _allProtocols.begin();
                            else
                                ++it;
                        }
                        else if(key == KEY_RIGHT)
                        {
                            if(it == _allProtocols.begin())
                                it = _allProtocols.end() - 1;
                            else
                                --it;
                        }
                        auto a = find_if(_statisticsContainers.begin(), _statisticsContainers.end(), [&](std::pair<AbstractProtocol*, std::vector<std::size_t>> p) {
                            return !(p.first->getProtocolName().compare(*it));
                        });
                        if(a != _statisticsContainers.end())
                        {
                            _activeProtocol = a->first;
                            statisticsWindow.setProtocol(_activeProtocol);
                            statisticsWindow.resize(mainWindow);
                            {
                                std::unique_lock<std::mutex> lck(_statisticsDeltaMutex);
                                tmp = a->second;
                            }
                            statisticsWindow.update(tmp);
                        }
                    }
                }
                else if(key == KEY_UP)
                {
                    statisticsWindow.scrollContent(SCROLL_UP);
                    statisticsWindow.update(tmp);
                }
                else if(key == KEY_DOWN)
                {
                    statisticsWindow.scrollContent(SCROLL_DOWN);
                    statisticsWindow.update(tmp);
                }
            }
            tv = getTimeval();
        }
    }
    catch(std::runtime_error& e)
    {
        std::cerr << "Watch plugin error: " << e.what();
    }
}