Statistics
| Branch: | Revision:

peerstreamer-src / src / streamer_creation_callback.c @ c81c126e

History | View | Annotate | Download (1.92 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
#include<streamer_creation_callback.h>
21

    
22
struct streamer_creation_callback {
23
        streamer_creation_handler_t callback;        
24
        const struct pstreamer * ps;
25
        struct mg_connection *nc;
26
};
27

    
28
int8_t streamer_creation_set_pstreamer_ref(struct streamer_creation_callback * scc, const struct pstreamer *ps)
29
{
30
        if (scc && ps)
31
        {
32
                scc->ps = ps;
33
                return 0;
34
        }
35
        return -1;
36
}
37

    
38
struct streamer_creation_callback * streamer_creation_callback_new(struct mg_connection *nc, streamer_creation_handler_t handler)
39
{
40
        struct streamer_creation_callback * scc = NULL;
41

    
42
        if (nc && handler)
43
        {
44
                scc = malloc(sizeof(struct streamer_creation_callback));
45
                scc->ps = NULL;
46
                scc->callback = handler;
47
                scc->nc = nc;
48
        }
49
        return scc;
50
}
51

    
52
int8_t streamer_creation_callback_trigger(struct streamer_creation_callback * scc, int8_t ret)
53
{
54
        int8_t res = -1;
55
        if (scc)
56
                res = scc->callback(scc->nc, scc->ps, ret);
57
        return res;
58
}
59

    
60
void streamer_creation_callback_destroy(struct streamer_creation_callback ** scc)
61
{
62
        if (scc && *scc)
63
        {
64
                free(*scc);
65
                *scc = NULL;
66
        }
67
}
68

    
69