QtPass 2.0.0
Developer documentation
Loading...
Searching...
No Matches
SimpleTransaction Class Reference

Tracks a sequence of processes that should be treated as one atomic operation. More...

#include <simpletransaction.h>

Public Member Functions

 SimpleTransaction ()
 Construct a SimpleTransaction in its initial idle state.
void transactionStart ()
 Open a transaction: the processes added until the matching transactionEnd() are reported as one operation.
void transactionAdd (Enums::PROCESS process)
 Note that process has been queued.
void transactionEnd (Enums::PROCESS process)
 Close the transaction opened by the matching transactionStart().
auto transactionIsOver (Enums::PROCESS current) -> Enums::PROCESS
 Tell whether the process that just finished ends the oldest pending transaction, and take that transaction off the queue if so.

Private Attributes

int transactionDepth {0}
 How many transactionStart() calls are still open.
Enums::PROCESS lastInTransaction {Enums::INVALID}
 The process most recently added to the open transaction, or Enums::INVALID when none was added yet.
std::queue< std::pair< Enums::PROCESS, Enums::PROCESS > > transactionQueue
 Closed transactions awaiting completion, oldest first: the process that ends each one, and the result to report when it does.

Detailed Description

Tracks a sequence of processes that should be treated as one atomic operation.

ImitatePass queues several processes for one operation (gpg, then git add, then git commit for an insert) and wants to report the operation once, when the last of them ends. Between transactionStart() and transactionEnd() it calls transactionAdd() for each process it queues; transactionEnd() names the result to report. As processes finish, transactionIsOver() answers with that result for the last one of a transaction and with Enums::INVALID for every earlier one. Transactions may nest; only the outermost one counts.

Definition at line 29 of file simpletransaction.h.

Constructor & Destructor Documentation

◆ SimpleTransaction()

SimpleTransaction::SimpleTransaction ( )
inline

Construct a SimpleTransaction in its initial idle state.

Definition at line 47 of file simpletransaction.h.

Member Function Documentation

◆ transactionAdd()

void SimpleTransaction::transactionAdd ( Enums::PROCESS process)

Note that process has been queued.

Inside an open transaction it becomes the transaction's latest step. Outside one it is a transaction of its own, reported as itself.

Parameters
processThe process just queued.

Definition at line 21 of file simpletransaction.cpp.

Here is the caller graph for this function:

◆ transactionEnd()

void SimpleTransaction::transactionEnd ( Enums::PROCESS process)

Close the transaction opened by the matching transactionStart().

When the outermost transaction closes and at least one process was added, the last one added becomes the step that completes it.

Parameters
processWhat transactionIsOver() reports once that step ends.

Definition at line 30 of file simpletransaction.cpp.

Here is the caller graph for this function:

◆ transactionIsOver()

auto SimpleTransaction::transactionIsOver ( Enums::PROCESS current) -> Enums::PROCESS

Tell whether the process that just finished ends the oldest pending transaction, and take that transaction off the queue if so.

Parameters
currentThe process that just finished.
Returns
The transaction's result as set by transactionAdd() or transactionEnd(), or Enums::INVALID while the transaction has steps left.

Definition at line 41 of file simpletransaction.cpp.

Here is the caller graph for this function:

◆ transactionStart()

void SimpleTransaction::transactionStart ( )

Open a transaction: the processes added until the matching transactionEnd() are reported as one operation.

Definition at line 16 of file simpletransaction.cpp.

Here is the caller graph for this function:

Member Data Documentation

◆ lastInTransaction

Enums::PROCESS SimpleTransaction::lastInTransaction {Enums::INVALID}
private

The process most recently added to the open transaction, or Enums::INVALID when none was added yet.

Definition at line 36 of file simpletransaction.h.

◆ transactionDepth

int SimpleTransaction::transactionDepth {0}
private

How many transactionStart() calls are still open.

Definition at line 31 of file simpletransaction.h.

◆ transactionQueue

std::queue<std::pair<Enums::PROCESS, Enums::PROCESS> > SimpleTransaction::transactionQueue
private

Closed transactions awaiting completion, oldest first: the process that ends each one, and the result to report when it does.

Definition at line 41 of file simpletransaction.h.


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