| Wireshark 4.7.3 The Wireshark network protocol analyzer

Loading...
Searching...
No Matches
Public Slots | Signals | Public Member Functions | List of all members
InterfaceStatsWorker Class Reference

Worker that runs a dumpcap "-S" statistics stream off the GUI thread. More...

`#include <interface_stats_worker.h>`

Inheritance diagram for InterfaceStatsWorker:

## Public Slots
void | start ()
| Opens the dumpcap statistics stream and begins periodic sampling.
void | stop ()
| Stops sampling and tears down the dumpcap stream and process.
void | setInterfaceFilter (const QStringList &interfaceNames)
| Restricts which interfaces appear in emitted snapshots.
void | setUpdateInterval (int intervalMsec)
| Sets the pipe-drain/emit interval.
void | pause ()
| Tears down the dumpcap stream but remembers the configuration.
void | resume ()
| Re-opens the stream previously suspended with pause().

## Signals
void | started ()
| Emitted once the dumpcap stream has been opened successfully.
void | stopped ()
| Emitted after the stream and process have been torn down.
void | failed (int exitCode, const QString &errorMessage)
| Emitted when the stream could not be opened or has broken.
void | sampled (const InterfaceStatsSnapshot &snapshot)
| Emitted each cycle in which new counters were read.

## Public Member Functions
| InterfaceStatsWorker (QObject *parent=nullptr)
| Constructs an idle worker with the default update interval.
| ~InterfaceStatsWorker () override
| Stops the stream (if running) and destroys the worker.
int | updateInterval () const
| Returns the current pipe-drain/emit interval, in milliseconds.

## Detailed Description

Worker that runs a dumpcap "-S" statistics stream off the GUI thread.

The worker is designed to be moved onto a dedicated QThread. It owns the dumpcap child process and its stat pipe, drains the pipe on a timer, and emits a snapshot of the latest per-interface counters. It deliberately knows nothing about the interface model, views, or the global capture options: the application name is supplied by the caller so the same worker serves both Wireshark and Stratoshark.

Threading contract: every public slot is meant to be invoked through the worker thread's event loop (queued/auto connections or QMetaObject::invokeMethod), never called directly across threads. The slots assert this.

Lifetime/teardown: the worker creates no thread of its own; an owner moves it onto a dedicated QThread and is responsible for destroying it safely using the standard idiom, so the destructor (and thus closeStream()) runs on the worker's own thread:

worker->moveToThread(&thread);
connect(&thread, &QThread::finished, worker, &QObject::deleteLater);
thread.start();
// teardown:
QMetaObject::invokeMethod(worker, &InterfaceStatsWorker::stop,
Qt::BlockingQueuedConnection);
thread.quit();
thread.wait();
InterfaceStatsWorker::stop
void stop()
Stops sampling and tears down the dumpcap stream and process.
Definition interface_stats_worker.cpp:87

The destructor asserts it is run on the worker's own thread to catch misuse. This worker is not a singleton: exactly one instance is expected, owned by the (single) statistics facade, never instantiated ad hoc.

## Constructor & Destructor Documentation

## ◆ InterfaceStatsWorker()

InterfaceStatsWorker::InterfaceStatsWorker | ( | QObject * | parent = nullptr | ) |
| explicit

Constructs an idle worker with the default update interval.

Parameters

  parent | Optional parent QObject. Leave null when the worker will be moved to its own thread.

## Member Function Documentation

## ◆ failed

void InterfaceStatsWorker::failed | ( | int | exitCode,
|  | const QString & | errorMessage )
| signal

Emitted when the stream could not be opened or has broken.

Parameters

  exitCode | Numerical exit code from the stats process.
  errorMessage | Human-readable description.

## ◆ pause

void InterfaceStatsWorker::pause | ( |  | ) |
| slot

Tears down the dumpcap stream but remembers the configuration.

Used to stop sampling (and free the dumpcap process) without forgetting the application name or filter, e.g. while a capture is active. resume() re-opens the stream. A no-op if not currently running.

## ◆ resume

void InterfaceStatsWorker::resume | ( |  | ) |
| slot

Re-opens the stream previously suspended with pause().

A no-op unless the worker is paused.

## ◆ sampled

void InterfaceStatsWorker::sampled | ( | const InterfaceStatsSnapshot & | snapshot | ) |
| signal

Emitted each cycle in which new counters were read.

Parameters

  snapshot | Latest cumulative per-interface counters.

## ◆ setInterfaceFilter

void InterfaceStatsWorker::setInterfaceFilter | ( | const QStringList & | interfaceNames | ) |
| slot

Restricts which interfaces appear in emitted snapshots.

dumpcap reports counters for every interface it can open; this filter is applied only to the emitted snapshot. An empty list (the default) emits every reported interface.

Parameters

  interfaceNames | Interface names to keep, or empty for all.

## ◆ setUpdateInterval

void InterfaceStatsWorker::setUpdateInterval | ( | int | intervalMsec | ) |
| slot

Sets the pipe-drain/emit interval.

Parameters

  intervalMsec | Interval in milliseconds; values < 1 are ignored.

## ◆ start

void InterfaceStatsWorker::start | ( |  | ) |
| slot

Opens the dumpcap statistics stream and begins periodic sampling.

Re-issuing start() while already running first tears down the existing stream. On failure, failed() is emitted and no sampling occurs.

## ◆ stop

void InterfaceStatsWorker::stop | ( |  | ) |
| slot

Stops sampling and tears down the dumpcap stream and process.

Clears the running state; a subsequent start() is required to resume.

## ◆ updateInterval()

int InterfaceStatsWorker::updateInterval | ( |  | ) | const

Returns the current pipe-drain/emit interval, in milliseconds.

Seeded from a built-in default at construction; overridable via setUpdateInterval() (e.g. from a preference).

The documentation for this class was generated from the following files:

- /builds/wireshark/wireshark/ui/qt/manager/interface_stats_worker.h
- /builds/wireshark/wireshark/ui/qt/manager/interface_stats_worker.cpp