Commit 222960cf authored by Pierre d'Herbemont's avatar Pierre d'Herbemont

playlist/services_discovery.c: Isolate more the services_discovery code from...

playlist/services_discovery.c: Isolate more the services_discovery code from the playlist code by having two separate header. Partly revert [22536].
parent 393b8a06
......@@ -35,6 +35,7 @@ extern "C" {
#include <assert.h>
#include <vlc_input.h>
#include <vlc_events.h>
#include <vlc_services_discovery.h>
#include <stdio.h>
#include <stdlib.h>
......@@ -158,32 +159,18 @@ struct playlist_item_t
typedef enum
{ PLAYLIST_STOPPED,PLAYLIST_RUNNING,PLAYLIST_PAUSED } playlist_status_t;
struct services_discovery_t
{
VLC_COMMON_MEMBERS
char * psz_module;
module_t * p_module;
char * psz_localized_name; /* Accessed through Setters for non class function */
vlc_event_manager_t event_manager; /* Accessed through Setters for non class function */
/* the playlist items for category and onelevel */
playlist_item_t* p_cat;
playlist_item_t* p_one;
services_discovery_sys_t *p_sys;
void (*pf_run) ( services_discovery_t *);
};
/** Structure containing information about the playlist */
struct playlist_t
{
VLC_COMMON_MEMBERS
/* pp_sd & i_sd are for internal use ONLY. Understood ? it's PRIVATE ! */
services_discovery_t **pp_sd; /**< Loaded service discovery modules */
int i_sd; /**< Number of service discovery modules */
struct playlist_services_discovery_support_t {
/* the playlist items for category and onelevel */
playlist_item_t* p_cat;
playlist_item_t* p_one;
services_discovery_t * p_sd; /**< Loaded service discovery modules */
} ** pp_sds;
int i_sds; /**< Number of service discovery modules */
int i_enabled; /**< How many items are enabled ? */
......@@ -417,33 +404,6 @@ VLC_EXPORT( playlist_item_t *, playlist_GetNextLeaf, ( playlist_t *p_playlist, p
VLC_EXPORT( playlist_item_t *, playlist_GetPrevLeaf, ( playlist_t *p_playlist, playlist_item_t *p_root, playlist_item_t *p_item, vlc_bool_t b_ena, vlc_bool_t b_unplayed ) );
VLC_EXPORT( playlist_item_t *, playlist_GetLastLeaf, ( playlist_t *p_playlist, playlist_item_t *p_root ) );
/***********************************************************************
* Service Discovery
***********************************************************************/
/* Get the services discovery modules names to use in Create(), in a null
* terminated string array. Array and string must be freed after use. */
VLC_EXPORT( char **, services_discovery_GetServicesNames, ( vlc_object_t * p_super ) );
/* Creation of a service_discovery object */
VLC_EXPORT( services_discovery_t *, services_discovery_Create, ( vlc_object_t * p_super, const char * psz_service_name ) );
VLC_EXPORT( void, services_discovery_Destroy, ( services_discovery_t * p_this ) );
VLC_EXPORT( int, services_discovery_Start, ( services_discovery_t * p_this ) );
VLC_EXPORT( void, services_discovery_Stop, ( services_discovery_t * p_this ) );
/* Read info from discovery object */
VLC_EXPORT( char *, services_discovery_GetLocalizedName, ( services_discovery_t * p_this ) );
/* Receive event notification (prefered way to get new items) */
VLC_EXPORT( vlc_event_manager_t *, services_discovery_EventManager, ( services_discovery_t * p_this ) );
/* Used by services_discovery to post update about their items */
VLC_EXPORT( void, services_discovery_SetLocalizedName, ( services_discovery_t * p_this, const char * ) );
/* About the psz_category, it is a legacy way to add info to the item,
* for more options, directly set the (meta) data on the input item */
VLC_EXPORT( void, services_discovery_AddItem, ( services_discovery_t * p_this, input_item_t * p_item, const char * psz_category ) );
VLC_EXPORT( void, services_discovery_RemoveItem, ( services_discovery_t * p_this, input_item_t * p_item ) );
/***********************************************************************
* Inline functions
***********************************************************************/
......
/*****************************************************************************
* vlc_services_discovery.h : Services Discover functions
*****************************************************************************
* Copyright (C) 1999-2004 the VideoLAN team
* $Id$
*
* Authors: Pierre d'Herbemont <pdherbemont # videolan.org>
*
* This program is free software; you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
* the Free Software Foundation; either version 2 of the License, or
* (at your option) any later version.
*
* This program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details.
*
* You should have received a copy of the GNU General Public License
* along with this program; if not, write to the Free Software
* Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston MA 02110-1301, USA.
*****************************************************************************/
#if !defined( __LIBVLC__ )
#error You are not libvlc or one of its plugins. You cannot include this file
#endif
#ifndef _VLC_SERVICES_DISCOVERY_H_
#define _VLC_SERVICES_DISCOVERY_H_
# ifdef __cplusplus
extern "C" {
# endif
/*
* @{
*/
#include <assert.h>
#include <vlc_input.h>
#include <vlc_events.h>
#include <stdio.h>
#include <stdlib.h>
struct services_discovery_t
{
VLC_COMMON_MEMBERS
char * psz_module;
module_t * p_module;
char * psz_localized_name; /* Accessed through Setters for non class function */
vlc_event_manager_t event_manager; /* Accessed through Setters for non class function */
services_discovery_sys_t *p_sys;
void (*pf_run) ( services_discovery_t *);
};
/***********************************************************************
* Service Discovery
***********************************************************************/
/* Get the services discovery modules names to use in Create(), in a null
* terminated string array. Array and string must be freed after use. */
VLC_EXPORT( char **, services_discovery_GetServicesNames, ( vlc_object_t * p_super ) );
/* Creation of a service_discovery object */
VLC_EXPORT( services_discovery_t *, services_discovery_Create, ( vlc_object_t * p_super, const char * psz_service_name ) );
VLC_EXPORT( void, services_discovery_Destroy, ( services_discovery_t * p_this ) );
VLC_EXPORT( int, services_discovery_Start, ( services_discovery_t * p_this ) );
VLC_EXPORT( void, services_discovery_Stop, ( services_discovery_t * p_this ) );
/* Read info from discovery object */
VLC_EXPORT( char *, services_discovery_GetLocalizedName, ( services_discovery_t * p_this ) );
/* Receive event notification (prefered way to get new items) */
VLC_EXPORT( vlc_event_manager_t *, services_discovery_EventManager, ( services_discovery_t * p_this ) );
/* Used by services_discovery to post update about their items */
VLC_EXPORT( void, services_discovery_SetLocalizedName, ( services_discovery_t * p_this, const char * ) );
/* About the psz_category, it is a legacy way to add info to the item,
* for more options, directly set the (meta) data on the input item */
VLC_EXPORT( void, services_discovery_AddItem, ( services_discovery_t * p_this, input_item_t * p_item, const char * psz_category ) );
VLC_EXPORT( void, services_discovery_RemoveItem, ( services_discovery_t * p_this, input_item_t * p_item ) );
/** @} */
# ifdef __cplusplus
}
# endif
#endif
......@@ -66,7 +66,7 @@ playlist_t * playlist_Create( vlc_object_t *p_parent )
return NULL;
}
TAB_INIT( p_playlist->i_sd, p_playlist->pp_sd );
TAB_INIT( p_playlist->i_sds, p_playlist->pp_sds );
p_parent->p_libvlc->p_playlist = p_playlist;
......@@ -437,10 +437,10 @@ void playlist_LastLoop( playlist_t *p_playlist )
vout_Destroy( (vout_thread_t *)p_obj );
}
while( p_playlist->i_sd )
while( p_playlist->i_sds )
{
playlist_ServicesDiscoveryRemove( p_playlist,
p_playlist->pp_sd[0]->psz_module );
p_playlist->pp_sds[0]->p_sd->psz_module );
}
playlist_MLDump( p_playlist );
......
......@@ -252,6 +252,7 @@ int playlist_ServicesDiscoveryAdd( playlist_t *p_playlist, const char *psz_modu
for (;;)
{
struct playlist_services_discovery_support_t * p_sds;
playlist_item_t * p_cat;
playlist_item_t * p_one;
......@@ -293,8 +294,6 @@ int playlist_ServicesDiscoveryAdd( playlist_t *p_playlist, const char *psz_modu
p_one = p_playlist->p_root_onelevel;
PL_UNLOCK;
}
p_sd->p_cat = p_cat;
p_sd->p_one = p_one;
vlc_event_attach( services_discovery_EventManager( p_sd ),
vlc_ServicesDiscoveryItemAdded,
......@@ -318,8 +317,19 @@ int playlist_ServicesDiscoveryAdd( playlist_t *p_playlist, const char *psz_modu
services_discovery_Start( p_sd );
/* Free in playlist_ServicesDiscoveryRemove */
p_sds = malloc( sizeof(struct playlist_services_discovery_support_t) );
if( !p_sds )
{
msg_Err( p_playlist, "No more memory" );
return VLC_ENOMEM;
}
p_sds->p_sd = p_sd;
p_sds->p_one = p_one;
p_sds->p_cat = p_cat;
PL_LOCK;
TAB_APPEND( p_playlist->i_sd, p_playlist->pp_sd, p_sd );
TAB_APPEND( p_playlist->i_sds, p_playlist->pp_sds, p_sds );
PL_UNLOCK;
}
......@@ -329,60 +339,60 @@ int playlist_ServicesDiscoveryAdd( playlist_t *p_playlist, const char *psz_modu
int playlist_ServicesDiscoveryRemove( playlist_t * p_playlist,
const char *psz_module )
{
struct playlist_services_discovery_support_t * p_sds = NULL;
int i;
struct services_discovery_t *p_sd = NULL;
PL_LOCK;
for( i = 0 ; i< p_playlist->i_sd ; i ++ )
for( i = 0 ; i< p_playlist->i_sds ; i ++ )
{
if( !strcmp( psz_module, p_playlist->pp_sd[i]->psz_module ) )
if( !strcmp( psz_module, p_playlist->pp_sds[i]->p_sd->psz_module ) )
{
p_sd = p_playlist->pp_sd[i];
REMOVE_ELEM( p_playlist->pp_sd, p_playlist->i_sd, i );
p_sds = p_playlist->pp_sds[i];
REMOVE_ELEM( p_playlist->pp_sds, p_playlist->i_sds, i );
break;
}
}
PL_UNLOCK;
if( p_sd == NULL )
if( !p_sds || !p_sds->p_sd )
{
msg_Warn( p_playlist, "module %s is not loaded", psz_module );
return VLC_EGENERIC;
}
services_discovery_Stop( p_sd );
services_discovery_Stop( p_sds->p_sd );
vlc_event_detach( services_discovery_EventManager( p_sd ),
vlc_event_detach( services_discovery_EventManager( p_sds->p_sd ),
vlc_ServicesDiscoveryItemAdded,
playlist_sd_item_added,
p_sd->p_one );
p_sds->p_one );
vlc_event_detach( services_discovery_EventManager( p_sd ),
vlc_event_detach( services_discovery_EventManager( p_sds->p_sd ),
vlc_ServicesDiscoveryItemAdded,
playlist_sd_item_added,
p_sd->p_cat );
p_sds->p_cat );
vlc_event_detach( services_discovery_EventManager( p_sd ),
vlc_event_detach( services_discovery_EventManager( p_sds->p_sd ),
vlc_ServicesDiscoveryItemRemoved,
playlist_sd_item_removed,
p_sd->p_one );
p_sds->p_one );
vlc_event_detach( services_discovery_EventManager( p_sd ),
vlc_event_detach( services_discovery_EventManager( p_sds->p_sd ),
vlc_ServicesDiscoveryItemRemoved,
playlist_sd_item_removed,
p_sd->p_cat );
p_sds->p_cat );
/* Remove the sd playlist node if it exists */
PL_LOCK;
if( p_sd->p_cat != p_playlist->p_root_category &&
p_sd->p_one != p_playlist->p_root_onelevel )
if( p_sds->p_cat != p_playlist->p_root_category &&
p_sds->p_one != p_playlist->p_root_onelevel )
{
playlist_NodeDelete( p_playlist, p_sd->p_cat, VLC_TRUE, VLC_FALSE );
playlist_NodeDelete( p_playlist, p_sd->p_one, VLC_TRUE, VLC_FALSE );
playlist_NodeDelete( p_playlist, p_sds->p_cat, VLC_TRUE, VLC_FALSE );
playlist_NodeDelete( p_playlist, p_sds->p_one, VLC_TRUE, VLC_FALSE );
}
PL_UNLOCK;
services_discovery_Destroy( p_sd );
services_discovery_Destroy( p_sds->p_sd );
return VLC_SUCCESS;
}
......@@ -393,9 +403,9 @@ vlc_bool_t playlist_IsServicesDiscoveryLoaded( playlist_t * p_playlist,
int i;
PL_LOCK;
for( i = 0 ; i< p_playlist->i_sd ; i ++ )
for( i = 0 ; i< p_playlist->i_sds ; i ++ )
{
if( !strcmp( psz_module, p_playlist->pp_sd[i]->psz_module ) )
if( !strcmp( psz_module, p_playlist->pp_sds[i]->p_sd->psz_module ) )
{
PL_UNLOCK;
return VLC_TRUE;
......
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