Add SimpleStatisticsDialog.

To do:
- Refactor dynamic menu item placement.

Change-Id: I087de9f2fa3c2ff7dc08e5d54bc9c1b984fdd7b1
Reviewed-on: https://code.wireshark.org/review/9561
Reviewed-by: Gerald Combs <gerald@wireshark.org>
This commit is contained in:
Gerald Combs 2015-07-07 16:18:00 -07:00
parent d3f71f923a
commit 4eca268935
11 changed files with 381 additions and 9 deletions

View File

@ -7499,7 +7499,7 @@ proto_register_bootp(void)
static new_stat_tap_ui bootp_stat_table = {
REGISTER_STAT_GROUP_UNSORTED,
"BOOTP-DHCP Statistics",
"DHCP (BOOTP) Statistics",
"bootp",
"bootp,stat",
bootp_stat_init,

View File

@ -209,7 +209,7 @@ void new_stat_tap_init_table_row(new_stat_tap_table *stat_table, guint table_ind
}
stat_tap_table_item_type* new_stat_tap_get_field_data(new_stat_tap_table *stat_table, guint table_index, guint field_index)
stat_tap_table_item_type* new_stat_tap_get_field_data(const new_stat_tap_table *stat_table, guint table_index, guint field_index)
{
stat_tap_table_item_type* field_value;
g_assert(table_index < stat_table->num_elements);

View File

@ -100,7 +100,7 @@ typedef struct _stat_tap_table_item
stat_tap_table_item_enum type;
tap_alignment_type align;
const char* column_name;
const char* field_format; /* printf style formating of field */
const char* field_format; /* printf style formating of field. Currently unused? */
} stat_tap_table_item;
@ -116,9 +116,9 @@ typedef struct _stat_tap_table
} new_stat_tap_table;
typedef void (*new_stat_tap_gui_init_cb)(new_stat_tap_table* stat_table, void* gui_data);
typedef void (*new_stat_tap_gui_reset_cb)(new_stat_tap_table* stat_table, void* gui_data);
typedef void (*new_stat_tap_gui_free_cb)(new_stat_tap_table* stat_table, void* gui_data);
typedef void (*new_stat_tap_gui_init_cb)(new_stat_tap_table* stat_table, void* gui_data); /* GTK+ only? */
typedef void (*new_stat_tap_gui_reset_cb)(new_stat_tap_table* stat_table, void* gui_data); /* GTK+ only? */
typedef void (*new_stat_tap_gui_free_cb)(new_stat_tap_table* stat_table, void* gui_data); /* GTK+ only? */
/*
* UI information for a tap.
@ -164,7 +164,7 @@ WS_DLL_PUBLIC new_stat_tap_table* new_stat_tap_init_table(const char *name, int
WS_DLL_PUBLIC void new_stat_tap_add_table(new_stat_tap_ui* new_stat, new_stat_tap_table* table);
WS_DLL_PUBLIC void new_stat_tap_init_table_row(new_stat_tap_table *stat_table, guint table_index, guint num_fields, stat_tap_table_item_type* fields);
WS_DLL_PUBLIC stat_tap_table_item_type* new_stat_tap_get_field_data(new_stat_tap_table *stat_table, guint table_index, guint field_index);
WS_DLL_PUBLIC stat_tap_table_item_type* new_stat_tap_get_field_data(const new_stat_tap_table *stat_table, guint table_index, guint field_index);
WS_DLL_PUBLIC void new_stat_tap_set_field_data(new_stat_tap_table *stat_table, guint table_index, guint field_index, stat_tap_table_item_type* field_data);
WS_DLL_PUBLIC void reset_stat_table(new_stat_tap_ui* new_stat, new_stat_tap_gui_reset_cb gui_callback, void *callback_data);
WS_DLL_PUBLIC void free_stat_table(new_stat_tap_ui* new_stat, new_stat_tap_gui_free_cb gui_callback, void *callback_data);

View File

@ -112,6 +112,7 @@ set(WIRESHARK_QT_HEADERS
splash_overlay.h
stats_tree_dialog.h
service_response_time_dialog.h
simple_statistics_dialog.h
syntax_line_edit.h
tap_parameter_dialog.h
tcp_stream_dialog.h
@ -234,6 +235,7 @@ set(WIRESHARK_QT_SRC
sequence_dialog.cpp
service_response_time_dialog.cpp
simple_dialog.cpp
simple_statistics_dialog.cpp
splash_overlay.cpp
sparkline_delegate.cpp
stock_icon.cpp

View File

@ -219,6 +219,7 @@ MOC_HDRS = \
sequence_dialog.h \
service_response_time_dialog.h \
simple_dialog.h \
simple_statistics_dialog.h \
sparkline_delegate.h \
splash_overlay.h \
stats_tree_dialog.h \
@ -447,6 +448,7 @@ WIRESHARK_QT_SRC = \
sequence_dialog.cpp \
service_response_time_dialog.cpp \
simple_dialog.cpp \
simple_statistics_dialog.cpp \
sparkline_delegate.cpp \
splash_overlay.cpp \
stats_tree_dialog.cpp \

View File

@ -332,6 +332,7 @@ HEADERS += $$HEADERS_WS_C \
sctp_graph_byte_dialog.h \
search_frame.h \
service_response_time_dialog.h \
simple_statistics_dialog.h \
splash_overlay.h \
stats_tree_dialog.h \
tango_colors.h \
@ -720,6 +721,7 @@ SOURCES += \
sequence_dialog.cpp \
service_response_time_dialog.cpp \
simple_dialog.cpp \
simple_statistics_dialog.cpp \
sparkline_delegate.cpp \
splash_overlay.cpp \
stats_tree_dialog.cpp \

View File

@ -1997,6 +1997,14 @@ void MainWindow::addStatisticsMenus()
main_ui_->menuServiceResponseTime->addAction(sg_action);
connect(sg_action, SIGNAL(triggered(bool)), this, SLOT(openTapParameterDialog()));
}
// Telephony
sg_actions = wsApp->statisticsGroupItems(REGISTER_STAT_GROUP_TELEPHONY);
foreach (QAction *sg_action, sg_actions) {
main_ui_->menuTelephony->addAction(sg_action);
connect(sg_action, SIGNAL(triggered(bool)), this, SLOT(openTapParameterDialog()));
}
}
void MainWindow::externalMenuHelper(ext_menu_t * menu, QMenu * subMenu, gint depth)

View File

@ -32,8 +32,6 @@
#include "qt_ui_utils.h"
#include "wireshark_application.h"
#include <QDebug>
static QHash<const QString, register_rtd_t *> cfg_str_to_rtd_;
extern "C" {

View File

@ -0,0 +1,283 @@
/* simple_statistics_dialog.cpp
*
* 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., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA.
*/
#include "simple_statistics_dialog.h"
#include "file.h"
#include "epan/stat_tap_ui.h"
#include <QMessageBox>
#include <QTreeWidget>
#include "wireshark_application.h"
// To do:
// - Hide rows with zero counts.
static QHash<const QString, new_stat_tap_ui *> cfg_str_to_stu_;
extern "C" {
static void
simple_stat_init(const char *args, void*) {
QStringList args_l = QString(args).split(',');
if (args_l.length() > 1) {
QString simple_stat = QString("%1,%2").arg(args_l[0]).arg(args_l[1]);
QString filter;
if (args_l.length() > 2) {
filter = QStringList(args_l.mid(2)).join(",");
}
wsApp->emitTapParameterSignal(simple_stat, filter, NULL);
}
}
}
void register_simple_stat_tables(gpointer data, gpointer) {
new_stat_tap_ui *stu = (new_stat_tap_ui*)data;
cfg_str_to_stu_[stu->cli_string] = stu;
TapParameterDialog::registerDialog(
stu->title,
stu->cli_string,
stu->group,
simple_stat_init,
SimpleStatisticsDialog::createSimpleStatisticsDialog);
}
enum {
simple_row_type_ = 1000
};
class SimpleStatisticsTreeWidgetItem : public QTreeWidgetItem
{
public:
SimpleStatisticsTreeWidgetItem(QTreeWidget *parent, int num_fields, const stat_tap_table_item_type *fields) :
QTreeWidgetItem (parent, simple_row_type_),
num_fields_(num_fields),
fields_(fields)
{
}
void draw() {
for (int i = 0; i < num_fields_ && i < treeWidget()->columnCount(); i++) {
switch (fields_[i].type) {
case TABLE_ITEM_UINT:
setText(i, QString::number(fields_[i].value.uint_value));
break;
case TABLE_ITEM_INT:
setText(i, QString::number(fields_[i].value.int_value));
break;
case TABLE_ITEM_STRING:
setText(i, fields_[i].value.string_value);
break;
case TABLE_ITEM_FLOAT:
setText(i, QString::number(fields_[i].value.float_value, 'f', 6));
break;
case TABLE_ITEM_ENUM:
setText(i, QString::number(fields_[i].value.enum_value));
break;
default:
break;
}
}
}
bool operator< (const QTreeWidgetItem &other) const
{
int col = treeWidget()->sortColumn();
if (other.type() != simple_row_type_ || col >= num_fields_) {
return QTreeWidgetItem::operator< (other);
}
const SimpleStatisticsTreeWidgetItem *other_row = static_cast<const SimpleStatisticsTreeWidgetItem *>(&other);
switch (fields_[col].type) {
case TABLE_ITEM_UINT:
return fields_[col].value.uint_value < other_row->fields_[col].value.uint_value;
case TABLE_ITEM_INT:
return fields_[col].value.int_value < other_row->fields_[col].value.int_value;
case TABLE_ITEM_STRING:
return g_strcmp0(fields_[col].value.string_value, other_row->fields_[col].value.string_value) < 0;
case TABLE_ITEM_FLOAT:
return fields_[col].value.float_value < other_row->fields_[col].value.float_value;
case TABLE_ITEM_ENUM:
return fields_[col].value.enum_value < other_row->fields_[col].value.enum_value;
default:
break;
}
return QTreeWidgetItem::operator< (other);
}
QList<QVariant> rowData() {
QList<QVariant> row_data;
for (int i = 0; i < num_fields_ && i < columnCount(); i++) {
switch (fields_[i].type) {
case TABLE_ITEM_UINT:
row_data << fields_[i].value.uint_value;
break;
case TABLE_ITEM_INT:
row_data << fields_[i].value.int_value;
break;
case TABLE_ITEM_STRING:
row_data << fields_[i].value.string_value;
break;
case TABLE_ITEM_FLOAT:
row_data << fields_[i].value.float_value;
break;
case TABLE_ITEM_ENUM:
row_data << fields_[i].value.enum_value;
break;
default:
break;
}
}
return row_data;
}
private:
const int num_fields_;
const stat_tap_table_item_type *fields_;
};
SimpleStatisticsDialog::SimpleStatisticsDialog(QWidget &parent, CaptureFile &cf, struct _new_stat_tap_ui *stu, const QString filter, int help_topic) :
TapParameterDialog(parent, cf, help_topic),
stu_(stu)
{
setWindowSubtitle(stu_->title);
QStringList header_labels;
for (int col = 0; col < (int) stu_->nfields; col++) {
header_labels << stu_->fields[col].column_name;
}
statsTreeWidget()->setHeaderLabels(header_labels);
for (int col = 0; col < (int) stu_->nfields; col++) {
if (stu_->fields[col].align == TAP_ALIGN_RIGHT) {
statsTreeWidget()->headerItem()->setTextAlignment(col, Qt::AlignRight);
}
}
setDisplayFilter(filter);
}
TapParameterDialog *SimpleStatisticsDialog::createSimpleStatisticsDialog(QWidget &parent, const QString cfg_str, const QString filter, CaptureFile &cf)
{
if (!cfg_str_to_stu_.contains(cfg_str)) {
// XXX MessageBox?
return NULL;
}
new_stat_tap_ui *stu = cfg_str_to_stu_[cfg_str];
return new SimpleStatisticsDialog(parent, cf, stu, filter);
}
void SimpleStatisticsDialog::addSimpleStatisticsTable(const _stat_tap_table *st_table)
{
// Hierarchy:
// - tables (GTK+ UI only supports one currently)
// - elements (rows?)
// - fields (columns?)
// For multiple table support we might want to add them as subtrees, with
// the top-level tree item text set to the column labels for that table.
for (guint element = 0; element < st_table->num_elements; element++) {
stat_tap_table_item_type* fields = new_stat_tap_get_field_data(st_table, element, 0);
new SimpleStatisticsTreeWidgetItem(statsTreeWidget(), st_table->num_fields, fields);
}
}
void SimpleStatisticsDialog::tapReset(void *sd_ptr)
{
new_stat_data_t *sd = (new_stat_data_t*) sd_ptr;
SimpleStatisticsDialog *ss_dlg = static_cast<SimpleStatisticsDialog *>(sd->user_data);
if (!ss_dlg) return;
reset_stat_table(sd->new_stat_tap_data, NULL, NULL);
ss_dlg->statsTreeWidget()->clear();
guint table_index = 0;
new_stat_tap_table* st_table = g_array_index(sd->new_stat_tap_data->tables, new_stat_tap_table*, table_index);
ss_dlg->addSimpleStatisticsTable(st_table);
}
void SimpleStatisticsDialog::tapDraw(void *sd_ptr)
{
new_stat_data_t *sd = (new_stat_data_t*) sd_ptr;
SimpleStatisticsDialog *ss_dlg = static_cast<SimpleStatisticsDialog *>(sd->user_data);
if (!ss_dlg) return;
QTreeWidgetItemIterator it(ss_dlg->statsTreeWidget());
while (*it) {
if ((*it)->type() == simple_row_type_) {
SimpleStatisticsTreeWidgetItem *ss_ti = static_cast<SimpleStatisticsTreeWidgetItem *>((*it));
ss_ti->draw();
}
++it;
}
for (int i = 0; i < ss_dlg->statsTreeWidget()->columnCount() - 1; i++) {
ss_dlg->statsTreeWidget()->resizeColumnToContents(i);
}
}
void SimpleStatisticsDialog::fillTree()
{
new_stat_data_t stat_data;
stat_data.new_stat_tap_data = stu_;
stat_data.user_data = this;
stu_->stat_tap_init_cb(stu_, NULL, NULL);
GString *error_string = register_tap_listener(stu_->tap_name,
&stat_data,
displayFilter(),
0,
tapReset,
stu_->packet_func,
tapDraw);
if (error_string) {
QMessageBox::critical(this, tr("Failed to attach to tap \"%1\"").arg(stu_->tap_name),
error_string->str);
g_string_free(error_string, TRUE);
free_stat_table(stu_, NULL, NULL);
reject();
}
cf_retap_packets(cap_file_.capFile());
tapDraw(&stat_data);
remove_tap_listener(&stat_data);
free_stat_table(stu_, NULL, NULL);
}
/*
* Editor modelines
*
* Local Variables:
* c-basic-offset: 4
* tab-width: 8
* indent-tabs-mode: nil
* End:
*
* ex: set shiftwidth=4 tabstop=8 expandtab:
* :indentSize=4:tabSize=8:noTabs=true:
*/

