00001 /* 00002 * thread.h 00003 * This file is part of dbPager Classes Library (DCL) 00004 * 00005 * Copyright (c) 2008 Dennis Prochko <wolfsoft@mail.ru> 00006 * 00007 * DCL is free software; you can redistribute it and/or modify 00008 * it under the terms of the GNU General Public License as published by 00009 * the Free Software Foundation version 3. 00010 * 00011 * DCL is distributed in the hope that it will be useful, 00012 * but WITHOUT ANY WARRANTY; without even the implied warranty of 00013 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 00014 * GNU General Public License for more details. 00015 * 00016 * You should have received a copy of the GNU General Public License 00017 * along with DCL; if not, write to the Free Software 00018 * Foundation, Inc., 51 Franklin St, Fifth Floor, 00019 * Boston, MA 02110-1301 USA 00020 */ 00021 00022 #ifndef _THREAD_H_ 00023 #define _THREAD_H_ 00024 00025 #include <dcl/exception.h> 00026 #include <dcl/delegate.h> 00027 00028 namespace dbp { 00029 00031 00034 class thread_exception: public exception { 00035 public: 00036 thread_exception(const std::string &msg): exception(msg) { } 00037 }; 00038 00040 00044 class thread_int { 00045 public: 00047 typedef delegate1<thread_int&,void> execute_handler; 00049 virtual ~thread_int() { }; 00051 virtual void start() = 0; 00053 virtual void stop() = 0; 00055 virtual void pause() = 0; 00057 virtual void resume() = 0; 00059 00069 virtual void on_execute(execute_handler handler) = 0; 00071 virtual void wait_for() = 0; 00072 }; 00073 00075 00079 class thread: public thread_int { 00080 public: 00082 thread(); 00084 thread(const thread &src); 00086 thread& operator=(const thread &src) { 00087 on_execute(src._handler); 00088 return *this; 00089 } 00090 virtual ~thread(); 00091 virtual void start(); 00092 virtual void stop(); 00093 virtual void pause(); 00094 virtual void resume(); 00095 virtual void on_execute(thread_int::execute_handler handler); 00096 virtual void wait_for(); 00097 private: 00098 thread_int::execute_handler _handler; 00099 thread_int *pimpl; 00100 }; 00101 00102 } 00103 00104 #endif /*_THREAD_H_*/