]> git.sesse.net Git - vlc/blob - include/vlc_epg.h
jvlc: libvlcState enum index comment added for reference
[vlc] / include / vlc_epg.h
1 /*****************************************************************************
2  * vlc_epg.h: Electronic Program Guide
3  *****************************************************************************
4  * Copyright (C) 2007 the VideoLAN team
5  * $Id$
6  *
7  * Authors: Laurent Aimar <fenrir@via.ecp.fr>
8  *
9  * This program is free software; you can redistribute it and/or modify
10  * it under the terms of the GNU General Public License as published by
11  * the Free Software Foundation; either version 2 of the License, or
12  * (at your option) any later version.
13  *
14  * This program is distributed in the hope that it will be useful,
15  * but WITHOUT ANY WARRANTY; without even the implied warranty of
16  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
17  * GNU General Public License for more details.
18  *
19  * You should have received a copy of the GNU General Public License
20  * along with this program; if not, write to the Free Software
21  * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston MA 02110-1301, USA.
22  *****************************************************************************/
23
24 #ifndef _VLC_EPG_H
25 #define _VLC_EPG_H 1
26
27 typedef struct
28 {
29     int64_t i_start;    /* Interpreted as a value return by time() */
30     int     i_duration;    /* Duration of the event in second */
31
32     char    *psz_name;
33     char    *psz_short_description;
34     char    *psz_description;
35
36 } vlc_epg_event_t;
37
38 typedef struct
39 {
40     char            *psz_name;
41     vlc_epg_event_t *p_current; /* Can be null or should be the same than one of pp_event entry */
42
43     int             i_event;
44     vlc_epg_event_t **pp_event;
45 } vlc_epg_t;
46
47 static inline void vlc_epg_Init( vlc_epg_t *p_epg, const char *psz_name )
48 {
49     p_epg->psz_name = psz_name ? strdup( psz_name ) : NULL;
50     p_epg->p_current = NULL;
51     TAB_INIT( p_epg->i_event, p_epg->pp_event );
52 }
53 static inline void vlc_epg_Clean( vlc_epg_t *p_epg )
54 {
55     int i;
56     for( i = 0; i < p_epg->i_event; i++ )
57     {
58         vlc_epg_event_t *p_evt = p_epg->pp_event[i];
59         free( p_evt->psz_name );
60         free( p_evt->psz_short_description );
61         free( p_evt->psz_description );
62         free( p_evt );
63     }
64     TAB_CLEAN( p_epg->i_event, p_epg->pp_event );
65     free( p_epg->psz_name );
66 }
67 static inline void vlc_epg_AddEvent( vlc_epg_t *p_epg, int64_t i_start, int i_duration,
68                                 const char *psz_name, const char *psz_short_description, const char *psz_description )
69 {
70     vlc_epg_event_t *p_evt = (vlc_epg_event_t*)malloc( sizeof(vlc_epg_event_t) );
71     if( !p_evt )
72         return;
73     p_evt->i_start = i_start;
74     p_evt->i_duration = i_duration;
75     p_evt->psz_name = psz_name ? strdup( psz_name ) : NULL;
76     p_evt->psz_short_description = psz_short_description ? strdup( psz_short_description ) : NULL;
77     p_evt->psz_description = psz_description ? strdup( psz_description ) : NULL;
78     TAB_APPEND_CPP( vlc_epg_event_t, p_epg->i_event, p_epg->pp_event, p_evt );
79 }
80
81 static inline vlc_epg_t *vlc_epg_New( const char *psz_name )
82 {
83     vlc_epg_t *p_epg = (vlc_epg_t*)malloc( sizeof(vlc_epg_t) );
84     if( p_epg )
85         vlc_epg_Init( p_epg, psz_name );
86     return p_epg;
87 }
88 static inline void vlc_epg_Delete( vlc_epg_t *p_epg )
89 {
90     vlc_epg_Clean( p_epg );
91     free( p_epg );
92 }
93 static inline void vlc_epg_SetCurrent( vlc_epg_t *p_epg, int64_t i_start )
94 {
95     int i;
96     p_epg->p_current = NULL;
97     if( i_start < 0 )
98         return;
99
100     for( i = 0; i < p_epg->i_event; i++ )
101     {
102         if( p_epg->pp_event[i]->i_start == i_start )
103         {
104             p_epg->p_current = p_epg->pp_event[i];
105             break;
106         }
107     }
108 }
109
110 #endif
111