]> git.sesse.net Git - vlc/blob - src/playlist/services_discovery.c
Split playlist include file in public/private
[vlc] / src / playlist / services_discovery.c
1 /*****************************************************************************
2  * services_discovery.c : Manage playlist services_discovery modules
3  *****************************************************************************
4  * Copyright (C) 1999-2004 the VideoLAN team
5  * $Id$
6  *
7  * Authors: ClĂ©ment Stenac <zorglub@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 <vlc/vlc.h>
24 #include <vlc/input.h>
25 #include "vlc_playlist.h"
26 #include "playlist_internal.h"
27
28 /*****************************************************************************
29  * Local prototypes
30  *****************************************************************************/
31
32 static void RunSD( services_discovery_t *p_sd );
33
34
35 /***************************************************************************
36 ***************************************************************************/
37
38 int playlist_ServicesDiscoveryAdd( playlist_t *p_playlist,
39                                    const char *psz_module )
40 {
41     services_discovery_t *p_sd;
42
43     p_sd = vlc_object_create( p_playlist, VLC_OBJECT_SD );
44     p_sd->pf_run = NULL;
45
46     p_sd->p_module = module_Need( p_sd, "services_discovery", psz_module, 0 );
47
48     if( p_sd->p_module == NULL )
49     {
50         msg_Err( p_playlist, "no suitable services discovery module" );
51         vlc_object_destroy( p_sd );
52         return VLC_EGENERIC;
53     }
54
55     p_sd->psz_module = strdup( psz_module );
56     p_sd->b_die = VLC_FALSE;
57
58     vlc_mutex_lock( &p_playlist->object_lock );
59
60     INSERT_ELEM( p_playlist->pp_sds, p_playlist->i_sds, p_playlist->i_sds,
61                  p_sd );
62
63     vlc_mutex_unlock( &p_playlist->object_lock );
64
65     if( vlc_thread_create( p_sd, "services_discovery", RunSD,
66                            VLC_THREAD_PRIORITY_LOW, VLC_FALSE ) )
67     {
68         msg_Err( p_sd, "cannot create services discovery thread" );
69         vlc_object_destroy( p_sd );
70         return VLC_EGENERIC;
71     }
72
73
74     return VLC_SUCCESS;
75 }
76
77 int playlist_ServicesDiscoveryRemove( playlist_t * p_playlist,
78                                        const char *psz_module )
79 {
80     int i;
81     services_discovery_t *p_sd = NULL;
82     vlc_mutex_lock( &p_playlist->object_lock );
83
84     for( i = 0 ; i< p_playlist->i_sds ; i ++ )
85     {
86         if( !strcmp( psz_module, p_playlist->pp_sds[i]->psz_module ) )
87         {
88             p_sd = p_playlist->pp_sds[i];
89             REMOVE_ELEM( p_playlist->pp_sds, p_playlist->i_sds, i );
90             break;
91         }
92     }
93
94     if( p_sd )
95     {
96         vlc_mutex_unlock( &p_playlist->object_lock );
97         p_sd->b_die = VLC_TRUE;
98         vlc_thread_join( p_sd );
99         free( p_sd->psz_module );
100         module_Unneed( p_sd, p_sd->p_module );
101         vlc_mutex_lock( &p_playlist->object_lock );
102         vlc_object_destroy( p_sd );
103     }
104     else
105     {
106         msg_Warn( p_playlist, "module %s is not loaded", psz_module );
107         vlc_mutex_unlock( &p_playlist->object_lock );
108         return VLC_EGENERIC;
109     }
110
111     vlc_mutex_unlock( &p_playlist->object_lock );
112     return VLC_SUCCESS;
113 }
114
115 vlc_bool_t playlist_IsServicesDiscoveryLoaded( playlist_t * p_playlist,
116                                               const char *psz_module )
117 {
118     int i;
119     vlc_mutex_lock( &p_playlist->object_lock );
120
121     for( i = 0 ; i< p_playlist->i_sds ; i ++ )
122     {
123         if( !strcmp( psz_module, p_playlist->pp_sds[i]->psz_module ) )
124         {
125             vlc_mutex_unlock( &p_playlist->object_lock );
126             return VLC_TRUE;
127         }
128     }
129     vlc_mutex_unlock( &p_playlist->object_lock );
130     return VLC_FALSE;
131 }
132
133
134 /**
135  * Load all service discovery modules in a string
136  *
137  * \param p_playlist the playlist
138  * \param psz_modules a list of modules separated by commads
139  * return VLC_SUCCESS or an error
140  */
141 int playlist_AddSDModules( playlist_t *p_playlist, char *psz_modules )
142 {
143     if( psz_modules && *psz_modules )
144     {
145         char *psz_parser = psz_modules;
146         char *psz_next;
147
148         while( psz_parser && *psz_parser )
149         {
150             while( *psz_parser == ' ' || *psz_parser == ':' )
151             {
152                 psz_parser++;
153             }
154
155             if( (psz_next = strchr( psz_parser, ':' ) ) )
156             {
157                 *psz_next++ = '\0';
158             }
159             if( *psz_parser == '\0' )
160             {
161                 break;
162             }
163
164             playlist_ServicesDiscoveryAdd( p_playlist, psz_parser );
165
166             psz_parser = psz_next;
167         }
168     }
169     return VLC_SUCCESS;
170 }
171
172 static void RunSD( services_discovery_t *p_sd )
173 {
174     p_sd->pf_run( p_sd );
175     return;
176 }