Maki
Formally verfied low-code orchestration
Loading...
Searching...
No Matches
Pipeline Class Reference

Executes and manages a sequence of external processes. More...

#include <pipeline.h>

Inheritance diagram for Pipeline:

Classes

struct  ProcessInfo
struct  GroupInfo
struct  Info
struct  PipelineProcess
 Internal representation of a process registered in the pipeline. More...
struct  PipelineGroup
 Internal representation of a group of processes. More...

Public Types

enum class  State {
  Unknown , Idle , Running , Aborting ,
  Done , Error
}
 Internal state of the pipeline execution. More...

Signals

void startingProcess (const Info &info, const QString &process, const QStringList &arguments)
 Emitted before a process starts.
void processStarted (const Info &info, const QString &process, const QStringList &arguments)
 Emitted after a process starts.
void finished (const Info &info, int exitCode, QProcess::ExitStatus status)
 Emitted when the currently running process finishes.
void finishedLast (const Info &info, int exitCode, const QString &message)
 Emitted when the last process in the pipeline finishes.
void startingPipeline (const Info &info)
 Emitted when the complete pipeline is started.
void startingGroup (const Info &info, const QString &groupName)
 Emitted before a group starts.
void finishedGroup (const Info &info, const QString &groupName, int exitCode, const QString &message)
 Emitted when the last process in a group finishes.
void readyReadStandardOutput (const QByteArray &message)
 Emitted when new data is available on the standard output stream.
void readyReadStandardError (const QByteArray &message)
 Emitted when new data is available on the standard error stream.
void errorOccurred (const Info &info, QProcess::ProcessError error, const QString &message)
 Emitted when a process error occurs.

Public Member Functions

 Pipeline (QObject *parent=nullptr)
 Constructs a Pipeline instance.
 ~Pipeline ()
 Destructs a Pipeline instance.
VoidResult add (QProcess *process, maki::OnFail onFail, std::function< void(int &exitCode, QProcess::ExitStatus &status)> callback=nullptr) override
 Adds a process to the pipeline.
VoidResult start ()
 Starts executing the pipeline.
QString name () const
 Returns the pipeline name.
void setName (const QString &name)
 Sets the pipeline name.
int size () const
 Returns the number of processes registered in the pipeline.
bool isRunning () const
 Indicates whether the pipeline is currently running.
VoidResult abort (bool syncAbort=false)
 Aborts the currently running pipeline.

Private Slots

void onReadyReadStandardOutput ()
 Slot triggered when the process produces standard output.
void onReadyReadStandardError ()
 Slot triggered when the process produces standard error output.
void onFinished (int exitCode, QProcess::ExitStatus status)
 Slot triggered when a process finishes execution.
void onErrorOccurred (QProcess::ProcessError error)
 Slot triggered when a process error occurs.

Private Member Functions

void startNextOrEnd (int exitCode, QProcess::ExitStatus status)
 Starts the next process or ends the pipeline.
bool handleInputData (QByteArray &data) const
 Processes incoming output data from the running process.

Private Attributes

std::mutex mStateMutex
 Mutex protecting access to the pipeline state.
QString mName
 Name of the pipeline.
std::shared_ptr< PipelineProcess > mRunningProcess
 Currently running process.

Detailed Description

Executes and manages a sequence of external processes.

Pipeline provides a simple orchestration mechanism for running a set of QProcess instances sequentially. Each process can define a failure policy and an optional callback that is invoked when the process finishes.

The class emits signals to allow observers (such as UI components) to track process execution, receive output streams, and react to failures.

Member Enumeration Documentation

◆ State

enum class Pipeline::State
strong

Internal state of the pipeline execution.

Enumerator
Unknown 

Not initialized.

Idle 

Not running.

Running 

Currently executing processes.

Aborting 

Aborting execution.

Done 

Done successfully.

Error 

Done with error.

Constructor & Destructor Documentation

◆ Pipeline()

Pipeline::Pipeline ( QObject * parent = nullptr)

Constructs a Pipeline instance.

Parameters
parentOptional Qt parent object.

Member Function Documentation

◆ abort()

VoidResult Pipeline::abort ( bool syncAbort = false)

Aborts the currently running pipeline.

If a process is currently executing, the pipeline transitions to the aborting state and stops further execution.

Returns
VoidResult indicating whether the abort request succeeded.

◆ add()

VoidResult Pipeline::add ( QProcess * process,
maki::OnFail onFail,
std::function< void(int &exitCode, QProcess::ExitStatus &status)> callback = nullptr )
override

Adds a process to the pipeline.

The process will be executed in the order it was added. The behavior in case of failure is determined by the provided OnFail policy.

