]> git.sesse.net Git - vlc/blob - src/playlist/services_discovery.c
include services discovery in interface
[vlc] / src / playlist / services_discovery.c
1 /*****************************************************************************
2  * services_discovery.c : Manage playlist services_discovery modules
3  *****************************************************************************
4  * Copyright (C) 1999-2004 VideoLAN
5  * $Id: playlist.c 9216 2004-11-07 10:43:52Z zorglub $
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., 59 Temple Place - Suite 330, Boston, MA  02111, USA.
22  *****************************************************************************/
23 #include <stdlib.h>                                      /* free(), strtol() */
24 #include <stdio.h>                                              /* sprintf() */
25 #include <string.h>                                            /* strerror() */
26
27 #include <vlc/vlc.h>
28 #include <vlc/vout.h>
29 #include <vlc/sout.h>
30 #include <vlc/input.h>
31
32 #include "vlc_playlist.h"
33
34 /*****************************************************************************
35  * Local prototypes
36  *****************************************************************************/
37
38 static void RunSD( services_discovery_t *p_sd );
39
40
41 /***************************************************************************
42 ***************************************************************************/
43
44 int playlist_ServicesDiscoveryAdd( playlist_t *p_playlist,
45                                    const char *psz_module )
46 {
47     services_discovery_t *p_sd;
48
49     p_sd = vlc_object_create( p_playlist, VLC_OBJECT_SD );
50     p_sd->pf_run = NULL;
51
52     p_sd->p_module = module_Need( p_sd, "services_discovery", psz_module, 0 );
53
54     if( p_sd->p_module == NULL )
55     {
56         msg_Err( p_playlist, "no suitable services discovery module" );
57         vlc_object_destroy( p_sd );
58         return VLC_EGENERIC;
59     }
60
61     p_sd->psz_module = strdup( psz_module );
62     p_sd->b_die = VLC_FALSE;
63
64     vlc_mutex_lock( &p_playlist->object_lock );
65
66     INSERT_ELEM( p_playlist->pp_sds, p_playlist->i_sds, p_playlist->i_sds,
67                  p_sd );
68
69     vlc_mutex_unlock( &p_playlist->object_lock );
70
71     if( vlc_thread_create( p_sd, "services_discovery", RunSD,
72                            VLC_THREAD_PRIORITY_LOW, VLC_FALSE ) )
73     {
74         msg_Err( p_sd, "cannot create services discovery thread" );
75         vlc_object_destroy( p_sd );
76         return VLC_EGENERIC;
77     }
78
79
80     return VLC_SUCCESS;
81 }
82
83 void playlist_ServicesDiscoveryRemove( playlist_t * p_playlist,
84                                        const char *psz_module )
85 {
86     int i;
87     services_discovery_t *p_sd = NULL;
88     vlc_mutex_lock( &p_playlist->object_lock );
89
90     for( i = 0 ; i< p_playlist->i_sds ; i ++ )
91     {
92         if( !strcmp( psz_module, p_playlist->pp_sds[i]->psz_module ) )
93         {
94             p_sd = p_playlist->pp_sds[i];
95             REMOVE_ELEM( p_playlist->pp_sds, p_playlist->i_sds, i );
96             break;
97         }
98     }
99
100     if( p_sd )
101     {
102         p_sd->b_die = VLC_TRUE;
103         vlc_thread_join( p_sd );
104         module_Unneed( p_sd, p_sd->p_module );
105         vlc_object_destroy( p_sd );
106     }
107     else
108     {
109         msg_Warn( p_playlist, "module %s is not loaded", psz_module );
110     }
111
112     vlc_mutex_unlock( &p_playlist->object_lock );
113     return;
114 }
115
116 vlc_bool_t playlist_IsServicesDiscoveryLoaded( playlist_t * p_playlist,
117                                               const char *psz_module )
118 {
119     int i;
120     vlc_mutex_lock( &p_playlist->object_lock );
121
122     for( i = 0 ; i< p_playlist->i_sds ; i ++ )
123     {
124         if( !strcmp( psz_module, p_playlist->pp_sds[i]->psz_module ) )
125         {
126             vlc_mutex_unlock( &p_playlist->object_lock );
127             return VLC_TRUE;
128         }
129     }
130     vlc_mutex_unlock( &p_playlist->object_lock );
131     return VLC_FALSE;
132 }
133
134
135 /**
136  * Load all service discovery modules in a string
137  *
138  * \param p_playlist the playlist
139  * \param psz_modules a list of modules separated by commads
140  * return VLC_SUCCESS or an error
141  */
142 int playlist_AddSDModules( playlist_t *p_playlist, char *psz_modules )
143 {
144     if( psz_modules && *psz_modules )
145     {
146         char *psz_parser = psz_modules;
147         char *psz_next;
148
149         while( psz_parser && *psz_parser )
150         {
151             while( *psz_parser == ' ' || *psz_parser == ',' )
152             {
153                 psz_parser++;
154             }
155
156             if( (psz_next = strchr( psz_parser, ',' ) ) )
157             {
158                 *psz_next++ = '\0';
159             }
160             if( *psz_parser == '\0' )
161             {
162                 break;
163             }
164
165             playlist_ServicesDiscoveryAdd( p_playlist, psz_parser );
166
167             psz_parser = psz_next;
168         }
169     }
170     return VLC_SUCCESS;
171 }
172
173 static void RunSD( services_discovery_t *p_sd )
174 {
175     p_sd->pf_run( p_sd );
176     return;
177 }