alarm 5.77 KB
Newer Older
Neil Turton's avatar
Neil Turton committed
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 174
/* Copyright 1996 Acorn Computers Ltd
 *
 * Licensed under the Apache License, Version 2.0 (the "License");
 * you may not use this file except in compliance with the License.
 * You may obtain a copy of the License at
 *
 *     http://www.apache.org/licenses/LICENSE-2.0
 *
 * Unless required by applicable law or agreed to in writing, software
 * distributed under the License is distributed on an "AS IS" BASIS,
 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
 * See the License for the specific language governing permissions and
 * limitations under the License.
 */
/****************************************************************************
 * This source file was written by Acorn Computers Limited. It is part of   *
 * the RISCOS library for writing applications in C for RISC OS. It may be  *
 * used freely in the creation of programs for Archimedes. It should be     *
 * used with Acorn's C Compiler Release 3 or later.                         *
 *                                                                          *
 ***************************************************************************/
/*
 * Title:    alarm.h
 * Purpose:  alarm facilities for wimp programs, using non-busy waiting
 *
 */

#ifndef __alarm_h
#define __alarm_h

# ifndef BOOL
# define BOOL int
# define TRUE 1
# define FALSE 0
# endif

typedef void (*alarm_handler)(int called_at, void *handle);


/* ----------------------------- alarm_init --------------------------------
 * Description:   Initialise the alarm system.
 *
 * Parameters:    void
 * Returns:       void.
 * Other Info:    If this call is made more than once, then any pending
 *                alarms are cancelled.
 *
 */

void alarm_init(void);


/* ----------------------------- alarm_timenow -----------------------------
 * Description:   Reports the current monotonic time.
 *
 * Parameters:    void
 * Returns:       the current monotonic time.
 * Other Info:    none.
 *
 */

int alarm_timenow(void);


/* --------------------------- alarm_timedifference ------------------------
 * Description:   Returns difference between two times.
 *
 * Parameters:    int t1 -- the earlier time
 *                int t2 -- the later time
 * Returns:       difference between t1 and t2.
 * Other Info:    Times are as in SWI OS_ReadMonotonicTime. Deals with wrap
 *                round of timer.
 *
 */

int alarm_timedifference(int t1, int t2);


/* ------------------------------ alarm_set --------------------------------
 * Description:   Set an alarm at the given time.
 *
 * Parameters:    int at -- time at which alarm should occur
 *                alarm_handler proc -- function to be called at alarm time
 *                void *handle -- caller-supplied handle to be passed to
 *                                function
 * Returns:       void.
 * Other Info:    The supplied function is called before passing the event
 *                on to any idle event claimer windows.
 *                "at" is in terms of the monotonic centi-second timer.
 *                The supplied function is passed the time at which it was
 *                called. If you have enabled idle events, then these are
 *                still returned to you; if not, RISC_OSlib uses idle events
 *                internally to implement alarm calls (using non-busy
 *                waiting via wimp_pollidle()).
 *
 */

void alarm_set(int at, alarm_handler proc, void *handle);


/* ----------------------------- alarm_remove ------------------------------
 * Description:   Removes an alarm which was set for a given time with a
 *                given handle.
 *
 * Parameters:    int at -- the time at which the alarm was to be made
 *                void *handle -- the given handle
 * Returns:       void.
 * Other Info:    If no such alarm exists this call has no effect.
 *
 */

void alarm_remove(int at, void *handle);


/* --------------------------- alarm_removeall -----------------------------
 * Description:   Removes all alarms which have a given handle.
 *
 * Parameters:    void *handle -- the handle to search for.
 * Returns:       void.
 * Other Info:    none.
 *
 */

void alarm_removeall(void *handle);


/* ---------------------------- alarm_anypending ---------------------------
 * Description:   Returns whether an alarm is pending with a given handle
 *
 * Parameters:    void *handle -- the handle.
 * Returns:       TRUE if there are any pending alarms for this handle.
 * Other Info:    none.
 *
 */

BOOL alarm_anypending(void *handle);


/* ----------------------------- alarm_next --------------------------------
 * Description:   Informs caller whether an alarm is pending and, if so, for
 *                when it is.
 *
 * Parameters:    int *result -- time for which alarm is pending
 * Returns:       TRUE if an alarm is pending.
 * Other Info:    This should be used by polling loops (if you use the
 *                standard "while(TRUE) event_process();" loop then this is
 *                done for you). If a polling loop finds that an alarm is set
 *                it should use wimp_pollidle(with earliest time set to
 *                *result of alarm_next()) rather than wimp_poll to do its
 *                polling.  If you handle idle events yourself, then your
 *                handler should use call_next to call the next alarm
 *                function upon receiving an idle event (ie. wimp_ENULL).
 *
 */

BOOL alarm_next(int *result);


/* ---------------------------- alarm_callnext -----------------------------
 * Description:   Calls the next alarm handler function.
 *
 * Parameters:    void
 * Returns:       void.
 * Other Info:    This is done for you if you use event_process() to do your
 *                polling (or even if you sink down as far as using wimpt
 *                for polling).
 *
 */

void alarm_callnext(void);

#endif

/* end of alarm.h */