aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorJirka Novak <j.novak@netsystem.cz>2021-05-09 16:29:11 +0200
committerj.novak@netsystem.cz <j.novak@netsystem.cz>2021-05-22 03:08:46 +0000
commitc01456b77e3bc329b761e907460ce725730466b3 (patch)
treeabc0d186f00eb6dd166760d09dd00b53c0a8189b
parentc22b857942ea3f123d9fa5c31e04e85c6f3928f5 (diff)
VoIP Dialogs: Refactoring of singleton windows to factory methods
Singletons moved from main_window to each class's static open<NameOfClass> method: - RtpPlayerDialog - RtpStreamDialog - VoipCallsDialog - RtpAnalysisDialog Fixed issue with selecting RTP stream in sequence dialog. When user selected a stream and moved mouse to Rtp Player button and pressed it, incorrect RTP stream was sent to it.
-rw-r--r--ui/qt/main_window.h15
-rw-r--r--ui/qt/main_window_slots.cpp189
-rw-r--r--ui/qt/rtp_analysis_dialog.cpp28
-rw-r--r--ui/qt/rtp_analysis_dialog.h22
-rw-r--r--ui/qt/rtp_player_dialog.cpp29
-rw-r--r--ui/qt/rtp_player_dialog.h22
-rw-r--r--ui/qt/rtp_stream_dialog.cpp39
-rw-r--r--ui/qt/rtp_stream_dialog.h22
-rw-r--r--ui/qt/sequence_dialog.cpp47
-rw-r--r--ui/qt/sequence_dialog.h4
-rw-r--r--ui/qt/voip_calls_dialog.cpp50
-rw-r--r--ui/qt/voip_calls_dialog.h24
12 files changed, 312 insertions, 179 deletions
diff --git a/ui/qt/main_window.h b/ui/qt/main_window.h
index 2f1421fe5a..1a5adf4be5 100644
--- a/ui/qt/main_window.h
+++ b/ui/qt/main_window.h
@@ -247,12 +247,6 @@ private:
QWidget* getLayoutWidget(layout_pane_content_e type);
- QPointer<RtpStreamDialog> rtp_stream_dialog_; // Singleton pattern used
- QPointer<VoipCallsDialog> voip_calls_dialog_; // Singleton pattern used
- QPointer<VoipCallsDialog> sip_calls_dialog_; // Singleton pattern used
- QPointer<RtpPlayerDialog> rtp_player_dialog_; // Singleton pattern used
- QPointer<RtpAnalysisDialog> rtp_analysis_dialog_; // Singleton pattern used
-
void freeze();
void thaw();
@@ -685,10 +679,11 @@ private slots:
void on_actionStatisticsHpfeeds_triggered();
void on_actionStatisticsHTTP2_triggered();
- void openTelephonyRtpStreamsDialog();
- void openTelephonyRtpPlayerDialog();
- void openTelephonyVoipCallsDialog(bool all_flows);
- void openTelephonyRtpAnalysisDialog();
+ RtpStreamDialog *openTelephonyRtpStreamsDialog();
+ RtpPlayerDialog *openTelephonyRtpPlayerDialog();
+ VoipCallsDialog *openTelephonyVoipCallsDialogVoip();
+ VoipCallsDialog *openTelephonyVoipCallsDialogSip();
+ RtpAnalysisDialog *openTelephonyRtpAnalysisDialog();
void on_actionTelephonyVoipCalls_triggered();
void on_actionTelephonyGsmMapSummary_triggered();
void statCommandLteMacStatistics(const char *arg, void *);
diff --git a/ui/qt/main_window_slots.cpp b/ui/qt/main_window_slots.cpp
index 802801b8b9..048eef1b92 100644
--- a/ui/qt/main_window_slots.cpp
+++ b/ui/qt/main_window_slots.cpp
@@ -3306,91 +3306,54 @@ void MainWindow::on_actionStatisticsHTTP2_triggered()
// Telephony Menu
-static QMutex telephony_dialog_mutex;
-
-void MainWindow::openTelephonyRtpPlayerDialog()
+RtpPlayerDialog *MainWindow::openTelephonyRtpPlayerDialog()
{
- if (!rtp_player_dialog_) {
+ RtpPlayerDialog *dialog;
+
#ifdef HAVE_LIBPCAP
- rtp_player_dialog_ = new RtpPlayerDialog(*this, capture_file_, captureSession()->state != CAPTURE_STOPPED);
+ dialog = RtpPlayerDialog::openRtpPlayerDialog(*this, capture_file_, packet_list_, captureSession()->state != CAPTURE_STOPPED);
#else
- rtp_player_dialog_ = new RtpPlayerDialog(*this, capture_file_, false);
+ dialog = RtpPlayerDialog::openRtpPlayerDialog(*this, capture_file_, packet_list_, false);
#endif
- connect(rtp_player_dialog_, SIGNAL(goToPacket(int)),
- packet_list_, SLOT(goToPacket(int)));
- connect(rtp_player_dialog_, SIGNAL(updateFilter(QString, bool)),
- this, SLOT(filterPackets(QString, bool)));
- connect(rtp_player_dialog_, SIGNAL(rtpAnalysisDialogReplaceRtpStreams(QVector<rtpstream_id_t *>)),
- this, SLOT(rtpAnalysisDialogReplaceRtpStreams(QVector<rtpstream_id_t *>)));
- connect(rtp_player_dialog_, SIGNAL(rtpAnalysisDialogAddRtpStreams(QVector<rtpstream_id_t *>)),
- this, SLOT(rtpAnalysisDialogAddRtpStreams(QVector<rtpstream_id_t *>)));
- connect(rtp_player_dialog_, SIGNAL(rtpAnalysisDialogRemoveRtpStreams(QVector<rtpstream_id_t *>)),
- this, SLOT(rtpAnalysisDialogRemoveRtpStreams(QVector<rtpstream_id_t *>)));
- }
- rtp_player_dialog_->show();
+ dialog->show();
+
+ return dialog;
}
-void MainWindow::openTelephonyVoipCallsDialog(bool all_flows)
+VoipCallsDialog *MainWindow::openTelephonyVoipCallsDialogVoip()
{
- VoipCallsDialog *dlg;
- bool set_signals;
+ VoipCallsDialog *dialog;
- set_signals = false;
- if (all_flows) {
- if (!sip_calls_dialog_) {
- sip_calls_dialog_ = new VoipCallsDialog(*this, capture_file_, true);
- set_signals = true;
- }
- dlg = sip_calls_dialog_;
- } else {
- if (!voip_calls_dialog_) {
- voip_calls_dialog_ = new VoipCallsDialog(*this, capture_file_, false);
- set_signals = true;
- }
- dlg = voip_calls_dialog_;
- }
- if (set_signals) {
- connect(dlg, SIGNAL(goToPacket(int)),
- packet_list_, SLOT(goToPacket(int)));
- connect(dlg, SIGNAL(updateFilter(QString, bool)),
- this, SLOT(filterPackets(QString, bool)));
- connect(this, SIGNAL(displayFilterSuccess(bool)),
- dlg, SLOT(displayFilterSuccess(bool)));
- connect(dlg, SIGNAL(rtpPlayerDialogReplaceRtpStreams(QVector<rtpstream_id_t *>)),
- this, SLOT(rtpPlayerDialogReplaceRtpStreams(QVector<rtpstream_id_t *>)));
- connect(dlg, SIGNAL(rtpPlayerDialogAddRtpStreams(QVector<rtpstream_id_t *>)),
- this, SLOT(rtpPlayerDialogAddRtpStreams(QVector<rtpstream_id_t *>)));
- connect(dlg, SIGNAL(rtpPlayerDialogRemoveRtpStreams(QVector<rtpstream_id_t *>)),
- this, SLOT(rtpPlayerDialogRemoveRtpStreams(QVector<rtpstream_id_t *>)));
- }
- dlg->show();
+ dialog = VoipCallsDialog::openVoipCallsDialogVoip(*this, capture_file_, packet_list_);
+ dialog->show();
+
+ return dialog;
}
-void MainWindow::openTelephonyRtpAnalysisDialog()
+VoipCallsDialog *MainWindow::openTelephonyVoipCallsDialogSip()
{
- if (!rtp_analysis_dialog_) {
- rtp_analysis_dialog_ = new RtpAnalysisDialog(*this, capture_file_);
+ VoipCallsDialog *dialog;
- connect(rtp_analysis_dialog_, SIGNAL(goToPacket(int)),
- packet_list_, SLOT(goToPacket(int)));
- connect(rtp_analysis_dialog_, SIGNAL(updateFilter(QString, bool)),
- this, SLOT(filterPackets(QString, bool)));
- connect(rtp_analysis_dialog_, SIGNAL(rtpPlayerDialogReplaceRtpStreams(QVector<rtpstream_id_t *>)),
- this, SLOT(rtpPlayerDialogReplaceRtpStreams(QVector<rtpstream_id_t *>)));
- connect(rtp_analysis_dialog_, SIGNAL(rtpPlayerDialogAddRtpStreams(QVector<rtpstream_id_t *>)),
- this, SLOT(rtpPlayerDialogAddRtpStreams(QVector<rtpstream_id_t *>)));
- connect(rtp_analysis_dialog_, SIGNAL(rtpPlayerDialogRemoveRtpStreams(QVector<rtpstream_id_t *>)),
- this, SLOT(rtpPlayerDialogRemoveRtpStreams(QVector<rtpstream_id_t *>)));
- }
- rtp_analysis_dialog_->show();
+ dialog = VoipCallsDialog::openVoipCallsDialogSip(*this, capture_file_, packet_list_);
+ dialog->show();
+
+ return dialog;
+}
+
+RtpAnalysisDialog *MainWindow::openTelephonyRtpAnalysisDialog()
+{
+ RtpAnalysisDialog *dialog;
+
+ dialog = RtpAnalysisDialog::openRtpAnalysisDialog(*this, capture_file_, packet_list_);
+ dialog->show();
+
+ return dialog;
}
void MainWindow::on_actionTelephonyVoipCalls_triggered()
{
- telephony_dialog_mutex.lock();
- openTelephonyVoipCallsDialog(false);
- telephony_dialog_mutex.unlock();
+ openTelephonyVoipCallsDialogVoip();
}
void MainWindow::on_actionTelephonyGsmMapSummary_triggered()
@@ -3475,39 +3438,19 @@ void MainWindow::on_actionTelephonyOsmuxPacketCounter_triggered()
openStatisticsTreeDialog("osmux");
}
-void MainWindow::openTelephonyRtpStreamsDialog()
-{
- if (!rtp_stream_dialog_) {
- rtp_stream_dialog_ = new RtpStreamDialog(*this, capture_file_);
- connect(rtp_stream_dialog_, SIGNAL(packetsMarked()),
- packet_list_, SLOT(redrawVisiblePackets()));
- connect(rtp_stream_dialog_, SIGNAL(goToPacket(int)),
- packet_list_, SLOT(goToPacket(int)));
- connect(rtp_stream_dialog_, SIGNAL(updateFilter(QString, bool)),
- this, SLOT(filterPackets(QString, bool)));
- connect(this, SIGNAL(displayFilterSuccess(bool)),
- rtp_stream_dialog_, SLOT(displayFilterSuccess(bool)));
- connect(rtp_stream_dialog_, SIGNAL(rtpPlayerDialogReplaceRtpStreams(QVector<rtpstream_id_t *>)),
- this, SLOT(rtpPlayerDialogReplaceRtpStreams(QVector<rtpstream_id_t *>)));
- connect(rtp_stream_dialog_, SIGNAL(rtpPlayerDialogAddRtpStreams(QVector<rtpstream_id_t *>)),
- this, SLOT(rtpPlayerDialogAddRtpStreams(QVector<rtpstream_id_t *>)));
- connect(rtp_stream_dialog_, SIGNAL(rtpPlayerDialogRemoveRtpStreams(QVector<rtpstream_id_t *>)),
- this, SLOT(rtpPlayerDialogRemoveRtpStreams(QVector<rtpstream_id_t *>)));
- connect(rtp_stream_dialog_, SIGNAL(rtpAnalysisDialogReplaceRtpStreams(QVector<rtpstream_id_t *>)),
- this, SLOT(rtpAnalysisDialogReplaceRtpStreams(QVector<rtpstream_id_t *>)));
- connect(rtp_stream_dialog_, SIGNAL(rtpAnalysisDialogAddRtpStreams(QVector<rtpstream_id_t *>)),
- this, SLOT(rtpAnalysisDialogAddRtpStreams(QVector<rtpstream_id_t *>)));
- connect(rtp_stream_dialog_, SIGNAL(rtpAnalysisDialogRemoveRtpStreams(QVector<rtpstream_id_t *>)),
- this, SLOT(rtpAnalysisDialogRemoveRtpStreams(QVector<rtpstream_id_t *>)));
- }
- rtp_stream_dialog_->show();
+RtpStreamDialog *MainWindow::openTelephonyRtpStreamsDialog()
+{
+ RtpStreamDialog *dialog;
+
+ dialog = RtpStreamDialog::openRtpStreamDialog(*this, capture_file_, packet_list_);
+ dialog->show();
+
+ return dialog;
}
void MainWindow::on_actionTelephonyRtpStreams_triggered()
{
- telephony_dialog_mutex.lock();
openTelephonyRtpStreamsDialog();
- telephony_dialog_mutex.unlock();
}
void MainWindow::on_actionTelephonyRtpStreamAnalysis_triggered()
@@ -3515,8 +3458,6 @@ void MainWindow::on_actionTelephonyRtpStreamAnalysis_triggered()
QVector<rtpstream_id_t *> stream_ids;
QString err;
- telephony_dialog_mutex.lock();
- openTelephonyRtpAnalysisDialog();
if (QGuiApplication::keyboardModifiers().testFlag(Qt::ControlModifier)) {
err = findRtpStreams(&stream_ids, true);
} else {
@@ -3527,12 +3468,11 @@ void MainWindow::on_actionTelephonyRtpStreamAnalysis_triggered()
err,
QMessageBox::Ok);
} else {
- rtp_analysis_dialog_->addRtpStreams(stream_ids);
+ openTelephonyRtpAnalysisDialog()->addRtpStreams(stream_ids);
}
foreach(rtpstream_id_t *id, stream_ids) {
rtpstream_id_free(id);
}
- telephony_dialog_mutex.unlock();
}
void MainWindow::on_actionTelephonyRtpPlayer_triggered()
@@ -3540,8 +3480,6 @@ void MainWindow::on_actionTelephonyRtpPlayer_triggered()
QVector<rtpstream_id_t *> stream_ids;
QString err;
- telephony_dialog_mutex.lock();
- openTelephonyRtpPlayerDialog();
if (QGuiApplication::keyboardModifiers().testFlag(Qt::ControlModifier)) {
err = findRtpStreams(&stream_ids, true);
} else {
@@ -3552,12 +3490,11 @@ void MainWindow::on_actionTelephonyRtpPlayer_triggered()
err,
QMessageBox::Ok);
} else {
- rtp_player_dialog_->addRtpStreams(stream_ids);
+ openTelephonyRtpPlayerDialog()->addRtpStreams(stream_ids);
}
foreach(rtpstream_id_t *id, stream_ids) {
rtpstream_id_free(id);
}
- telephony_dialog_mutex.unlock();
}
void MainWindow::on_actionTelephonyRTSPPacketCounter_triggered()
@@ -3577,9 +3514,7 @@ void MainWindow::on_actionTelephonyUCPMessages_triggered()
void MainWindow::on_actionTelephonySipFlows_triggered()
{
- telephony_dialog_mutex.lock();
- openTelephonyVoipCallsDialog(true);
- telephony_dialog_mutex.unlock();
+ openTelephonyVoipCallsDialogSip();
}
// Wireless Menu
@@ -4135,66 +4070,42 @@ void MainWindow::activatePluginIFToolbar(bool)
void MainWindow::rtpPlayerDialogReplaceRtpStreams(QVector<rtpstream_id_t *> stream_ids)
{
- telephony_dialog_mutex.lock();
- openTelephonyRtpPlayerDialog();
- rtp_player_dialog_->replaceRtpStreams(stream_ids);
- telephony_dialog_mutex.unlock();
+ openTelephonyRtpPlayerDialog()->replaceRtpStreams(stream_ids);
}
void MainWindow::rtpPlayerDialogAddRtpStreams(QVector<rtpstream_id_t *> stream_ids)
{
- telephony_dialog_mutex.lock();
- openTelephonyRtpPlayerDialog();
- rtp_player_dialog_->addRtpStreams(stream_ids);
- telephony_dialog_mutex.unlock();
+ openTelephonyRtpPlayerDialog()->addRtpStreams(stream_ids);
}
void MainWindow::rtpPlayerDialogRemoveRtpStreams(QVector<rtpstream_id_t *> stream_ids)
{
- telephony_dialog_mutex.lock();
- openTelephonyRtpPlayerDialog();
- rtp_player_dialog_->removeRtpStreams(stream_ids);
- telephony_dialog_mutex.unlock();
+ openTelephonyRtpPlayerDialog()->removeRtpStreams(stream_ids);
}
void MainWindow::rtpAnalysisDialogReplaceRtpStreams(QVector<rtpstream_id_t *> stream_ids)
{
- telephony_dialog_mutex.lock();
- openTelephonyRtpAnalysisDialog();
- rtp_analysis_dialog_->replaceRtpStreams(stream_ids);
- telephony_dialog_mutex.unlock();
+ openTelephonyRtpAnalysisDialog()->replaceRtpStreams(stream_ids);
}
void MainWindow::rtpAnalysisDialogAddRtpStreams(QVector<rtpstream_id_t *> stream_ids)
{
- telephony_dialog_mutex.lock();
- openTelephonyRtpAnalysisDialog();
- rtp_analysis_dialog_->addRtpStreams(stream_ids);
- telephony_dialog_mutex.unlock();
+ openTelephonyRtpAnalysisDialog()->addRtpStreams(stream_ids);
}
void MainWindow::rtpAnalysisDialogRemoveRtpStreams(QVector<rtpstream_id_t *> stream_ids)
{
- telephony_dialog_mutex.lock();
- openTelephonyRtpAnalysisDialog();
- rtp_analysis_dialog_->removeRtpStreams(stream_ids);
- telephony_dialog_mutex.unlock();
+ openTelephonyRtpAnalysisDialog()->removeRtpStreams(stream_ids);
}
void MainWindow::rtpStreamsDialogSelectRtpStreams(QVector<rtpstream_id_t *> stream_ids)
{
- telephony_dialog_mutex.lock();
- openTelephonyRtpStreamsDialog();
- rtp_stream_dialog_->selectRtpStream(stream_ids);
- telephony_dialog_mutex.unlock();
+ openTelephonyRtpStreamsDialog()->selectRtpStream(stream_ids);
}
void MainWindow::rtpStreamsDialogDeselectRtpStreams(QVector<rtpstream_id_t *> stream_ids)
{
- telephony_dialog_mutex.lock();
- openTelephonyRtpStreamsDialog();
- rtp_stream_dialog_->deselectRtpStream(stream_ids);
- telephony_dialog_mutex.unlock();
+ openTelephonyRtpStreamsDialog()->deselectRtpStream(stream_ids);
}
#ifdef _MSC_VER
diff --git a/ui/qt/rtp_analysis_dialog.cpp b/ui/qt/rtp_analysis_dialog.cpp
index 2a345d0758..920d8cab94 100644
--- a/ui/qt/rtp_analysis_dialog.cpp
+++ b/ui/qt/rtp_analysis_dialog.cpp
@@ -239,6 +239,21 @@ enum {
num_graphs_
};
+RtpAnalysisDialog *RtpAnalysisDialog::pinstance_{nullptr};
+std::mutex RtpAnalysisDialog::mutex_;
+
+RtpAnalysisDialog *RtpAnalysisDialog::openRtpAnalysisDialog(QWidget &parent, CaptureFile &cf, QObject *packet_list)
+{
+ std::lock_guard<std::mutex> lock(mutex_);
+ if (pinstance_ == nullptr)
+ {
+ pinstance_ = new RtpAnalysisDialog(parent, cf);
+ connect(pinstance_, SIGNAL(goToPacket(int)),
+ packet_list, SLOT(goToPacket(int)));
+ }
+ return pinstance_;
+}
+
RtpAnalysisDialog::RtpAnalysisDialog(QWidget &parent, CaptureFile &cf) :
WiresharkDialog(parent, cf),
ui(new Ui::RtpAnalysisDialog),
@@ -285,6 +300,14 @@ RtpAnalysisDialog::RtpAnalysisDialog(QWidget &parent, CaptureFile &cf) :
this, SLOT(updateWidgets()));
connect(ui->tabWidget->tabBar(), SIGNAL(tabCloseRequested(int)),
this, SLOT(closeTab(int)));
+ connect(this, SIGNAL(updateFilter(QString, bool)),
+ &parent, SLOT(filterPackets(QString, bool)));
+ connect(this, SIGNAL(rtpPlayerDialogReplaceRtpStreams(QVector<rtpstream_id_t *>)),
+ &parent, SLOT(rtpPlayerDialogReplaceRtpStreams(QVector<rtpstream_id_t *>)));
+ connect(this, SIGNAL(rtpPlayerDialogAddRtpStreams(QVector<rtpstream_id_t *>)),
+ &parent, SLOT(rtpPlayerDialogAddRtpStreams(QVector<rtpstream_id_t *>)));
+ connect(this, SIGNAL(rtpPlayerDialogRemoveRtpStreams(QVector<rtpstream_id_t *>)),
+ &parent, SLOT(rtpPlayerDialogRemoveRtpStreams(QVector<rtpstream_id_t *>)));
updateWidgets();
@@ -293,11 +316,13 @@ RtpAnalysisDialog::RtpAnalysisDialog(QWidget &parent, CaptureFile &cf) :
RtpAnalysisDialog::~RtpAnalysisDialog()
{
+ std::lock_guard<std::mutex> lock(mutex_);
delete ui;
for(int i=0; i<tabs_.count(); i++) {
deleteTabInfo(tabs_[i]);
g_free(tabs_[i]);
}
+ pinstance_ = nullptr;
}
void RtpAnalysisDialog::deleteTabInfo(tab_info_t *tab_info)
@@ -970,6 +995,7 @@ void RtpAnalysisDialog::showStreamMenu(QPoint pos)
void RtpAnalysisDialog::replaceRtpStreams(QVector<rtpstream_id_t *> stream_ids)
{
+ std::lock_guard<std::mutex> lock(mutex_);
// Delete existing tabs (from last to first)
if (tabs_.count() > 0) {
for(int i=tabs_.count(); i>0; i--) {
@@ -981,6 +1007,7 @@ void RtpAnalysisDialog::replaceRtpStreams(QVector<rtpstream_id_t *> stream_ids)
void RtpAnalysisDialog::addRtpStreams(QVector<rtpstream_id_t *> stream_ids)
{
+ std::lock_guard<std::mutex> lock(mutex_);
addRtpStreamsPrivate(stream_ids);
}
@@ -1031,6 +1058,7 @@ void RtpAnalysisDialog::addRtpStreamsPrivate(QVector<rtpstream_id_t *> stream_id
void RtpAnalysisDialog::removeRtpStreams(QVector<rtpstream_id_t *> stream_ids)
{
+ std::lock_guard<std::mutex> lock(mutex_);
setUpdatesEnabled(false);
foreach(rtpstream_id_t *id, stream_ids) {
QList<tab_info_t *> tabs = tab_hash_.values(rtpstream_id_to_hash(id));
diff --git a/ui/qt/rtp_analysis_dialog.h b/ui/qt/rtp_analysis_dialog.h
index 9fdc469cb8..66d54d7c57 100644
--- a/ui/qt/rtp_analysis_dialog.h
+++ b/ui/qt/rtp_analysis_dialog.h
@@ -13,6 +13,7 @@
#include <config.h>
#include <glib.h>
+#include <mutex>
#include "epan/address.h"
@@ -57,13 +58,23 @@ typedef struct {
QCheckBox *delta_checkbox;
} tab_info_t;
+// Singleton by https://refactoring.guru/design-patterns/singleton/cpp/example#example-1
class RtpAnalysisDialog : public WiresharkDialog
{
Q_OBJECT
public:
- explicit RtpAnalysisDialog(QWidget &parent, CaptureFile &cf);
- ~RtpAnalysisDialog();
+ /**
+ * Returns singleton
+ */
+ static RtpAnalysisDialog *openRtpAnalysisDialog(QWidget &parent, CaptureFile &cf, QObject *packet_list);
+
+ /**
+ * Should not be clonnable and assignable
+ */
+ RtpAnalysisDialog(RtpAnalysisDialog &other) = delete;
+ void operator=(const RtpAnalysisDialog &) = delete;
+
/**
* @brief Common routine to add a "Analyze" button to a QDialogButtonBox.
* @param button_box Caller's QDialogButtonBox.
@@ -95,6 +106,10 @@ public slots:
protected slots:
virtual void updateWidgets();
+protected:
+ explicit RtpAnalysisDialog(QWidget &parent, CaptureFile &cf);
+ ~RtpAnalysisDialog();
+
private slots:
void on_actionGoToPacket_triggered();
void on_actionNextProblem_triggered();
@@ -111,6 +126,9 @@ private slots:
void on_actionPrepareFilterAll_triggered();
private:
+ static RtpAnalysisDialog *pinstance_;
+ static std::mutex mutex_;
+
Ui::RtpAnalysisDialog *ui;
enum StreamDirection { dir_all_, dir_one_ };
int tab_seq;
diff --git a/ui/qt/rtp_player_dialog.cpp b/ui/qt/rtp_player_dialog.cpp
index cd58797c7f..6e5f5f9160 100644
--- a/ui/qt/rtp_player_dialog.cpp
+++ b/ui/qt/rtp_player_dialog.cpp
@@ -131,6 +131,22 @@ public:
}
};
+
+RtpPlayerDialog *RtpPlayerDialog::pinstance_{nullptr};
+std::mutex RtpPlayerDialog::mutex_;
+
+RtpPlayerDialog *RtpPlayerDialog::openRtpPlayerDialog(QWidget &parent, CaptureFile &cf, QObject *packet_list, bool capture_running)
+{
+ std::lock_guard<std::mutex> lock(mutex_);
+ if (pinstance_ == nullptr)
+ {
+ pinstance_ = new RtpPlayerDialog(parent, cf, capture_running);
+ connect(pinstance_, SIGNAL(goToPacket(int)),
+ packet_list, SLOT(goToPacket(int)));
+ }
+ return pinstance_;
+}
+
RtpPlayerDialog::RtpPlayerDialog(QWidget &parent, CaptureFile &cf, bool capture_running) :
WiresharkDialog(parent, cf)
#ifdef QT_MULTIMEDIA_LIB
@@ -306,6 +322,14 @@ RtpPlayerDialog::RtpPlayerDialog(QWidget &parent, CaptureFile &cf, bool capture_
connect(&cap_file_, SIGNAL(captureEvent(CaptureEvent)),
this, SLOT(captureEvent(CaptureEvent)));
+ connect(this, SIGNAL(updateFilter(QString, bool)),
+ &parent, SLOT(filterPackets(QString, bool)));
+ connect(this, SIGNAL(rtpAnalysisDialogReplaceRtpStreams(QVector<rtpstream_id_t *>)),
+ &parent, SLOT(rtpAnalysisDialogReplaceRtpStreams(QVector<rtpstream_id_t *>)));
+ connect(this, SIGNAL(rtpAnalysisDialogAddRtpStreams(QVector<rtpstream_id_t *>)),
+ &parent, SLOT(rtpAnalysisDialogAddRtpStreams(QVector<rtpstream_id_t *>)));
+ connect(this, SIGNAL(rtpAnalysisDialogRemoveRtpStreams(QVector<rtpstream_id_t *>)),
+ &parent, SLOT(rtpAnalysisDialogRemoveRtpStreams(QVector<rtpstream_id_t *>)));
#endif // QT_MULTIMEDIA_LIB
}
@@ -352,6 +376,7 @@ QToolButton *RtpPlayerDialog::addPlayerButton(QDialogButtonBox *button_box, QDia
#ifdef QT_MULTIMEDIA_LIB
RtpPlayerDialog::~RtpPlayerDialog()
{
+ std::lock_guard<std::mutex> lock(mutex_);
cleanupMarkerStream();
for (int row = 0; row < ui->streamTreeWidget->topLevelItemCount(); row++) {
QTreeWidgetItem *ti = ui->streamTreeWidget->topLevelItem(row);
@@ -360,6 +385,7 @@ RtpPlayerDialog::~RtpPlayerDialog()
delete audio_stream;
}
delete ui;
+ pinstance_ = nullptr;
}
void RtpPlayerDialog::accept()
@@ -746,6 +772,7 @@ void RtpPlayerDialog::unlockUI()
void RtpPlayerDialog::replaceRtpStreams(QVector<rtpstream_id_t *> stream_ids)
{
+ std::lock_guard<std::mutex> lock(mutex_);
lockUI();
// Delete all existing rows
@@ -773,6 +800,7 @@ void RtpPlayerDialog::replaceRtpStreams(QVector<rtpstream_id_t *> stream_ids)
void RtpPlayerDialog::addRtpStreams(QVector<rtpstream_id_t *> stream_ids)
{
+ std::lock_guard<std::mutex> lock(mutex_);
lockUI();
int tli_count = ui->streamTreeWidget->topLevelItemCount();
@@ -794,6 +822,7 @@ void RtpPlayerDialog::addRtpStreams(QVector<rtpstream_id_t *> stream_ids)
void RtpPlayerDialog::removeRtpStreams(QVector<rtpstream_id_t *> stream_ids)
{
+ std::lock_guard<std::mutex> lock(mutex_);
lockUI();
int tli_count = ui->streamTreeWidget->topLevelItemCount();
diff --git a/ui/qt/rtp_player_dialog.h b/ui/qt/rtp_player_dialog.h
index d07f08e996..cc3d20b516 100644
--- a/ui/qt/rtp_player_dialog.h
+++ b/ui/qt/rtp_player_dialog.h
@@ -13,12 +13,14 @@
#include "config.h"
#include <glib.h>
+#include <mutex>
#include "ui/rtp_stream.h"
#include "wireshark_dialog.h"
#include "rtp_audio_stream.h"
+#include <QWidget>
#include <QMap>
#include <QMultiHash>
#include <QTreeWidgetItem>
@@ -54,6 +56,7 @@ typedef enum {
save_mode_sync_file
} save_mode_t;
+// Singleton by https://refactoring.guru/design-patterns/singleton/cpp/example#example-1
class RtpPlayerDialog : public WiresharkDialog
{
Q_OBJECT
@@ -62,7 +65,16 @@ class RtpPlayerDialog : public WiresharkDialog
#endif
public:
- explicit RtpPlayerDialog(QWidget &parent, CaptureFile &cf, bool capture_running);
+ /**
+ * Returns singleton
+ */
+ static RtpPlayerDialog *openRtpPlayerDialog(QWidget &parent, CaptureFile &cf, QObject *packet_list, bool capture_running);
+
+ /**
+ * Should not be clonnable and assignable
+ */
+ RtpPlayerDialog(RtpPlayerDialog &other) = delete;
+ void operator=(const RtpPlayerDialog &) = delete;
/**
* @brief Common routine to add a "Play call" button to a QDialogButtonBox.
@@ -72,8 +84,6 @@ public:
static QToolButton *addPlayerButton(QDialogButtonBox *button_box, QDialog *dialog);
#ifdef QT_MULTIMEDIA_LIB
- ~RtpPlayerDialog();
-
void accept();
void reject();
@@ -107,6 +117,9 @@ public slots:
void rtpAnalysisRemove();
protected:
+ explicit RtpPlayerDialog(QWidget &parent, CaptureFile &cf, bool capture_running);
+ ~RtpPlayerDialog();
+
virtual void showEvent(QShowEvent *);
void contextMenuEvent(QContextMenuEvent *event);
bool eventFilter(QObject *obj, QEvent *event);
@@ -182,6 +195,9 @@ private slots:
void on_actionReadCapture_triggered();
private:
+ static RtpPlayerDialog *pinstance_;
+ static std::mutex mutex_;
+
Ui::RtpPlayerDialog *ui;
QMenu *graph_ctx_menu_;
QMenu *list_ctx_menu_;
diff --git a/ui/qt/rtp_stream_dialog.cpp b/ui/qt/rtp_stream_dialog.cpp
index 89754ddaaa..7f8f8188a0 100644
--- a/ui/qt/rtp_stream_dialog.cpp
+++ b/ui/qt/rtp_stream_dialog.cpp
@@ -259,6 +259,24 @@ private:
gboolean tod_;
};
+
+RtpStreamDialog *RtpStreamDialog::pinstance_{nullptr};
+std::mutex RtpStreamDialog::mutex_;
+
+RtpStreamDialog *RtpStreamDialog::openRtpStreamDialog(QWidget &parent, CaptureFile &cf, QObject *packet_list)
+{
+ std::lock_guard<std::mutex> lock(mutex_);
+ if (pinstance_ == nullptr)
+ {
+ pinstance_ = new RtpStreamDialog(parent, cf);
+ connect(pinstance_, SIGNAL(packetsMarked()),
+ packet_list, SLOT(redrawVisiblePackets()));
+ connect(pinstance_, SIGNAL(goToPacket(int)),
+ packet_list, SLOT(goToPacket(int)));
+ }
+ return pinstance_;
+}
+
RtpStreamDialog::RtpStreamDialog(QWidget &parent, CaptureFile &cf) :
WiresharkDialog(parent, cf),
ui(new Ui::RtpStreamDialog),
@@ -334,6 +352,23 @@ RtpStreamDialog::RtpStreamDialog(QWidget &parent, CaptureFile &cf) :
ui->displayFilterCheckBox->setChecked(true);
}
+ connect(this, SIGNAL(updateFilter(QString, bool)),
+ &parent, SLOT(filterPackets(QString, bool)));
+ connect(&parent, SIGNAL(displayFilterSuccess(bool)),
+ this, SLOT(displayFilterSuccess(bool)));
+ connect(this, SIGNAL(rtpPlayerDialogReplaceRtpStreams(QVector<rtpstream_id_t *>)),
+ &parent, SLOT(rtpPlayerDialogReplaceRtpStreams(QVector<rtpstream_id_t *>)));
+ connect(this, SIGNAL(rtpPlayerDialogAddRtpStreams(QVector<rtpstream_id_t *>)),
+ &parent, SLOT(rtpPlayerDialogAddRtpStreams(QVector<rtpstream_id_t *>)));
+ connect(this, SIGNAL(rtpPlayerDialogRemoveRtpStreams(QVector<rtpstream_id_t *>)),
+ &parent, SLOT(rtpPlayerDialogRemoveRtpStreams(QVector<rtpstream_id_t *>)));
+ connect(this, SIGNAL(rtpAnalysisDialogReplaceRtpStreams(QVector<rtpstream_id_t *>)),
+ &parent, SLOT(rtpAnalysisDialogReplaceRtpStreams(QVector<rtpstream_id_t *>)));
+ connect(this, SIGNAL(rtpAnalysisDialogAddRtpStreams(QVector<rtpstream_id_t *>)),
+ &parent, SLOT(rtpAnalysisDialogAddRtpStreams(QVector<rtpstream_id_t *>)));
+ connect(this, SIGNAL(rtpAnalysisDialogRemoveRtpStreams(QVector<rtpstream_id_t *>)),
+ &parent, SLOT(rtpAnalysisDialogRemoveRtpStreams(QVector<rtpstream_id_t *>)));
+
/* Scan for RTP streams (redissect all packets) */
rtpstream_scan(&tapinfo_, cf.capFile(), NULL);
@@ -342,9 +377,11 @@ RtpStreamDialog::RtpStreamDialog(QWidget &parent, CaptureFile &cf) :
RtpStreamDialog::~RtpStreamDialog()
{
+ std::lock_guard<std::mutex> lock(mutex_);
freeLastSelected();
delete ui;
remove_tap_listener_rtpstream(&tapinfo_);
+ pinstance_ = nullptr;
}
void RtpStreamDialog::setRtpStreamSelection(rtpstream_id_t *id, bool state)
@@ -364,6 +401,7 @@ void RtpStreamDialog::setRtpStreamSelection(rtpstream_id_t *id, bool state)
void RtpStreamDialog::selectRtpStream(QVector<rtpstream_id_t *> stream_ids)
{
+ std::lock_guard<std::mutex> lock(mutex_);
foreach(rtpstream_id_t *id, stream_ids) {
setRtpStreamSelection(id, true);
}
@@ -371,6 +409,7 @@ void RtpStreamDialog::selectRtpStream(QVector<rtpstream_id_t *> stream_ids)
void RtpStreamDialog::deselectRtpStream(QVector<rtpstream_id_t *> stream_ids)
{
+ std::lock_guard<std::mutex> lock(mutex_);
foreach(rtpstream_id_t *id, stream_ids) {
setRtpStreamSelection(id, false);
}
diff --git a/ui/qt/rtp_stream_dialog.h b/ui/qt/rtp_stream_dialog.h
index 084a2efffb..ddc01630b0 100644
--- a/ui/qt/rtp_stream_dialog.h
+++ b/ui/qt/rtp_stream_dialog.h
@@ -12,6 +12,8 @@
#include "wireshark_dialog.h"
+#include <mutex>
+
#include "ui/rtp_stream.h"
#include "rtp_player_dialog.h"
@@ -22,13 +24,23 @@ namespace Ui {
class RtpStreamDialog;
}
+// Singleton by https://refactoring.guru/design-patterns/singleton/cpp/example#example-1
class RtpStreamDialog : public WiresharkDialog
{
Q_OBJECT
public:
- explicit RtpStreamDialog(QWidget &parent, CaptureFile &cf);
- ~RtpStreamDialog();
+ /**
+ * Returns singleton
+ */
+ static RtpStreamDialog *openRtpStreamDialog(QWidget &parent, CaptureFile &cf, QObject *packet_list);
+
+ /**
+ * Should not be clonnable and assignable
+ */
+ RtpStreamDialog(RtpStreamDialog &other) = delete;
+ void operator=(const RtpStreamDialog &) = delete;
+
// Caller must provide ids which are immutable to recap
void selectRtpStream(QVector<rtpstream_id_t *> stream_ids);
// Caller must provide ids which are immutable to recap
@@ -58,11 +70,17 @@ public slots:
void rtpAnalysisRemove();
protected:
+ explicit RtpStreamDialog(QWidget &parent, CaptureFile &cf);
+ ~RtpStreamDialog();
+
bool eventFilter(QObject *obj, QEvent *event);
void captureFileClosing();
void captureFileClosed();
private:
+ static RtpStreamDialog *pinstance_;
+ static std::mutex mutex_;
+
Ui::RtpStreamDialog *ui;
rtpstream_tapinfo_t tapinfo_;
QToolButton *find_reverse_button_;
diff --git a/ui/qt/sequence_dialog.cpp b/ui/qt/sequence_dialog.cpp
index e533bc68a7..dd22a3d144 100644
--- a/ui/qt/sequence_dialog.cpp
+++ b/ui/qt/sequence_dialog.cpp
@@ -339,7 +339,7 @@ void SequenceDialog::yAxisChanged(QCPRange range)
void SequenceDialog::diagramClicked(QMouseEvent *event)
{
- current_rtp_sai_ = NULL;
+ current_rtp_sai_selected_ = NULL;
if (event) {
seq_analysis_item_t *sai = seq_diagram_->itemForPosY(event->pos().y());
if (voipFeaturesEnabled) {
@@ -351,7 +351,7 @@ void SequenceDialog::diagramClicked(QMouseEvent *event)
ui->actionSelectRtpStreams->setEnabled(true && !file_closed_);
ui->actionDeselectRtpStreams->setEnabled(true && !file_closed_);
player_button_->setEnabled(true && !file_closed_);
- current_rtp_sai_ = sai;
+ current_rtp_sai_selected_ = sai;
}
}
}
@@ -371,7 +371,7 @@ void SequenceDialog::diagramClicked(QMouseEvent *event)
void SequenceDialog::mouseMoved(QMouseEvent *event)
{
- current_rtp_sai_ = NULL;
+ current_rtp_sai_hovered_ = NULL;
packet_num_ = 0;
QString hint;
if (event) {
@@ -380,7 +380,7 @@ void SequenceDialog::mouseMoved(QMouseEvent *event)
if (GA_INFO_TYPE_RTP == sai->info_type) {
ui->actionSelectRtpStreams->setEnabled(true);
ui->actionDeselectRtpStreams->setEnabled(true);
- current_rtp_sai_ = sai;
+ current_rtp_sai_hovered_ = sai;
}
packet_num_ = sai->frame_number;
QString raw_comment = html_escape(sai->comment);
@@ -752,28 +752,39 @@ void SequenceDialog::on_actionZoomOut_triggered()
zoomXAxis(false);
}
-void SequenceDialog::on_actionSelectRtpStreams_triggered()
+void SequenceDialog::processRtpStream(bool select)
{
- if (current_rtp_sai_ && GA_INFO_TYPE_RTP == current_rtp_sai_->info_type) {
+ seq_analysis_item_t *current_rtp_sai = NULL;
+
+ // If RTP sai is below mouse, use it. If not, try selected RTP sai
+ if (current_rtp_sai_hovered_ && GA_INFO_TYPE_RTP == current_rtp_sai_hovered_->info_type) {
+ current_rtp_sai = current_rtp_sai_hovered_;
+ } else if (current_rtp_sai_selected_ && GA_INFO_TYPE_RTP == current_rtp_sai_selected_->info_type) {
+ current_rtp_sai = current_rtp_sai_selected_;
+ }
+
+ if (current_rtp_sai) {
QVector<rtpstream_id_t *> stream_ids;
// We don't need copy it as it is not cleared during retap
- stream_ids << &((rtpstream_info_t *)current_rtp_sai_->info_ptr)->id;
- emit rtpStreamsDialogSelectRtpStreams(stream_ids);
+ stream_ids << &((rtpstream_info_t *)current_rtp_sai->info_ptr)->id;
+ if (select) {
+ emit rtpStreamsDialogSelectRtpStreams(stream_ids);
+ } else {
+ emit rtpStreamsDialogDeselectRtpStreams(stream_ids);
+ }
raise();
}
}
-void SequenceDialog::on_actionDeselectRtpStreams_triggered()
+void SequenceDialog::on_actionSelectRtpStreams_triggered()
{
- if (current_rtp_sai_ && GA_INFO_TYPE_RTP == current_rtp_sai_->info_type) {
- QVector<rtpstream_id_t *> stream_ids;
+ processRtpStream(true);
+}
- // We don't need copy it as it is not cleared during retap
- stream_ids << &((rtpstream_info_t *)current_rtp_sai_->info_ptr)->id;
- emit rtpStreamsDialogDeselectRtpStreams(stream_ids);
- raise();
- }
+void SequenceDialog::on_actionDeselectRtpStreams_triggered()
+{
+ processRtpStream(false);
}
void SequenceDialog::zoomXAxis(bool in)
@@ -814,8 +825,8 @@ QVector<rtpstream_id_t *>SequenceDialog::getSelectedRtpIds()
{
QVector<rtpstream_id_t *> stream_ids;
- if (current_rtp_sai_ && GA_INFO_TYPE_RTP == current_rtp_sai_->info_type) {
- stream_ids << &((rtpstream_info_t *)current_rtp_sai_->info_ptr)->id;
+ if (current_rtp_sai_selected_ && GA_INFO_TYPE_RTP == current_rtp_sai_selected_->info_type) {
+ stream_ids << &((rtpstream_info_t *)current_rtp_sai_selected_->info_ptr)->id;
}
return stream_ids;
diff --git a/ui/qt/sequence_dialog.h b/ui/qt/sequence_dialog.h
index 358c2aa7e4..38be9cde72 100644
--- a/ui/qt/sequence_dialog.h
+++ b/ui/qt/sequence_dialog.h
@@ -118,7 +118,8 @@ private:
QMenu ctx_menu_;
QCPItemText *key_text_;
QCPItemText *comment_text_;
- seq_analysis_item_t *current_rtp_sai_; // Used for passing current sai to rtp processing
+ seq_analysis_item_t *current_rtp_sai_selected_; // Used for passing current sai to rtp processing
+ seq_analysis_item_t *current_rtp_sai_hovered_; // Used for passing current sai to rtp processing
QPointer<RtpStreamDialog> rtp_stream_dialog_; // Singleton pattern used
bool voipFeaturesEnabled;
@@ -129,6 +130,7 @@ private:
static gboolean addFlowSequenceItem(const void *key, void *value, void *userdata);
+ void processRtpStream(bool select);
QVector<rtpstream_id_t *>getSelectedRtpIds();
};
diff --git a/ui/qt/voip_calls_dialog.cpp b/ui/qt/voip_calls_dialog.cpp
index 168bc3bf23..a801de9ac9 100644
--- a/ui/qt/voip_calls_dialog.cpp
+++ b/ui/qt/voip_calls_dialog.cpp
@@ -42,8 +42,37 @@
enum { voip_calls_type_ = 1000 };
+VoipCallsDialog *VoipCallsDialog::pinstance_voip_{nullptr};
+VoipCallsDialog *VoipCallsDialog::pinstance_sip_{nullptr};
+std::mutex VoipCallsDialog::mutex_;
+
+VoipCallsDialog *VoipCallsDialog::openVoipCallsDialogVoip(QWidget &parent, CaptureFile &cf, QObject *packet_list)
+{
+ std::lock_guard<std::mutex> lock(mutex_);
+ if (pinstance_voip_ == nullptr)
+ {
+ pinstance_voip_ = new VoipCallsDialog(parent, cf, false);
+ connect(pinstance_voip_, SIGNAL(goToPacket(int)),
+ packet_list, SLOT(goToPacket(int)));
+ }
+ return pinstance_voip_;
+}
+
+VoipCallsDialog *VoipCallsDialog::openVoipCallsDialogSip(QWidget &parent, CaptureFile &cf, QObject *packet_list)
+{
+ std::lock_guard<std::mutex> lock(mutex_);
+ if (pinstance_sip_ == nullptr)
+ {
+ pinstance_sip_ = new VoipCallsDialog(parent, cf, true);
+ connect(pinstance_sip_, SIGNAL(goToPacket(int)),
+ packet_list, SLOT(goToPacket(int)));
+ }
+ return pinstance_sip_;
+}
+
VoipCallsDialog::VoipCallsDialog(QWidget &parent, CaptureFile &cf, bool all_flows) :
WiresharkDialog(parent, cf),
+ all_flows_(all_flows),
ui(new Ui::VoipCallsDialog),
parent_(parent),
voip_calls_tap_listeners_removed_(false)
@@ -64,7 +93,7 @@ VoipCallsDialog::VoipCallsDialog(QWidget &parent, CaptureFile &cf, bool all_flow
connect(ui->callTreeView->selectionModel(), SIGNAL(selectionChanged(QItemSelection,QItemSelection)),
this, SLOT(updateWidgets()));
ui->callTreeView->sortByColumn(VoipCallsInfoModel::StartTime, Qt::AscendingOrder);
- setWindowSubtitle(all_flows ? tr("SIP Flows") : tr("VoIP Calls"));
+ setWindowSubtitle(all_flows_ ? tr("SIP Flows") : tr("VoIP Calls"));
sequence_button_ = ui->buttonBox->addButton(ui->actionFlowSequence->text(), QDialogButtonBox::ActionRole);
sequence_button_->setToolTip(ui->actionFlowSequence->toolTip());
@@ -96,7 +125,7 @@ VoipCallsDialog::VoipCallsDialog(QWidget &parent, CaptureFile &cf, bool all_flow
tapinfo_.tap_data = this;
tapinfo_.callsinfos = g_queue_new();
tapinfo_.h225_cstype = H225_OTHER;
- tapinfo_.fs_option = all_flows ? FLOW_ALL : FLOW_ONLY_INVITES; /* flow show option */
+ tapinfo_.fs_option = all_flows_ ? FLOW_ALL : FLOW_ONLY_INVITES; /* flow show option */
tapinfo_.graph_analysis = sequence_analysis_info_new();
tapinfo_.graph_analysis->name = "voip";
sequence_info_ = new SequenceInfo(tapinfo_.graph_analysis);
@@ -109,6 +138,17 @@ VoipCallsDialog::VoipCallsDialog(QWidget &parent, CaptureFile &cf, bool all_flow
ui->displayFilterCheckBox->setChecked(true);
}
+ connect(this, SIGNAL(updateFilter(QString, bool)),
+ &parent, SLOT(filterPackets(QString, bool)));
+ connect(&parent, SIGNAL(displayFilterSuccess(bool)),
+ this, SLOT(displayFilterSuccess(bool)));
+ connect(this, SIGNAL(rtpPlayerDialogReplaceRtpStreams(QVector<rtpstream_id_t *>)),
+ &parent, SLOT(rtpPlayerDialogReplaceRtpStreams(QVector<rtpstream_id_t *>)));
+ connect(this, SIGNAL(rtpPlayerDialogAddRtpStreams(QVector<rtpstream_id_t *>)),
+ &parent, SLOT(rtpPlayerDialogAddRtpStreams(QVector<rtpstream_id_t *>)));
+ connect(this, SIGNAL(rtpPlayerDialogRemoveRtpStreams(QVector<rtpstream_id_t *>)),
+ &parent, SLOT(rtpPlayerDialogRemoveRtpStreams(QVector<rtpstream_id_t *>)));
+
updateWidgets();
if (cap_file_.isValid()) {
@@ -155,6 +195,7 @@ bool VoipCallsDialog::eventFilter(QObject *, QEvent *event)
VoipCallsDialog::~VoipCallsDialog()
{
+ std::lock_guard<std::mutex> lock(mutex_);
delete ui;
voip_calls_reset_all_taps(&tapinfo_);
@@ -168,6 +209,11 @@ VoipCallsDialog::~VoipCallsDialog()
// with tapinfo_.callsinfos and was cleared
// during voip_calls_reset_all_taps
g_queue_free(shown_callsinfos_);
+ if (all_flows_) {
+ pinstance_sip_ = nullptr;
+ } else {
+ pinstance_voip_ = nullptr;
+ }
}
void VoipCallsDialog::removeTapListeners()
diff --git a/ui/qt/voip_calls_dialog.h b/ui/qt/voip_calls_dialog.h
index 665b5240ee..8a4c08093c 100644
--- a/ui/qt/voip_calls_dialog.h
+++ b/ui/qt/voip_calls_dialog.h
@@ -13,6 +13,7 @@
#include <config.h>
#include <glib.h>
+#include <mutex>
#include "cfile.h"
@@ -36,13 +37,23 @@ namespace Ui {
class VoipCallsDialog;
}
+// Singleton by https://refactoring.guru/design-patterns/singleton/cpp/example#example-1
class VoipCallsDialog : public WiresharkDialog
{
Q_OBJECT
public:
- explicit VoipCallsDialog(QWidget &parent, CaptureFile &cf, bool all_flows = false);
- ~VoipCallsDialog();
+ /**
+ * Returns singleton
+ */
+ static VoipCallsDialog *openVoipCallsDialogVoip(QWidget &parent, CaptureFile &cf, QObject *packet_list);
+ static VoipCallsDialog *openVoipCallsDialogSip(QWidget &parent, CaptureFile &cf, QObject *packet_list);
+
+ /**
+ * Should not be clonnable and assignable
+ */
+ VoipCallsDialog(VoipCallsDialog &other) = delete;
+ void operator=(const VoipCallsDialog &) = delete;
signals:
void updateFilter(QString filter, bool force = false);
@@ -61,6 +72,9 @@ public slots:
void rtpPlayerRemove();
protected:
+ explicit VoipCallsDialog(QWidget &parent, CaptureFile &cf, bool all_flows = false);
+ ~VoipCallsDialog();
+
void contextMenuEvent(QContextMenuEvent *event);
virtual void removeTapListeners();
void captureFileClosing();
@@ -71,6 +85,12 @@ protected slots:
void changeEvent(QEvent* event);
private:
+ // We have two singletones - one for all protocols, one for sip protocol
+ static VoipCallsDialog *pinstance_voip_;
+ static VoipCallsDialog *pinstance_sip_;
+ bool all_flows_;
+ static std::mutex mutex_;
+
Ui::VoipCallsDialog *ui;
VoipCallsInfoModel *call_infos_model_;
CacheProxyModel *cache_model_;