summaryrefslogtreecommitdiffstats
path: root/pceplib/pcep_timers.h
blob: b2cc6ec546c607791c55cc187f08f84bb2bd97cf (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
/*
 * This file is part of the PCEPlib, a PCEP protocol library.
 *
 * Copyright (C) 2020 Volta Networks https://voltanet.io/
 *
 * This library is free software; you can redistribute it and/or
 * modify it under the terms of the GNU Lesser General Public
 * License as published by the Free Software Foundation; either
 * version 2 of the License, or (at your option) any later version.
 *
 * This library is distributed in the hope that it will be useful,
 * but WITHOUT ANY WARRANTY; without even the implied warranty of
 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
 * Lesser General Public License for more details.
 *
 * You should have received a copy of the GNU General Public License
 * along with this program.  If not, see <https://www.gnu.org/licenses/>.
 *
 * Author : Brady Johnson <brady@voltanet.io>
 *
 */


/*
 * Public API for pcep_timers
 */

#ifndef PCEPTIMERS_H_
#define PCEPTIMERS_H_

#include <pthread.h>
#include <stdbool.h>

#include "pcep_timer_internals.h"

#define TIMER_ID_NOT_SET -1

/*
 * Initialize the timers module.
 * The timer_expire_handler function pointer will be called each time a timer
 * expires. Return true for successful initialization, false otherwise.
 */
bool initialize_timers(timer_expire_handler expire_handler);

/*
 * Initialize the timers module with an external back-end infrastructure, like
 * FRR.
 */
bool initialize_timers_external_infra(
	timer_expire_handler expire_handler, void *external_timer_infra_data,
	ext_timer_create timer_create_func, ext_timer_cancel timer_cancel_func,
	ext_pthread_create_callback thread_create_func);

/*
 * Teardown the timers module.
 */
bool teardown_timers(void);

/*
 * Create a new timer for "sleep_seconds" seconds.
 * If the timer expires before being cancelled, the timer_expire_handler
 * passed to initialize_timers() will be called with the pointer to "data".
 * Returns a timer_id <= 0 that can be used to cancel_timer.
 * Returns < 0 on error.
 */
int create_timer(uint16_t sleep_seconds, void *data);

/*
 * Cancel a timer created with create_timer().
 * Returns true if the timer was found and cancelled, false otherwise.
 */
bool cancel_timer(int timer_id);

/*
 * Reset an previously created timer, maintaining the same timer_id.
 * Returns true if the timer was found and reset, false otherwise.
 */
bool reset_timer(int timer_id);

/*
 * If an external timer infra like FRR is used, then this function
 * will be called when the timers expire in the external infra.
 */
void pceplib_external_timer_expire_handler(void *data);

int timer_list_node_compare(void *list_entry, void *new_entry);
int timer_list_node_timer_id_compare(void *list_entry, void *new_entry);
int timer_list_node_timer_ptr_compare(void *list_entry, void *new_entry);
void free_all_timers(pcep_timers_context *timers_context);
int get_next_timer_id(void);

#endif /* PCEPTIMERS_H_ */