]>
Commit | Line | Data |
---|---|---|
acddc0ed | 1 | // SPDX-License-Identifier: LGPL-2.1-or-later |
74971473 JG |
2 | /* |
3 | * This file is part of the PCEPlib, a PCEP protocol library. | |
4 | * | |
5 | * Copyright (C) 2020 Volta Networks https://voltanet.io/ | |
6 | * | |
74971473 JG |
7 | * Author : Brady Johnson <brady@voltanet.io> |
8 | * | |
9 | */ | |
10 | ||
11 | ||
12 | /* | |
13 | * Public API for pcep_timers | |
14 | */ | |
15 | ||
16 | #ifndef PCEPTIMERS_H_ | |
17 | #define PCEPTIMERS_H_ | |
18 | ||
19 | #include <pthread.h> | |
20 | #include <stdbool.h> | |
21 | ||
22 | #include "pcep_timer_internals.h" | |
23 | ||
24 | #define TIMER_ID_NOT_SET -1 | |
25 | ||
26 | /* | |
27 | * Initialize the timers module. | |
28 | * The timer_expire_handler function pointer will be called each time a timer | |
29 | * expires. Return true for successful initialization, false otherwise. | |
30 | */ | |
31 | bool initialize_timers(timer_expire_handler expire_handler); | |
32 | ||
33 | /* | |
34 | * Initialize the timers module with an external back-end infrastructure, like | |
35 | * FRR. | |
36 | */ | |
37 | bool initialize_timers_external_infra( | |
38 | timer_expire_handler expire_handler, void *external_timer_infra_data, | |
39 | ext_timer_create timer_create_func, ext_timer_cancel timer_cancel_func, | |
40 | ext_pthread_create_callback thread_create_func); | |
41 | ||
42 | /* | |
43 | * Teardown the timers module. | |
44 | */ | |
45 | bool teardown_timers(void); | |
46 | ||
47 | /* | |
48 | * Create a new timer for "sleep_seconds" seconds. | |
49 | * If the timer expires before being cancelled, the timer_expire_handler | |
50 | * passed to initialize_timers() will be called with the pointer to "data". | |
51 | * Returns a timer_id <= 0 that can be used to cancel_timer. | |
52 | * Returns < 0 on error. | |
53 | */ | |
54 | int create_timer(uint16_t sleep_seconds, void *data); | |
55 | ||
56 | /* | |
57 | * Cancel a timer created with create_timer(). | |
58 | * Returns true if the timer was found and cancelled, false otherwise. | |
59 | */ | |
60 | bool cancel_timer(int timer_id); | |
61 | ||
62 | /* | |
63 | * Reset an previously created timer, maintaining the same timer_id. | |
64 | * Returns true if the timer was found and reset, false otherwise. | |
65 | */ | |
66 | bool reset_timer(int timer_id); | |
67 | ||
68 | /* | |
69 | * If an external timer infra like FRR is used, then this function | |
70 | * will be called when the timers expire in the external infra. | |
71 | */ | |
72 | void pceplib_external_timer_expire_handler(void *data); | |
73 | ||
74 | int timer_list_node_compare(void *list_entry, void *new_entry); | |
75 | int timer_list_node_timer_id_compare(void *list_entry, void *new_entry); | |
76 | int timer_list_node_timer_ptr_compare(void *list_entry, void *new_entry); | |
77 | void free_all_timers(pcep_timers_context *timers_context); | |
78 | int get_next_timer_id(void); | |
79 | ||
80 | #endif /* PCEPTIMERS_H_ */ |