]> git.sesse.net Git - vlc/blob - src/playlist/services_discovery.c
* Documentation belongs to the .h, step 1
[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 static void RunSD( services_discovery_t *p_sd );
29
30 int playlist_ServicesDiscoveryAdd( playlist_t *p_playlist,  const char *psz_modules )
31 {
32     if( psz_modules && *psz_modules )
33     {
34         char *psz_parser = psz_modules;
35         char *psz_next;
36
37         while( psz_parser && *psz_parser )
38         {
39             while( *psz_parser == ' ' || *psz_parser == ':' || *psz_parser == ',' )
40                 psz_parser++;
41
42             if( (psz_next = strchr( psz_parser, ':' ) ) )
43                 *psz_next++ = '\0';
44
45             if( *psz_parser == '\0' )
46                 break;
47             fprintf(stderr,"Add %s\n", psz_parser);
48             /* Perform the addition */
49             {
50                 services_discovery_t *p_sd = vlc_object_create( p_playlist,
51                                                                 VLC_OBJECT_SD );
52                 p_sd->pf_run = NULL;
53                 p_sd->p_module = module_Need( p_sd, "services_discovery", psz_parser, 0 );
54
55                 if( p_sd->p_module == NULL )
56                 {
57                     msg_Err( p_playlist, "no suitable services discovery module" );
58                     vlc_object_destroy( p_sd );
59                     return VLC_EGENERIC;
60                 }
61                 p_sd->psz_module = strdup( psz_parser );
62                 p_sd->b_die = VLC_FALSE;
63
64                 PL_LOCK;
65                 TAB_APPEND( p_playlist->i_sds, p_playlist->pp_sds, p_sd );
66                 PL_UNLOCK;
67
68                 if( !p_sd->pf_run ) {
69                     psz_parser = psz_next;
70                     continue;
71                 }
72
73                 if( vlc_thread_create( p_sd, "services_discovery", RunSD,
74                                        VLC_THREAD_PRIORITY_LOW, VLC_FALSE ) )
75                 {
76                     msg_Err( p_sd, "cannot create services discovery thread" );
77                     vlc_object_destroy( p_sd );
78                     return VLC_EGENERIC;
79                 }
80             }
81             psz_parser = psz_next;
82         }
83     }
84     return VLC_SUCCESS;
85 }
86
87 int playlist_ServicesDiscoveryRemove( playlist_t * p_playlist,
88                                        const char *psz_module )
89 {
90     int i;
91     services_discovery_t *p_sd = NULL;
92
93     PL_LOCK;
94     for( i = 0 ; i< p_playlist->i_sds ; i ++ )
95     {
96         if( !strcmp( psz_module, p_playlist->pp_sds[i]->psz_module ) )
97         {
98             p_sd = p_playlist->pp_sds[i];
99             REMOVE_ELEM( p_playlist->pp_sds, p_playlist->i_sds, i );
100             break;
101         }
102     }
103
104     if( p_sd )
105     {
106         PL_UNLOCK;
107         p_sd->b_die = VLC_TRUE;
108         if( p_sd->pf_run ) vlc_thread_join( p_sd );
109
110         free( p_sd->psz_module );
111         module_Unneed( p_sd, p_sd->p_module );
112         PL_LOCK;
113         vlc_object_destroy( p_sd );
114     }
115     else
116     {
117         msg_Warn( p_playlist, "module %s is not loaded", psz_module );
118         PL_UNLOCK;
119         return VLC_EGENERIC;
120     }
121     PL_UNLOCK;
122     return VLC_SUCCESS;
123 }
124
125 vlc_bool_t playlist_IsServicesDiscoveryLoaded( playlist_t * p_playlist,
126                                               const char *psz_module )
127 {
128     int i;
129     PL_LOCK;
130
131     for( i = 0 ; i< p_playlist->i_sds ; i ++ )
132     {
133         if( !strcmp( psz_module, p_playlist->pp_sds[i]->psz_module ) )
134         {
135             PL_UNLOCK;
136             return VLC_TRUE;
137         }
138     }
139     PL_UNLOCK;
140     return VLC_FALSE;
141 }
142
143 static void RunSD( services_discovery_t *p_sd )
144 {
145     p_sd->pf_run( p_sd );
146     return;
147 }