Statistics
| Branch: | Revision:

peerstreamer-src / src / streamer_creation_callback.c @ 58fb2cdc

History | View | Annotate | Download (2.03 KB)

1 c81c126e Luca Baldesi
/*******************************************************************
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 92a361ca Luca Baldesi
        const struct pschannel_bucket * psb;
26 c81c126e Luca Baldesi
        struct mg_connection *nc;
27
};
28
29
int8_t streamer_creation_set_pstreamer_ref(struct streamer_creation_callback * scc, const struct pstreamer *ps)
30
{
31
        if (scc && ps)
32
        {
33
                scc->ps = ps;
34
                return 0;
35
        }
36
        return -1;
37
}
38
39 92a361ca Luca Baldesi
struct streamer_creation_callback * streamer_creation_callback_new(struct mg_connection *nc, const struct pschannel_bucket * psb, streamer_creation_handler_t handler)
40 c81c126e Luca Baldesi
{
41
        struct streamer_creation_callback * scc = NULL;
42
43 92a361ca Luca Baldesi
        if (nc && handler && psb)
44 c81c126e Luca Baldesi
        {
45
                scc = malloc(sizeof(struct streamer_creation_callback));
46
                scc->ps = NULL;
47
                scc->callback = handler;
48
                scc->nc = nc;
49 92a361ca Luca Baldesi
                scc->psb = psb;
50 c81c126e Luca Baldesi
        }
51
        return scc;
52
}
53
54
int8_t streamer_creation_callback_trigger(struct streamer_creation_callback * scc, int8_t ret)
55
{
56
        int8_t res = -1;
57
        if (scc)
58 92a361ca Luca Baldesi
                res = scc->callback(scc->nc, scc->psb, scc->ps, ret);
59 c81c126e Luca Baldesi
        return res;
60
}
61
62
void streamer_creation_callback_destroy(struct streamer_creation_callback ** scc)
63
{
64
        if (scc && *scc)
65
        {
66
                free(*scc);
67
                *scc = NULL;
68
        }
69
}
70