1 /*****************************************************************************
2 * tag_query.c: libvlc new API media tag query functions
3 *****************************************************************************
4 * Copyright (C) 2007 the VideoLAN team
7 * Authors: Pierre d'Herbemont <pdherbemont # videolan.org>
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.
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.
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"
27 /* XXX This API is in construction
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.
35 * Public libvlc functions
38 /**************************************************************************
42 **************************************************************************/
44 libvlc_tag_query_new( libvlc_instance_t * p_inst,
45 libvlc_exception_t * p_e )
48 libvlc_tag_query_t * p_q;
50 p_q = malloc(sizeof(libvlc_tag_query_t));
55 p_q->p_libvlc_instance = p_inst;
58 p_q->psz_tag_key = NULL;
60 libvlc_retain( p_inst );
64 /**************************************************************************
68 **************************************************************************/
69 void libvlc_tag_query_release( libvlc_tag_query_t * p_q )
73 if( p_q->i_refcount > 0 )
77 free( p_q->psz_tag_key );
79 libvlc_release( p_q->p_libvlc_instance );
83 /**************************************************************************
87 **************************************************************************/
88 void libvlc_tag_query_retain( libvlc_tag_query_t * p_q )
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,
99 libvlc_exception_t * p_e )
103 p_q->tag = strdup( tag );
104 p_q->psz_tag_key = strdup( psz_tag_key );
107 /**************************************************************************
110 * Return true if the query p_q is matched in p_md
111 **************************************************************************/
113 libvlc_tag_query_match( libvlc_tag_query_t * p_q,
114 libvlc_media_descriptor_t * p_md,
115 libvlc_exception_t * p_e )
118 struct libvlc_tags_storage_t * p_ts;
121 if( !p_q->psz_tag_key )
124 p_ts = vlc_dictionary_value_for_key( &p_md->tags, p_q->psz_tag_key );
126 return p_ts->i_count > 0;
128 for( i = 0; i < p_ts->i_count; i++ )
130 if( !strcmp( p_ts->ppsz_tags[i], p_q->tag ) )
134 /* In construction... */