seperated capture dialog from capture.c and put into new gtk/capture_info_dlg.c
authorulfl <ulfl@f5534014-38df-0310-8fa8-9805f1628bb7>
Sat, 15 Nov 2003 08:48:14 +0000 (08:48 +0000)
committerulfl <ulfl@f5534014-38df-0310-8fa8-9805f1628bb7>
Sat, 15 Nov 2003 08:48:14 +0000 (08:48 +0000)
git-svn-id: http://anonsvn.wireshark.org/wireshark/trunk@8968 f5534014-38df-0310-8fa8-9805f1628bb7

capture.c
capture.h
gtk/Makefile.am
gtk/Makefile.nmake

index 3d4009a897463535f43d04d378b78d46d919e98d..336fe06b8944ab077c1e22837f1eabdda76fda8c 100644 (file)
--- a/capture.c
+++ b/capture.c
@@ -1,7 +1,7 @@
 /* capture.c
  * Routines for packet capture windows
  *
- * $Id: capture.c,v 1.214 2003/11/14 21:18:06 guy Exp $
+ * $Id: capture.c,v 1.215 2003/11/15 08:47:27 ulfl Exp $
  *
  * Ethereal - Network traffic analyzer
  * By Gerald Combs <gerald@ethereal.com>
@@ -195,14 +195,11 @@ static void wait_for_child(gboolean);
 #ifndef _WIN32
 static char *signame(int);
 #endif
-static void capture_delete_cb(GtkWidget *, GdkEvent *, gpointer);
-static void capture_stop_cb(GtkWidget *, gpointer);
 static void capture_pcap_cb(guchar *, const struct pcap_pkthdr *,
   const guchar *);
 static void get_capture_file_io_error(char *, int, const char *, int, gboolean);
 static void popup_errmsg(const char *);
 static void send_errmsg_to_parent(const char *);
-static float pct(gint, gint);
 static void stop_capture(int signo);
 
 typedef struct _loop_data {
@@ -1380,14 +1377,11 @@ static loop_data   ld;
 int
 capture(gboolean *stats_known, struct pcap_stat *stats)
 {
-  GtkWidget  *cap_w, *main_vb, *stop_bt, *counts_tb;
-  GtkWidget  *counts_fr, *running_tb, *running_label, *running_time;
   pcap_t     *pch;
   int         pcap_encap;
   int         file_snaplen;
   gchar       open_err_str[PCAP_ERRBUF_SIZE];
   gchar       lookup_net_err_str[PCAP_ERRBUF_SIZE];
-  gchar       label_str[64];
   bpf_u_int32 netnum, netmask;
   struct bpf_program fcode;
   const char *set_linktype_err_str;
@@ -1404,26 +1398,7 @@ capture(gboolean *stats_known, struct pcap_stat *stats)
   gboolean    close_ok;
   fd_set      set1;
   struct timeval timeout;
-  struct {
-      const gchar *title;
-      gint *value_ptr;
-      GtkWidget *label, *value, *percent;
-  } counts[] = {
-      { "Total", &ld.counts.total, NULL, NULL, NULL },
-      { "SCTP", &ld.counts.sctp, NULL, NULL, NULL },
-      { "TCP", &ld.counts.tcp, NULL, NULL, NULL },
-      { "UDP", &ld.counts.udp, NULL, NULL, NULL },
-      { "ICMP", &ld.counts.icmp, NULL, NULL, NULL },
-      { "ARP", &ld.counts.arp, NULL, NULL, NULL },
-      { "OSPF", &ld.counts.ospf, NULL, NULL, NULL },
-      { "GRE", &ld.counts.gre, NULL, NULL, NULL },
-      { "NetBIOS", &ld.counts.netbios, NULL, NULL, NULL },
-      { "IPX", &ld.counts.ipx, NULL, NULL, NULL },
-      { "VINES", &ld.counts.vines, NULL, NULL, NULL },
-      { "Other", &ld.counts.other, NULL, NULL, NULL }
-  };
-
-#define N_COUNTS (sizeof counts / sizeof counts[0])
+  capture_info   capture_ui;
 
 #ifdef _WIN32
   WORD        wVersionRequested;
@@ -1738,84 +1713,10 @@ capture(gboolean *stats_known, struct pcap_stat *stats)
     write(1, &capstart_msg, 1);
   }
 
-  cap_w = gtk_window_new(GTK_WINDOW_TOPLEVEL);
-  gtk_window_set_title(GTK_WINDOW(cap_w), "Ethereal: Capture");
-  gtk_window_set_modal(GTK_WINDOW(cap_w), TRUE);
-
-  /* Container for capture display widgets */
-  main_vb = gtk_vbox_new(FALSE, 1);
-  gtk_container_border_width(GTK_CONTAINER(main_vb), 5);
-  gtk_container_add(GTK_CONTAINER(cap_w), main_vb);
-  gtk_widget_show(main_vb);
-
-  counts_fr = gtk_frame_new("Captured Frames");
-  gtk_box_pack_start(GTK_BOX(main_vb), counts_fr, FALSE, FALSE, 3);
-  gtk_widget_show(counts_fr);
-
-  /* Individual statistic elements */
-  counts_tb = gtk_table_new(N_COUNTS, 3, TRUE);
-  gtk_container_add(GTK_CONTAINER(counts_fr), counts_tb);
-  gtk_container_border_width(GTK_CONTAINER(counts_tb), 5);
-  gtk_widget_show(counts_tb);
-
-  for (i = 0; i < N_COUNTS; i++) {
-      counts[i].label = gtk_label_new(counts[i].title);
-      gtk_misc_set_alignment(GTK_MISC(counts[i].label), 0.0f, 0.0f);
-
-      counts[i].value = gtk_label_new("0");
-      gtk_misc_set_alignment(GTK_MISC(counts[i].value), 0.0f, 0.0f);
-
-      counts[i].percent = gtk_label_new("0.0%");
-      gtk_misc_set_alignment(GTK_MISC(counts[i].percent), 0.0f, 0.0f);
-
-      gtk_table_attach_defaults(GTK_TABLE(counts_tb),
-                                counts[i].label, 0, 1, i, i + 1);
-
-      gtk_table_attach(GTK_TABLE(counts_tb),
-                       counts[i].value,
-                       1, 2, i, i + 1, 0, 0, 5, 0);
-
-      gtk_table_attach_defaults(GTK_TABLE(counts_tb),
-                                counts[i].percent, 2, 3, i, i + 1);
-
-      gtk_widget_show(counts[i].label);
-      gtk_widget_show(counts[i].value);
-      gtk_widget_show(counts[i].percent);
-  }
-
-  /* Running time */
-  running_tb = gtk_table_new(1, 3, TRUE);
-  gtk_box_pack_start(GTK_BOX(main_vb), running_tb, FALSE, FALSE, 3);
-  gtk_widget_show(running_tb);
-
-  running_label = gtk_label_new("Running");
-  gtk_misc_set_alignment(GTK_MISC(running_label), 0.0f, 0.0f);
-  gtk_widget_show(running_label);
-  gtk_table_attach_defaults(GTK_TABLE(running_tb),
-                                running_label, 0, 1, 0, 1);
-
-  running_time = gtk_label_new("00:00:00");
-  gtk_misc_set_alignment(GTK_MISC(running_time), 0.0f, 0.0f);
-  gtk_widget_show(running_time);
-  gtk_table_attach(GTK_TABLE(running_tb),
-                       running_time,
-                       1, 2, 0, 1, 0, 0, 5, 0);
-
-  /* allow user to either click a stop button, or the close button on
-       the window to stop a capture in progress. */
-  stop_bt = gtk_button_new_with_label ("Stop");
-  gtk_signal_connect(GTK_OBJECT(stop_bt), "clicked",
-    GTK_SIGNAL_FUNC(capture_stop_cb), (gpointer) &ld);
-  gtk_signal_connect(GTK_OBJECT(cap_w), "delete_event",
-       GTK_SIGNAL_FUNC(capture_delete_cb), (gpointer) &ld);
-  gtk_box_pack_start(GTK_BOX(main_vb), stop_bt, FALSE, FALSE, 3);
-  GTK_WIDGET_SET_FLAGS(stop_bt, GTK_CAN_DEFAULT);
-  gtk_widget_grab_default(stop_bt);
-  GTK_WIDGET_SET_FLAGS(stop_bt, GTK_CAN_DEFAULT);
-  gtk_widget_grab_default(stop_bt);
-  gtk_widget_show(stop_bt);
-
-  gtk_widget_show(cap_w);
+  /* start capture info dialog */
+  capture_ui.callback_data  = &ld;
+  capture_ui.counts         = &ld.counts;
+  capture_info_create(&capture_ui);
 
   start_time = time(NULL);
   upd_time = time(NULL);
