00001 /*00002 * The Software License00003 * =================================================================================00004 * Copyright (c) 2003-.The Terimber Corporation. All rights reserved.00005 * =================================================================================00006 * Redistributions of source code must retain the above copyright notice, 00007 * this list of conditions and the following disclaimer.00008 * Redistributions in binary form must reproduce the above copyright notice, 00009 * this list of conditions and the following disclaimer in the documentation 00010 * and/or other materials provided with the distribution.00011 * The end-user documentation included with the redistribution, if any, 00012 * must include the following acknowledgment:00013 * "This product includes software developed by the Terimber Corporation."00014 * =================================================================================00015 * THIS SOFTWARE IS PROVIDED "AS IS" AND ANY EXPRESSED OR IMPLIED WARRANTIES, 00016 * INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY 00017 * AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. 00018 * IN NO EVENT SHALL THE TERIMBER CORPORATION OR ITS CONTRIBUTORS BE LIABLE FOR 00019 * ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES 00020 * (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; 00021 * LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON 00022 * ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT00023 * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE00024 * OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.00025 * ================================================================================00026 */00027
00028 #ifndef _terimber_timer_h_00029 #define _terimber_timer_h_00030
00031 #include "threadpool/thread.h"00032
00033 BEGIN_TERIMBER_NAMESPACE00034 #pragma pack(4)00035
00038class timer_callback00039 {
00040 public:
00042 virtual00043~timer_callback() {}
00045 virtual00046 void00047 notify( size_t ident,
00048 size_t interval,
00049 size_t multiplier
00050 ) = 0;
00051 };
00052
00055class timer : publicterimber_thread_employer00056 {
00057 public:
00059 timer();
00061 ~timer();
00063 void00064 activate( timer_callback* callback,
00065 size_t ident,
00066 size_t interval,
00067 size_t multiplier = 1,
00068 bool reactivate = true00069 );
00072 void00073 deactivate();
00074 protected:
00077 virtual00078 bool00079 v_has_job( size_t ident,
00080 void* user_data
00081 );
00083 virtual00084 void00085 v_do_job( size_t ident,
00086 void* user_data
00087 );
00088 private:
00089thread_thread;
00090mutex_mtx;
00091size_t_ident;
00092size_t_interval;
00093size_t_multiplier;
00094size_t_trigger;
00095bool_reactivate;
00096bool_first;
00097timer_callback* _callback;
00098 };
00099
00100 #pragma pack()00101 END_TERIMBER_NAMESPACE00102
00103 #endif // _terimber_timer_h_