Playlist: fix scrolling events in selector
[vlc/vlc-skelet.git] / src / misc / xml.c
blob1748bfc9f69a2729a1c2185fc60d477152793f07
1 /*****************************************************************************
2 * xml.c: XML parser wrapper for XML modules
3 *****************************************************************************
4 * Copyright (C) 2004-2010 the VideoLAN team
6 * Authors: Gildas Bazin <gbazin@videolan.org>
8 * This program is free software; you can redistribute it and/or modify
9 * it under the terms of the GNU General Public License as published by
10 * the Free Software Foundation; either version 2 of the License, or
11 * (at your option) any later version.
13 * This program is distributed in the hope that it will be useful,
14 * but WITHOUT ANY WARRANTY; without even the implied warranty of
15 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
16 * GNU General Public License for more details.
18 * You should have received a copy of the GNU General Public License
19 * along with this program; if not, write to the Free Software
20 * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston MA 02110-1301, USA.
21 *****************************************************************************/
23 #ifdef HAVE_CONFIG_H
24 # include "config.h"
25 #endif
27 #include <vlc_common.h>
28 #include <vlc_xml.h>
29 #include <vlc_modules.h>
30 #include "../libvlc.h"
32 #undef xml_Create
33 /*****************************************************************************
34 * xml_Create:
35 *****************************************************************************
36 * Create an instance of an XML parser.
37 * Returns NULL on error.
38 *****************************************************************************/
39 xml_t *xml_Create( vlc_object_t *p_this )
41 xml_t *p_xml;
43 p_xml = vlc_custom_create( p_this, sizeof( *p_xml ), VLC_OBJECT_GENERIC,
44 "xml" );
45 vlc_object_attach( p_xml, p_this );
47 p_xml->p_module = module_need( p_xml, "xml", NULL, false );
48 if( !p_xml->p_module )
50 vlc_object_release( p_xml );
51 msg_Err( p_this, "XML provider not found" );
52 return NULL;
55 return p_xml;
58 /*****************************************************************************
59 * xml_Delete: Deletes an instance of xml_t
60 *****************************************************************************/
61 void xml_Delete( xml_t *p_xml )
63 module_unneed( p_xml, p_xml->p_module );
64 vlc_object_release( p_xml );
68 #undef xml_ReaderCreate
69 /**
70 * Creates an XML reader.
71 * @param obj parent VLC object
72 * @param stream stream to read XML from
73 * @return NULL on error.
75 xml_reader_t *xml_ReaderCreate(vlc_object_t *obj, stream_t *stream)
77 xml_reader_t *reader;
79 reader = vlc_custom_create(obj, sizeof(*reader), VLC_OBJECT_GENERIC,
80 "xml reader");
81 vlc_object_attach(reader, obj);
83 reader->p_stream = stream;
84 reader->p_module = module_need(reader, "xml reader", NULL, false);
85 if (unlikely(reader->p_module == NULL))
87 msg_Err(reader, "XML reader not found");
88 vlc_object_release(reader);
89 return NULL;
91 return reader;
95 /**
96 * Deletes an XML reader.
97 * @param reader XML reader created with xml_RaederCreate().
99 void xml_ReaderDelete(xml_reader_t *reader)
101 if (reader->p_stream)
102 module_stop(reader, reader->p_module);
103 module_release(reader->p_module);
104 vlc_object_release(reader);
109 * Resets an existing XML reader.
110 * If you need to parse several XML files, this function is much faster than
111 * xml_ReaderCreate() and xml_ReaderDelete() combined.
112 * If the stream parameter is NULL, the XML reader will be stopped, but
113 * not restarted until the next xml_ReaderReset() call with a non-NULL stream.
115 * @param reader XML reader to reinitialize
116 * @param stream new stream to read XML data from (or NULL)
117 * @return reader on success,
118 * NULL on error (in that case, the reader is destroyed).
120 xml_reader_t *xml_ReaderReset(xml_reader_t *reader, stream_t *stream)
122 if (reader->p_stream)
123 module_stop(reader, reader->p_module);
125 reader->p_stream = stream;
126 if ((stream != NULL) && module_start(reader, reader->p_module))
128 module_release(reader->p_module);
129 vlc_object_release(reader);
130 return NULL;
132 return reader;