evq_timer.h

Go to the documentation of this file.
00001 // This component produces timer events. On Symbian, it should be implementable based on RTimer. On a POSIX system, an implementation based on pthread_cond_timedwait should work just fine. In fact, the same implementation may just work with Open C on Symbian.
00002 
00003 // Note that this API is not intended to be thread safe, even though some worker thread(s) may be used internally.
00004 
00005 #ifndef __EVQ_TIMER_H__
00006 #define __EVQ_TIMER_H__
00007 
00008 #include "common/evq_event.h"
00009 
00010 // 0 value indicates no error.
00011 // Other error codes are POSIX style.
00012 typedef MAYBE_ERROR_RTYPE (TimerCallback)(int errCode, void* user_data MAYBE_ERROR_PARAM);
00013 
00014 // Only one timer request per Timer object may be outstanding at any one time.
00015 typedef struct {
00016   Event event;
00017   EventQueue* queue;
00018   pthread_t worker;
00019   pthread_mutex_t mutex;
00020   pthread_cond_t cond;
00021   int running; // worker thread is running
00022   int active; // timer is active
00023   struct timespec* time;
00024   TimerCallback* callback;
00025   void* user_data;
00026 } Timer;
00027 
00028 // Initializes the passed timer object.
00029 // You must specify the event queue of the thread in which any callbacks are to be made.
00030 // In the Symbian OS implementation the "queue" argument is pointless, and may be passed as NULL.
00031 void timer_init(EventQueue* queue, Timer* timer);
00032 
00033 // Makes a timer request. Expiration is at the specified absolute
00034 // time.
00035 // time:: Expiration time is not copied, and hence must persist until
00036 //        completion.
00037 void timer_at(Timer* timer, struct timespec* time, TimerCallback* callback, void* user_data);
00038 
00039 // Cancels any outstanding timer request.
00040 // No harm in calling this if there is no outstanding request.
00041 void timer_cancel(Timer* timer);
00042 
00043 // Frees the resources associated with the timer object.
00044 void timer_close(Timer* timer);
00045 
00046 #endif //  __EVQ_TIMER_H__
00047 
00048 /**
00049 
00050 evq_timer.h
00051 
00052 Copyright 2009 Helsinki Institute for Information Technology (HIIT)
00053 and the authors. All rights reserved.
00054 
00055 Authors: Tero Hasu <tero.hasu@hut.fi>
00056 
00057 Permission is hereby granted, free of charge, to any person
00058 obtaining a copy of this software and associated documentation files
00059 (the "Software"), to deal in the Software without restriction,
00060 including without limitation the rights to use, copy, modify, merge,
00061 publish, distribute, sublicense, and/or sell copies of the Software,
00062 and to permit persons to whom the Software is furnished to do so,
00063 subject to the following conditions:
00064 
00065 The above copyright notice and this permission notice shall be
00066 included in all copies or substantial portions of the Software.
00067 
00068 THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
00069 EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
00070 MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
00071 NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS
00072 BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN
00073 ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN
00074 CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
00075 SOFTWARE.
00076 
00077  **/

ContextLogger2—ContextLogger2 Logger Daemon Internals—Generated on Mon May 2 13:49:52 2011 by Doxygen 1.6.1