iSpike  2.1
Spike conversion library for robotics
D:/Home/Programs/iSpike/include/iSpike/ISpikeThread.hpp
Go to the documentation of this file.
00001 #ifndef ISPIKETHREAD_HPP
00002 #define ISPIKETHREAD_HPP
00003 
00004 //iSpike includes
00005 #include <iSpike/Log/Log.hpp>
00006 
00007 //Other includes
00008 #include <string>
00009 #include <boost/thread.hpp>
00010 #include <boost/smart_ptr.hpp>
00011 using namespace std;
00012 
00013 namespace ispike {
00014 
00016         class ISpikeThread {
00017 
00018                 public:
00020                         ISpikeThread(){
00021                                 errorFlag = false;
00022                                 running = false;
00023                                 stopRequested = false;
00024                                 errorMessage = "";
00025                         }
00026 
00028                         virtual ~ISpikeThread(){}
00029 
00031                         void clearError(){ errorFlag = false; errorMessage = ""; }
00032 
00034                         string getErrorMessage() { return errorMessage; }
00035 
00037                         bool isError() { return errorFlag; }
00038 
00040                         bool isRunning() { return running; }
00041 
00043                         bool isStopRequested() { return stopRequested; }
00044 
00046                         void requestStop() { stopRequested = true; }
00047 
00049                         void setError(string errorMsg) { errorFlag = true; errorMessage = errorMsg; LOG(LOG_CRITICAL)<<"Thread error: "<< errorMsg; }
00050 
00052                         void setRunning(bool running) { this->running = running; stopRequested = !running; }
00053 
00055                         virtual void start() = 0;
00056 
00057 
00058                 protected:
00060                         virtual void workerFunction() = 0;
00061 
00063                         boost::shared_ptr<boost::thread> getThreadPointer() const { return threadPointer; }
00064 
00066                         void setThreadPointer(boost::shared_ptr<boost::thread> threadPointer) { this->threadPointer = threadPointer; }
00067 
00069                         boost::mutex threadMutex;
00070 
00071 
00072                 private:
00074                         bool errorFlag;
00075 
00077                         string errorMessage;
00078 
00080                         bool running;
00081 
00083                         bool stopRequested;
00084 
00086                         boost::shared_ptr<boost::thread> threadPointer;
00087 
00088         };
00089 
00090 }
00091 
00092 #endif//ISPIKETHREAD_HPP
 All Classes Namespaces Files Functions Variables Enumerations Enumerator Defines