Emotiv EPOC plugin 1.0

D:/SVN/Scol/trunk/plugins/Epoc/lib/ou_thread.h

00001 
00007 /* Copyright 2000 - 2005 Vijay Mathew Pandyalakal.  All rights reserved.
00008  *
00009  * This software may be used or modified for any purpose, personal or
00010  * commercial.  Open Source redistributions are permitted.  
00011  *
00012  * Redistributions qualify as "Open Source" under  one of the following terms:
00013  *   
00014  *    Redistributions are made at no charge beyond the reasonable cost of
00015  *    materials and delivery.
00016  *
00017  *    Redistributions are accompanied by a copy of the Source Code or by an
00018  *    irrevocable offer to provide a copy of the Source Code for up to three
00019  *    years at the cost of materials and delivery.  Such redistributions
00020  *    must allow further use, modification, and redistribution of the Source
00021  *    Code under substantially the same terms as this license.
00022  *
00023  * Redistributions of source code must retain the copyright notices as they
00024  * appear in each source code file, these license terms, and the
00025  * disclaimer/limitation of liability set forth as paragraph 6 below.
00026  *
00027  * Redistributions in binary form must reproduce this Copyright Notice,
00028  * these license terms, and the disclaimer/limitation of liability set
00029  * forth as paragraph 6 below, in the documentation and/or other materials
00030  * provided with the distribution.
00031  *
00032  * The Software is provided on an "AS IS" basis.  No warranty is
00033  * provided that the Software is free of defects, or fit for a
00034  * particular purpose.  
00035  *
00036  * Limitation of Liability. The Author shall not be liable
00037  * for any damages suffered by the Licensee or any third party resulting
00038  * from use of the Software.
00039  */
00040 #include <string>
00041 #include <windows.h>
00042 //#include <scol.h>
00043 namespace openutils {
00044         class ThreadException;
00045         class Mutex;
00046 
00053         class Thread {
00054 
00055         private:
00056                 // unsigned long* to the low-level thread object
00057                 unsigned long* m_hThread;
00058                 // a name to identify the thread
00059     std::string m_strName;
00060 
00061         public:
00062                 Thread();
00063                 Thread(const char* nm);
00064                 virtual ~Thread();
00065                 void setName(const char* nm);
00066                 std::string getName() const;
00067                 void start();
00068                 virtual void run();
00069                 void sleep(long ms);
00070                 void suspend();
00071                 void resume();
00072                 void stop();
00073 
00074                 void setPriority(int p);
00075 
00076                 bool wait(const char* m,long ms=5000);
00077                 void release(const char* m);
00078 
00079         public:
00080                 // Thread priorities
00081                 static const int P_ABOVE_NORMAL;
00082                 static const int P_BELOW_NORMAL;
00083                 static const int P_HIGHEST;
00084                 static const int P_IDLE;
00085                 static const int P_LOWEST;
00086                 static const int P_NORMAL;
00087                 static const int P_CRITICAL;
00088         private:                                
00089         };// class Thread       
00090 
00095         class Mutex {
00096         private:
00097                 // unsigned long* to the low-level mutex object
00098                 unsigned long* m_hMutex;
00099                 // name to identify the mutex
00100                 std::string m_strName;
00101         public:
00102                 Mutex();
00103                 Mutex(const char* nm);
00104                 void create(const char* nm);
00105                 unsigned long* getMutexHandle();
00106                 std::string getName();
00107                 void release();
00108                 ~Mutex();
00109         };
00110 
00115         class ThreadException {
00116         private:
00117                 std::string msg;
00118         public:
00119                 ThreadException(const char* m);
00120                 std::string getMessage() const;
00121         };      
00122 } // namespace openutils
00123 
00124 // global function called by the thread object.
00125 // this in turn calls the overridden run()
00126 extern "C" {
00127         unsigned int _ou_thread_proc(void* param);
00128 }
00129 
00130 
00131