2 * This file is part of the PCEPlib, a PCEP protocol library.
4 * Copyright (C) 2020 Volta Networks https://voltanet.io/
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.
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.
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/>.
19 * Author : Brady Johnson <brady@voltanet.io>
25 * Public API for pcep_timers
34 #include "pcep_timer_internals.h"
36 #define TIMER_ID_NOT_SET -1
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.
43 bool initialize_timers(timer_expire_handler expire_handler
);
46 * Initialize the timers module with an external back-end infrastructure, like
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
);
55 * Teardown the timers module.
57 bool teardown_timers(void);
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.
66 int create_timer(uint16_t sleep_seconds
, void *data
);
69 * Cancel a timer created with create_timer().
70 * Returns true if the timer was found and cancelled, false otherwise.
72 bool cancel_timer(int timer_id
);
75 * Reset an previously created timer, maintaining the same timer_id.
76 * Returns true if the timer was found and reset, false otherwise.
78 bool reset_timer(int timer_id
);
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.
84 void pceplib_external_timer_expire_handler(void *data
);
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);
92 #endif /* PCEPTIMERS_H_ */