1 /*****************************************************************************
2 * services_discovery.c : Manage playlist services_discovery modules
3 *****************************************************************************
4 * Copyright (C) 1999-2004 the VideoLAN team
7 * Authors: Clément Stenac <zorglub@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 *****************************************************************************/
24 #include <vlc/input.h>
25 #include "vlc_playlist.h"
26 #include "playlist_internal.h"
28 /*****************************************************************************
30 *****************************************************************************/
32 static void RunSD( services_discovery_t *p_sd );
35 /***************************************************************************
36 ***************************************************************************/
38 int playlist_ServicesDiscoveryAdd( playlist_t *p_playlist,
39 const char *psz_module )
41 services_discovery_t *p_sd;
43 p_sd = vlc_object_create( p_playlist, VLC_OBJECT_SD );
46 p_sd->p_module = module_Need( p_sd, "services_discovery", psz_module, 0 );
48 if( p_sd->p_module == NULL )
50 msg_Err( p_playlist, "no suitable services discovery module" );
51 vlc_object_destroy( p_sd );
55 p_sd->psz_module = strdup( psz_module );
56 p_sd->b_die = VLC_FALSE;
58 vlc_mutex_lock( &p_playlist->object_lock );
60 INSERT_ELEM( p_playlist->pp_sds, p_playlist->i_sds, p_playlist->i_sds,
63 vlc_mutex_unlock( &p_playlist->object_lock );
65 if( vlc_thread_create( p_sd, "services_discovery", RunSD,
66 VLC_THREAD_PRIORITY_LOW, VLC_FALSE ) )
68 msg_Err( p_sd, "cannot create services discovery thread" );
69 vlc_object_destroy( p_sd );
77 int playlist_ServicesDiscoveryRemove( playlist_t * p_playlist,
78 const char *psz_module )
81 services_discovery_t *p_sd = NULL;
82 vlc_mutex_lock( &p_playlist->object_lock );
84 for( i = 0 ; i< p_playlist->i_sds ; i ++ )
86 if( !strcmp( psz_module, p_playlist->pp_sds[i]->psz_module ) )
88 p_sd = p_playlist->pp_sds[i];
89 REMOVE_ELEM( p_playlist->pp_sds, p_playlist->i_sds, i );
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 );
106 msg_Warn( p_playlist, "module %s is not loaded", psz_module );
107 vlc_mutex_unlock( &p_playlist->object_lock );
111 vlc_mutex_unlock( &p_playlist->object_lock );
115 vlc_bool_t playlist_IsServicesDiscoveryLoaded( playlist_t * p_playlist,
116 const char *psz_module )
119 vlc_mutex_lock( &p_playlist->object_lock );
121 for( i = 0 ; i< p_playlist->i_sds ; i ++ )
123 if( !strcmp( psz_module, p_playlist->pp_sds[i]->psz_module ) )
125 vlc_mutex_unlock( &p_playlist->object_lock );
129 vlc_mutex_unlock( &p_playlist->object_lock );
135 * Load all service discovery modules in a string
137 * \param p_playlist the playlist
138 * \param psz_modules a list of modules separated by commads
139 * return VLC_SUCCESS or an error
141 int playlist_AddSDModules( playlist_t *p_playlist, char *psz_modules )
143 if( psz_modules && *psz_modules )
145 char *psz_parser = psz_modules;
148 while( psz_parser && *psz_parser )
150 while( *psz_parser == ' ' || *psz_parser == ':' )
155 if( (psz_next = strchr( psz_parser, ':' ) ) )
159 if( *psz_parser == '\0' )
164 playlist_ServicesDiscoveryAdd( p_playlist, psz_parser );
166 psz_parser = psz_next;
172 static void RunSD( services_discovery_t *p_sd )
174 p_sd->pf_run( p_sd );