View File

@ -0,0 +1,75 @@
/* simple_statistics_dialog.h
*
* 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., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA.
*/
#ifndef __SIMPLE_STATISTICS_DIALOG_H__
#define __SIMPLE_STATISTICS_DIALOG_H__
#include "tap_parameter_dialog.h"
class SimpleStatisticsDialog : public TapParameterDialog
{
Q_OBJECT
public:
SimpleStatisticsDialog(QWidget &parent, CaptureFile &cf, struct _new_stat_tap_ui *stu, const QString filter, int help_topic = 0);
static TapParameterDialog *createSimpleStatisticsDialog(QWidget &parent, const QString cfg_str, const QString filter, CaptureFile &cf);
protected:
/** Add a simple statistics table.
*
* @param rtd_table The table to add.
* @return A
*/
// gtk:service_response_table.h:init_srt_table
void addSimpleStatisticsTable(const struct _stat_tap_table *st_table);
private:
struct _new_stat_tap_ui *stu_;
// Callbacks for register_tap_listener
static void tapReset(void *sd_ptr);
static void tapDraw(void *sd_ptr);
virtual void fillTree();
};
/** Register function to register dissectors that support a "simple" statistics table.
*
* @param data new_stat_tap_ui* representing dissetor stat table
* @param user_data is unused
*/
void register_simple_stat_tables(gpointer data, gpointer);
#endif // __SIMPLE_STATISTICS_DIALOG_H__
/*
* Editor modelines
*
* Local Variables:
* c-basic-offset: 4
* tab-width: 8
* indent-tabs-mode: nil
* End:
*
* ex: set shiftwidth=4 tabstop=8 expandtab:
* :indentSize=4:tabSize=8:noTabs=true:
*/

View File

@ -94,6 +94,7 @@
#include "ui/qt/response_time_delay_dialog.h"
#include "ui/qt/service_response_time_dialog.h"
#include "ui/qt/simple_dialog.h"
#include "ui/qt/simple_statistics_dialog.h"
#include "ui/qt/splash_overlay.h"
#include "ui/qt/wireshark_application.h"
@ -843,6 +844,7 @@ DIAG_ON(cast-qual)
hostlist_table_set_gui_info(init_endpoint_table);
srt_table_iterate_tables(register_service_response_tables, NULL);
rtd_table_iterate_tables(register_response_time_delay_tables, NULL);
new_stat_tap_iterate_tables(register_simple_stat_tables, NULL);
if (ex_opt_count("read_format") > 0) {
in_file_type = open_info_name_to_type(ex_opt_get_next("read_format"));