From 4852c618d8f38a20111ab38a45c92a0d98f2713d Mon Sep 17 00:00:00 2001 From: Ulf Lamping Date: Wed, 27 Apr 2005 19:43:02 +0000 Subject: [PATCH] add a state member to the capture_opts, and set it according to the capture engine svn path=/trunk/; revision=14205 --- capture.c | 15 +++++++++++++-- capture.h | 10 ++++++++++ capture_opts.c | 1 + 3 files changed, 24 insertions(+), 2 deletions(-) diff --git a/capture.c b/capture.c index f9f6788af8..daf653f611 100644 --- a/capture.c +++ b/capture.c @@ -82,6 +82,9 @@ capture_start(capture_options *capture_opts) /* close the currently loaded capture file */ cf_close(capture_opts->cf); + g_assert(capture_opts->state == CAPTURE_STOPPED); + capture_opts->state = CAPTURE_PREPARING; + /* try to start the capture child process */ ret = sync_pipe_start(capture_opts, capture_opts->save_file == NULL); if(!ret) { @@ -89,6 +92,8 @@ capture_start(capture_options *capture_opts) g_free(capture_opts->save_file); capture_opts->save_file = NULL; } + + capture_opts->state = CAPTURE_STOPPED; } return ret; @@ -209,6 +214,7 @@ capture_input_new_file(capture_options *capture_opts, gchar *new_file) int err; + g_assert(capture_opts->state == CAPTURE_PREPARING || capture_opts->state == CAPTURE_RUNNING); /*g_warning("New capture file: %s", new_file);*/ /* free the old filename */ @@ -251,6 +257,7 @@ capture_input_new_file(capture_options *capture_opts, gchar *new_file) cf_callback_invoke(cf_cb_live_capture_fixed_started, capture_opts); } + capture_opts->state = CAPTURE_RUNNING; return TRUE; } @@ -299,8 +306,10 @@ capture_input_closed(capture_options *capture_opts) int err; - /* if we have no file (happens if an error occured), do a fake start */ - if(capture_opts->save_file == NULL) { + g_assert(capture_opts->state == CAPTURE_PREPARING || capture_opts->state == CAPTURE_RUNNING); + + /* if we didn't started the capture (happens if an error occured), do a fake start */ + if(capture_opts->state == CAPTURE_PREPARING) { if(capture_opts->real_time_mode) { cf_callback_invoke(cf_cb_live_capture_update_started, capture_opts); } else { @@ -349,6 +358,8 @@ capture_input_closed(capture_options *capture_opts) } } + capture_opts->state = CAPTURE_STOPPED; + /* if we couldn't open a capture file, there's nothing more for us to do */ if(capture_opts->save_file == NULL) { cf_close(capture_opts->cf); diff --git a/capture.h b/capture.h index b903b2e71e..c7e3677f5c 100644 --- a/capture.h +++ b/capture.h @@ -34,6 +34,15 @@ /** Name we give to the child process when doing a "-S" capture. */ #define CHILD_NAME "ethereal-capture" + +/* Current state of capture engine. XXX - differentiate states */ +typedef enum { + CAPTURE_STOPPED, /**< stopped */ + CAPTURE_PREPARING, /**< preparing, but still no response from capture child */ + CAPTURE_RUNNING /**< capture child signalled ok, capture is running now */ +} capture_state; + + /** Capture options coming from user interface */ typedef struct capture_options_tag { /* general */ @@ -86,6 +95,7 @@ typedef struct capture_options_tag { #ifdef _WIN32 int signal_pipe_fd; /**< the pipe to signal the child */ #endif + capture_state state; /**< current state of the capture engine */ } capture_options; diff --git a/capture_opts.c b/capture_opts.c index 3c4f126dc2..938c2832b7 100644 --- a/capture_opts.c +++ b/capture_opts.c @@ -85,6 +85,7 @@ capture_opts_init(capture_options *capture_opts, void *cfile) #ifdef _WIN32 capture_opts->signal_pipe_fd = -1; #endif + capture_opts->state = CAPTURE_STOPPED; }