]> git.sesse.net Git - vlc/blob - src/control/media_list_view.c
libvlc: Implement media_list_view, which will be used to present/access/edit the...
[vlc] / src / control / media_list_view.c
1 /*****************************************************************************
2  * flat_media_list.c: libvlc flat media list functions. (extension to
3  * media_list.c).
4  *****************************************************************************
5  * Copyright (C) 2007 the VideoLAN team
6  * $Id: flat_media_list.c 21287 2007-08-20 01:28:12Z pdherbemont $
7  *
8  * Authors: Pierre d'Herbemont <pdherbemont # videolan.org>
9  *
10  * This program is free software; you can redistribute it and/or modify
11  * it under the terms of the GNU General Public License as published by
12  * the Free Software Foundation; either version 2 of the License, or
13  * (at your option) any later version.
14  *
15  * This program is distributed in the hope that it will be useful,
16  * but WITHOUT ANY WARRANTY; without even the implied warranty of
17  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
18  * GNU General Public License for more details.
19  *
20  * You should have received a copy of the GNU General Public License
21  * along with this program; if not, write to the Free Software
22  * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston MA 02110-1301, USA.
23  *****************************************************************************/
24
25 #include "libvlc_internal.h"
26 #include <vlc/libvlc.h>
27 #include <assert.h>
28 #include "vlc_arrays.h"
29
30 //#define DEBUG_FLAT_LIST
31
32 #ifdef DEBUG_FLAT_LIST
33 # define trace( fmt, ... ) printf( "%s(): " fmt, __FUNCTION__, ##__VA_ARGS__ )
34 #else
35 # define trace( ... )
36 #endif
37
38 /*
39  * Private functions
40  */
41
42 /*
43  * Public libvlc functions
44  */
45
46 /* Limited to four args, because it should be enough */
47
48 #define AN_SELECT( collapser, dec1, dec2, dec3, dec4, p, ...) p
49 #define ARGS(...) AN_SELECT( collapser, ##__VA_ARGS__, \
50                                               (p_mlv, arg1, arg2, arg3, arg4, p_e), \
51                                               (p_mlv, arg1, arg2, arg3, p_e), \
52                                               (p_mlv, arg1, arg2, p_e), \
53                                               (p_mlv, arg1, p_e), (p_mlv, p_e) )
54
55 #define MEDIA_LIST_VIEW_FUNCTION( name, ret_type, default_ret_value, /* Params */ ... ) \
56     ret_type \
57     libvlc_media_list_view_##name( libvlc_media_list_view_t * p_mlv, \
58                                   ##__VA_ARGS__, \
59                                   libvlc_exception_t * p_e ) \
60     { \
61         if( p_mlv->pf_##name ) \
62             return p_mlv->pf_##name ARGS(__VA_ARGS__) ; \
63         libvlc_exception_raise( p_e, "No '" #name "' method in this media_list_view" ); \
64         return default_ret_value;\
65     }
66
67 #define MEDIA_LIST_VIEW_FUNCTION_VOID_RET( name, /* Params */ ... ) \
68     void \
69     libvlc_media_list_view_##name( libvlc_media_list_view_t * p_mlv, \
70                                   ##__VA_ARGS__, \
71                                   libvlc_exception_t * p_e ) \
72     { \
73         if( p_mlv->pf_##name ) \
74         { \
75             p_mlv->pf_##name ARGS(__VA_ARGS__) ; \
76             return; \
77         } \
78         libvlc_exception_raise( p_e, "No '" #name "' method in this media_list_view" ); \
79     }
80
81
82 MEDIA_LIST_VIEW_FUNCTION( count, int, 0 )
83 MEDIA_LIST_VIEW_FUNCTION( item_at_index, libvlc_media_descriptor_t *, NULL, int arg1 )
84 MEDIA_LIST_VIEW_FUNCTION( index_of_item, int, -1, libvlc_media_descriptor_t * arg1 )
85
86 MEDIA_LIST_VIEW_FUNCTION_VOID_RET( insert_at_index, libvlc_media_descriptor_t * arg1, int arg2 )
87 MEDIA_LIST_VIEW_FUNCTION_VOID_RET( remove_at_index, int arg1 )
88 MEDIA_LIST_VIEW_FUNCTION_VOID_RET( add_item, libvlc_media_descriptor_t * arg1 )
89