@@ -1845,6 +1746,9 @@ capture(gboolean *stats_known, struct pcap_stat *stats)
     cnd_ring_timeout =
        cnd_new(CND_CLASS_TIMEOUT, capture_opts.ringbuffer_duration);
 
+
+  /* WOW, everything is prepared! */
+  /* please fasten your seat belts, we will enter now the actual capture loop */
   while (ld.go) {
     while (gtk_events_pending()) gtk_main_iteration();
 
@@ -1969,28 +1873,19 @@ capture(gboolean *stats_known, struct pcap_stat *stats)
     if (cur_time > upd_time) {
       upd_time = cur_time;
 
+      /*if (pcap_stats(pch, stats) >= 0) {
+        *stats_known = TRUE;
+      }*/
+
+       /* Let the parent process know. */
       /* calculate and display running time */
       cur_time -= start_time;
-      snprintf(label_str, sizeof(label_str), "%02ld:%02ld:%02ld", 
-               (long)(cur_time/3600), (long)((cur_time%3600)/60),
-               (long)(cur_time%60));
-      gtk_label_set(GTK_LABEL(running_time), label_str);
+      capture_ui.running_time   = cur_time;
+      capture_ui.new_packets    = ld.sync_packets;
+      capture_info_update(&capture_ui);
 
       if (ld.sync_packets) {
-
-        for (i = 0; i < N_COUNTS; i++) {
-            snprintf(label_str, sizeof(label_str), "%d",
-                     *counts[i].value_ptr);
-
-            gtk_label_set(GTK_LABEL(counts[i].value), label_str);
-
-            snprintf(label_str, sizeof(label_str), "(%.1f%%)",
-                     pct(*counts[i].value_ptr, ld.counts.total));
-
-            gtk_label_set(GTK_LABEL(counts[i].percent), label_str);
-        }
-
-        /* do sync here, too */
+        /* do sync here */
         fflush(wtap_dump_file(ld.pdh));
 
         if (capture_child) {
@@ -2104,8 +1999,7 @@ capture(gboolean *stats_known, struct pcap_stat *stats)
   WSACleanup();
 #endif
 
-  gtk_grab_remove(GTK_WIDGET(cap_w));
-  gtk_widget_destroy(GTK_WIDGET(cap_w));
+  capture_info_destroy(&capture_ui);
 
   return write_ok;
 
@@ -2223,33 +2117,21 @@ send_errmsg_to_parent(const char *errmsg)
     write(1, errmsg, msglen);
 }
 
-static float
-pct(gint num, gint denom) {
-  if (denom) {
-    return (float) num * 100.0 / (float) denom;
-  } else {
-    return 0.0;
-  }
-}
-
 static void
 stop_capture(int signo _U_)
 {
   ld.go = FALSE;
 }
 
-static void
-capture_delete_cb(GtkWidget *w _U_, GdkEvent *event _U_, gpointer data) {
-  capture_stop_cb(NULL, data);
-}
-
-static void
-capture_stop_cb(GtkWidget *w _U_, gpointer data) {
-  loop_data *ld = (loop_data *) data;
+void capture_ui_stop_callback(
+gpointer               callback_data)
+{
+  loop_data *ld = (loop_data *) callback_data;
 
   ld->go = FALSE;
 }
 
+
 void
 capture_stop(void)
 {
index 609220dc62cf99e4c1732735b567222c081b91aa..2826bac7c0d0b46bfdb381645c4cc7080a8cad74 100644 (file)
--- a/capture.h
+++ b/capture.h
@@ -1,7 +1,7 @@
 /* capture.h
  * Definitions for packet capture windows
  *
- * $Id: capture.h,v 1.37 2003/11/01 02:30:14 guy Exp $
+ * $Id: capture.h,v 1.38 2003/11/15 08:47:28 ulfl Exp $
  *
  * Ethereal - Network traffic analyzer
  * By Gerald Combs <gerald@ethereal.com>
@@ -73,6 +73,39 @@ void   capture_stop(void);
 /* Terminate the capture child cleanly when exiting. */
 void   kill_capture_child(void);
 
+
+/* XXX: improve this macro (put something like this into epan/packet.h?) */
+#define CAPTURE_PACKET_COUNTS sizeof(packet_counts) / sizeof (gint)
+
+typedef struct {
+    /* handles */
+    gpointer        callback_data;  /* capture callback handle */
+    gpointer        ui;             /* user interfaces own handle */
+
+    /* capture info */
+    packet_counts   *counts;        /* protocol specific counters */
+    time_t          running_time;   /* running time since last update */
+    gint            new_packets;    /* packets since last update */
+} capture_info;
+
+
+/* create the capture info dialog */
+extern void capture_info_create(
+capture_info    *cinfo);
+
+/* Update the capture info counters in the dialog */
+extern void capture_info_update(
+capture_info    *cinfo);
+
+/* destroy the capture info dialog again */
+extern void capture_info_destroy(
+capture_info    *cinfo);
+
+/* ui calls this, when user wants to stop capturing */
+extern void capture_ui_stop_callback(
+gpointer               callback_data);
+
+
 #endif /* HAVE_LIBPCAP */
 
 #define EMPTY_FILTER ""
index 5730578550244799414fdf7c201705010b5ed01d..ab57244fc1547c1a35b2d2899b4e9a65cc7ec429 100644 (file)
@@ -1,7 +1,7 @@
 # Makefile.am
 # Automake file for the GTK interface routines for Ethereal
 #
-# $Id: Makefile.am,v 1.73 2003/11/05 09:04:17 sahlberg Exp $
+# $Id: Makefile.am,v 1.74 2003/11/15 08:47:29 ulfl Exp $
 #
 # Ethereal - Network traffic analyzer
 # By Gerald Combs <gerald@ethereal.com>
@@ -64,6 +64,7 @@ libui_a_SOURCES = \
        capture_dlg.h   \
        capture_prefs.c \
        capture_prefs.h \
+       capture_info_dlg.c \
        color_dlg.c     \
        color_dlg.h     \
        color_filters.c \
@@ -151,6 +152,7 @@ libui_a_SOURCES = \
        capture_dlg.h   \
        capture_prefs.c \
        capture_prefs.h \
+       capture_info_dlg.c \
        color_dlg.c     \
        color_dlg.h     \
        color_filters.c \
index bb048ea3eb3c222f45983d7643a87951af97e4d9..eb7f08546ccae57eda40cd5720e8f4c9c91b6ddd 100644 (file)
@@ -1,7 +1,7 @@
 ## Makefile for building ethereal.exe with Microsoft C and nmake
 ## Use: $(MAKE) /$(MAKEFLAGS) -f makefile.nmake
 #
-# $Id: Makefile.nmake,v 1.58 2003/11/07 23:26:15 guy Exp $
+# $Id: Makefile.nmake,v 1.59 2003/11/15 08:48:14 ulfl Exp $
 
 include ..\config.nmake
 
@@ -57,6 +57,7 @@ OBJECTS = \
        capture_combo_utils.obj \
        capture_dlg.obj \
        capture_prefs.obj \
+       capture_info_dlg.obj \
        color_dlg.obj    \
        color_filters.obj \
        column_prefs.obj \