blob: f5d17786c1e88a8813766342f68ab3bdc1cb200a [file] [log] [blame]
Neels Hofmeyrcbdfb782018-02-12 16:45:39 +01001/* Manage a list of penalty timers per BTS;
2 * initially used by handover algorithm 2 to keep per-BTS timers for each subscriber connection. */
3#pragma once
4
5/* Opaque struct to manage penalty timers */
6struct penalty_timers;
7
8/* Initialize a list of penalty timers.
9 * param ctx: talloc context to allocate in.
10 * returns an empty struct penalty_timers. */
11struct penalty_timers *penalty_timers_init(void *ctx);
12
Martin Haukea29affd2019-11-13 22:10:41 +010013/* Add a penalty timer for an arbitrary object.
Neels Hofmeyrfb75d102018-05-18 03:46:41 +020014 * Note: the ownership of for_object remains with the caller; it is handled as a mere void* value, so
15 * invalid pointers can be handled without problems, while common sense dictates that invalidated
16 * pointers (freed objects) should probably be removed from this list. More importantly, the pointer must
17 * match any pointers used to query penalty timers, so for_object should reference some global/singleton
18 * object that tends to stay around longer than the penalty timers.
Neels Hofmeyrcbdfb782018-02-12 16:45:39 +010019 * param pt: penalty timers list as from penalty_timers_init().
20 * param for_object: arbitrary pointer reference to store a penalty timer for (passing NULL is possible,
21 * but note that penalty_timers_clear() will clear all timers if given for_object=NULL).
22 * param timeout: penalty time in seconds. */
Neels Hofmeyrfb75d102018-05-18 03:46:41 +020023void penalty_timers_add(struct penalty_timers *pt, const void *for_object, int timeout);
Neels Hofmeyrcbdfb782018-02-12 16:45:39 +010024
Neels Hofmeyrfb75d102018-05-18 03:46:41 +020025/* Return the amount of penalty time remaining for an object.
Neels Hofmeyrcbdfb782018-02-12 16:45:39 +010026 * param pt: penalty timers list as from penalty_timers_init().
27 * param for_object: arbitrary pointer reference to query penalty timers for.
28 * returns seconds remaining until all penalty time has expired. */
Neels Hofmeyrfb75d102018-05-18 03:46:41 +020029unsigned int penalty_timers_remaining(struct penalty_timers *pt, const void *for_object);
Neels Hofmeyrcbdfb782018-02-12 16:45:39 +010030
Neels Hofmeyrfb75d102018-05-18 03:46:41 +020031/* Clear penalty timers for one or all objects.
Neels Hofmeyrcbdfb782018-02-12 16:45:39 +010032 * param pt: penalty timers list as from penalty_timers_init().
33 * param for_object: arbitrary pointer reference to clear penalty time for,
34 * or NULL to clear all timers. */
Neels Hofmeyrfb75d102018-05-18 03:46:41 +020035void penalty_timers_clear(struct penalty_timers *pt, const void *for_object);
Neels Hofmeyrcbdfb782018-02-12 16:45:39 +010036
37/* Free a struct as returned from penalty_timers_init().
38 * Clear all timers from the list, deallocate the list and set the pointer to NULL.
39 * param pt: pointer-to-pointer which references a struct penalty_timers as returned by
40 * penalty_timers_init(); *pt_p will be set to NULL. */
41void penalty_timers_free(struct penalty_timers **pt_p);