Kannel: Open Source WAP and SMS gateway  svn-r5335
gw-timer.h
Go to the documentation of this file.
1 /* ====================================================================
2  * The Kannel Software License, Version 1.0
3  *
4  * Copyright (c) 2001-2018 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);
99 long gw_timerset_count(Timerset *set);
100 
101 
102 /*
103  * Create a timer and tell it to use the specified output list or
104  * callback function when it elapses.
105  * Do not start it yet. Return the new timer.
106  */
107 Timer *gw_timer_create(Timerset *set, List *outputlist, void (*callback) (void*));
108 
109 /*
110  * Destroy this timer and free its resources. Stop it first, if needed.
111  *
112  * (The _elapsed_ variant assumes that there can't be any further events
113  * within the output list for this timer, which reduces the need to
114  * traverse the output list and delete the corresponding events.)
115  *
116  * (The _destroy_cb variant MUST be used for callback'ed time events, as
117  * it will not try to lock the Timerset again, being already locked.)
118  */
119 void gw_timer_destroy(Timer *timer);
120 void gw_timer_elapsed_destroy(Timer *timer);
122 
123 
124 /*
125  * Make the timer elapse after 'interval' seconds, at which time it
126  * will push event 'event' on the output list defined for its timer set.
127  * - If the timer was already running, these parameters will override
128  * its old settings.
129  * - If the timer has already elapsed, try to remove its event from
130  * the output list.
131  * If this is not the first time the timer was started, the event
132  * pointer is allowed to be NULL. In that case the event pointer
133  * from the previous call to timer_start for this timer is re-used.
134  * NOTE: Each timer must have a unique event pointer. The caller must
135  * create the event, and passes control of it to the timer module with
136  * this call.
137  *
138  * (The _elapsed_ variant assumes that there can't be any further events
139  * within the output list for this timer, which reduces the need to
140  * traverse the output list and delete the corresponding events.)
141  */
142 void gw_timer_start(Timer *timer, int interval, void *data);
143 void gw_timer_elapsed_start(Timer *timer, int interval, void *data);
144 void gw_timer_elapsed_start_cb(Timer *timer, int interval, void *data);
145 
146 
147 /*
148  * Stop this timer. If it has already elapsed, try to remove its
149  * event from the output list.
150  *
151  * (The _elapsed_ variant assumes that there can't be any further events
152  * within the output list for this timer, which reduces the need to
153  * traverse the output list and delete the corresponding events.)
154  *
155  * (The _destroy_cb variant MUST be used for callback'ed time events, as
156  * it will not try to lock the Timerset again, being already locked.)
157  */
158 void gw_timer_stop(Timer *timer);
159 void gw_timer_elapsed_stop(Timer *timer);
160 void gw_timer_elapsed_stop_cb(Timer *timer);
161 
162 /*
163  * Stop all active timers, elapsed or not, and return them via the
164  * returned List result. They are not destroyed yet.
165  */
167 
168 /*
169  * Return the void* pointer to the associated data of the Timer.
170  */
171 void *gw_timer_data(Timer *timer);
172 
173 #endif
void gw_timer_elapsed_start_cb(Timer *timer, int interval, void *data)
Definition: gw-timer.c:399
Timer * gw_timer_create(Timerset *set, List *outputlist, void(*callback)(void *))
Definition: gw-timer.c:255
List * gw_timer_break(Timerset *set)
Definition: gw-timer.c:501
Timerset * gw_timerset_create(void)
Definition: gw-timer.c:190
long gw_timerset_count(Timerset *set)
Definition: gw-timer.c:244
void gw_timer_elapsed_start(Timer *timer, int interval, void *data)
Definition: gw-timer.c:352
void gw_timer_elapsed_destroy_cb(Timer *timer)
Definition: gw-timer.c:295
void gw_timer_elapsed_destroy(Timer *timer)
Definition: gw-timer.c:284
void gw_timer_elapsed_stop(Timer *timer)
Definition: gw-timer.c:462
void gw_timer_stop(Timer *timer)
Definition: gw-timer.c:442
void gw_timer_destroy(Timer *timer)
Definition: gw-timer.c:273
void gw_timer_start(Timer *timer, int interval, void *data)
Definition: gw-timer.c:306
double interval
Definition: fakewap.c:234
void gw_timerset_elapsed_destroy(Timerset *set)
Definition: gw-timer.c:223
void * gw_timer_data(Timer *timer)
Definition: gw-timer.c:538
Definition: list.c:102
void gw_timer_elapsed_stop_cb(Timer *timer)
Definition: gw-timer.c:483
void gw_timerset_destroy(Timerset *set)
Definition: gw-timer.c:203
See file LICENSE for details about the license agreement for using, modifying, copying or deriving work from this software.