25 #ifndef WWORKERTHREAD_H
26 #define WWORKERTHREAD_H
32 #include <boost/shared_ptr.hpp>
35 #include <boost/signals2/signal.hpp>
39 #include "WException.h"
40 #include "WThreadedRunner.h"
45 template<
class Function_T >
70 WWorkerThread( boost::shared_ptr< Function_T > func, std::size_t
id, std::size_t numThreads );
126 template<
class Function_T >
130 m_numThreads( numThreads ),
134 if(
id >= numThreads )
136 throw WException( std::string(
"The id of this thread is not valid." ) );
140 throw WException( std::string(
"No thread function provided!" ) );
144 template<
class Function_T >
147 m_exceptionSignal.disconnect_all_slots();
148 m_stopSignal.disconnect_all_slots();
151 template<
class Function_T >
156 m_exceptionSignal.connect( func );
160 template<
class Function_T >
165 m_stopSignal.connect( func );
169 template<
class Function_T >
176 m_func->operator() ( m_id, m_numThreads, m_shutdownFlag );
180 m_exceptionSignal( e );
183 catch( std::exception
const& e )
186 m_exceptionSignal( w );
191 WException w( std::string(
"An exception was thrown." ) );
192 m_exceptionSignal( w );
199 #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