]> git.sesse.net Git - vlc/blob - src/control/tag_query.c
libvlc: Introduce VLC_DEPRECATED_API. And mark the libvlc_playlist_* and VLC_* API...
[vlc] / src / control / tag_query.c
1 /*****************************************************************************
2  * tag_query.c: libvlc new API media tag query functions
3  *****************************************************************************
4  * Copyright (C) 2007 the VideoLAN team
5  * $Id$
6  *
7  * Authors: Pierre d'Herbemont <pdherbemont # videolan.org>
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 #include "libvlc_internal.h"
24 #include <vlc/libvlc.h>
25 #include "vlc_arrays.h"
26
27 /* XXX This API is in construction
28  *
29  * It's goal is to represent a meta tag query
30  * It should be also able to say if a query can be matched in a media
31  * descriptor through libvlc_query_match.
32  */
33  
34 /*
35  * Public libvlc functions
36  */
37
38 /**************************************************************************
39  *       new (Public)
40  *
41  * Init an object.
42  **************************************************************************/
43 libvlc_tag_query_t *
44 libvlc_tag_query_new( libvlc_instance_t * p_inst,
45                       libvlc_exception_t * p_e )
46 {
47     (void)p_e;
48     libvlc_tag_query_t * p_q;
49
50     p_q = malloc(sizeof(libvlc_tag_query_t));
51
52     if( !p_q )
53         return NULL;
54     
55     p_q->p_libvlc_instance = p_inst;
56     p_q->i_refcount = 1;
57     p_q->tag = NULL;
58     p_q->psz_tag_key = NULL;
59
60     libvlc_retain( p_inst );
61     return p_q;
62 }
63
64 /**************************************************************************
65  *       release (Public)
66  *
67  * Release an object.
68  **************************************************************************/
69 void libvlc_tag_query_release( libvlc_tag_query_t * p_q )
70 {
71     p_q->i_refcount--;
72
73     if( p_q->i_refcount > 0 )
74         return;
75
76     free( p_q->tag );
77     free( p_q->psz_tag_key );
78  
79     libvlc_release( p_q->p_libvlc_instance );
80     free( p_q );
81 }
82
83 /**************************************************************************
84  *       retain (Public)
85  *
86  * Release an object.
87  **************************************************************************/
88 void libvlc_tag_query_retain( libvlc_tag_query_t * p_q )
89 {
90     p_q->i_refcount++;
91 }
92
93 /**************************************************************************
94  *       set_match_tag_and_key (Public)
95  **************************************************************************/
96 void libvlc_tag_query_set_match_tag_and_key( libvlc_tag_query_t * p_q,
97                                              libvlc_tag_t tag,
98                                              char * psz_tag_key,
99                                              libvlc_exception_t * p_e )
100 {
101     (void)p_e;
102
103     p_q->tag = strdup( tag );
104     p_q->psz_tag_key = strdup( psz_tag_key );
105 }
106
107 /**************************************************************************
108  *       match (Public)
109  *
110  * Return true if the query p_q is matched in p_md
111  **************************************************************************/
112 int
113 libvlc_tag_query_match( libvlc_tag_query_t * p_q,
114                         libvlc_media_descriptor_t * p_md,
115                         libvlc_exception_t * p_e )
116 {
117     int i;
118     struct libvlc_tags_storage_t * p_ts;
119     (void)p_e;
120  
121     if( !p_q->psz_tag_key )
122         return 1;
123
124     p_ts = vlc_dictionary_value_for_key( &p_md->tags, p_q->psz_tag_key );
125     if( !p_q->tag )
126         return p_ts->i_count > 0;
127
128     for( i = 0; i < p_ts->i_count; i++ )
129     {
130         if( !strcmp( p_ts->ppsz_tags[i], p_q->tag ) )
131             return 1;
132     }
133
134     /* In construction... */
135     return 0;
136 }