25 #ifndef WTHREADEDRUNNER_H
26 #define WTHREADEDRUNNER_H
32 #include <boost/function.hpp>
33 #include <boost/signals2.hpp>
34 #include <boost/thread.hpp>
35 #include <boost/thread/thread.hpp>
38 #include "WThreadedRunnerSignals.h"
49 typedef std::shared_ptr< WThreadedRunner >
SPtr;
54 typedef std::shared_ptr< const WThreadedRunner >
ConstSPtr;
88 void wait(
bool requestFinish =
false );
105 virtual boost::signals2::connection
subscribeSignal( THREAD_SIGNAL signal, t_ThreadErrorSignalHandlerType notifier );
170 void sleep(
const int32_t t )
const;
177 void msleep(
const int32_t t )
const;
Base class for all classes needing to be executed in a separate thread.
void msleep(const int32_t t) const
Sets thread asleep.
virtual boost::signals2::connection subscribeSignal(THREAD_SIGNAL signal, t_ThreadErrorSignalHandlerType notifier)
Connects a specified notify function with a signal this thread instance is offering.
virtual void run()
Run thread.
void threadMainSave()
The is the thread entry point.
void yield() const
Give remaining execution timeslice to another thread.
boost::function< void(void) > THREADFUNCTION
Type used for simple thread functions.
const std::string & getCrashMessage() const
Get the message of the exception finally causing the crash.
std::string m_threadName
This threads name.
virtual void threadMain()
Function that has to be overwritten for execution.
std::string getThreadName() const
Returns the current thread name.
std::shared_ptr< WThreadedRunner > SPtr
Abbreviation to a shared_ptr to this type.
void setThreadName(std::string name)
Set the name of the thread.
std::string m_crashMessage
The crash message.
static void setThisThreadName(std::string name)
Static function to set the name of the calling thread.
WThreadedRunner(const WThreadedRunner &rhs)
Disallow copy construction.
void sleep(const int32_t t) const
Sets thread asleep.
void handleDeadlyException(const WException &e, std::string sender="WThreadedRunner")
Handle the specified exception which was not caught in the thread, which basically means the thread h...
WThreadedRunner()
Default constructor.
void waitForStop()
Let the thread sleep until a stop request was given.
virtual void requestStop()
This method's purpose is to request a stop without waiting for it.
virtual ~WThreadedRunner()
Destructor.
void wait(bool requestFinish=false)
Wait for the thread to be finished.
virtual void notifyStop()
Gets called when the thread should be stopped.
boost::thread m_thread
Thread instance.
WBoolFlag m_isCrashed
True whenever an exception is thrown during threadMain.
WBoolFlag m_shutdownFlag
Condition getting fired whenever the thread should quit.
std::shared_ptr< const WThreadedRunner > ConstSPtr
Abbreviation to a const shared_ptr to this type.
t_ThreadErrorSignalType signal_thread_error
Signal fired whenever a thread throws an exception/error.
const WBoolFlag & isCrashed() const
Checks whether this thread has been crashed.
WThreadedRunner & operator=(const WThreadedRunner &rhs)
Disallow copy assignment.
virtual void onThreadException(const WException &e)
This method is called if an exception was caught, which came from the custom thread code.