]>
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 | * Timer definitions to be used internally by the pcep_timers library. | |
25 | */ | |
26 | ||
27 | #ifndef PCEPTIMERINTERNALS_H_ | |
28 | #define PCEPTIMERINTERNALS_H_ | |
29 | ||
30 | #include <stdint.h> | |
31 | #include <pthread.h> | |
32 | ||
33 | #include "pcep_utils_ordered_list.h" | |
34 | ||
35 | /* Function pointer to be called when timers expire. | |
36 | * Parameters: | |
37 | * void *data - passed into create_timer | |
38 | * int timer_id - the timer_id returned by create_timer | |
39 | */ | |
40 | typedef void (*timer_expire_handler)(void *, int); | |
41 | ||
42 | /* Function pointer when an external timer infrastructure is used */ | |
43 | typedef void (*ext_timer_create)(void *infra_data, void **timer, int seconds, | |
44 | void *data); | |
45 | typedef void (*ext_timer_cancel)(void **timer); | |
46 | typedef int (*ext_pthread_create_callback)(pthread_t *pthread_id, | |
47 | const pthread_attr_t *attr, | |
48 | void *(*start_routine)(void *), | |
49 | void *data, const char *thread_name); | |
50 | ||
51 | typedef struct pcep_timer_ { | |
52 | time_t expire_time; | |
53 | uint16_t sleep_seconds; | |
54 | int timer_id; | |
55 | void *data; | |
56 | void *external_timer; | |
57 | ||
58 | } pcep_timer; | |
59 | ||
60 | typedef struct pcep_timers_context_ { | |
61 | ordered_list_handle *timer_list; | |
62 | bool active; | |
63 | timer_expire_handler expire_handler; | |
64 | pthread_t event_loop_thread; | |
65 | pthread_mutex_t timer_list_lock; | |
66 | void *external_timer_infra_data; | |
67 | ext_timer_create timer_create_func; | |
68 | ext_timer_cancel timer_cancel_func; | |
69 | ||
70 | } pcep_timers_context; | |
71 | ||
72 | /* functions implemented in pcep_timers_loop.c */ | |
73 | void *event_loop(void *context); | |
74 | ||
75 | ||
76 | #endif /* PCEPTIMERINTERNALS_H_ */ |