From Michael Lum:
[obnox/wireshark/wip.git] / gtk / gsm_map_summary.c
1 /* gsm_map_summary.c
2  * Routines for GSM MAP Statictics summary window
3  *
4  * Copyright 2004, Michael Lum <mlum [AT] telostech.com>
5  * In association with Telos Technology Inc.
6  *
7  * Modified from summary_dlg.c
8  *
9  * $Id: gsm_map_summary.c,v 1.1 2004/04/21 17:57:31 guy Exp $
10  *
11  * Ethereal - Network traffic analyzer
12  * By Gerald Combs <gerald@ethereal.com>
13  * Copyright 1998 Gerald Combs
14  *
15  * This program is free software; you can redistribute it and/or
16  * modify it under the terms of the GNU General Public License
17  * as published by the Free Software Foundation; either version 2
18  * of the License, or (at your option) any later version.
19  *
20  * This program is distributed in the hope that it will be useful,
21  * but WITHOUT ANY WARRANTY; without even the implied warranty of
22  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
23  * GNU General Public License for more details.
24  *
25  * You should have received a copy of the GNU General Public License
26  * along with this program; if not, write to the Free Software
27  * Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA  02111-1307, USA.
28  */
29
30 #ifdef HAVE_CONFIG_H
31 # include "config.h"
32 #endif
33
34 #include <gtk/gtk.h>
35
36 #include <wtap.h>
37
38 #include "epan/packet_info.h"
39 #include "epan/epan.h"
40 #include "epan/value_string.h"
41 #include "tap_menu.h"
42 #include "summary.h"
43 #include "dlg_utils.h"
44 #include "ui_util.h"
45 #include "compat_macros.h"
46 #include "tap.h"
47
48 #include "packet-gsm_map.h"
49 #include "gsm_map_stat.h"
50
51 #define SUM_STR_MAX 1024
52
53
54 static void
55 add_string_to_box(gchar *str, GtkWidget *box)
56 {
57   GtkWidget *lb;
58   lb = gtk_label_new(str);
59   gtk_misc_set_alignment(GTK_MISC(lb), 0.0, 0.5);
60   gtk_box_pack_start(GTK_BOX(box), lb,FALSE,FALSE, 0);
61   gtk_widget_show(lb);
62 }
63
64
65 void
66 gsm_map_stat_gtk_sum_cb(GtkWidget *w _U_, gpointer d _U_)
67 {
68   summary_tally summary;
69   GtkWidget     *sum_open_w,
70                 *main_vb, *file_fr, *data_fr, *file_box,
71                 *data_box, *bbox, *close_bt,
72                 *invoke_fr, *invoke_box,
73                 *rr_fr, *rr_box,
74                 *tot_fr, *tot_box;
75
76   gchar         string_buff[SUM_STR_MAX];
77   double        seconds;
78   int           i;
79   int           tot_invokes, tot_rr;
80   double        tot_invokes_size, tot_rr_size;
81
82   /* initialize the tally */
83   summary_fill_in(&summary);
84
85   /* initial compututations */
86   seconds = summary.stop_time - summary.start_time;
87
88   sum_open_w = window_new(GTK_WINDOW_TOPLEVEL, "GSM MAP Statistics: Summary");
89
90   /* Container for each row of widgets */
91   main_vb = gtk_vbox_new(FALSE, 3);
92   gtk_container_border_width(GTK_CONTAINER(main_vb), 5);
93   gtk_container_add(GTK_CONTAINER(sum_open_w), main_vb);
94   gtk_widget_show(main_vb);
95
96   /* File frame */
97   file_fr = gtk_frame_new("File");
98   gtk_container_add(GTK_CONTAINER(main_vb), file_fr);
99   gtk_widget_show(file_fr);
100
101   file_box = gtk_vbox_new(FALSE, 3);
102   gtk_container_add(GTK_CONTAINER(file_fr), file_box);
103   gtk_widget_show(file_box);
104
105   /* filename */
106   g_snprintf(string_buff, SUM_STR_MAX, "Name: %s", summary.filename);
107   add_string_to_box(string_buff, file_box);
108
109   /* length */
110   g_snprintf(string_buff, SUM_STR_MAX, "Length: %lu", summary.file_length);
111   add_string_to_box(string_buff, file_box);
112
113   /* format */
114   g_snprintf(string_buff, SUM_STR_MAX, "Format: %s", wtap_file_type_string(summary.encap_type));
115   add_string_to_box(string_buff, file_box);
116
117   if (summary.has_snap) {
118     /* snapshot length */
119     g_snprintf(string_buff, SUM_STR_MAX, "Snapshot length: %u", summary.snap);
120     add_string_to_box(string_buff, file_box);
121   }
122
123   /* Data frame */
124   data_fr = gtk_frame_new("Data");
125   gtk_container_add(GTK_CONTAINER(main_vb), data_fr);
126   gtk_widget_show(data_fr);
127
128   data_box = gtk_vbox_new(FALSE, 3);
129   gtk_container_add(GTK_CONTAINER(data_fr), data_box);
130   gtk_widget_show(data_box);
131
132   /* seconds */
133   g_snprintf(string_buff, SUM_STR_MAX, "Elapsed time: %.3f seconds", summary.elapsed_time);
134   add_string_to_box(string_buff, data_box);
135
136   g_snprintf(string_buff, SUM_STR_MAX, "Between first and last packet: %.3f seconds", seconds);
137   add_string_to_box(string_buff, data_box);
138
139   /* Packet count */
140   g_snprintf(string_buff, SUM_STR_MAX, "Packet count: %i", summary.packet_count);
141   add_string_to_box(string_buff, data_box);
142
143   tot_invokes = 0;
144   tot_invokes_size = 0;
145   for (i=0; i < GSM_MAP_MAX_NUM_OPR_CODES; i++)
146   {
147     tot_invokes += gsm_map_stat.opr_code[i];
148     tot_invokes_size += gsm_map_stat.size[i];
149   }
150
151   tot_rr = 0;
152   tot_rr_size = 0;
153   for (i=0; i < GSM_MAP_MAX_NUM_OPR_CODES; i++)
154   {
155     tot_rr += gsm_map_stat.opr_code_rr[i];
156     tot_rr_size += gsm_map_stat.size_rr[i];
157   }
158
159   /* Invoke frame */
160   invoke_fr = gtk_frame_new("Invokes");
161   gtk_container_add(GTK_CONTAINER(main_vb), invoke_fr);
162   gtk_widget_show(invoke_fr);
163
164   invoke_box = gtk_vbox_new(FALSE, 3);
165   gtk_container_add(GTK_CONTAINER(invoke_fr), invoke_box);
166   gtk_widget_show(invoke_box);
167
168   /* Total number of invokes */
169   g_snprintf(string_buff, SUM_STR_MAX, "Total number of Invokes: %u", tot_invokes);
170   add_string_to_box(string_buff, invoke_box);
171
172   /* Total number of invokes per second */
173   g_snprintf(string_buff, SUM_STR_MAX, "Total number of Invokes per second: %.2f", tot_invokes/seconds);
174   add_string_to_box(string_buff, invoke_box);
175
176   /* Total size of invokes */
177   g_snprintf(string_buff, SUM_STR_MAX, "Total number of bytes for Invokes: %.0f", tot_invokes_size);
178   add_string_to_box(string_buff, invoke_box);
179
180   /* Average size of invokes */
181   g_snprintf(string_buff, SUM_STR_MAX, "Average number of bytes per Invoke: %.2f", tot_invokes_size/tot_invokes);
182   add_string_to_box(string_buff, invoke_box);
183
184   /* Average size of invokes per second */
185   g_snprintf(string_buff, SUM_STR_MAX, "Average number of bytes per second: %.2f", tot_invokes_size/seconds);
186   add_string_to_box(string_buff, invoke_box);
187
188   /* Return Results frame */
189   rr_fr = gtk_frame_new("Return Results");
190   gtk_container_add(GTK_CONTAINER(main_vb), rr_fr);
191   gtk_widget_show(rr_fr);
192
193   rr_box = gtk_vbox_new(FALSE, 3);
194   gtk_container_add(GTK_CONTAINER(rr_fr), rr_box);
195   gtk_widget_show(rr_box);
196
197   /* Total number of return results */
198   g_snprintf(string_buff, SUM_STR_MAX, "Total number of Return Results: %u", tot_rr);
199   add_string_to_box(string_buff, rr_box);
200
201   /* Total number of return results per second */
202   g_snprintf(string_buff, SUM_STR_MAX, "Total number of Return Results per second: %.2f", tot_rr/seconds);
203   add_string_to_box(string_buff, rr_box);
204
205   /* Total size of return results */
206   g_snprintf(string_buff, SUM_STR_MAX, "Total number of bytes for Return Results: %.0f", tot_rr_size);
207   add_string_to_box(string_buff, rr_box);
208
209   /* Average size of return results */
210   g_snprintf(string_buff, SUM_STR_MAX, "Average number of bytes per Return Result: %.2f", tot_rr_size/tot_rr);
211   add_string_to_box(string_buff, rr_box);
212
213   /* Average size of return results per second */
214   g_snprintf(string_buff, SUM_STR_MAX, "Average number of bytes per second: %.2f", tot_rr_size/seconds);
215   add_string_to_box(string_buff, rr_box);
216
217   /* Totals frame */
218   tot_fr = gtk_frame_new("Totals");
219   gtk_container_add(GTK_CONTAINER(main_vb), tot_fr);
220   gtk_widget_show(tot_fr);
221
222   tot_box = gtk_vbox_new(FALSE, 3);
223   gtk_container_add(GTK_CONTAINER(tot_fr), tot_box);
224   gtk_widget_show(tot_box);
225
226   /* Total number of return results */
227   g_snprintf(string_buff, SUM_STR_MAX, "Total number of GSM MAP messages: %u", tot_invokes + tot_rr);
228   add_string_to_box(string_buff, tot_box);
229
230   g_snprintf(string_buff, SUM_STR_MAX, "Total number of GSM MAP messages per second: %.2f",
231     (tot_invokes + tot_rr)/seconds);
232   add_string_to_box(string_buff, tot_box);
233
234   g_snprintf(string_buff, SUM_STR_MAX, "Total number of bytes for GSM MAP messages: %.0f", tot_invokes_size + tot_rr_size);
235   add_string_to_box(string_buff, tot_box);
236
237   g_snprintf(string_buff, SUM_STR_MAX, "Average number of bytes per GSM MAP messages: %.2f",
238     (tot_invokes_size + tot_rr_size)/(tot_invokes + tot_rr));
239   add_string_to_box(string_buff, tot_box);
240
241   g_snprintf(string_buff, SUM_STR_MAX, "Average number of bytes second: %.2f",
242     (tot_invokes_size + tot_rr_size)/seconds);
243   add_string_to_box(string_buff, tot_box);
244
245
246   /* Button row. */
247   bbox = dlg_button_row_new(GTK_STOCK_CLOSE, NULL);
248   gtk_container_add(GTK_CONTAINER(main_vb), bbox);
249   gtk_widget_show(bbox);
250
251   close_bt = OBJECT_GET_DATA(bbox, GTK_STOCK_CLOSE);
252   SIGNAL_CONNECT_OBJECT(close_bt, "clicked", gtk_widget_destroy, sum_open_w);
253   gtk_widget_grab_default(close_bt);
254
255   /* Catch the "key_press_event" signal in the window, so that we can catch
256      the ESC key being pressed and act as if the "Close" button had
257      been selected. */
258   dlg_set_cancel(sum_open_w, close_bt);
259
260   gtk_window_set_position(GTK_WINDOW(sum_open_w), GTK_WIN_POS_MOUSE);
261   gtk_widget_show(sum_open_w);
262 }
263
264
265 void
266 register_tap_listener_gtkgsm_map_summary(void)
267 {
268     register_tap_menu_item("GSM/MAP Summary",  REGISTER_TAP_GROUP_NONE,
269         gsm_map_stat_gtk_sum_cb, NULL, NULL, NULL);
270 }