25 #ifndef WWORKERTHREAD_H
26 #define WWORKERTHREAD_H
31 #include <boost/shared_ptr.hpp>
32 #include <boost/signals2/signal.hpp>
35 #include "WException.h"
36 #include "WThreadedRunner.h"
41 template<
class Function_T >
66 WWorkerThread( boost::shared_ptr< Function_T > func, std::size_t
id, std::size_t numThreads );
122 template<
class Function_T >
126 m_numThreads( numThreads ),
130 if(
id >= numThreads )
132 throw WException( std::string(
"The id of this thread is not valid." ) );
136 throw WException( std::string(
"No thread function provided!" ) );
140 template<
class Function_T >
143 m_exceptionSignal.disconnect_all_slots();
144 m_stopSignal.disconnect_all_slots();
147 template<
class Function_T >
152 m_exceptionSignal.connect( func );
156 template<
class Function_T >
161 m_stopSignal.connect( func );
165 template<
class Function_T >
172 m_func->operator() ( m_id, m_numThreads, m_shutdownFlag );
176 m_exceptionSignal( e );
179 catch( std::exception
const& e )
182 m_exceptionSignal( w );
187 WException w( std::string(
"An exception was thrown." ) );
188 m_exceptionSignal( w );
195 #endif // WWORKERTHREAD_H
boost::signals2::signal< void(WException const &) > ExceptionSignal
a type for exception signals
A worker thread that belongs to a.
std::size_t m_numThreads
the number of threads
ExceptionSignal m_exceptionSignal
the exception signal
void subscribeExceptionSignal(ExceptionFunction func)
Subscribe a function to the exception signal.
boost::function< void() > StopFunction
a type for stop callbacks
Base class for all classes needing to be executed in a separate thread.
boost::shared_ptr< Function_T > m_func
the functor called in threadMain()
boost::function< void(WException const &) > ExceptionFunction
a type for exception callbacks
void subscribeStopSignal(StopFunction func)
Subscribe a function to the stop signal.
virtual ~WWorkerThread()
Default destructor.
WWorkerThread(boost::shared_ptr< Function_T > func, std::size_t id, std::size_t numThreads)
Default constructor.
std::size_t m_id
a thread id between 0 and m_numThreads - 1
WWorkerThread & operator=(WWorkerThread const &)
WWorkerThread is non-copyable, so the copy operator is not implemented.
boost::signals2::signal< void() > StopSignal
a type for stop signals
virtual void threadMain()
The thread's main function.
StopSignal m_stopSignal
the stop signal