1 /*****************************************************************************
2 * sd.c: Services discovery related functions
3 *****************************************************************************
4 * Copyright (C) 2007-2008 the VideoLAN team
7 * Authors: Antoine Cellerier <dionoea at videolan tod 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 /*****************************************************************************
26 *****************************************************************************/
35 #include <vlc_common.h>
36 #include <vlc_services_discovery.h>
37 #include <vlc_playlist.h>
39 #include <lua.h> /* Low level lua C API */
40 #include <lauxlib.h> /* Higher level C API */
41 #include <lualib.h> /* Lua libs */
47 /*****************************************************************************
49 *****************************************************************************/
50 static int vlclua_sd_get_services_names( lua_State *L )
52 playlist_t *p_playlist = vlclua_get_playlist_internal( L );
53 char **ppsz_longnames;
54 char **ppsz_names = vlc_sd_GetNames( p_playlist, &ppsz_longnames );
55 vlclua_release_playlist_internal( p_playlist );
59 char **ppsz_longname = ppsz_longnames;
60 char **ppsz_name = ppsz_names;
63 for( ; *ppsz_name; ppsz_name++,ppsz_longname++ )
65 lua_pushstring( L, *ppsz_longname );
66 lua_setfield( L, -2, *ppsz_name );
68 free( *ppsz_longname );
71 free( ppsz_longnames );
75 static int vlclua_sd_add( lua_State *L )
77 const char *psz_sd = luaL_checkstring( L, 1 );
78 playlist_t *p_playlist = vlclua_get_playlist_internal( L );
79 int i_ret = playlist_ServicesDiscoveryAdd( p_playlist, psz_sd );
80 vlclua_release_playlist_internal( p_playlist );
81 return vlclua_push_ret( L, i_ret );
84 static int vlclua_sd_remove( lua_State *L )
86 const char *psz_sd = luaL_checkstring( L, 1 );
87 playlist_t *p_playlist = vlclua_get_playlist_internal( L );
88 int i_ret = playlist_ServicesDiscoveryRemove( p_playlist, psz_sd );
89 vlclua_release_playlist_internal( p_playlist );
90 return vlclua_push_ret( L, i_ret );
93 static int vlclua_sd_is_loaded( lua_State *L )
95 const char *psz_sd = luaL_checkstring( L, 1 );
96 playlist_t *p_playlist = vlclua_get_playlist_internal( L );
97 lua_pushboolean( L, playlist_IsServicesDiscoveryLoaded( p_playlist, psz_sd ));
98 vlclua_release_playlist_internal( p_playlist );
102 /*****************************************************************************
104 *****************************************************************************/
105 static const luaL_Reg vlclua_sd_reg[] = {
106 { "get_services_names", vlclua_sd_get_services_names },
107 { "add", vlclua_sd_add },
108 { "remove", vlclua_sd_remove },
109 { "is_loaded", vlclua_sd_is_loaded },
113 void luaopen_sd( lua_State *L )
116 luaL_register( L, NULL, vlclua_sd_reg );
117 lua_setfield( L, -2, "sd" );