]> git.sesse.net Git - vlc/blob - src/misc/xml.c
decoder: inline DecoderSignalWait()
[vlc] / src / misc / xml.c
1 /*****************************************************************************
2  * xml.c: XML parser wrapper for XML modules
3  *****************************************************************************
4  * Copyright (C) 2004-2010 VLC authors and VideoLAN
5  *
6  * Authors: Gildas Bazin <gbazin@videolan.org>
7  *
8  * This program is free software; you can redistribute it and/or modify it
9  * under the terms of the GNU Lesser General Public License as published by
10  * the Free Software Foundation; either version 2.1 of the License, or
11  * (at your option) any later version.
12  *
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 Lesser General Public License for more details.
17  *
18  * You should have received a copy of the GNU Lesser General Public License
19  * along with this program; if not, write to the Free Software Foundation,
20  * Inc., 51 Franklin Street, Fifth Floor, Boston MA 02110-1301, USA.
21  *****************************************************************************/
22
23 #ifdef HAVE_CONFIG_H
24 # include "config.h"
25 #endif
26
27 #include <vlc_common.h>
28 #include <vlc_xml.h>
29 #include <vlc_modules.h>
30 #include "../libvlc.h"
31
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 )
40 {
41     xml_t *p_xml;
42
43     p_xml = vlc_custom_create( p_this, sizeof( *p_xml ), "xml" );
44
45     p_xml->p_module = module_need( p_xml, "xml", NULL, false );
46     if( !p_xml->p_module )
47     {
48         vlc_object_release( p_xml );
49         msg_Err( p_this, "XML provider not found" );
50         return NULL;
51     }
52
53     return p_xml;
54 }
55
56 /*****************************************************************************
57  * xml_Delete: Deletes an instance of xml_t
58  *****************************************************************************/
59 void xml_Delete( xml_t *p_xml )
60 {
61     module_unneed( p_xml, p_xml->p_module );
62     vlc_object_release( p_xml );
63 }
64
65
66 #undef xml_ReaderCreate
67 /**
68  * Creates an XML reader.
69  * @param obj parent VLC object
70  * @param stream stream to read XML from
71  * @return NULL on error.
72  */
73 xml_reader_t *xml_ReaderCreate(vlc_object_t *obj, stream_t *stream)
74 {
75     xml_reader_t *reader;
76
77     reader = vlc_custom_create(obj, sizeof(*reader), "xml reader");
78
79     reader->p_stream = stream;
80     reader->p_module = module_need(reader, "xml reader", NULL, false);
81     if (unlikely(reader->p_module == NULL))
82     {
83         msg_Err(reader, "XML reader not found");
84         vlc_object_release(reader);
85         return NULL;
86     }
87     return reader;
88 }
89
90
91 /**
92  * Deletes an XML reader.
93  * @param reader XML reader created with xml_ReaderCreate().
94  */
95 void xml_ReaderDelete(xml_reader_t *reader)
96 {
97     if (reader->p_stream)
98         module_stop(reader, reader->p_module);
99     vlc_object_release(reader);
100 }
101
102
103 /**
104  * Resets an existing XML reader.
105  * If you need to parse several XML files, this function is much faster than
106  * xml_ReaderCreate() and xml_ReaderDelete() combined.
107  * If the stream parameter is NULL, the XML reader will be stopped, but
108  * not restarted until the next xml_ReaderReset() call with a non-NULL stream.
109  *
110  * @param reader XML reader to reinitialize
111  * @param stream new stream to read XML data from (or NULL)
112  * @return reader on success,
113  *         NULL on error (in that case, the reader is destroyed).
114  */
115 xml_reader_t *xml_ReaderReset(xml_reader_t *reader, stream_t *stream)
116 {
117     if (reader->p_stream)
118         module_stop(reader, reader->p_module);
119
120     reader->p_stream = stream;
121     if ((stream != NULL) && module_start(reader, reader->p_module))
122     {
123         vlc_object_release(reader);
124         return NULL;
125     }
126     return reader;
127 }