4#ifndef ABSTRACTTHREADCLASS_H
5#define ABSTRACTTHREADCLASS_H
12#include <Kanoop/mutexevent.h>
13#include <Kanoop/log.h>
14#include <Kanoop/kanoopcommon.h>
16#include "loggingbaseclass.h"
76 bool isRunning()
const {
return _thread.isRunning(); }
132 void writeLine(
const QString& line) { _stdout << line << Qt::endl; }
144 bool _success =
false;
147 bool _stopping =
false;
148 bool _blockingStart =
false;
165 void onThreadStarted();
167 void onThreadFinished();
Abstract base class for QObject-based workers that run in a dedicated QThread.
bool waitForCompletion(const TimeSpan &timeout=TimeSpan::zero())
Block until the worker thread finishes or the timeout elapses.
AbstractThreadClass(const QString &category, QObject *parent=nullptr)
Construct with a category name string and optional parent.
void setBlockingStart(bool value)
Control whether start() blocks until the thread signals readiness.
void finished()
Emitted when the worker thread has finished.
void writeLine(const QString &line)
Write a line to the standard output stream.
bool success() const
Return whether the last run completed successfully.
virtual void threadStarted()=0
Entry point called on the worker thread immediately after it starts.
virtual ~AbstractThreadClass()
Destructor — stops the thread if still running.
bool isRunning() const
Test whether the worker thread is currently running.
virtual bool start(const TimeSpan &timeout=TimeSpan::zero())
Start the worker thread and optionally wait for it to signal readiness.
void started()
Emitted when the worker thread has started.
bool waitForStart(const TimeSpan &timeout)
Block until the thread has entered threadStarted() or the timeout elapses.
bool isStopping() const
Test whether stop() has been called and the thread is winding down.
void finishAndStop(bool success, const QString &message=QString())
Signal that the worker has finished, recording success and a message.
virtual void abort()
Immediately interrupt the worker thread (sets the stopping flag).
QString completionMessage() const
Return the completion message set by finishAndStop().
virtual bool stop(const TimeSpan &timeout=TimeSpan::zero())
Request the worker thread to stop and optionally wait for it to finish.
AbstractThreadClass(const Log::LogCategory &category=Log::LogCategory(), QObject *parent=nullptr)
Construct with an optional log category and parent.
void writeErrorLine(const QString &line)
Write a line to the standard error stream.
virtual void threadFinished()
Called on the worker thread just before it exits.
A named logging category with an associated minimum log level.
Mixin base class providing categorized logging at four nesting levels.
static TimeSpan zero()
Return a zero-length TimeSpan.