C/C++ Reference
BaTimer.h
00001 /*
00002  *     ____             _________                __                _     
00003  *    / __ \___  ____ _/ /_  __(_)___ ___  ___  / /   ____  ____ _(_)____
00004  *   / /_/ / _ \/ __ `/ / / / / / __ `__ \/ _ \/ /   / __ \/ __ `/ / ___/
00005  *  / _, _/  __/ /_/ / / / / / / / / / / /  __/ /___/ /_/ / /_/ / / /__  
00006  * /_/ |_|\___/\__,_/_/ /_/ /_/_/ /_/ /_/\___/_____/\____/\__, /_/\___/  
00007  *                                                       /____/          
00008  *
00009  *                  Barracuda Embedded Web-Server 
00010  ****************************************************************************
00011  *            HEADER
00012  *
00013  *   $Id: BaTimer.h 2534 2011-12-27 20:55:40Z wini $
00014  *
00015  *   COPYRIGHT:  Real Time Logic LLC, 2008
00016  *               http://www.realtimelogic.com
00017  *
00018  *   The copyright to the program herein is the property of
00019  *   Real Time Logic. The program may be used or copied only
00020  *   with the written permission from Real Time Logic LLC or
00021  *   in accordance with the terms and conditions stipulated in
00022  *   the agreement under which the program has been supplied.
00023  ****************************************************************************
00024  *
00025  */
00026 
00027 #ifndef __BaTimer_h
00028 #define __BaTimer_h
00029 
00030 #include <HttpServerLib.h>
00031 #include <SplayTree.h>
00032 #include <DoubleList.h>
00033 #include <ThreadLib.h>
00034 
00035 /* The number of slots in the timer. This must be a value of 2^x */
00036 #define BA_TIMER_SLOTS 32
00037 
00040 typedef BaBool (*BaTimer_CB)(void* data);
00041 
00046 typedef struct BaTimer
00047 #ifdef __cplusplus
00048 : public Thread
00049 {
00057       BaTimer(ThreadMutex* mutex,int stackSize, BaTime ticklen=10,
00058               ThreadPriority priority=ThreadPrioNormal,
00059               AllocatorIntf* alloc=0);
00062       ~BaTimer();
00063 
00073       U32 set(BaTimer_CB cb, void* data, U32 milliSec);
00074 
00080       int reset(U32 tkey, U32 milliSec);
00081 
00086       int cancel(U32 tkey);
00087 #else
00088 #if 0
00089 }
00090 #endif
00091 {
00092    Thread super;
00093 #endif
00094    DoubleList slots[BA_TIMER_SLOTS];
00095    DoubleList readyQ;
00096    SplayTree tnTree;
00097    ThreadMutex* mutex;
00098    AllocatorIntf* alloc;
00099    BaTime ticklen;
00100    S16 dataInReadyQ;
00101    U16 curIndex;
00102 } BaTimer;
00103 
00104 #ifdef __cplusplus
00105 extern "C" {
00106 #endif  
00107 BA_API void BaTimer_constructor(
00108    BaTimer* o, ThreadMutex* mutex,int stackSize, BaTime ticklen,
00109    ThreadPriority priority, AllocatorIntf* alloc);
00110 BA_API void BaTimer_destructor(BaTimer* o);
00111 BA_API U32 BaTimer_set(BaTimer* o, BaTimer_CB cb, void* data, U32 milliSec);
00112 BA_API int BaTimer_reset(BaTimer* o, U32 tkey, U32 milliSec);
00113 BA_API int BaTimer_cancel(BaTimer* o, U32 tkey);
00114 #ifdef __cplusplus
00115 }
00116 inline BaTimer::BaTimer(ThreadMutex* mutex,int stackSize, BaTime ticklen,
00117                  ThreadPriority priority, AllocatorIntf* alloc) {
00118    BaTimer_constructor(this, mutex, stackSize, ticklen, priority,alloc);
00119 }
00120 inline BaTimer::~BaTimer() {
00121    BaTimer_destructor(this);
00122 }
00123 inline U32 BaTimer::set(BaTimer_CB cb, void* data, U32 milliSec) {
00124    return BaTimer_set(this, cb, data, milliSec);
00125 }
00126 inline int BaTimer::reset(U32 tkey, U32 milliSec) {
00127    return BaTimer_reset(this, tkey, milliSec);
00128 }
00129 inline int BaTimer::cancel(U32 tkey) {
00130    return BaTimer_cancel(this, tkey);
00131 }
00132 #endif  
00133 
00134 #endif