From: Pierre d'Herbemont Date: Thu, 11 Oct 2007 01:02:50 +0000 (+0000) Subject: playlist/services_discovery.c: Isolate more the services_discovery code from the... X-Git-Tag: 0.9.0-test0~5099 X-Git-Url: https://git.sesse.net/?a=commitdiff_plain;h=222960cff9c3968b0c6b8c073bfa08182e3cc78a;p=vlc playlist/services_discovery.c: Isolate more the services_discovery code from the playlist code by having two separate header. Partly revert [22536]. --- diff --git a/include/vlc_playlist.h b/include/vlc_playlist.h index 869c1007cb..989947171a 100644 --- a/include/vlc_playlist.h +++ b/include/vlc_playlist.h @@ -35,6 +35,7 @@ extern "C" { #include #include #include +#include #include #include @@ -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 ***********************************************************************/ diff --git a/include/vlc_services_discovery.h b/include/vlc_services_discovery.h new file mode 100644 index 0000000000..1b0cde073d --- /dev/null +++ b/include/vlc_services_discovery.h @@ -0,0 +1,91 @@ +/***************************************************************************** + * vlc_services_discovery.h : Services Discover functions + ***************************************************************************** + * Copyright (C) 1999-2004 the VideoLAN team + * $Id$ + * + * Authors: Pierre d'Herbemont + * + * 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 +#include +#include +#include +#include + +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 diff --git a/src/playlist/engine.c b/src/playlist/engine.c index 7cd1bff6f6..04d82b80c4 100644 --- a/src/playlist/engine.c +++ b/src/playlist/engine.c @@ -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 ); diff --git a/src/playlist/services_discovery.c b/src/playlist/services_discovery.c index 88d1e5af79..6e55b91c86 100644 --- a/src/playlist/services_discovery.c +++ b/src/playlist/services_discovery.c @@ -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;