Main Page | Modules | Class Hierarchy | Class List | Directories | File List | Class Members | File Members | Related Pages

services_discovery.c

00001 /*****************************************************************************
00002  * services_discovery.c : Manage playlist services_discovery modules
00003  *****************************************************************************
00004  * Copyright (C) 1999-2004 the VideoLAN team
00005  * $Id: playlist.c 9216 2004-11-07 10:43:52Z zorglub $
00006  *
00007  * Authors: Clément Stenac <[email protected]>
00008  *
00009  * This program is free software; you can redistribute it and/or modify
00010  * it under the terms of the GNU General Public License as published by
00011  * the Free Software Foundation; either version 2 of the License, or
00012  * (at your option) any later version.
00013  *
00014  * This program is distributed in the hope that it will be useful,
00015  * but WITHOUT ANY WARRANTY; without even the implied warranty of
00016  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
00017  * GNU General Public License for more details.
00018  *
00019  * You should have received a copy of the GNU General Public License
00020  * along with this program; if not, write to the Free Software
00021  * Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA  02111, USA.
00022  *****************************************************************************/
00023 #include <stdlib.h>                                      /* free(), strtol() */
00024 #include <stdio.h>                                              /* sprintf() */
00025 #include <string.h>                                            /* strerror() */
00026 
00027 #include <vlc/vlc.h>
00028 #include <vlc/vout.h>
00029 #include <vlc/sout.h>
00030 #include <vlc/input.h>
00031 
00032 #include "vlc_playlist.h"
00033 
00034 /*****************************************************************************
00035  * Local prototypes
00036  *****************************************************************************/
00037 
00038 static void RunSD( services_discovery_t *p_sd );
00039 
00040 
00041 /***************************************************************************
00042 ***************************************************************************/
00043 
00044 int playlist_ServicesDiscoveryAdd( playlist_t *p_playlist,
00045                                    const char *psz_module )
00046 {
00047     services_discovery_t *p_sd;
00048 
00049     p_sd = vlc_object_create( p_playlist, VLC_OBJECT_SD );
00050     p_sd->pf_run = NULL;
00051 
00052     p_sd->p_module = module_Need( p_sd, "services_discovery", psz_module, 0 );
00053 
00054     if( p_sd->p_module == NULL )
00055     {
00056         msg_Err( p_playlist, "no suitable services discovery module" );
00057         vlc_object_destroy( p_sd );
00058         return VLC_EGENERIC;
00059     }
00060 
00061     p_sd->psz_module = strdup( psz_module );
00062     p_sd->b_die = VLC_FALSE;
00063 
00064     vlc_mutex_lock( &p_playlist->object_lock );
00065 
00066     INSERT_ELEM( p_playlist->pp_sds, p_playlist->i_sds, p_playlist->i_sds,
00067                  p_sd );
00068 
00069     vlc_mutex_unlock( &p_playlist->object_lock );
00070 
00071     if( vlc_thread_create( p_sd, "services_discovery", RunSD,
00072                            VLC_THREAD_PRIORITY_LOW, VLC_FALSE ) )
00073     {
00074         msg_Err( p_sd, "cannot create services discovery thread" );
00075         vlc_object_destroy( p_sd );
00076         return VLC_EGENERIC;
00077     }
00078 
00079 
00080     return VLC_SUCCESS;
00081 }
00082 
00083 int playlist_ServicesDiscoveryRemove( playlist_t * p_playlist,
00084                                        const char *psz_module )
00085 {
00086     int i;
00087     services_discovery_t *p_sd = NULL;
00088     vlc_mutex_lock( &p_playlist->object_lock );
00089 
00090     for( i = 0 ; i< p_playlist->i_sds ; i ++ )
00091     {
00092         if( !strcmp( psz_module, p_playlist->pp_sds[i]->psz_module ) )
00093         {
00094             p_sd = p_playlist->pp_sds[i];
00095             REMOVE_ELEM( p_playlist->pp_sds, p_playlist->i_sds, i );
00096             break;
00097         }
00098     }
00099 
00100     if( p_sd )
00101     {
00102         vlc_mutex_unlock( &p_playlist->object_lock );
00103         p_sd->b_die = VLC_TRUE;
00104         vlc_thread_join( p_sd );
00105         free( p_sd->psz_module );
00106         module_Unneed( p_sd, p_sd->p_module );
00107         vlc_mutex_lock( &p_playlist->object_lock );
00108         vlc_object_destroy( p_sd );
00109     }
00110     else
00111     {
00112         msg_Warn( p_playlist, "module %s is not loaded", psz_module );
00113         vlc_mutex_unlock( &p_playlist->object_lock );
00114         return VLC_EGENERIC;
00115     }
00116 
00117     vlc_mutex_unlock( &p_playlist->object_lock );
00118     return VLC_SUCCESS;
00119 }
00120 
00121 vlc_bool_t playlist_IsServicesDiscoveryLoaded( playlist_t * p_playlist,
00122                                               const char *psz_module )
00123 {
00124     int i;
00125     vlc_mutex_lock( &p_playlist->object_lock );
00126 
00127     for( i = 0 ; i< p_playlist->i_sds ; i ++ )
00128     {
00129         if( !strcmp( psz_module, p_playlist->pp_sds[i]->psz_module ) )
00130         {
00131             vlc_mutex_unlock( &p_playlist->object_lock );
00132             return VLC_TRUE;
00133         }
00134     }
00135     vlc_mutex_unlock( &p_playlist->object_lock );
00136     return VLC_FALSE;
00137 }
00138 
00139 
00147 int playlist_AddSDModules( playlist_t *p_playlist, char *psz_modules )
00148 {
00149     if( psz_modules && *psz_modules )
00150     {
00151         char *psz_parser = psz_modules;
00152         char *psz_next;
00153 
00154         while( psz_parser && *psz_parser )
00155         {
00156             while( *psz_parser == ' ' || *psz_parser == ':' )
00157             {
00158                 psz_parser++;
00159             }
00160 
00161             if( (psz_next = strchr( psz_parser, ':' ) ) )
00162             {
00163                 *psz_next++ = '\0';
00164             }
00165             if( *psz_parser == '\0' )
00166             {
00167                 break;
00168             }
00169 
00170             playlist_ServicesDiscoveryAdd( p_playlist, psz_parser );
00171 
00172             psz_parser = psz_next;
00173         }
00174     }
00175     return VLC_SUCCESS;
00176 }
00177 
00178 static void RunSD( services_discovery_t *p_sd )
00179 {
00180     p_sd->pf_run( p_sd );
00181     return;
00182 }

Generated on Tue Dec 20 10:15:01 2005 for vlc-0.8.4a by  doxygen 1.4.2