Parameters
processPointer to the QProcess to execute.
onFailPolicy describing what should happen if the process fails.
callbackOptional callback executed when the process finishes.
Returns
VoidResult indicating whether the process was successfully added.

◆ errorOccurred

void Pipeline::errorOccurred ( const Info & info,
QProcess::ProcessError error,
const QString & message )
signal

Emitted when a process error occurs.

Parameters
infoInformation about the pipeline and group.
errorError reported by QProcess.
messageAdditional message.

◆ finished

void Pipeline::finished ( const Info & info,
int exitCode,
QProcess::ExitStatus status )
signal

Emitted when the currently running process finishes.

Parameters
infoInformation about the pipeline and group.
exitCodeExit code returned by the process.
statusExit status reported by QProcess.

◆ finishedGroup

void Pipeline::finishedGroup ( const Info & info,
const QString & groupName,
int exitCode,
const QString & message )
signal

Emitted when the last process in a group finishes.

Parameters
infoInformation about the pipeline and group.
groupNameName of the group which finished
exitCodeExit code returned by the process.
messageAdditional message.

◆ finishedLast

void Pipeline::finishedLast ( const Info & info,
int exitCode,
const QString & message )
signal

Emitted when the last process in the pipeline finishes.

Parameters
infoInformation about the pipeline and group.
exitCodeExit code returned by the process.
messageAdditional message.

◆ handleInputData()

bool Pipeline::handleInputData ( QByteArray & data) const
private

Processes incoming output data from the running process.

This may perform filtering, buffering, or preprocessing of the data before it is emitted through signals.

Parameters
dataData read from the process stream.
Returns
True if the data was handled successfully.

◆ isRunning()

bool Pipeline::isRunning ( ) const

Indicates whether the pipeline is currently running.

Returns
True if a process is executing or the pipeline is active.

◆ name()

QString Pipeline::name ( ) const

Returns the pipeline name.

Returns
Name of the pipeline.

◆ onErrorOccurred

void Pipeline::onErrorOccurred ( QProcess::ProcessError error)
privateslot

Slot triggered when a process error occurs.

Parameters
errorError reported by QProcess.

◆ onFinished

void Pipeline::onFinished ( int exitCode,
QProcess::ExitStatus status )
privateslot

Slot triggered when a process finishes execution.

Parameters
exitCodeExit code returned by the process.
statusExit status reported by QProcess.

◆ processStarted

void Pipeline::processStarted ( const Info & info,
const QString & process,
const QStringList & arguments )
signal

Emitted after a process starts.

Allows observers to track which external command is being executed.

Parameters
infoInformation about the pipeline and group.
processExecutable name.
argumentsCommand line arguments.

◆ readyReadStandardError

void Pipeline::readyReadStandardError ( const QByteArray & message)
signal

Emitted when new data is available on the standard error stream.

Parameters
messageData read from the process stderr.

◆ readyReadStandardOutput

void Pipeline::readyReadStandardOutput ( const QByteArray & message)
signal

Emitted when new data is available on the standard output stream.

Parameters
messageData read from the process stdout.

◆ setName()

void Pipeline::setName ( const QString & name)

Sets the pipeline name.

Parameters
nameNew pipeline name.

◆ size()

int Pipeline::size ( ) const

Returns the number of processes registered in the pipeline.

Returns
Total number of processes.

◆ start()

VoidResult Pipeline::start ( )

Starts executing the pipeline.

Processes will be executed sequentially until the pipeline finishes, aborts, or encounters a failure depending on the configured policy.

Returns
VoidResult indicating whether the pipeline started successfully.

◆ startingGroup

void Pipeline::startingGroup ( const Info & info,
const QString & groupName )
signal

Emitted before a group starts.

Allows observers to track which group is being executed

Parameters
infoInformation about the pipeline and group.
groupNameName of the group which is starting

◆ startingPipeline

void Pipeline::startingPipeline ( const Info & info)
signal

Emitted when the complete pipeline is started.

Parameters
infoInformation about the pipeline and group.

◆ startingProcess

void Pipeline::startingProcess ( const Info & info,
const QString & process,
const QStringList & arguments )
signal

Emitted before a process starts.

Allows observers to track which external command is being executed.

Parameters
infoInformation about the pipeline and group.
processExecutable name.
argumentsCommand line arguments.

◆ startNextOrEnd()

void Pipeline::startNextOrEnd ( int exitCode,
QProcess::ExitStatus status )
private

Starts the next process or ends the pipeline.

This method decides whether to continue with the next process or finish the pipeline depending on the exit status and failure policies.

Parameters
exitCodeExit code of the completed process.
statusExit status of the completed process.

The documentation for this class was generated from the following files:
  • /__w/maki/maki/app/compiler/pipeline.h
  • /__w/maki/maki/app/compiler/pipeline.cpp