QGroundControl
Ground Control Station for MAVLink Drones
Loading...
Searching...
No Matches
StateHistoryRecorder Class Reference

Records state machine transitions for debugging and analysis. More...

#include <StateHistoryRecorder.h>

Inheritance diagram for StateHistoryRecorder:
Collaboration diagram for StateHistoryRecorder:

Classes

struct  HistoryEntry
 A recorded state transition entry. More...

Public Types

enum  TransitionReason {
  Entered , Exited , Timeout , Error ,
  Signal , Event , Unknown
}
 Reason for a state transition. More...

Public Member Functions

 StateHistoryRecorder (QGCStateMachine *machine, int maxEntries=1000)
 ~StateHistoryRecorder () override=default
void setEnabled (bool enabled)
 Enable or disable recording.
bool isEnabled () const
void setMaxEntries (int max)
 Set the maximum number of entries to keep (circular buffer).
int maxEntries () const
void clear ()
 Clear all recorded history.
int count () const
 Get the number of recorded entries.
QList< HistoryEntry > history () const
 Get all history entries (oldest first).
QList< HistoryEntry > lastEntries (int n) const
 Get the last N entries.
QList< HistoryEntry > entriesForState (const QString &stateName) const
 Get entries for a specific state.
QString dumpHistory () const
 Get a human-readable dump of the history.
QJsonArray toJson () const
 Export history as JSON array.
void logHistory () const
 Log history to debug output.
void addEntry (const QString &stateName, TransitionReason reason, const QString &details=QString())
 Manually add an entry (for custom transition types).

Detailed Description

Records state machine transitions for debugging and analysis.

Maintains a circular buffer of state transitions with timestamps, transition reasons, and optional metadata.

Usage:

QGCStateMachine machine("MyMachine", nullptr);
StateHistoryRecorder recorder(&machine);
recorder.setEnabled(true);
// ... run state machine ...
qDebug() << recorder.dumpHistory();
QGroundControl specific state machine with enhanced error handling.
StateHistoryRecorder(QGCStateMachine *machine, int maxEntries=1000)

Definition at line 29 of file StateHistoryRecorder.h.

Member Enumeration Documentation

◆ TransitionReason

Reason for a state transition.

Enumerator
Entered 

State was entered.

Exited 

State was exited.

Timeout 

Transition due to timeout.

Error 

Transition due to error.

Signal 

Transition triggered by signal.

Event 

Transition triggered by event.

Unknown 

Unknown reason.

Definition at line 35 of file StateHistoryRecorder.h.

Constructor & Destructor Documentation

◆ StateHistoryRecorder()

StateHistoryRecorder::StateHistoryRecorder ( QGCStateMachine * machine,
int maxEntries = 1000 )
explicit

Definition at line 40 of file StateHistoryRecorder.cc.

References maxEntries().

◆ ~StateHistoryRecorder()

StateHistoryRecorder::~StateHistoryRecorder ( )
overridedefault

Member Function Documentation

◆ addEntry()

void StateHistoryRecorder::addEntry ( const QString & stateName,
TransitionReason reason,
const QString & details = QString() )

◆ clear()

void StateHistoryRecorder::clear ( )

Clear all recorded history.

Definition at line 90 of file StateHistoryRecorder.cc.

◆ count()

int StateHistoryRecorder::count ( ) const
inline

Get the number of recorded entries.

Definition at line 72 of file StateHistoryRecorder.h.

◆ dumpHistory()

QString StateHistoryRecorder::dumpHistory ( ) const

Get a human-readable dump of the history.

Definition at line 114 of file StateHistoryRecorder.cc.

Referenced by logHistory().

◆ entriesForState()

QList< StateHistoryRecorder::HistoryEntry > StateHistoryRecorder::entriesForState ( const QString & stateName) const

Get entries for a specific state.

Definition at line 103 of file StateHistoryRecorder.cc.

◆ history()

QList< HistoryEntry > StateHistoryRecorder::history ( ) const
inline

Get all history entries (oldest first).

Definition at line 75 of file StateHistoryRecorder.h.

◆ isEnabled()

bool StateHistoryRecorder::isEnabled ( ) const
inline

Definition at line 62 of file StateHistoryRecorder.h.

◆ lastEntries()

QList< StateHistoryRecorder::HistoryEntry > StateHistoryRecorder::lastEntries ( int n) const

Get the last N entries.

Definition at line 95 of file StateHistoryRecorder.cc.

◆ logHistory()

void StateHistoryRecorder::logHistory ( ) const

Log history to debug output.

Definition at line 137 of file StateHistoryRecorder.cc.

References dumpHistory().

◆ maxEntries()

int StateHistoryRecorder::maxEntries ( ) const
inline

Definition at line 66 of file StateHistoryRecorder.h.

Referenced by StateHistoryRecorder().

◆ setEnabled()

void StateHistoryRecorder::setEnabled ( bool enabled)

Enable or disable recording.

Definition at line 47 of file StateHistoryRecorder.cc.

◆ setMaxEntries()

void StateHistoryRecorder::setMaxEntries ( int max)

Set the maximum number of entries to keep (circular buffer).

Definition at line 80 of file StateHistoryRecorder.cc.

◆ toJson()

QJsonArray StateHistoryRecorder::toJson ( ) const

Export history as JSON array.

Definition at line 128 of file StateHistoryRecorder.cc.


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