aboutsummaryrefslogtreecommitdiffstats
path: root/ui/logray
diff options
context:
space:
mode:
authorTomasz Moń <desowin@gmail.com>2022-07-29 20:16:16 +0200
committerTomasz Moń <desowin@gmail.com>2022-07-30 16:42:12 +0200
commit2d1380ae5bfe68f099a0e83f0e80b68efbd87b10 (patch)
tree89530d48d764ce1c8b12b3651ec7fc7d69c942af /ui/logray
parent5aba5772e9cb535e770f1774ab5819926dcd4d2b (diff)
capture: Move capture pipe polling out of UI
Both CLI and Qt interfaces spin GLib mainloop. Move the capture pipe polling into common code to reduce code duplication.
Diffstat (limited to 'ui/logray')
-rw-r--r--ui/logray/logray_main_window.cpp47
-rw-r--r--ui/logray/logray_main_window.h16
-rw-r--r--ui/logray/logray_main_window_slots.cpp71
3 files changed, 5 insertions, 129 deletions
diff --git a/ui/logray/logray_main_window.cpp b/ui/logray/logray_main_window.cpp
index f96c6eb7ef..1a43c61f67 100644
--- a/ui/logray/logray_main_window.cpp
+++ b/ui/logray/logray_main_window.cpp
@@ -95,11 +95,6 @@ DIAG_ON(frame-larger-than=)
// If we ever add support for multiple windows this will need to be replaced.
static LograyMainWindow *gbl_cur_main_window_ = NULL;
-void pipe_input_set_handler(gint source, gpointer user_data, ws_process_id *child_process, pipe_input_cb_t input_cb)
-{
- gbl_cur_main_window_->setPipeInputHandler(source, user_data, child_process, input_cb);
-}
-
static void plugin_if_mainwindow_apply_filter(GHashTable * data_set)
{
if (!gbl_cur_main_window_ || !data_set)
@@ -334,11 +329,6 @@ LograyMainWindow::LograyMainWindow(QWidget *parent) :
#endif
, display_filter_dlg_(NULL)
, capture_filter_dlg_(NULL)
-#ifdef _WIN32
- , pipe_timer_(NULL)
-#else
- , pipe_notifier_(NULL)
-#endif
#if defined(Q_OS_MAC)
, dock_menu_(NULL)
#endif
@@ -844,43 +834,6 @@ void LograyMainWindow::removeInterfaceToolbar(const gchar *menu_title)
menu->menuAction()->setVisible(!menu->actions().isEmpty());
}
-void LograyMainWindow::setPipeInputHandler(gint source, gpointer user_data, ws_process_id *child_process, pipe_input_cb_t input_cb)
-{
- pipe_source_ = source;
- pipe_child_process_ = child_process;
- pipe_user_data_ = user_data;
- pipe_input_cb_ = input_cb;
-
-#ifdef _WIN32
- /* Tricky to use pipes in win9x, as no concept of wait. NT can
- do this but that doesn't cover all win32 platforms. GTK can do
- this but doesn't seem to work over processes. Attempt to do
- something similar here, start a timer and check for data on every
- timeout. */
- /*ws_log(NULL, LOG_LEVEL_DEBUG, "pipe_input_set_handler: new");*/
-
- if (pipe_timer_) {
- disconnect(pipe_timer_, SIGNAL(timeout()), this, SLOT(pipeTimeout()));
- delete pipe_timer_;
- }
-
- pipe_timer_ = new QTimer(this);
- connect(pipe_timer_, SIGNAL(timeout()), this, SLOT(pipeTimeout()));
- connect(pipe_timer_, SIGNAL(destroyed()), this, SLOT(pipeNotifierDestroyed()));
- pipe_timer_->start(200);
-#else
- if (pipe_notifier_) {
- disconnect(pipe_notifier_, SIGNAL(activated(int)), this, SLOT(pipeActivated(int)));
- delete pipe_notifier_;
- }
-
- pipe_notifier_ = new QSocketNotifier(pipe_source_, QSocketNotifier::Read);
- // XXX ui/gtk/gui_utils.c sets the encoding. Do we need to do the same?
- connect(pipe_notifier_, SIGNAL(activated(int)), this, SLOT(pipeActivated(int)));
- connect(pipe_notifier_, SIGNAL(destroyed()), this, SLOT(pipeNotifierDestroyed()));
-#endif
-}
-
bool LograyMainWindow::eventFilter(QObject *obj, QEvent *event) {
// The user typed some text. Start filling in a filter.
diff --git a/ui/logray/logray_main_window.h b/ui/logray/logray_main_window.h
index d9393f3609..6bec7ece31 100644
--- a/ui/logray/logray_main_window.h
+++ b/ui/logray/logray_main_window.h
@@ -106,7 +106,6 @@ class LograyMainWindow : public MainWindow
public:
explicit LograyMainWindow(QWidget *parent = nullptr);
~LograyMainWindow();
- void setPipeInputHandler(gint source, gpointer user_data, ws_process_id *child_process, pipe_input_cb_t input_cb);
#ifdef HAVE_LIBPCAP
capture_session *captureSession() { return &cap_session_; }
@@ -195,17 +194,6 @@ private:
FilterDialog *display_filter_dlg_;
FilterDialog *capture_filter_dlg_;
- // Pipe input
- gint pipe_source_;
- gpointer pipe_user_data_;
- ws_process_id *pipe_child_process_;
- pipe_input_cb_t pipe_input_cb_;
-#ifdef _WIN32
- QTimer *pipe_timer_;
-#else
- QSocketNotifier *pipe_notifier_;
-#endif
-
#if defined(Q_OS_MAC)
QMenu *dock_menu_;
#endif
@@ -333,9 +321,7 @@ private slots:
*/
void startCapture(QStringList);
void startCapture();
- void pipeTimeout();
- void pipeActivated(int source);
- void pipeNotifierDestroyed();
+ void popLiveCaptureInProgress();
void stopCapture();
void loadWindowGeometry();
diff --git a/ui/logray/logray_main_window_slots.cpp b/ui/logray/logray_main_window_slots.cpp
index 48645cbf35..7168d6683e 100644
--- a/ui/logray/logray_main_window_slots.cpp
+++ b/ui/logray/logray_main_window_slots.cpp
@@ -516,6 +516,7 @@ void LograyMainWindow::captureCaptureUpdateFinished(capture_session *session) {
setMenusForCaptureFile();
setWindowIcon(mainApp->normalIcon());
+ popLiveCaptureInProgress();
if (global_commandline_info.quit_after_cap) {
// Command line asked us to quit after capturing.
@@ -538,6 +539,7 @@ void LograyMainWindow::captureCaptureFixedFinished(capture_session *) {
setMenusForCaptureFile(true);
setWindowIcon(mainApp->normalIcon());
+ popLiveCaptureInProgress();
if (global_commandline_info.quit_after_cap) {
// Command line asked us to quit after capturing.
@@ -558,6 +560,7 @@ void LograyMainWindow::captureCaptureFailed(capture_session *) {
mainApp->popStatus(WiresharkApplication::FileStatus);
setWindowIcon(mainApp->normalIcon());
+ popLiveCaptureInProgress();
if (global_commandline_info.quit_after_cap) {
// Command line asked us to quit after capturing.
@@ -917,75 +920,9 @@ void LograyMainWindow::startCapture(QStringList interfaces _U_) {
#endif // HAVE_LIBPCAP
}
-// Copied from ui/gtk/gui_utils.c
-void LograyMainWindow::pipeTimeout() {
-#ifdef _WIN32
- HANDLE handle;
- DWORD avail = 0;
- gboolean result, result1;
- DWORD childstatus;
- gint iterations = 0;
-
-
- /* try to read data from the pipe only 5 times, to avoid blocking */
- while (iterations < 5) {
- /* Oddly enough although Named pipes don't work on win9x,
- PeekNamedPipe does !!! */
- handle = (HANDLE)_get_osfhandle(pipe_source_);
- result = PeekNamedPipe(handle, NULL, 0, NULL, &avail, NULL);
-
- /* Get the child process exit status */
- result1 = GetExitCodeProcess((HANDLE)*(pipe_child_process_),
- &childstatus);
-
- /* If the Peek returned an error, or there are bytes to be read
- or the childwatcher thread has terminated then call the normal
- callback */
- if (!result || avail > 0 || childstatus != STILL_ACTIVE) {
-
- /* And call the real handler */
- if (!pipe_input_cb_(pipe_source_, pipe_user_data_)) {
- ws_log(LOG_DOMAIN_MAIN, LOG_LEVEL_DEBUG, "pipe_timer_cb: input pipe closed, iterations: %u", iterations);
- /* pipe closed, return false so that the old timer is not run again */
- delete pipe_timer_;
- return;
- }
- } else {
- /* No data, stop now */
- break;
- }
-
- iterations++;
- }
-#endif // _WIN32
-}
-
-void LograyMainWindow::pipeActivated(int source) {
- Q_UNUSED(source)
-
-#ifndef _WIN32
- ws_assert(source == pipe_source_);
-
- pipe_notifier_->setEnabled(false);
- if (pipe_input_cb_(pipe_source_, pipe_user_data_)) {
- pipe_notifier_->setEnabled(true);
- }
- else {
- delete pipe_notifier_;
- }
-#endif // _WIN32
-}
-
-void LograyMainWindow::pipeNotifierDestroyed()
-{
+void LograyMainWindow::popLiveCaptureInProgress() {
/* Pop the "<live capture in progress>" message off the status bar. */
main_ui_->statusBar->setFileName(capture_file_);
-
-#ifdef _WIN32
- pipe_timer_ = NULL;
-#else
- pipe_notifier_ = NULL;
-#endif // _WIN32
}
void LograyMainWindow::stopCapture() {