1 // SPDX-License-Identifier: LGPL-2.1-or-later
3 * This file is part of the PCEPlib, a PCEP protocol library.
5 * Copyright (C) 2020 Volta Networks https://voltanet.io/
7 * Author : Brady Johnson <brady@voltanet.io>
13 * Public API for pcep_timers
22 #include "pcep_timer_internals.h"
24 #define TIMER_ID_NOT_SET -1
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.
31 bool initialize_timers(timer_expire_handler expire_handler
);
34 * Initialize the timers module with an external back-end infrastructure, like
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
);
43 * Teardown the timers module.
45 bool teardown_timers(void);
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.
54 int create_timer(uint16_t sleep_seconds
, void *data
);
57 * Cancel a timer created with create_timer().
58 * Returns true if the timer was found and cancelled, false otherwise.
60 bool cancel_timer(int timer_id
);
63 * Reset an previously created timer, maintaining the same timer_id.
64 * Returns true if the timer was found and reset, false otherwise.
66 bool reset_timer(int timer_id
);
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.
72 void pceplib_external_timer_expire_handler(void *data
);
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);
80 #endif /* PCEPTIMERS_H_ */