Commit c4932893 authored by Guy Harris's avatar Guy Harris

Have separate callback mechanisms in file.c and capture.c; pass the

capture callbacks the capture_options * as its second argument in all
cases.  This makes it a bit clearer what arguments callbacks take, and
means we can get rid of all global_capture_opts references in
gtk/main_statusbar.c.

Put the interface between gtk/main.c and gtk/main_statusbar.c into a
private header.

svn path=/trunk/; revision=25576
parent a9ffacc1
......@@ -104,6 +104,62 @@ struct if_stat_cache_s {
GList *cache_list; /* List of if_stat_chache_entry_t */
};
/* this callback mechanism should possibly be replaced by the g_signal_...() stuff (if I only would know how :-) */
typedef struct {
capture_callback_t cb_fct;
gpointer user_data;
} capture_callback_data_t;
static GList *capture_callbacks = NULL;
static void
capture_callback_invoke(int event, capture_options *capture_opts)
{
capture_callback_data_t *cb;
GList *cb_item = capture_callbacks;
/* there should be at least one interested */
g_assert(cb_item != NULL);
while(cb_item != NULL) {
cb = cb_item->data;
cb->cb_fct(event, capture_opts, cb->user_data);
cb_item = g_list_next(cb_item);
}
}
void
capture_callback_add(capture_callback_t func, gpointer user_data)
{
capture_callback_data_t *cb;
cb = g_malloc(sizeof(capture_callback_data_t));
cb->cb_fct = func;
cb->user_data = user_data;
capture_callbacks = g_list_append(capture_callbacks, cb);
}
void
capture_callback_remove(capture_callback_t func)
{
capture_callback_data_t *cb;
GList *cb_item = capture_callbacks;
while(cb_item != NULL) {
cb = cb_item->data;
if(cb->cb_fct == func) {
capture_callbacks = g_list_remove(capture_callbacks, cb);
g_free(cb);
return;
}
cb_item = g_list_next(cb_item);
}
g_assert_not_reached();
}
/**
* Start a capture.
*
......@@ -139,7 +195,7 @@ capture_start(capture_options *capture_opts)
/* to prevent problems, bring the main GUI into "capture mode" right after successfully */
/* spawn/exec the capture child, without waiting for any response from it */
cf_callback_invoke(cf_cb_live_capture_prepared, capture_opts);
capture_callback_invoke(capture_cb_capture_prepared, capture_opts);
if(capture_opts->show_info)
capture_info_open(capture_opts);
......@@ -154,7 +210,7 @@ capture_stop(capture_options *capture_opts)
{
g_log(LOG_DOMAIN_CAPTURE, G_LOG_LEVEL_MESSAGE, "Capture Stop ...");
cf_callback_invoke(cf_cb_live_capture_stopping, capture_opts);
capture_callback_invoke(capture_cb_capture_stopping, capture_opts);
/* stop the capture child gracefully */
sync_pipe_stop(capture_opts);
......@@ -295,7 +351,7 @@ capture_input_new_file(capture_options *capture_opts, gchar *new_file)
/* we start a new capture file, close the old one (if we had one before) */
/* (we can only have an open capture file in real_time_mode!) */
if( ((capture_file *) capture_opts->cf)->state != FILE_CLOSED) {
cf_callback_invoke(cf_cb_live_capture_update_finished, capture_opts->cf);
capture_callback_invoke(capture_cb_capture_update_finished, capture_opts);
cf_finish_tail(capture_opts->cf, &err);
cf_close(capture_opts->cf);
}
......@@ -332,9 +388,9 @@ capture_input_new_file(capture_options *capture_opts, gchar *new_file)
}
if(capture_opts->real_time_mode) {
cf_callback_invoke(cf_cb_live_capture_update_started, capture_opts);
capture_callback_invoke(capture_cb_capture_update_started, capture_opts);
} else {
cf_callback_invoke(cf_cb_live_capture_fixed_started, capture_opts);
capture_callback_invoke(capture_cb_capture_fixed_started, capture_opts);
}
capture_opts->state = CAPTURE_RUNNING;
......@@ -362,7 +418,7 @@ capture_input_new_packets(capture_options *capture_opts, int to_read)
file.
XXX - abort on a read error? */
cf_callback_invoke(cf_cb_live_capture_update_continue, capture_opts->cf);
capture_callback_invoke(capture_cb_capture_update_continue, capture_opts);
break;
case CF_READ_ABORTED:
......@@ -376,7 +432,7 @@ capture_input_new_packets(capture_options *capture_opts, int to_read)
cf_set_packet_count(capture_opts->cf,
cf_get_packet_count(capture_opts->cf) + to_read);
cf_callback_invoke(cf_cb_live_capture_fixed_continue, capture_opts->cf);
capture_callback_invoke(capture_cb_capture_fixed_continue, capture_opts);
}
/* update the main window, so we get events (e.g. from the stop toolbar button) */
......@@ -498,9 +554,9 @@ capture_input_closed(capture_options *capture_opts)
/* (happens if we got an error message - we won't get a filename then) */
if(capture_opts->state == CAPTURE_PREPARING) {
if(capture_opts->real_time_mode) {
cf_callback_invoke(cf_cb_live_capture_update_started, capture_opts);
capture_callback_invoke(capture_cb_capture_update_started, capture_opts);
} else {
cf_callback_invoke(cf_cb_live_capture_fixed_started, capture_opts);
capture_callback_invoke(capture_cb_capture_fixed_started, capture_opts);
}
}
......@@ -515,7 +571,7 @@ capture_input_closed(capture_options *capture_opts)
/* Tell the GUI, we are not doing a capture any more.
Must be done after the cf_finish_tail(), so file lengths are displayed
correct. */
cf_callback_invoke(cf_cb_live_capture_update_finished, capture_opts->cf);
capture_callback_invoke(capture_cb_capture_update_finished, capture_opts);
/* Finish the capture. */
switch (status) {
......@@ -556,7 +612,7 @@ capture_input_closed(capture_options *capture_opts)
} else {
/* first of all, we are not doing a capture any more */
cf_callback_invoke(cf_cb_live_capture_fixed_finished, capture_opts->cf);
capture_callback_invoke(capture_cb_capture_fixed_finished, capture_opts);
/* this is a normal mode capture and if no error happened, read in the capture file data */
if(capture_opts->save_file != NULL) {
......
......@@ -33,6 +33,26 @@
#include "capture_opts.h"
typedef enum {
capture_cb_capture_prepared,
capture_cb_capture_update_started,
capture_cb_capture_update_continue,
capture_cb_capture_update_finished,
capture_cb_capture_fixed_started,
capture_cb_capture_fixed_continue,
capture_cb_capture_fixed_finished,
capture_cb_capture_stopping
} capture_cbs;
typedef void (*capture_callback_t) (gint event, capture_options *capture_opts,
gpointer user_data);
extern void
capture_callback_add(capture_callback_t func, gpointer user_data);
extern void
capture_callback_remove(capture_callback_t func);
/**
* Start a capture session.
*
......
......@@ -135,9 +135,9 @@ typedef struct {
gpointer user_data;
} cf_callback_data_t;
GList *cf_callbacks = NULL;
static GList *cf_callbacks = NULL;
void
static void
cf_callback_invoke(int event, gpointer data)
{
cf_callback_data_t *cb;
......
......@@ -60,16 +60,6 @@ typedef enum {
cf_cb_file_closed,
cf_cb_file_read_start,
cf_cb_file_read_finished,
#ifdef HAVE_LIBPCAP
cf_cb_live_capture_prepared,
cf_cb_live_capture_update_started,
cf_cb_live_capture_update_continue,
cf_cb_live_capture_update_finished,
cf_cb_live_capture_fixed_started,
cf_cb_live_capture_fixed_continue,
cf_cb_live_capture_fixed_finished,
cf_cb_live_capture_stopping,
#endif
cf_cb_packet_selected,
cf_cb_packet_unselected,
cf_cb_field_unselected,
......@@ -81,9 +71,6 @@ typedef enum {
typedef void (*cf_callback_t) (gint event, gpointer data, gpointer user_data);
extern void
cf_callback_invoke(int event, gpointer data);
extern void
cf_callback_add(cf_callback_t func, gpointer user_data);
......
......@@ -250,6 +250,7 @@ noinst_HEADERS = \
main_packet_list.h \
main_proto_draw.h \
main_statusbar.h \
main_statusbar_private.h \
main_toolbar.h \
main_welcome.h \
mcast_stream.h \
......
......@@ -131,6 +131,7 @@
#include "gtk/main_menu.h"
#include "gtk/main_packet_list.h"
#include "gtk/main_statusbar.h"
#include "gtk/main_statusbar_private.h"
#include "gtk/main_toolbar.h"
#include "gtk/main_welcome.h"
#include "gtk/drag_and_drop.h"
......@@ -1285,7 +1286,7 @@ GList *icon_list_create(
#ifdef HAVE_LIBPCAP
static void
main_cf_cb_live_capture_prepared(capture_options *capture_opts)
main_capture_cb_capture_prepared(capture_options *capture_opts)
{
gchar *title;
static GList *icon_list = NULL;
......@@ -1315,7 +1316,7 @@ main_cf_cb_live_capture_prepared(capture_options *capture_opts)
}
static void
main_cf_cb_live_capture_update_started(capture_options *capture_opts)
main_capture_cb_capture_update_started(capture_options *capture_opts)
{
gchar *title;
......@@ -1342,8 +1343,9 @@ main_cf_cb_live_capture_update_started(capture_options *capture_opts)
}
static void
main_cf_cb_live_capture_update_finished(capture_file *cf)
main_capture_cb_capture_update_finished(capture_options *capture_opts)
{
capture_file *cf = capture_opts->cf;
static GList *icon_list = NULL;
set_display_filename(cf);
......@@ -1373,15 +1375,18 @@ main_cf_cb_live_capture_update_finished(capture_file *cf)
}
static void
main_cf_cb_live_capture_fixed_started(capture_options *capture_opts _U_)
main_capture_cb_capture_fixed_started(capture_options *capture_opts _U_)
{
/* Don't set up main window for a capture file. */
main_set_for_capture_file(FALSE);
}
static void
main_cf_cb_live_capture_fixed_finished(capture_file *cf _U_)
main_capture_cb_capture_fixed_finished(capture_options *capture_opts _U_)
{
#if 0
capture_file *cf = capture_opts->cf;
#endif
static GList *icon_list = NULL;
/*set_display_filename(cf);*/
......@@ -1477,39 +1482,6 @@ main_cf_callback(gint event, gpointer data, gpointer user_data _U_)
g_log(LOG_DOMAIN_MAIN, G_LOG_LEVEL_DEBUG, "Callback: Read finished");
main_cf_cb_file_read_finished(data);
break;
#ifdef HAVE_LIBPCAP
case(cf_cb_live_capture_prepared):
g_log(LOG_DOMAIN_MAIN, G_LOG_LEVEL_DEBUG, "Callback: capture prepared");
main_cf_cb_live_capture_prepared(data);
break;
case(cf_cb_live_capture_update_started):
g_log(LOG_DOMAIN_MAIN, G_LOG_LEVEL_DEBUG, "Callback: capture update started");
main_cf_cb_live_capture_update_started(data);
break;
case(cf_cb_live_capture_update_continue):
/*g_log(LOG_DOMAIN_MAIN, G_LOG_LEVEL_DEBUG, "Callback: capture update continue");*/
break;
case(cf_cb_live_capture_update_finished):
g_log(LOG_DOMAIN_MAIN, G_LOG_LEVEL_DEBUG, "Callback: capture update finished");
main_cf_cb_live_capture_update_finished(data);
break;
case(cf_cb_live_capture_fixed_started):
g_log(LOG_DOMAIN_MAIN, G_LOG_LEVEL_DEBUG, "Callback: capture fixed started");
main_cf_cb_live_capture_fixed_started(data);
break;
case(cf_cb_live_capture_fixed_continue):
g_log(LOG_DOMAIN_MAIN, G_LOG_LEVEL_DEBUG, "Callback: capture fixed continue");
break;
case(cf_cb_live_capture_fixed_finished):
g_log(LOG_DOMAIN_MAIN, G_LOG_LEVEL_DEBUG, "Callback: capture fixed finished");
main_cf_cb_live_capture_fixed_finished(data);
break;
case(cf_cb_live_capture_stopping):
g_log(LOG_DOMAIN_MAIN, G_LOG_LEVEL_DEBUG, "Callback: capture stopping");
/* Beware: this state won't be called, if the capture child
* closes the capturing on it's own! */
break;
#endif
case(cf_cb_packet_selected):
main_cf_cb_packet_selected(data);
break;
......@@ -1538,6 +1510,49 @@ main_cf_callback(gint event, gpointer data, gpointer user_data _U_)
}
}
#ifdef HAVE_LIBPCAP
static void
main_capture_callback(gint event, capture_options *capture_opts, gpointer user_data _U_)
{
switch(event) {
case(capture_cb_capture_prepared):
g_log(LOG_DOMAIN_MAIN, G_LOG_LEVEL_DEBUG, "Callback: capture prepared");
main_capture_cb_capture_prepared(capture_opts);
break;
case(capture_cb_capture_update_started):
g_log(LOG_DOMAIN_MAIN, G_LOG_LEVEL_DEBUG, "Callback: capture update started");
main_capture_cb_capture_update_started(capture_opts);
break;
case(capture_cb_capture_update_continue):
/*g_log(LOG_DOMAIN_MAIN, G_LOG_LEVEL_DEBUG, "Callback: capture update continue");*/
break;
case(capture_cb_capture_update_finished):
g_log(LOG_DOMAIN_MAIN, G_LOG_LEVEL_DEBUG, "Callback: capture update finished");
main_capture_cb_capture_update_finished(capture_opts);
break;
case(capture_cb_capture_fixed_started):
g_log(LOG_DOMAIN_MAIN, G_LOG_LEVEL_DEBUG, "Callback: capture fixed started");
main_capture_cb_capture_fixed_started(capture_opts);
break;
case(capture_cb_capture_fixed_continue):
g_log(LOG_DOMAIN_MAIN, G_LOG_LEVEL_DEBUG, "Callback: capture fixed continue");
break;
case(capture_cb_capture_fixed_finished):
g_log(LOG_DOMAIN_MAIN, G_LOG_LEVEL_DEBUG, "Callback: capture fixed finished");
main_capture_cb_capture_fixed_finished(capture_opts);
break;
case(capture_cb_capture_stopping):
g_log(LOG_DOMAIN_MAIN, G_LOG_LEVEL_DEBUG, "Callback: capture stopping");
/* Beware: this state won't be called, if the capture child
* closes the capturing on it's own! */
break;
default:
g_warning("main_capture_callback: event %u unknown", event);
g_assert_not_reached();
}
}
#endif
static void
get_gui_compiled_info(GString *str)
{
......@@ -1928,7 +1943,13 @@ main(int argc, char *argv[])
gtk_init (&argc, &argv);
cf_callback_add(main_cf_callback, NULL);
#ifdef HAVE_LIBPCAP
capture_callback_add(main_capture_callback, NULL);
#endif
cf_callback_add(statusbar_cf_callback, NULL);
#ifdef HAVE_LIBPCAP
capture_callback_add(statusbar_capture_callback, NULL);
#endif
/* Arrange that if we have no console window, and a GLib message logging
routine is called to log a message, we pop up a console window.
......
......@@ -42,13 +42,16 @@
#include "../file.h"
#include "../capture_opts.h"
#include "../capture_ui_utils.h"
#ifdef HAVE_LIBPCAP
#include "../capture.h"
#endif
#include "gtk/recent.h"
#include "gtk/main.h"
#include "gtk/main_statusbar.h"
#include "gtk/main_statusbar_private.h"
#include "gtk/gui_utils.h"
#include "gtk/gtkglobals.h"
#include "gtk/capture_globals.h"
#include "gtk/expert_comp_dlg.h"
#include "gtk/profile_dlg.h"
......@@ -566,13 +569,13 @@ statusbar_cf_file_read_finished_cb(capture_file *cf)
#ifdef HAVE_LIBPCAP
static void
statusbar_cf_live_capture_prepared_cb(capture_options *capture_opts _U_)
statusbar_capture_prepared_cb(capture_options *capture_opts _U_)
{
statusbar_push_file_msg(" Waiting for capture input data ...");
}
static void
statusbar_cf_live_capture_update_started_cb(capture_options *capture_opts)
statusbar_capture_update_started_cb(capture_options *capture_opts)
{
gchar *capture_msg;
......@@ -594,8 +597,9 @@ statusbar_cf_live_capture_update_started_cb(capture_options *capture_opts)
}
static void
statusbar_cf_live_capture_update_continue_cb(capture_file *cf)
statusbar_capture_update_continue_cb(capture_options *capture_opts)
{
capture_file *cf = capture_opts->cf;
gchar *capture_msg;
......@@ -605,18 +609,18 @@ statusbar_cf_live_capture_update_continue_cb(capture_file *cf)
if (cf->f_datalen/1024/1024 > 10) {
capture_msg = g_strdup_printf(" %s: <live capture in progress> File: %s %" G_GINT64_MODIFIER "d MB",
get_iface_description(&global_capture_opts),
global_capture_opts.save_file,
get_iface_description(capture_opts),
capture_opts->save_file,
cf->f_datalen/1024/1024);
} else if (cf->f_datalen/1024 > 10) {
capture_msg = g_strdup_printf(" %s: <live capture in progress> File: %s %" G_GINT64_MODIFIER "d KB",
get_iface_description(&global_capture_opts),
global_capture_opts.save_file,
get_iface_description(capture_opts),
capture_opts->save_file,
cf->f_datalen/1024);
} else {
capture_msg = g_strdup_printf(" %s: <live capture in progress> File: %s %" G_GINT64_MODIFIER "d Bytes",
get_iface_description(&global_capture_opts),
global_capture_opts.save_file,
get_iface_description(capture_opts),
capture_opts->save_file,
cf->f_datalen);
}
......@@ -624,15 +628,17 @@ statusbar_cf_live_capture_update_continue_cb(capture_file *cf)
}
static void
statusbar_cf_live_capture_update_finished_cb(capture_file *cf)
statusbar_capture_update_finished_cb(capture_options *capture_opts)
{
capture_file *cf = capture_opts->cf;
/* Pop the "<live capture in progress>" message off the status bar. */
statusbar_pop_file_msg();
statusbar_set_filename(cf->filename, cf->f_datalen, &(cf->elapsed_time));
}
static void
statusbar_cf_live_capture_fixed_started_cb(capture_options *capture_opts)
statusbar_capture_fixed_started_cb(capture_options *capture_opts)
{
gchar *capture_msg;
......@@ -650,8 +656,9 @@ statusbar_cf_live_capture_fixed_started_cb(capture_options *capture_opts)
}
static void
statusbar_cf_live_capture_fixed_continue_cb(capture_file *cf)
statusbar_capture_fixed_continue_cb(capture_options *capture_opts)
{
capture_file *cf = capture_opts->cf;
gchar *capture_msg;
......@@ -663,8 +670,12 @@ statusbar_cf_live_capture_fixed_continue_cb(capture_file *cf)
static void
statusbar_cf_live_capture_fixed_finished_cb(capture_file *cf _U_)
statusbar_capture_fixed_finished_cb(capture_options *capture_opts _U_)
{
#if 0
capture_file *cf = capture_opts->cf;
#endif
/* Pop the "<live capture in progress>" message off the status bar. */
statusbar_pop_file_msg();
......@@ -723,33 +734,6 @@ statusbar_cf_callback(gint event, gpointer data, gpointer user_data _U_)
case(cf_cb_file_read_finished):
statusbar_cf_file_read_finished_cb(data);
break;
#ifdef HAVE_LIBPCAP
case(cf_cb_live_capture_prepared):
statusbar_cf_live_capture_prepared_cb(data);
break;
case(cf_cb_live_capture_update_started):
statusbar_cf_live_capture_update_started_cb(data);
break;
case(cf_cb_live_capture_update_continue):
statusbar_cf_live_capture_update_continue_cb(data);
break;
case(cf_cb_live_capture_update_finished):
statusbar_cf_live_capture_update_finished_cb(data);
break;
case(cf_cb_live_capture_fixed_started):
statusbar_cf_live_capture_fixed_started_cb(data);
break;
case(cf_cb_live_capture_fixed_continue):
statusbar_cf_live_capture_fixed_continue_cb(data);
break;
case(cf_cb_live_capture_fixed_finished):
statusbar_cf_live_capture_fixed_finished_cb(data);
break;
case(cf_cb_live_capture_stopping):
/* Beware: this state won't be called, if the capture child
* closes the capturing on it's own! */
break;
#endif
case(cf_cb_packet_selected):
break;
case(cf_cb_packet_unselected):
......@@ -774,3 +758,40 @@ statusbar_cf_callback(gint event, gpointer data, gpointer user_data _U_)
}
}
#ifdef HAVE_LIBPCAP
void
statusbar_capture_callback(gint event, capture_options *capture_opts,
gpointer user_data _U_)
{
switch(event) {
case(capture_cb_capture_prepared):
statusbar_capture_prepared_cb(capture_opts);
break;
case(capture_cb_capture_update_started):
statusbar_capture_update_started_cb(capture_opts);
break;
case(capture_cb_capture_update_continue):
statusbar_capture_update_continue_cb(capture_opts);
break;
case(capture_cb_capture_update_finished):
statusbar_capture_update_finished_cb(capture_opts);
break;
case(capture_cb_capture_fixed_started):
statusbar_capture_fixed_started_cb(capture_opts);
break;
case(capture_cb_capture_fixed_continue):
statusbar_capture_fixed_continue_cb(capture_opts);
break;
case(capture_cb_capture_fixed_finished):
statusbar_capture_fixed_finished_cb(capture_opts);
break;
case(capture_cb_capture_stopping):
/* Beware: this state won't be called, if the capture child
* closes the capturing on it's own! */
break;
default:
g_warning("statusbar_capture_callback: event %u unknown", event);
g_assert_not_reached();
}
}
#endif
......@@ -49,16 +49,4 @@ void statusbar_push_filter_msg(const gchar *msg);
*/
void statusbar_pop_filter_msg(void);
/*** PRIVATE INTERFACE BETWEEN main.c AND main_statusbar.c DON'T USE OR TOUCH :-)*/
GtkWidget *statusbar_new(void);
void statusbar_load_window_geometry(void);
void statusbar_save_window_geometry(void);
void statusbar_widgets_emptying(GtkWidget *statusbar);
void statusbar_widgets_pack(GtkWidget *statusbar);
void statusbar_widgets_show_or_hide(GtkWidget *statusbar);
void statusbar_cf_callback(gint event, gpointer data, gpointer user_data);
#endif /* __MAIN_STATUSBAR_H__ */
/* main_statusbar_private.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., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.
*/
#ifndef __MAIN_STATUSBAR_PRIVATE_H__
#define __MAIN_STATUSBAR_PRIVATE_H__
/*** PRIVATE INTERFACE BETWEEN main.c AND main_statusbar.c DON'T USE OR TOUCH :-)*/
GtkWidget *statusbar_new(void);
void statusbar_load_window_geometry(void);
void statusbar_save_window_geometry(void);
void statusbar_widgets_emptying(GtkWidget *statusbar);
void statusbar_widgets_pack(GtkWidget *statusbar);
void statusbar_widgets_show_or_hide(GtkWidget *statusbar);
void statusbar_cf_callback(gint event, gpointer data, gpointer user_data);
#ifdef HAVE_LIBPCAP
void statusbar_capture_callback(gint event, capture_options *capture_opts,
gpointer user_data);
#endif
#endif /* __MAIN_STATUSBAR_PRIVATE_H__ */
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment