Commit 7c5348b6 authored by Rémi Duraffort's avatar Rémi Duraffort

sd: remove the pf_search and use a more generic pf_control function.

This way we can implement both a search function and a description function.
parent b131df4e
......@@ -324,7 +324,7 @@ VLC_EXPORT( int, playlist_ServicesDiscoveryRemove, (playlist_t *, const char *))
/** Check whether a given SD is loaded */
VLC_EXPORT( bool, playlist_IsServicesDiscoveryLoaded, ( playlist_t *,const char *));
/** Query a services discovery */
VLC_EXPORT( int, playlist_QueryServicesDiscovery, ( playlist_t *, const char *, const char * ) );
VLC_EXPORT( int, playlist_ServicesDiscoveryControl, ( playlist_t *, const char *, int, ... ) );
......
......@@ -51,11 +51,14 @@ struct services_discovery_t
char *psz_name;
config_chain_t *p_cfg;
int ( *pf_search ) ( services_discovery_t *, const char * );
int ( *pf_control ) ( services_discovery_t *, int, va_list );
services_discovery_sys_t *p_sys;
};
/**
* Service discovery categories
*/
enum services_discovery_category_e
{
SD_CAT_DEVICES = 1,
......@@ -64,6 +67,34 @@ enum services_discovery_category_e
SD_CAT_MYCOMPUTER
};
/**
* Service discovery control commands
*/
enum services_discovery_command_e
{
SD_CMD_SEARCH = 1, /**< arg1 = query */
SD_CMD_CAPABILITIES /**< arg1 = services_discovery_descriptor_t* */
};
/**
* Service discovery capabilities
*/
enum services_discovery_capability_e
{
SD_CAP_SEARCH = 1
};
/**
* Service discovery descriptor
*/
typedef struct
{
char *psz_short_desc;
char *psz_icon_url;
char *psz_url;
int i_capabilities;
} services_discovery_descriptor_t;
/***********************************************************************
* Service Discovery
***********************************************************************/
......@@ -71,13 +102,14 @@ enum services_discovery_category_e
/**
* Ask for a research in the SD
* @param p_sd: the Service Discovery
* @param psz_query: the query
* @param i_control: the command to issue
* @param args: the argument list
* @return VLC_SUCCESS in case of success, the error code overwise
*/
static inline int vlc_sd_search( services_discovery_t *p_sd, const char *psz_query )
static inline int vlc_sd_control( services_discovery_t *p_sd, int i_control, va_list args )
{
if( p_sd->pf_search )
return p_sd->pf_search( p_sd, psz_query );
if( p_sd->pf_control )
return p_sd->pf_control( p_sd, i_control, args );
else
return VLC_EGENERIC;
}
......
......@@ -35,7 +35,7 @@
*****************************************************************************/
static void *Run( void * );
static int DoSearch( services_discovery_t *p_sd, const char *psz_query );
static int Search( services_discovery_t *p_sd, const char *psz_query );
static int Control( services_discovery_t *p_sd, int i_command, va_list args );
static const char * const ppsz_sd_options[] = { "sd", "longname", NULL };
......@@ -88,7 +88,7 @@ int Open_LuaSD( vlc_object_t *p_this )
return VLC_ENOMEM;
}
p_sd->p_sys = p_sys;
p_sd->pf_search = Search;
p_sd->pf_control = Control;
p_sys->psz_filename = vlclua_find_file( p_this, "sd", psz_name );
if( !p_sys->psz_filename )
{
......@@ -243,13 +243,25 @@ static void* Run( void *data )
/*****************************************************************************
* Search: search for items according to the given query
****************************************************************************/
static int Search( services_discovery_t *p_sd, const char *psz_query )
static int Control( services_discovery_t *p_sd, int i_command, va_list args )
{
services_discovery_sys_t *p_sys = p_sd->p_sys;
switch( i_command )
{
case SD_CMD_SEARCH:
{
const char *psz_query = va_arg( args, const char * );
vlc_mutex_lock( &p_sys->lock );
TAB_APPEND( p_sys->i_query, p_sys->ppsz_query, strdup( psz_query ) );
vlc_cond_signal( &p_sys->cond );
vlc_mutex_unlock( &p_sys->lock );
break;
}
case SD_CMD_CAPABILITIES:
return VLC_EGENERIC;
}
return VLC_SUCCESS;
}
......
......@@ -361,9 +361,9 @@ playlist_NodeDelete
playlist_NodeInsert
playlist_NodeRemoveItem
playlist_PreparseEnqueue
playlist_QueryServicesDiscovery
playlist_RecursiveNodeSort
playlist_ServicesDiscoveryAdd
playlist_ServicesDiscoveryControl
playlist_ServicesDiscoveryRemove
playlist_Status
playlist_TreeMove
......
......@@ -440,7 +440,7 @@ bool playlist_IsServicesDiscoveryLoaded( playlist_t * p_playlist,
return found;
}
int playlist_QueryServicesDiscovery( playlist_t *p_playlist, const char *psz_name, const char *psz_query )
int playlist_ServicesDiscoveryControl( playlist_t *p_playlist, const char *psz_name, int i_control, ... )
{
playlist_private_t *priv = pl_priv( p_playlist );
int i_ret = VLC_EGENERIC;
......@@ -452,7 +452,10 @@ int playlist_QueryServicesDiscovery( playlist_t *p_playlist, const char *psz_nam
vlc_sd_internal_t *sd = priv->pp_sds[i];
if( sd->psz_name && !strcmp( psz_name, sd->psz_name ) )
{
i_ret = vlc_sd_search( sd->p_sd, psz_query );
va_list args;
va_start( args, i_control );
i_ret = vlc_sd_control( sd->p_sd, i_control, args );
va_end( args );
break;
}
}
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment