Neels Hofmeyr | cbdfb78 | 2018-02-12 16:45:39 +0100 | [diff] [blame] | 1 | /* 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 */ |
| 6 | struct 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. */ |
| 11 | struct penalty_timers *penalty_timers_init(void *ctx); |
| 12 | |
Neels Hofmeyr | fb75d10 | 2018-05-18 03:46:41 +0200 | [diff] [blame] | 13 | /* Add a penalty timer for an arbitary object. |
| 14 | * 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 Hofmeyr | cbdfb78 | 2018-02-12 16:45:39 +0100 | [diff] [blame] | 19 | * 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 Hofmeyr | fb75d10 | 2018-05-18 03:46:41 +0200 | [diff] [blame] | 23 | void penalty_timers_add(struct penalty_timers *pt, const void *for_object, int timeout); |
Neels Hofmeyr | cbdfb78 | 2018-02-12 16:45:39 +0100 | [diff] [blame] | 24 | |
Neels Hofmeyr | fb75d10 | 2018-05-18 03:46:41 +0200 | [diff] [blame] | 25 | /* Return the amount of penalty time remaining for an object. |
Neels Hofmeyr | cbdfb78 | 2018-02-12 16:45:39 +0100 | [diff] [blame] | 26 | * 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 Hofmeyr | fb75d10 | 2018-05-18 03:46:41 +0200 | [diff] [blame] | 29 | unsigned int penalty_timers_remaining(struct penalty_timers *pt, const void *for_object); |
Neels Hofmeyr | cbdfb78 | 2018-02-12 16:45:39 +0100 | [diff] [blame] | 30 | |
Neels Hofmeyr | fb75d10 | 2018-05-18 03:46:41 +0200 | [diff] [blame] | 31 | /* Clear penalty timers for one or all objects. |
Neels Hofmeyr | cbdfb78 | 2018-02-12 16:45:39 +0100 | [diff] [blame] | 32 | * 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 Hofmeyr | fb75d10 | 2018-05-18 03:46:41 +0200 | [diff] [blame] | 35 | void penalty_timers_clear(struct penalty_timers *pt, const void *for_object); |
Neels Hofmeyr | cbdfb78 | 2018-02-12 16:45:39 +0100 | [diff] [blame] | 36 | |
| 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. */ |
| 41 | void penalty_timers_free(struct penalty_timers **pt_p); |