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_playlist.h"
25 #include "playlist_internal.h"
27 static void RunSD( services_discovery_t *p_sd );
29 int playlist_ServicesDiscoveryAdd( playlist_t *p_playlist, const char *psz_modules )
31 if( psz_modules && *psz_modules )
33 char *psz_parser = psz_modules;
36 while( psz_parser && *psz_parser )
38 while( *psz_parser == ' ' || *psz_parser == ':' || *psz_parser == ',' )
41 if( (psz_next = strchr( psz_parser, ':' ) ) )
44 if( *psz_parser == '\0' )
46 msg_Dbg( p_playlist, "Add services_discovery %s", psz_parser );
47 /* Perform the addition */
49 services_discovery_t *p_sd = vlc_object_create( p_playlist,
52 p_sd->p_module = module_Need( p_sd, "services_discovery", psz_parser, 0 );
54 if( p_sd->p_module == NULL )
56 msg_Err( p_playlist, "no suitable services discovery module" );
57 vlc_object_destroy( p_sd );
60 p_sd->psz_module = strdup( psz_parser );
61 p_sd->b_die = VLC_FALSE;
64 TAB_APPEND( p_playlist->i_sds, p_playlist->pp_sds, p_sd );
68 psz_parser = psz_next;
72 if( vlc_thread_create( p_sd, "services_discovery", RunSD,
73 VLC_THREAD_PRIORITY_LOW, VLC_FALSE ) )
75 msg_Err( p_sd, "cannot create services discovery thread" );
76 vlc_object_destroy( p_sd );
80 psz_parser = psz_next;
86 int playlist_ServicesDiscoveryRemove( playlist_t * p_playlist,
87 const char *psz_module )
90 services_discovery_t *p_sd = NULL;
93 for( i = 0 ; i< p_playlist->i_sds ; i ++ )
95 if( !strcmp( psz_module, p_playlist->pp_sds[i]->psz_module ) )
97 p_sd = p_playlist->pp_sds[i];
98 REMOVE_ELEM( p_playlist->pp_sds, p_playlist->i_sds, i );
106 p_sd->b_die = VLC_TRUE;
107 if( p_sd->pf_run ) vlc_thread_join( p_sd );
109 free( p_sd->psz_module );
110 module_Unneed( p_sd, p_sd->p_module );
112 vlc_object_destroy( p_sd );
116 msg_Warn( p_playlist, "module %s is not loaded", psz_module );
124 vlc_bool_t playlist_IsServicesDiscoveryLoaded( playlist_t * p_playlist,
125 const char *psz_module )
130 for( i = 0 ; i< p_playlist->i_sds ; i ++ )
132 if( !strcmp( psz_module, p_playlist->pp_sds[i]->psz_module ) )
142 static void RunSD( services_discovery_t *p_sd )
144 p_sd->pf_run( p_sd );