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 static void RunSD( services_discovery_t *p_sd );
30 int playlist_ServicesDiscoveryAdd( playlist_t *p_playlist, const char *psz_modules )
32 if( psz_modules && *psz_modules )
34 char *psz_parser = psz_modules;
37 while( psz_parser && *psz_parser )
39 while( *psz_parser == ' ' || *psz_parser == ':' || *psz_parser == ',' )
42 if( (psz_next = strchr( psz_parser, ':' ) ) )
45 if( *psz_parser == '\0' )
47 fprintf(stderr,"Add %s\n", psz_parser);
48 /* Perform the addition */
50 services_discovery_t *p_sd = vlc_object_create( p_playlist,
53 p_sd->p_module = module_Need( p_sd, "services_discovery", psz_parser, 0 );
55 if( p_sd->p_module == NULL )
57 msg_Err( p_playlist, "no suitable services discovery module" );
58 vlc_object_destroy( p_sd );
61 p_sd->psz_module = strdup( psz_parser );
62 p_sd->b_die = VLC_FALSE;
65 TAB_APPEND( p_playlist->i_sds, p_playlist->pp_sds, p_sd );
69 psz_parser = psz_next;
73 if( vlc_thread_create( p_sd, "services_discovery", RunSD,
74 VLC_THREAD_PRIORITY_LOW, VLC_FALSE ) )
76 msg_Err( p_sd, "cannot create services discovery thread" );
77 vlc_object_destroy( p_sd );
81 psz_parser = psz_next;
87 int playlist_ServicesDiscoveryRemove( playlist_t * p_playlist,
88 const char *psz_module )
91 services_discovery_t *p_sd = NULL;
94 for( i = 0 ; i< p_playlist->i_sds ; i ++ )
96 if( !strcmp( psz_module, p_playlist->pp_sds[i]->psz_module ) )
98 p_sd = p_playlist->pp_sds[i];
99 REMOVE_ELEM( p_playlist->pp_sds, p_playlist->i_sds, i );
107 p_sd->b_die = VLC_TRUE;
108 if( p_sd->pf_run ) vlc_thread_join( p_sd );
110 free( p_sd->psz_module );
111 module_Unneed( p_sd, p_sd->p_module );
113 vlc_object_destroy( p_sd );
117 msg_Warn( p_playlist, "module %s is not loaded", psz_module );
125 vlc_bool_t playlist_IsServicesDiscoveryLoaded( playlist_t * p_playlist,
126 const char *psz_module )
131 for( i = 0 ; i< p_playlist->i_sds ; i ++ )
133 if( !strcmp( psz_module, p_playlist->pp_sds[i]->psz_module ) )
143 static void RunSD( services_discovery_t *p_sd )
145 p_sd->pf_run( p_sd );