Kannel: Open Source WAP and SMS gateway  $Revision: 5037 $
timers.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  * timers.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 TIMERS_H
88 #define TIMERS_H
89 
90 #include "gwlib/gwlib.h"
91 #include "wap_events.h"
92 
93 typedef struct Timer Timer;
94 
95 /*
96  * Start up the timer system.
97  * Can be called more than once, in which case multiple shutdowns are
98  * also required.
99  */
100 void timers_init(void);
101 
102 /*
103  * Stop all timers and shut down the timer system.
104  */
105 void timers_shutdown(void);
106 
107 /*
108  * Create a timer and tell it to use the specified output list when
109  * it elapses. Do not start it yet. Return the new timer.
110  */
111 Timer *gwtimer_create(List *outputlist);
112 
113 /*
114  * Destroy this timer and free its resources. Stop it first, if needed.
115  */
116 void gwtimer_destroy(Timer *timer);
117 
118 /*
119  * Make the timer elapse after 'interval' seconds, at which time it
120  * will push event 'event' on the output list defined for its timer set.
121  * - If the timer was already running, these parameters will override
122  * its old settings.
123  * - If the timer has already elapsed, try to remove its event from
124  * the output list.
125  * If this is not the first time the timer was started, the event
126  * pointer is allowed to be NULL. In that case the event pointer
127  * from the previous call to timer_start for this timer is re-used.
128  * NOTE: Each timer must have a unique event pointer. The caller must
129  * create the event, and passes control of it to the timer module with
130  * this call.
131  */
132 void gwtimer_start(Timer *timer, int interval, WAPEvent *event);
133 
134 /*
135  * Stop this timer. If it has already elapsed, try to remove its
136  * event from the output list.
137  */
138 void gwtimer_stop(Timer *timer);
139 
140 #endif
void gwtimer_destroy(Timer *timer)
Definition: timers.c:241
void timers_shutdown(void)
Definition: timers.c:196
void timers_init(void)
Definition: timers.c:184
Timer * gwtimer_create(List *outputlist)
Definition: timers.c:224
void gwtimer_stop(Timer *timer)
Definition: timers.c:299
double interval
Definition: fakewap.c:234
WAPEvent * event
Definition: timers.c:138
void gwtimer_start(Timer *timer, int interval, WAPEvent *event)
Definition: timers.c:254
Definition: list.c:102
See file LICENSE for details about the license agreement for using, modifying, copying or deriving work from this software.