Statistics
| Branch: | Revision:

peerstreamer-src / src / task_manager.h @ 58fb2cdc

History | View | Annotate | Download (2.38 KB)

1
/*******************************************************************
2
* PeerStreamer-ng is a P2P video streaming application exposing a ReST
3
* interface.
4
* Copyright (C) 2017 Luca Baldesi <luca.baldesi@unitn.it>
5
*
6
* This program is free software: you can redistribute it and/or modify
7
* it under the terms of the GNU Affero General Public License as published by
8
* the Free Software Foundation, either version 3 of the License, or
9
* (at your option) any later version.
10
*
11
* This program 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
14
* GNU Affero General Public License for more details.
15
*
16
* You should have received a copy of the GNU Affero General Public License
17
* along with this program.  If not, see <http://www.gnu.org/licenses/>.
18
*******************************************************************/
19

    
20
#ifndef __TASK_MANAGER__
21
#define __TASK_MANAGER__ 1
22

    
23
#include<stdint.h>
24
#include<sys/select.h>
25
#include<mongoose.h>
26

    
27
typedef uint16_t timeout; // milliseconds
28

    
29
struct periodic_task;
30

    
31
struct task_manager;
32

    
33
typedef uint8_t (*periodic_task_callback)(struct periodic_task * pt, int ret, fd_set * readfds, fd_set * writefds, fd_set * errfds);
34

    
35
typedef uint8_t (*periodic_task_reinit)(struct periodic_task * pt);
36

    
37
struct task_manager * task_manager_new();
38

    
39
void task_manager_destroy(struct task_manager **tm);
40

    
41
struct periodic_task * task_manager_new_task(struct task_manager *tm, periodic_task_reinit reinit, periodic_task_callback callback, timeout to, void * data);
42

    
43
void task_manager_destroy_task(struct task_manager * tm, struct periodic_task ** pt);
44

    
45
int task_manager_poll(struct task_manager * tm, timeout to);
46

    
47
/**** WARNING: the following do not have test cases ********/
48

    
49
int periodic_task_writefd_add(struct periodic_task * pt, int fd);
50

    
51
int periodic_task_readfd_add(struct periodic_task * pt, int fd);
52

    
53
int periodic_task_errfd_add(struct periodic_task * pt, int fd);
54

    
55
void periodic_task_flush_fdsets(struct periodic_task *pt);
56

    
57
int periodic_task_set_data(struct periodic_task * pt, void * data);
58

    
59
void * periodic_task_get_data(const struct periodic_task * pt);
60

    
61
timeout periodic_task_reset_timeout(struct periodic_task * pt);
62

    
63
int periodic_task_set_remaining_time(struct periodic_task * pt, timeout to);
64

    
65
timeout periodic_task_get_remaining_time(const struct periodic_task * pt);
66

    
67
#endif