aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorgerald <gerald@f5534014-38df-0310-8fa8-9805f1628bb7>2012-08-23 18:42:48 +0000
committergerald <gerald@f5534014-38df-0310-8fa8-9805f1628bb7>2012-08-23 18:42:48 +0000
commit09064c4b722ccc46bdb06e1657e9d1f2f8448c6f (patch)
treeceb6f4c63d6cea857d0469d7217723439b2cf37e
parent4f9f0170ba02fde5b12e0197c4d084ed2515afc4 (diff)
Move the pipe input routines to the common UI directory.
git-svn-id: http://anonsvn.wireshark.org/wireshark/trunk@44644 f5534014-38df-0310-8fa8-9805f1628bb7
-rw-r--r--CMakeLists.txt1
-rw-r--r--capture_sync.c1
-rw-r--r--ui/Makefile.common2
-rw-r--r--ui/gtk/gui_utils.c145
-rw-r--r--ui/pipe_input.c181
-rw-r--r--ui/pipe_input.h45
-rw-r--r--ui/ui_util.h5
7 files changed, 230 insertions, 150 deletions
diff --git a/CMakeLists.txt b/CMakeLists.txt
index edd7619f0e..9b03547f49 100644
--- a/CMakeLists.txt
+++ b/CMakeLists.txt
@@ -722,6 +722,7 @@ if( (BUILD_wireshark AND GTK_FOUND) OR (BUILD_qtshark AND QT_FOUND) )
u3.c
ui/alert_box.c
ui/iface_lists.c
+ ui/pipe_input.c
ui/util.c
ws80211_utils.c
${SHARK_COMMON_CAPTURE_SRC}
diff --git a/capture_sync.c b/capture_sync.c
index 57f4ba67e8..a7282650f0 100644
--- a/capture_sync.c
+++ b/capture_sync.c
@@ -98,6 +98,7 @@
#include "capture-wpcap.h"
#endif
+#include "ui/pipe_input.h"
#include "ui/ui_util.h"
#include <wsutil/file_util.h>
diff --git a/ui/Makefile.common b/ui/Makefile.common
index adde03f0ef..0831744c67 100644
--- a/ui/Makefile.common
+++ b/ui/Makefile.common
@@ -43,6 +43,7 @@ GENERATOR_FILES =
WIRESHARK_UI_SRC = \
alert_box.c \
iface_lists.c \
+ pipe_input.c \
util.c
noinst_HEADERS = \
@@ -51,6 +52,7 @@ noinst_HEADERS = \
last_open_dir.h \
iface_lists.h \
main_statusbar.h \
+ pipe_input.h \
progress_dlg.h \
recent.h \
recent_utils.h \
diff --git a/ui/gtk/gui_utils.c b/ui/gtk/gui_utils.c
index f9cdd804f9..f4b9ce3054 100644
--- a/ui/gtk/gui_utils.c
+++ b/ui/gtk/gui_utils.c
@@ -642,151 +642,6 @@ void main_window_quit(void)
gtk_main_quit();
}
-
-
-typedef struct pipe_input_tag {
- gint source;
- gpointer user_data;
- int *child_process;
- pipe_input_cb_t input_cb;
- guint pipe_input_id;
-#ifdef _WIN32
-#else
- GIOChannel *channel;
-#endif
-} pipe_input_t;
-
-
-#ifdef _WIN32
-/* The timer has expired, see if there's stuff to read from the pipe,
- if so, do the callback */
-static gboolean
-pipe_timer_cb(gpointer data)
-{
- HANDLE handle;
- DWORD avail = 0;
- gboolean result, result1;
- DWORD childstatus;
- pipe_input_t *pipe_input = data;
- gint iterations = 0;
-
-
- /* try to read data from the pipe only 5 times, to avoid blocking */
- while(iterations < 5) {
- /*g_log(NULL, G_LOG_LEVEL_DEBUG, "pipe_timer_cb: new iteration");*/
-
- /* Oddly enough although Named pipes don't work on win9x,
- PeekNamedPipe does !!! */
- handle = (HANDLE) _get_osfhandle (pipe_input->source);
- result = PeekNamedPipe(handle, NULL, 0, NULL, &avail, NULL);
-
- /* Get the child process exit status */
- result1 = GetExitCodeProcess((HANDLE)*(pipe_input->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) {
-
- /*g_log(NULL, G_LOG_LEVEL_DEBUG, "pipe_timer_cb: data avail");*/
-
- if(pipe_input->pipe_input_id != 0) {
- /*g_log(NULL, G_LOG_LEVEL_DEBUG, "pipe_timer_cb: stop timer");*/
- /* avoid reentrancy problems and stack overflow */
- g_source_remove(pipe_input->pipe_input_id);
- pipe_input->pipe_input_id = 0;
- }
-
- /* And call the real handler */
- if (!pipe_input->input_cb(pipe_input->source, pipe_input->user_data)) {
- g_log(NULL, G_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 */
- return FALSE;
- }
- }
- else {
- /*g_log(NULL, G_LOG_LEVEL_DEBUG, "pipe_timer_cb: no data avail");*/
- /* No data, stop now */
- break;
- }
-
- iterations++;
- }
-
- if(pipe_input->pipe_input_id == 0) {
- /* restore pipe handler */
- pipe_input->pipe_input_id = g_timeout_add(200, pipe_timer_cb, data);
- /*g_log(NULL, G_LOG_LEVEL_DEBUG, "pipe_timer_cb: finished with iterations: %u, new timer", iterations);*/
-
- /* Return false so that the old timer is not run again */
- return FALSE;
- } else {
- /*g_log(NULL, G_LOG_LEVEL_DEBUG, "pipe_timer_cb: finished with iterations: %u, old timer", iterations);*/
-
- /* we didn't stopped the old timer, so let it run */
- return TRUE;
- }
-}
-
-#else /* _WIN32 */
-
-/* There's stuff to read from the sync pipe, meaning the child has sent
- us a message, or the sync pipe has closed, meaning the child has
- closed it (perhaps because it exited). */
-static gboolean
-pipe_input_cb(GIOChannel *source _U_, GIOCondition condition _U_,
- gpointer data)
-{
- pipe_input_t *pipe_input = data;
-
-
- /* avoid reentrancy problems and stack overflow */
- g_source_remove(pipe_input->pipe_input_id);
-
- if (pipe_input->input_cb(pipe_input->source, pipe_input->user_data)) {
- /* restore pipe handler */
- pipe_input->pipe_input_id = g_io_add_watch_full (pipe_input->channel,
- G_PRIORITY_HIGH,
- G_IO_IN|G_IO_ERR|G_IO_HUP,
- pipe_input_cb,
- pipe_input,
- NULL);
- }
- return TRUE;
-}
-#endif
-
-void pipe_input_set_handler(gint source, gpointer user_data, int *child_process, pipe_input_cb_t input_cb)
-{
- static pipe_input_t pipe_input;
-
- pipe_input.source = source;
- pipe_input.child_process = child_process;
- pipe_input.user_data = user_data;
- pipe_input.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. */
- /*g_log(NULL, G_LOG_LEVEL_DEBUG, "pipe_input_set_handler: new");*/
- pipe_input.pipe_input_id = g_timeout_add(200, pipe_timer_cb, &pipe_input);
-#else
- pipe_input.channel = g_io_channel_unix_new(source);
- g_io_channel_set_encoding(pipe_input.channel, NULL, NULL);
- pipe_input.pipe_input_id = g_io_add_watch_full(pipe_input.channel,
- G_PRIORITY_HIGH,
- G_IO_IN|G_IO_ERR|G_IO_HUP,
- pipe_input_cb,
- &pipe_input,
- NULL);
-#endif
-}
-
-
#endif /* HAVE_LIBPCAP */
/* Given a pointer to a GtkWidget for a top-level window, raise it and
diff --git a/ui/pipe_input.c b/ui/pipe_input.c
new file mode 100644
index 0000000000..eaccb539d2
--- /dev/null
+++ b/ui/pipe_input.c
@@ -0,0 +1,181 @@
+/* pipe_input.c
+ * Pipe input routines. Declared in pipe_input.h
+ *
+ * $Id$
+ *
+ * Wireshark - Network traffic analyzer
+ * By Gerald Combs <gerald@wireshark.org>
+ * Copyright 1998 Gerald Combs
+ *
+ * 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; either version 2
+ * of the License, or (at your option) any later version.
+ *
+ * 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 General Public License
+ * along with this program; if not, write to the Free Software
+ * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA.
+ */
+
+#ifdef HAVE_CONFIG_H
+# include "config.h"
+#endif
+
+#include <glib.h>
+
+#include "pipe_input.h"
+
+#ifdef _WIN32
+#include <windows.h>
+#endif
+
+#ifdef HAVE_LIBPCAP
+
+typedef struct pipe_input_tag {
+ gint source;
+ gpointer user_data;
+ int *child_process;
+ pipe_input_cb_t input_cb;
+ guint pipe_input_id;
+#ifdef _WIN32
+#else
+ GIOChannel *channel;
+#endif
+} pipe_input_t;
+
+
+#ifdef _WIN32
+/* The timer has expired, see if there's stuff to read from the pipe,
+ if so, do the callback */
+static gboolean
+pipe_timer_cb(gpointer data)
+{
+ HANDLE handle;
+ DWORD avail = 0;
+ gboolean result, result1;
+ DWORD childstatus;
+ pipe_input_t *pipe_input = data;
+ gint iterations = 0;
+
+
+ /* try to read data from the pipe only 5 times, to avoid blocking */
+ while(iterations < 5) {
+ /*g_log(NULL, G_LOG_LEVEL_DEBUG, "pipe_timer_cb: new iteration");*/
+
+ /* Oddly enough although Named pipes don't work on win9x,
+ PeekNamedPipe does !!! */
+ handle = (HANDLE) _get_osfhandle (pipe_input->source);
+ result = PeekNamedPipe(handle, NULL, 0, NULL, &avail, NULL);
+
+ /* Get the child process exit status */
+ result1 = GetExitCodeProcess((HANDLE)*(pipe_input->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) {
+
+ /*g_log(NULL, G_LOG_LEVEL_DEBUG, "pipe_timer_cb: data avail");*/
+
+ if(pipe_input->pipe_input_id != 0) {
+ /*g_log(NULL, G_LOG_LEVEL_DEBUG, "pipe_timer_cb: stop timer");*/
+ /* avoid reentrancy problems and stack overflow */
+ g_source_remove(pipe_input->pipe_input_id);
+ pipe_input->pipe_input_id = 0;
+ }
+
+ /* And call the real handler */
+ if (!pipe_input->input_cb(pipe_input->source, pipe_input->user_data)) {
+ g_log(NULL, G_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 */
+ return FALSE;
+ }
+ }
+ else {
+ /*g_log(NULL, G_LOG_LEVEL_DEBUG, "pipe_timer_cb: no data avail");*/
+ /* No data, stop now */
+ break;
+ }
+
+ iterations++;
+ }
+
+ if(pipe_input->pipe_input_id == 0) {
+ /* restore pipe handler */
+ pipe_input->pipe_input_id = g_timeout_add(200, pipe_timer_cb, data);
+ /*g_log(NULL, G_LOG_LEVEL_DEBUG, "pipe_timer_cb: finished with iterations: %u, new timer", iterations);*/
+
+ /* Return false so that the old timer is not run again */
+ return FALSE;
+ } else {
+ /*g_log(NULL, G_LOG_LEVEL_DEBUG, "pipe_timer_cb: finished with iterations: %u, old timer", iterations);*/
+
+ /* we didn't stopped the old timer, so let it run */
+ return TRUE;
+ }
+}
+
+#else /* _WIN32 */
+
+/* There's stuff to read from the sync pipe, meaning the child has sent
+ us a message, or the sync pipe has closed, meaning the child has
+ closed it (perhaps because it exited). */
+static gboolean
+pipe_input_cb(GIOChannel *source _U_, GIOCondition condition _U_,
+ gpointer data)
+{
+ pipe_input_t *pipe_input = data;
+
+
+ /* avoid reentrancy problems and stack overflow */
+ g_source_remove(pipe_input->pipe_input_id);
+
+ if (pipe_input->input_cb(pipe_input->source, pipe_input->user_data)) {
+ /* restore pipe handler */
+ pipe_input->pipe_input_id = g_io_add_watch_full (pipe_input->channel,
+ G_PRIORITY_HIGH,
+ G_IO_IN|G_IO_ERR|G_IO_HUP,
+ pipe_input_cb,
+ pipe_input,
+ NULL);
+ }
+ return TRUE;
+}
+#endif
+
+void pipe_input_set_handler(gint source, gpointer user_data, int *child_process, pipe_input_cb_t input_cb)
+{
+ static pipe_input_t pipe_input;
+
+ pipe_input.source = source;
+ pipe_input.child_process = child_process;
+ pipe_input.user_data = user_data;
+ pipe_input.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. */
+ /*g_log(NULL, G_LOG_LEVEL_DEBUG, "pipe_input_set_handler: new");*/
+ pipe_input.pipe_input_id = g_timeout_add(200, pipe_timer_cb, &pipe_input);
+#else /* _WIN32 */
+ pipe_input.channel = g_io_channel_unix_new(source);
+ g_io_channel_set_encoding(pipe_input.channel, NULL, NULL);
+ pipe_input.pipe_input_id = g_io_add_watch_full(pipe_input.channel,
+ G_PRIORITY_HIGH,
+ G_IO_IN|G_IO_ERR|G_IO_HUP,
+ pipe_input_cb,
+ &pipe_input,
+ NULL);
+#endif /* _WIN32 */
+}
+
+#endif /* HAVE_LIBPCAP */
diff --git a/ui/pipe_input.h b/ui/pipe_input.h
new file mode 100644
index 0000000000..42992b615d
--- /dev/null
+++ b/ui/pipe_input.h
@@ -0,0 +1,45 @@
+/* pipe_input.h
+ * Declarations of pipe input routines.
+ *
+ * $Id$
+ *
+ * Wireshark - Network traffic analyzer
+ * By Gerald Combs <gerald@wireshark.org>
+ * Copyright 1998 Gerald Combs
+ *
+ * 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; either version 2
+ * of the License, or (at your option) any later version.
+ *
+ * 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 General Public License
+ * along with this program; if not, write to the Free Software
+ * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA.
+ */
+
+#ifndef __PIPE_INPUT_H__
+#define __PIPE_INPUT_H__
+
+#ifdef __cplusplus
+extern "C" {
+#endif /* __cplusplus */
+
+#ifdef HAVE_LIBPCAP
+
+/* Read from a pipe (callback) */
+typedef gboolean (*pipe_input_cb_t) (gint source, gpointer user_data);
+/* Install callback function, called if pipe input is available */
+extern void pipe_input_set_handler(gint source, gpointer user_data, int *child_process, pipe_input_cb_t input_cb);
+
+#endif /* HAVE_LIBPCAP */
+
+#ifdef __cplusplus
+}
+#endif /* __cplusplus */
+
+#endif /* __PIPE_INPUT_H__ */
diff --git a/ui/ui_util.h b/ui/ui_util.h
index 0afadca0cc..0132148e5d 100644
--- a/ui/ui_util.h
+++ b/ui/ui_util.h
@@ -56,11 +56,6 @@ extern void main_window_nested_quit(void);
/* quit the main window */
extern void main_window_quit(void);
-/* read from a pipe (callback) */
-typedef gboolean (*pipe_input_cb_t) (gint source, gpointer user_data);
-/* install callback function, called if pipe input is available */
-extern void pipe_input_set_handler(gint source, gpointer user_data, int *child_process, pipe_input_cb_t input_cb);
-
/* packet_list.c */
void new_packet_list_clear(void);