Skip to content

Commit

Permalink
get main_window_update out of the way... pass an update_cb to the cap…
Browse files Browse the repository at this point in the history
…ture_sync stuff

... as per the XXX comment removed from tshark.c this was a mess to keep the linker
happy... I couldn't!

I did this without even understanding whether calling main_window_update was realy
necessary in most cases. I guess nothing or more specific update cbs would be best.


svn path=/trunk/; revision=50188
  • Loading branch information
Luis Ontanon committed Jun 27, 2013
1 parent b450609 commit 0bdc0ef
Show file tree
Hide file tree
Showing 17 changed files with 90 additions and 80 deletions.
8 changes: 4 additions & 4 deletions capture.c
Original file line number Diff line number Diff line change
Expand Up @@ -130,7 +130,7 @@ capture_callback_remove(capture_callback_t func)
* @return TRUE if the capture starts successfully, FALSE otherwise.
*/
gboolean
capture_start(capture_options *capture_opts, capture_session *cap_session)
capture_start(capture_options *capture_opts, capture_session *cap_session, void(*update_cb)(void))
{
gboolean ret;
guint i;
Expand Down Expand Up @@ -168,7 +168,7 @@ capture_start(capture_options *capture_opts, capture_session *cap_session)
cf_set_tempfile_source((capture_file *)cap_session->cf, source->str);
g_string_free(source, TRUE);
/* try to start the capture child process */
ret = sync_pipe_start(capture_opts, cap_session);
ret = sync_pipe_start(capture_opts, cap_session, update_cb);
if(!ret) {
if(capture_opts->save_file != NULL) {
g_free(capture_opts->save_file);
Expand Down Expand Up @@ -660,7 +660,7 @@ capture_input_closed(capture_session *cap_session, gchar *msg)
/* close the currently loaded capture file */
cf_close((capture_file *)cap_session->cf);

capture_start(capture_opts, cap_session);
capture_start(capture_opts, cap_session,NULL); /*XXX is this NULL ok or we need an update_cb???*/
} else {
/* We're not doing a capture any more, so we don't have a save file. */
g_free(capture_opts->save_file);
Expand Down Expand Up @@ -696,7 +696,7 @@ capture_stat_start(capture_options *capture_opts) {
* mechanism, so opening all the devices and presenting packet
* counts might not always be a good idea.
*/
if (sync_interface_stats_open(&stat_fd, &fork_child, &msg) == 0) {
if (sync_interface_stats_open(&stat_fd, &fork_child, &msg, NULL) == 0) {
sc = (if_stat_cache_t *)g_malloc(sizeof(if_stat_cache_t));
sc->stat_fd = stat_fd;
sc->fork_child = fork_child;
Expand Down
2 changes: 1 addition & 1 deletion capture.h
Original file line number Diff line number Diff line change
Expand Up @@ -66,7 +66,7 @@ capture_callback_remove(capture_callback_t func);
* @return TRUE if the capture starts successfully, FALSE otherwise.
*/
extern gboolean
capture_start(capture_options *capture_opts, capture_session *cap_session);
capture_start(capture_options *capture_opts, capture_session *cap_session, void(*update_cb)(void));

/** Stop a capture session (usually from a menu item). */
extern void
Expand Down
8 changes: 4 additions & 4 deletions capture_ifinfo.c
Original file line number Diff line number Diff line change
Expand Up @@ -105,7 +105,7 @@ static void append_remote_list(GList *iflist)
/* XXX - We parse simple text output to get our interface list. Should
* we use "real" data serialization instead, e.g. via XML? */
GList *
capture_interface_list(int *err, char **err_str)
capture_interface_list(int *err, char **err_str, void (*update_cb)(void))
{
int ret;
GList *if_list = NULL;
Expand All @@ -119,7 +119,7 @@ capture_interface_list(int *err, char **err_str)
g_log(LOG_DOMAIN_CAPTURE, G_LOG_LEVEL_MESSAGE, "Capture Interface List ...");

/* Try to get our interface list */
ret = sync_interface_list_open(&data, &primary_msg, &secondary_msg);
ret = sync_interface_list_open(&data, &primary_msg, &secondary_msg, update_cb);
if (ret != 0) {
g_log(LOG_DOMAIN_CAPTURE, G_LOG_LEVEL_MESSAGE, "Capture Interface List failed!");
if (err_str) {
Expand Down Expand Up @@ -206,7 +206,7 @@ capture_interface_list(int *err, char **err_str)
* we use "real" data serialization instead, e.g. via XML? */
if_capabilities_t *
capture_get_if_capabilities(const gchar *ifname, gboolean monitor_mode,
char **err_str)
char **err_str, void (*update_cb)(void))
{
if_capabilities_t *caps;
GList *linktype_list = NULL;
Expand All @@ -219,7 +219,7 @@ capture_get_if_capabilities(const gchar *ifname, gboolean monitor_mode,

/* Try to get our interface list */
err = sync_if_capabilities_open(ifname, monitor_mode, &data,
&primary_msg, &secondary_msg);
&primary_msg, &secondary_msg, update_cb);
if (err != 0) {
g_log(LOG_DOMAIN_CAPTURE, G_LOG_LEVEL_MESSAGE, "Capture Interface Capabilities failed!");
if (err_str) {
Expand Down
4 changes: 2 additions & 2 deletions capture_ifinfo.h
Original file line number Diff line number Diff line change
Expand Up @@ -77,7 +77,7 @@ typedef struct {
/**
* Fetch the interface list from a child process.
*/
extern GList *capture_interface_list(int *err, char **err_str);
extern GList *capture_interface_list(int *err, char **err_str, void (*update_cb)(void));

/* Error values from "get_interface_list()/capture_interface_list()". */
#define CANT_GET_INTERFACE_LIST 1 /* error getting list */
Expand Down Expand Up @@ -110,7 +110,7 @@ typedef struct {
*/
extern if_capabilities_t *
capture_get_if_capabilities(const char *devname, gboolean monitor_mode,
char **err_str);
char **err_str, void (*update_cb)(void));

void free_if_capabilities(if_capabilities_t *caps);

Expand Down
34 changes: 17 additions & 17 deletions capture_sync.c
Original file line number Diff line number Diff line change
Expand Up @@ -334,7 +334,7 @@ init_pipe_args(int *argc) {
#define ARGV_NUMBER_LEN 24
/* a new capture run: start a new dumpcap task and hand over parameters through command line */
gboolean
sync_pipe_start(capture_options *capture_opts, capture_session *cap_session)
sync_pipe_start(capture_options *capture_opts, capture_session *cap_session, void (*update_cb)(void))
{
char ssnap[ARGV_NUMBER_LEN];
char scount[ARGV_NUMBER_LEN];
Expand Down Expand Up @@ -687,7 +687,7 @@ sync_pipe_start(capture_options *capture_opts, capture_session *cap_session)
cap_session->capture_opts = capture_opts;

/* we might wait for a moment till child is ready, so update screen now */
main_window_update();
if (update_cb) update_cb();

/* We were able to set up to read the capture file;
arrange that our callback be called whenever it's possible
Expand Down Expand Up @@ -718,7 +718,7 @@ sync_pipe_start(capture_options *capture_opts, capture_session *cap_session)
#define PIPE_BUF_SIZE 5120
static int
sync_pipe_open_command(char** argv, int *data_read_fd,
int *message_read_fd, int *fork_child, gchar **msg)
int *message_read_fd, int *fork_child, gchar **msg, void(*update_cb)(void))
{
enum PIPES { PIPE_READ, PIPE_WRITE }; /* Constants 0 and 1 for PIPE_READ and PIPE_WRITE */
#ifdef _WIN32
Expand Down Expand Up @@ -912,7 +912,7 @@ sync_pipe_open_command(char** argv, int *data_read_fd,
}

/* we might wait for a moment till child is ready, so update screen now */
main_window_update();
if (update_cb) update_cb();
return 0;
}

Expand Down Expand Up @@ -957,7 +957,7 @@ sync_pipe_close_command(int *data_read_fd, int *message_read_fd,
#define PIPE_BUF_SIZE 5120
static int
sync_pipe_run_command_actual(char** argv, gchar **data, gchar **primary_msg,
gchar **secondary_msg)
gchar **secondary_msg, void(*update_cb)(void))
{
gchar *msg;
int data_pipe_read_fd, sync_pipe_read_fd, fork_child, ret;
Expand All @@ -974,7 +974,7 @@ sync_pipe_run_command_actual(char** argv, gchar **data, gchar **primary_msg,
ssize_t count;

ret = sync_pipe_open_command(argv, &data_pipe_read_fd, &sync_pipe_read_fd,
&fork_child, &msg);
&fork_child, &msg, update_cb);
if (ret == -1) {
*primary_msg = msg;
*secondary_msg = NULL;
Expand Down Expand Up @@ -1133,7 +1133,7 @@ sync_pipe_run_command_actual(char** argv, gchar **data, gchar **primary_msg,
*/
static int
sync_pipe_run_command(char** argv, gchar **data, gchar **primary_msg,
gchar **secondary_msg)
gchar **secondary_msg, void (*update_cb)(void))
{
int ret, i;
GTimeVal start_time;
Expand All @@ -1151,7 +1151,7 @@ sync_pipe_run_command(char** argv, gchar **data, gchar **primary_msg,
}
}
/* do the actual sync pipe run command */
ret=sync_pipe_run_command_actual(argv, data, primary_msg, secondary_msg);
ret=sync_pipe_run_command_actual(argv, data, primary_msg, secondary_msg, update_cb);

if(logging_enabled){
g_get_current_time(&end_time);
Expand All @@ -1168,7 +1168,7 @@ sync_pipe_run_command(char** argv, gchar **data, gchar **primary_msg,
int
sync_interface_set_80211_chan(const gchar *iface, const char *freq, const gchar *type,
gchar **data, gchar **primary_msg,
gchar **secondary_msg)
gchar **secondary_msg, void (*update_cb)(void))
{
int argc, ret;
char **argv;
Expand Down Expand Up @@ -1207,7 +1207,7 @@ sync_interface_set_80211_chan(const gchar *iface, const char *freq, const gchar
argv = sync_pipe_add_arg(argv, &argc, SIGNAL_PIPE_CTRL_ID_NONE);
#endif

ret = sync_pipe_run_command(argv, data, primary_msg, secondary_msg);
ret = sync_pipe_run_command(argv, data, primary_msg, secondary_msg, update_cb);
g_free(opt);
return ret;
}
Expand All @@ -1226,7 +1226,7 @@ sync_interface_set_80211_chan(const gchar *iface, const char *freq, const gchar
*/
int
sync_interface_list_open(gchar **data, gchar **primary_msg,
gchar **secondary_msg)
gchar **secondary_msg, void (*update_cb)(void))
{
int argc;
char **argv;
Expand All @@ -1236,7 +1236,7 @@ sync_interface_list_open(gchar **data, gchar **primary_msg,
argv = init_pipe_args(&argc);

if (!argv) {
*primary_msg = g_strdup("We don't know where to find dumpcap.");
*primary_msg = g_strdup("We don't know where to find dumpcap..");
*secondary_msg = NULL;
*data = NULL;
return -1;
Expand All @@ -1250,7 +1250,7 @@ sync_interface_list_open(gchar **data, gchar **primary_msg,
argv = sync_pipe_add_arg(argv, &argc, "-Z");
argv = sync_pipe_add_arg(argv, &argc, SIGNAL_PIPE_CTRL_ID_NONE);
#endif
return sync_pipe_run_command(argv, data, primary_msg, secondary_msg);
return sync_pipe_run_command(argv, data, primary_msg, secondary_msg, update_cb);
}

/*
Expand All @@ -1268,7 +1268,7 @@ sync_interface_list_open(gchar **data, gchar **primary_msg,
int
sync_if_capabilities_open(const gchar *ifname, gboolean monitor_mode,
gchar **data, gchar **primary_msg,
gchar **secondary_msg)
gchar **secondary_msg, void (*update_cb)(void))
{
int argc;
char **argv;
Expand Down Expand Up @@ -1296,7 +1296,7 @@ sync_if_capabilities_open(const gchar *ifname, gboolean monitor_mode,
argv = sync_pipe_add_arg(argv, &argc, "-Z");
argv = sync_pipe_add_arg(argv, &argc, SIGNAL_PIPE_CTRL_ID_NONE);
#endif
return sync_pipe_run_command(argv, data, primary_msg, secondary_msg);
return sync_pipe_run_command(argv, data, primary_msg, secondary_msg, update_cb);
}

/*
Expand All @@ -1306,7 +1306,7 @@ sync_if_capabilities_open(const gchar *ifname, gboolean monitor_mode,
* that must be g_free()d, and -1 will be returned.
*/
int
sync_interface_stats_open(int *data_read_fd, int *fork_child, gchar **msg)
sync_interface_stats_open(int *data_read_fd, int *fork_child, gchar **msg, void (*update_cb)(void))
{
int argc;
char **argv;
Expand Down Expand Up @@ -1338,7 +1338,7 @@ sync_interface_stats_open(int *data_read_fd, int *fork_child, gchar **msg)
argv = sync_pipe_add_arg(argv, &argc, SIGNAL_PIPE_CTRL_ID_NONE);
#endif
ret = sync_pipe_open_command(argv, data_read_fd, &message_read_fd,
fork_child, msg);
fork_child, msg, update_cb);
if (ret == -1)
return -1;

Expand Down
10 changes: 5 additions & 5 deletions capture_sync.h
Original file line number Diff line number Diff line change
Expand Up @@ -47,7 +47,7 @@
* @return TRUE if a capture could be started, FALSE if not
*/
extern gboolean
sync_pipe_start(capture_options *capture_opts, capture_session *cap_session);
sync_pipe_start(capture_options *capture_opts, capture_session *cap_session, void(*update_cb)(void));

/** User wants to stop capturing, gracefully close the capture child */
extern void
Expand All @@ -61,22 +61,22 @@ sync_pipe_kill(int fork_child);
extern int
sync_interface_set_80211_chan(const gchar *iface, const char *freq, const gchar *type,
gchar **data, gchar **primary_msg,
gchar **secondary_msg);
gchar **secondary_msg, void (*update_cb)(void));

/** Get an interface list using dumpcap */
extern int
sync_interface_list_open(gchar **data, gchar **primary_msg,
gchar **secondary_msg);
gchar **secondary_msg, void (*update_cb)(void));

/** Get interface capabilities using dumpcap */
extern int
sync_if_capabilities_open(const gchar *ifname, gboolean monitor_mode,
gchar **data, gchar **primary_msg,
gchar **secondary_msg);
gchar **secondary_msg, void (*update_cb)(void));

/** Start getting interface statistics using dumpcap. */
extern int
sync_interface_stats_open(int *read_fd, int *fork_child, gchar **msg);
sync_interface_stats_open(int *read_fd, int *fork_child, gchar **msg, void (*update_cb)(void));

/** Stop gathering statistics. */
extern int
Expand Down
2 changes: 1 addition & 1 deletion capture_ui_utils.c
Original file line number Diff line number Diff line change
Expand Up @@ -290,7 +290,7 @@ get_interface_descriptive_name(const char *if_name)
/* No, we don't have a user-supplied description; did we get
one from the OS or libpcap? */
descr = NULL;
if_list = capture_interface_list(&err, NULL);
if_list = capture_interface_list(&err, NULL, NULL);
if (if_list != NULL) {
if_entry = if_list;
do {
Expand Down
Loading

0 comments on commit 0bdc0ef

Please sign in to comment.