]>
Commit | Line | Data |
---|---|---|
74971473 JG |
1 | /* |
2 | * This file is part of the PCEPlib, a PCEP protocol library. | |
3 | * | |
4 | * Copyright (C) 2020 Volta Networks https://voltanet.io/ | |
5 | * | |
6 | * This library is free software; you can redistribute it and/or | |
7 | * modify it under the terms of the GNU Lesser General Public | |
8 | * License as published by the Free Software Foundation; either | |
9 | * version 2 of the License, or (at your option) any later version. | |
10 | * | |
11 | * This library is distributed in the hope that it will be useful, | |
12 | * but WITHOUT ANY WARRANTY; without even the implied warranty of | |
13 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU | |
14 | * Lesser General Public License for more details. | |
15 | * | |
16 | * You should have received a copy of the GNU General Public License | |
17 | * along with this program. If not, see <https://www.gnu.org/licenses/>. | |
18 | * | |
19 | * Author : Brady Johnson <brady@voltanet.io> | |
20 | * | |
21 | */ | |
22 | ||
23 | ||
24 | /* | |
25 | * Public API for pcep_timers | |
26 | */ | |
27 | ||
28 | #ifndef PCEPTIMERS_H_ | |
29 | #define PCEPTIMERS_H_ | |
30 | ||
31 | #include <pthread.h> | |
32 | #include <stdbool.h> | |
33 | ||
34 | #include "pcep_timer_internals.h" | |
35 | ||
36 | #define TIMER_ID_NOT_SET -1 | |
37 | ||
38 | /* | |
39 | * Initialize the timers module. | |
40 | * The timer_expire_handler function pointer will be called each time a timer | |
41 | * expires. Return true for successful initialization, false otherwise. | |
42 | */ | |
43 | bool initialize_timers(timer_expire_handler expire_handler); | |
44 | ||
45 | /* | |
46 | * Initialize the timers module with an external back-end infrastructure, like | |
47 | * FRR. | |
48 | */ | |
49 | bool initialize_timers_external_infra( | |
50 | timer_expire_handler expire_handler, void *external_timer_infra_data, | |
51 | ext_timer_create timer_create_func, ext_timer_cancel timer_cancel_func, | |
52 | ext_pthread_create_callback thread_create_func); | |
53 | ||
54 | /* | |
55 | * Teardown the timers module. | |
56 | */ | |
57 | bool teardown_timers(void); | |
58 | ||
59 | /* | |
60 | * Create a new timer for "sleep_seconds" seconds. | |
61 | * If the timer expires before being cancelled, the timer_expire_handler | |
62 | * passed to initialize_timers() will be called with the pointer to "data". | |
63 | * Returns a timer_id <= 0 that can be used to cancel_timer. | |
64 | * Returns < 0 on error. | |
65 | */ | |
66 | int create_timer(uint16_t sleep_seconds, void *data); | |
67 | ||
68 | /* | |
69 | * Cancel a timer created with create_timer(). | |
70 | * Returns true if the timer was found and cancelled, false otherwise. | |
71 | */ | |
72 | bool cancel_timer(int timer_id); | |
73 | ||
74 | /* | |
75 | * Reset an previously created timer, maintaining the same timer_id. | |
76 | * Returns true if the timer was found and reset, false otherwise. | |
77 | */ | |
78 | bool reset_timer(int timer_id); | |
79 | ||
80 | /* | |
81 | * If an external timer infra like FRR is used, then this function | |
82 | * will be called when the timers expire in the external infra. | |
83 | */ | |
84 | void pceplib_external_timer_expire_handler(void *data); | |
85 | ||
86 | int timer_list_node_compare(void *list_entry, void *new_entry); | |
87 | int timer_list_node_timer_id_compare(void *list_entry, void *new_entry); | |
88 | int timer_list_node_timer_ptr_compare(void *list_entry, void *new_entry); | |
89 | void free_all_timers(pcep_timers_context *timers_context); | |
90 | int get_next_timer_id(void); | |
91 | ||
92 | #endif /* PCEPTIMERS_H_ */ |