Kannel: Open Source WAP and SMS gateway  $Revision: 5037 $
gw-timer.h
Go to the documentation of this file.
1 /* ====================================================================
2  * The Kannel Software License, Version 1.0
3  *
4  * Copyright (c) 2001-2016 Kannel Group
5  * Copyright (c) 1998-2001 WapIT Ltd.
6  * All rights reserved.
7  *
8  * Redistribution and use in source and binary forms, with or without
9  * modification, are permitted provided that the following conditions
10  * are met:
11  *
12  * 1. Redistributions of source code must retain the above copyright
13  * notice, this list of conditions and the following disclaimer.
14  *
15  * 2. Redistributions in binary form must reproduce the above copyright
16  * notice, this list of conditions and the following disclaimer in
17  * the documentation and/or other materials provided with the
18  * distribution.
19  *
20  * 3. The end-user documentation included with the redistribution,
21  * if any, must include the following acknowledgment:
22  * "This product includes software developed by the
23  * Kannel Group (http://www.kannel.org/)."
24  * Alternately, this acknowledgment may appear in the software itself,
25  * if and wherever such third-party acknowledgments normally appear.
26  *
27  * 4. The names "Kannel" and "Kannel Group" must not be used to
28  * endorse or promote products derived from this software without
29  * prior written permission. For written permission, please
30  * contact org@kannel.org.
31  *
32  * 5. Products derived from this software may not be called "Kannel",
33  * nor may "Kannel" appear in their name, without prior written
34  * permission of the Kannel Group.
35  *
36  * THIS SOFTWARE IS PROVIDED ``AS IS'' AND ANY EXPRESSED OR IMPLIED
37  * WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES
38  * OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
39  * DISCLAIMED. IN NO EVENT SHALL THE KANNEL GROUP OR ITS CONTRIBUTORS
40  * BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY,
41  * OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT
42  * OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR
43  * BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY,
44  * WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE
45  * OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE,
46  * EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
47  * ====================================================================
48  *
49  * This software consists of voluntary contributions made by many
50  * individuals on behalf of the Kannel Group. For more information on
51  * the Kannel Group, please see <http://www.kannel.org/>.
52  *
53  * Portions of this software are based upon software originally written at
54  * WapIT Ltd., Helsinki, Finland for the Kannel project.
55  */
56 
57 /*
58  * gw-timer.h - interface to timers and timer sets.
59  *
60  * Timers can be set to elapse after a specified number of seconds
61  * (the "interval"). They can be stopped before elapsing, and the
62  * interval can be changed.
63  *
64  * An "output list" is defined for each timer. When it elapses, an
65  * event is generated on this list. The event may be removed from
66  * the output list if the timer is destroyed or extended before the
67  * event is consumed.
68  *
69  * The event to use when a timer elapses is provided by the caller.
70  * The timer module will "own" it, and be responsible for deallocation.
71  * This will be true until the event has been consumed from the output
72  * list (at which point it is owned by the consuming thread).
73  * While the event is on the output list, it is in a gray area, because
74  * the timer module might still take it back. This won't be a problem
75  * as long as you access the event only by consuming it.
76  *
77  * Timers work best if the thread that manipulates the timer (the
78  * "calling thread") is the same thread that consumes the output list.
79  * This way, it can be guaranteed that the calling thread will not
80  * see a timer elapse after being destroyed, or while being extended,
81  * because the elapse event will be deleted during such an operation.
82  *
83  * The timer_* functions have been renamed to gwtimer_* to avoid
84  * a name conflict on Solaris systems.
85  */
86 
87 #ifndef GW_TIMER_H
88 #define GW_TIMER_H
89 
90 #include "gwlib/gwlib.h"
91 
92 typedef struct Timer Timer;
93 typedef struct Timerset Timerset;
94 
95 
97 void gw_timerset_destroy(Timerset *set);
98 
99 
100 /*
101  * Create a timer and tell it to use the specified output list or
102  * callback function when it elapses.
103  * Do not start it yet. Return the new timer.
104  */
105 Timer *gw_timer_create(Timerset *set, List *outputlist, void (*callback) (void*));
106 
107 /*
108  * Destroy this timer and free its resources. Stop it first, if needed.
109  *
110  * (The _elapsed_ variant assumes that there can't be any further events
111  * within the output list for this timer, which reduces the need to
112  * traverse the output list and delete the corresponding events.)
113  */
114 void gw_timer_destroy(Timer *timer);
115 void gw_timer_elapsed_destroy(Timer *timer);
116 
117 /*
118  * Make the timer elapse after 'interval' seconds, at which time it
119  * will push event 'event' on the output list defined for its timer set.
120  * - If the timer was already running, these parameters will override
121  * its old settings.
122  * - If the timer has already elapsed, try to remove its event from
123  * the output list.
124  * If this is not the first time the timer was started, the event
125  * pointer is allowed to be NULL. In that case the event pointer
126  * from the previous call to timer_start for this timer is re-used.
127  * NOTE: Each timer must have a unique event pointer. The caller must
128  * create the event, and passes control of it to the timer module with
129  * this call.
130  *
131  * (The _elapsed_ variant assumes that there can't be any further events
132  * within the output list for this timer, which reduces the need to
133  * traverse the output list and delete the corresponding events.)
134  */
135 void gw_timer_start(Timer *timer, int interval, void *data);
136 void gw_timer_elapsed_start(Timer *timer, int interval, void *data);
137 
138 /*
139  * Stop this timer. If it has already elapsed, try to remove its
140  * event from the output list.
141  *
142  * (The _elapsed_ variant assumes that there can't be any further events
143  * within the output list for this timer, which reduces the need to
144  * traverse the output list and delete the corresponding events.)
145  */
146 void gw_timer_stop(Timer *timer);
147 void gw_timer_elapsed_stop(Timer *timer);
148 
149 /*
150  * Stop all active timers, elapsed or not, and return them via the
151  * returned List result. They are not destroyed yet.
152  */
154 
155 /*
156  * Return the void* pointer to the associated data of the Timer.
157  */
158 void *gw_timer_data(Timer *timer);
159 
160 #endif
Timer * gw_timer_create(Timerset *set, List *outputlist, void(*callback)(void *))
Definition: gw-timer.c:211
List * gw_timer_break(Timerset *set)
Definition: gw-timer.c:385
Timerset * gw_timerset_create(void)
Definition: gw-timer.c:177
void gw_timer_elapsed_start(Timer *timer, int interval, void *data)
Definition: gw-timer.c:297
void gw_timer_elapsed_destroy(Timer *timer)
Definition: gw-timer.c:240
void gw_timer_elapsed_stop(Timer *timer)
Definition: gw-timer.c:364
void gw_timer_stop(Timer *timer)
Definition: gw-timer.c:344
void gw_timer_destroy(Timer *timer)
Definition: gw-timer.c:229
void gw_timer_start(Timer *timer, int interval, void *data)
Definition: gw-timer.c:251
double interval
Definition: fakewap.c:234
void * gw_timer_data(Timer *timer)
Definition: gw-timer.c:422
Definition: list.c:102
void gw_timerset_destroy(Timerset *set)
Definition: gw-timer.c:190
See file LICENSE for details about the license agreement for using, modifying, copying or deriving work from this software.