Commit 83a9495b authored by Rafaël Carré's avatar Rafaël Carré

services_discovery: stores the category & onelevel playlist_item_t* in the...

services_discovery: stores the category & onelevel playlist_item_t* in the services_discovery_t structure
simplify upnp* and hal modules
parent 27048ded
...@@ -168,6 +168,10 @@ struct services_discovery_t ...@@ -168,6 +168,10 @@ struct services_discovery_t
char * psz_localized_name; /* Accessed through Setters for non class function */ char * psz_localized_name; /* Accessed through Setters for non class function */
vlc_event_manager_t event_manager; /* 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; services_discovery_sys_t *p_sys;
void (*pf_run) ( services_discovery_t *); void (*pf_run) ( services_discovery_t *);
}; };
......
...@@ -2,7 +2,7 @@ ...@@ -2,7 +2,7 @@
* hal.c : HAL interface module * hal.c : HAL interface module
***************************************************************************** *****************************************************************************
* Copyright (C) 2004 the VideoLAN team * Copyright (C) 2004 the VideoLAN team
* Copyright (C) 2006 Rafaël Carré * Copyright © 2006-2007 Rafaël Carré
* $Id$ * $Id$
* *
* Authors: Clément Stenac <zorglub@videolan.org> * Authors: Clément Stenac <zorglub@videolan.org>
...@@ -48,16 +48,14 @@ ...@@ -48,16 +48,14 @@
/* store relation between item id and udi for ejection */ /* store relation between item id and udi for ejection */
struct udi_input_id_t struct udi_input_id_t
{ {
char *psz_udi; char *psz_udi;
int i_id; input_item_t *p_item;
}; };
#endif #endif
struct services_discovery_sys_t struct services_discovery_sys_t
{ {
LibHalContext *p_ctx; LibHalContext *p_ctx;
playlist_item_t *p_node_cat;
playlist_item_t *p_node_one;
#ifdef HAVE_HAL_1 #ifdef HAVE_HAL_1
DBusConnection *p_connection; DBusConnection *p_connection;
int i_devices_number; int i_devices_number;
...@@ -100,8 +98,6 @@ static int Open( vlc_object_t *p_this ) ...@@ -100,8 +98,6 @@ static int Open( vlc_object_t *p_this )
services_discovery_sys_t *p_sys = malloc( services_discovery_sys_t *p_sys = malloc(
sizeof( services_discovery_sys_t ) ); sizeof( services_discovery_sys_t ) );
playlist_t *p_playlist;
#ifdef HAVE_HAL_1 #ifdef HAVE_HAL_1
DBusError dbus_error; DBusError dbus_error;
DBusConnection *p_connection; DBusConnection *p_connection;
...@@ -160,19 +156,7 @@ static int Open( vlc_object_t *p_this ) ...@@ -160,19 +156,7 @@ static int Open( vlc_object_t *p_this )
} }
#endif #endif
/* Create our playlist node */ services_discovery_SetLocalizedName( p_sd, _("Devices") );
p_playlist = (playlist_t *)vlc_object_find( p_sd, VLC_OBJECT_PLAYLIST,
FIND_ANYWHERE );
if( !p_playlist )
{
msg_Warn( p_sd, "unable to find playlist, cancelling HAL listening");
return VLC_EGENERIC;
}
playlist_NodesPairCreate( p_playlist, _("Devices"),
&p_sys->p_node_cat, &p_sys->p_node_one,
VLC_TRUE );
vlc_object_release( p_playlist );
return VLC_SUCCESS; return VLC_SUCCESS;
} }
...@@ -184,17 +168,8 @@ static void Close( vlc_object_t *p_this ) ...@@ -184,17 +168,8 @@ static void Close( vlc_object_t *p_this )
{ {
services_discovery_t *p_sd = ( services_discovery_t* )p_this; services_discovery_t *p_sd = ( services_discovery_t* )p_this;
services_discovery_sys_t *p_sys = p_sd->p_sys; services_discovery_sys_t *p_sys = p_sd->p_sys;
playlist_t *p_playlist = (playlist_t *) vlc_object_find( p_sd,
VLC_OBJECT_PLAYLIST, FIND_ANYWHERE );
if( p_playlist )
{
playlist_NodeDelete( p_playlist, p_sys->p_node_cat, VLC_TRUE,VLC_TRUE );
playlist_NodeDelete( p_playlist, p_sys->p_node_one, VLC_TRUE,VLC_TRUE );
vlc_object_release( p_playlist );
}
#ifdef HAVE_HAL_1 #ifdef HAVE_HAL_1
dbus_connection_unref( p_sys->p_connection ); dbus_connection_unref( p_sys->p_connection );
struct udi_input_id_t *p_udi_entry; struct udi_input_id_t *p_udi_entry;
while( p_sys->i_devices_number > 0 ) while( p_sys->i_devices_number > 0 )
...@@ -216,25 +191,8 @@ static void AddItem( services_discovery_t *p_sd, input_item_t * p_input ...@@ -216,25 +191,8 @@ static void AddItem( services_discovery_t *p_sd, input_item_t * p_input
#endif #endif
) )
{ {
playlist_item_t *p_item_cat, *p_item_one;
services_discovery_sys_t *p_sys = p_sd->p_sys; services_discovery_sys_t *p_sys = p_sd->p_sys;
playlist_t *p_playlist = (playlist_t *)vlc_object_find( p_sd, services_discovery_AddItem( p_sd, p_input, NULL /* no category */ );
VLC_OBJECT_PLAYLIST, FIND_ANYWHERE );
if( !p_playlist )
{
msg_Err( p_sd, "playlist not found" );
return;
}
p_item_cat = playlist_NodeAddInput( p_playlist,
p_input,p_sd->p_sys->p_node_cat, PLAYLIST_APPEND, PLAYLIST_END,
VLC_FALSE );
p_item_cat->i_flags &= ~PLAYLIST_SKIP_FLAG;
p_item_one = playlist_NodeAddInput( p_playlist,
p_input,p_sd->p_sys->p_node_one, PLAYLIST_APPEND, PLAYLIST_END,
VLC_FALSE );
p_item_one->i_flags &= ~PLAYLIST_SKIP_FLAG;
vlc_object_release( p_playlist );
#ifdef HAVE_HAL_1 #ifdef HAVE_HAL_1
struct udi_input_id_t *p_udi_entry; struct udi_input_id_t *p_udi_entry;
...@@ -243,7 +201,7 @@ static void AddItem( services_discovery_t *p_sd, input_item_t * p_input ...@@ -243,7 +201,7 @@ static void AddItem( services_discovery_t *p_sd, input_item_t * p_input
{ {
return; return;
} }
p_udi_entry->i_id = p_item_cat->i_id; p_udi_entry->p_item = p_input;
p_udi_entry->psz_udi = strdup( psz_device ); p_udi_entry->psz_udi = strdup( psz_device );
TAB_APPEND( p_sys->i_devices_number, p_sys->pp_devices, p_udi_entry ); TAB_APPEND( p_sys->i_devices_number, p_sys->pp_devices, p_udi_entry );
#endif #endif
...@@ -266,7 +224,8 @@ static void AddDvd( services_discovery_t *p_sd, char *psz_device ) ...@@ -266,7 +224,8 @@ static void AddDvd( services_discovery_t *p_sd, char *psz_device )
psz_blockdevice = hal_device_get_property_string( p_sd->p_sys->p_ctx, psz_blockdevice = hal_device_get_property_string( p_sd->p_sys->p_ctx,
psz_device, "block.device" ); psz_device, "block.device" );
#endif #endif
asprintf( &psz_uri, "dvd://%s", psz_blockdevice ); if( asprintf( &psz_uri, "dvd://%s", psz_blockdevice ) == -1 )
return;
/* Create the playlist item here */ /* Create the playlist item here */
p_input = input_ItemNew( p_sd, psz_uri, psz_name ); p_input = input_ItemNew( p_sd, psz_uri, psz_name );
free( psz_uri ); free( psz_uri );
...@@ -285,41 +244,35 @@ static void AddDvd( services_discovery_t *p_sd, char *psz_device ) ...@@ -285,41 +244,35 @@ static void AddDvd( services_discovery_t *p_sd, char *psz_device )
static void DelItem( services_discovery_t *p_sd, char* psz_udi ) static void DelItem( services_discovery_t *p_sd, char* psz_udi )
{ {
services_discovery_sys_t *p_sys = p_sd->p_sys; services_discovery_sys_t *p_sys = p_sd->p_sys;
int i,j;
playlist_item_t *p_pl_item; playlist_item_t *p_pl_item;
playlist_t *p_playlist = (playlist_t *)vlc_object_find( p_sd, playlist_t *p_playlist = pl_Yield( p_sd );
VLC_OBJECT_PLAYLIST, FIND_ANYWHERE );
if( !p_playlist ) if( !p_playlist )
{ {
msg_Err( p_sd, "playlist not found" ); msg_Err( p_sd, "playlist not found" );
return; return;
} }
int i;
for( i = 0; i < p_sys->i_devices_number; i++ ) for( i = 0; i < p_sys->i_devices_number; i++ )
{ /* looks for a matching udi */ { /* looks for a matching udi */
if( strcmp( psz_udi, p_sys->pp_devices[i]->psz_udi ) == 0 ) if( strcmp( psz_udi, p_sys->pp_devices[i]->psz_udi ) == 0 )
{ /* delete the corresponding item */ { /* delete the corresponding item */
p_pl_item = playlist_ItemGetById( p_playlist, p_pl_item = playlist_ItemGetByInputId( p_playlist,
p_sys->pp_devices[i]->i_id, VLC_FALSE ); p_sys->pp_devices[i]->p_item->i_id, p_sd->p_cat );
if( p_pl_item ) if( p_pl_item )
{ {
j = 0;
while( p_pl_item->i_children > 0 ) while( p_pl_item->i_children > 0 )
{ /* delete all childs */ { /* delete all childs */
playlist_DeleteFromInput( p_playlist, playlist_DeleteFromInput( p_playlist,
p_pl_item->pp_children[j]->p_input->i_id, VLC_FALSE ); p_pl_item->pp_children[0]->p_input->i_id, VLC_FALSE );
} }
/* delete parent item */
/* HACK: if i_children == 0 the item won't be deleted /* HACK: if i_children == 0 the item won't be deleted
* That means that it _had_ children but they were deleted */ * That means that it _had_ children but they were deleted */
if( p_pl_item->i_children == 0 ) if( p_pl_item->i_children == 0 )
p_pl_item->i_children = -1; p_pl_item->i_children = -1;
playlist_DeleteFromInput( p_playlist,
p_pl_item->p_input->i_id, VLC_FALSE );
} }
services_discovery_RemoveItem( p_sd, p_sys->pp_devices[i]->p_item );
if( p_sys->pp_devices[i]->psz_udi ) if( p_sys->pp_devices[i]->psz_udi )
free( p_sys->pp_devices[i]->psz_udi ); free( p_sys->pp_devices[i]->psz_udi );
...@@ -328,7 +281,7 @@ static void DelItem( services_discovery_t *p_sd, char* psz_udi ) ...@@ -328,7 +281,7 @@ static void DelItem( services_discovery_t *p_sd, char* psz_udi )
} }
} }
vlc_object_release( p_playlist ); pl_Release( p_playlist );
} }
#endif #endif
...@@ -344,7 +297,8 @@ static void AddCdda( services_discovery_t *p_sd, char *psz_device ) ...@@ -344,7 +297,8 @@ static void AddCdda( services_discovery_t *p_sd, char *psz_device )
psz_blockdevice = hal_device_get_property_string( p_sd->p_sys->p_ctx, psz_blockdevice = hal_device_get_property_string( p_sd->p_sys->p_ctx,
psz_device, "block.device" ); psz_device, "block.device" );
#endif #endif
asprintf( &psz_uri, "cdda://%s", psz_blockdevice ); if( asprintf( &psz_uri, "cdda://%s", psz_blockdevice ) == -1 )
return;
/* Create the playlist item here */ /* Create the playlist item here */
p_input = input_ItemNew( p_sd, psz_uri, "Audio CD" ); p_input = input_ItemNew( p_sd, psz_uri, "Audio CD" );
free( psz_uri ); free( psz_uri );
......
...@@ -63,17 +63,6 @@ vlc_module_begin(); ...@@ -63,17 +63,6 @@ vlc_module_begin();
vlc_module_end(); vlc_module_end();
/*****************************************************************************
* Local structures
*****************************************************************************/
struct services_discovery_sys_t
{
playlist_item_t *p_node_one;
playlist_item_t *p_node_cat;
};
/***************************************************************************** /*****************************************************************************
* Local prototypes * Local prototypes
*****************************************************************************/ *****************************************************************************/
...@@ -87,15 +76,11 @@ struct services_discovery_sys_t ...@@ -87,15 +76,11 @@ struct services_discovery_sys_t
static int Open( vlc_object_t *p_this ) static int Open( vlc_object_t *p_this )
{ {
services_discovery_t *p_sd = ( services_discovery_t* )p_this; services_discovery_t *p_sd = ( services_discovery_t* )p_this;
services_discovery_sys_t *p_sys = (services_discovery_sys_t *)
malloc( sizeof( services_discovery_sys_t ) );
p_sd->pf_run = Run; p_sd->pf_run = Run;
p_sd->p_sys = p_sys;
playlist_NodesPairCreate( pl_Get( p_sd ), _("Devices"), services_discovery_SetLocalizedName( p_sd, _("Devices") );
&p_sys->p_node_cat, &p_sys->p_node_one,
VLC_TRUE );
return VLC_SUCCESS; return VLC_SUCCESS;
} }
...@@ -105,15 +90,6 @@ static int Open( vlc_object_t *p_this ) ...@@ -105,15 +90,6 @@ static int Open( vlc_object_t *p_this )
*****************************************************************************/ *****************************************************************************/
static void Close( vlc_object_t *p_this ) static void Close( vlc_object_t *p_this )
{ {
services_discovery_t *p_sd = ( services_discovery_t* )p_this;
services_discovery_sys_t *p_sys = p_sd->p_sys;
playlist_t *p_playlist = pl_Yield( p_sd );
playlist_NodeDelete( p_playlist, p_sys->p_node_one, VLC_TRUE,
VLC_TRUE );
playlist_NodeDelete( p_playlist, p_sys->p_node_cat, VLC_TRUE,
VLC_TRUE );
pl_Release();
free( p_sys );
} }
/***************************************************************************** /*****************************************************************************
...@@ -126,7 +102,6 @@ class UPnPHandler : public MediaPlayer, public DeviceChangeListener, ...@@ -126,7 +102,6 @@ class UPnPHandler : public MediaPlayer, public DeviceChangeListener,
{ {
private: private:
services_discovery_t *p_sd; services_discovery_t *p_sd;
services_discovery_sys_t *p_sys;
Device *GetDeviceFromUSN( const string& usn ) Device *GetDeviceFromUSN( const string& usn )
{ {
...@@ -135,7 +110,7 @@ class UPnPHandler : public MediaPlayer, public DeviceChangeListener, ...@@ -135,7 +110,7 @@ class UPnPHandler : public MediaPlayer, public DeviceChangeListener,
playlist_item_t *FindDeviceNode( Device *dev ) playlist_item_t *FindDeviceNode( Device *dev )
{ {
return playlist_ChildSearchName( p_sys->p_node, dev->getFriendlyName() ); return playlist_ChildSearchName( p_sd->p_cat, dev->getFriendlyName() );
} }
playlist_item_t *FindDeviceNode( const string &usn ) playlist_item_t *FindDeviceNode( const string &usn )
...@@ -159,7 +134,7 @@ class UPnPHandler : public MediaPlayer, public DeviceChangeListener, ...@@ -159,7 +134,7 @@ class UPnPHandler : public MediaPlayer, public DeviceChangeListener,
public: public:
UPnPHandler( services_discovery_t *p_this ) UPnPHandler( services_discovery_t *p_this )
: p_sd( p_this ), p_sys( p_this->p_sys ) : p_sd( p_this )
{ {
addDeviceChangeListener( this ); addDeviceChangeListener( this );
addSearchResponseListener( this ); addSearchResponseListener( this );
...@@ -205,7 +180,7 @@ playlist_item_t *UPnPHandler::AddDevice( Device *dev ) ...@@ -205,7 +180,7 @@ playlist_item_t *UPnPHandler::AddDevice( Device *dev )
*/ */
char *str = strdup( dev->getFriendlyName( ) ); char *str = strdup( dev->getFriendlyName( ) );
p_item = playlist_NodeCreate( p_sys->p_playlist, str, p_sys->p_node_cat,0 ); p_item = playlist_NodeCreate( p_playlist, str, p_sd->p_cat,0 );
p_item->i_flags &= ~PLAYLIST_SKIP_FLAG; p_item->i_flags &= ~PLAYLIST_SKIP_FLAG;
msg_Dbg( p_sd, "device %s added", str ); msg_Dbg( p_sd, "device %s added", str );
free( str ); free( str );
...@@ -238,7 +213,7 @@ void UPnPHandler::AddContent( playlist_item_t *p_parent, ContentNode *node ) ...@@ -238,7 +213,7 @@ void UPnPHandler::AddContent( playlist_item_t *p_parent, ContentNode *node )
{ {
ItemNode *iNode = (ItemNode *)node; ItemNode *iNode = (ItemNode *)node;
input_item_t *p_input = input_ItemNew( p_sd, iNode->getResource(), title ); input_item_t *p_input = input_ItemNew( p_sd, iNode->getResource(), title );
playlist_BothAddInput( p_sys->p_playlist, p_input, p_parent, playlist_BothAddInput( p_playlist, p_input, p_parent,
PLAYLIST_APPEND, PLAYLIST_END, NULL, NULL, PLAYLIST_APPEND, PLAYLIST_END, NULL, NULL,
VLC_FALSE ); VLC_FALSE );
} else if ( node->isContainerNode() ) } else if ( node->isContainerNode() )
...@@ -246,7 +221,7 @@ void UPnPHandler::AddContent( playlist_item_t *p_parent, ContentNode *node ) ...@@ -246,7 +221,7 @@ void UPnPHandler::AddContent( playlist_item_t *p_parent, ContentNode *node )
ContainerNode *conNode = (ContainerNode *)node; ContainerNode *conNode = (ContainerNode *)node;
char* p_name = strdup(title); /* See other comment on strdup */ char* p_name = strdup(title); /* See other comment on strdup */
playlist_item_t* p_node = playlist_NodeCreate( p_sys->p_playlist, playlist_item_t* p_node = playlist_NodeCreate( p_playlist,
p_name, p_parent, 0 ); p_name, p_parent, 0 );
free(p_name); free(p_name);
...@@ -263,7 +238,7 @@ void UPnPHandler::RemoveDevice( Device *dev ) ...@@ -263,7 +238,7 @@ void UPnPHandler::RemoveDevice( Device *dev )
playlist_item_t *p_item = FindDeviceNode( dev ); playlist_item_t *p_item = FindDeviceNode( dev );
if( p_item != NULL ) if( p_item != NULL )
playlist_NodeDelete( p_sys->p_playlist, p_item, VLC_TRUE, VLC_TRUE ); playlist_NodeDelete( p_playlist, p_item, VLC_TRUE, VLC_TRUE );
} }
......
...@@ -42,15 +42,6 @@ ...@@ -42,15 +42,6 @@
#include "vlc_strings.h" #include "vlc_strings.h"
// VLC handle
struct services_discovery_sys_t
{
playlist_item_t *p_node_cat;
playlist_item_t *p_node_one;
};
// Constants // Constants
const char* MEDIA_SERVER_DEVICE_TYPE = "urn:schemas-upnp-org:device:MediaServer:1"; const char* MEDIA_SERVER_DEVICE_TYPE = "urn:schemas-upnp-org:device:MediaServer:1";
...@@ -277,31 +268,16 @@ IXML_Document* parseBrowseResult( IXML_Document* doc ); ...@@ -277,31 +268,16 @@ IXML_Document* parseBrowseResult( IXML_Document* doc );
static int Open( vlc_object_t *p_this ) static int Open( vlc_object_t *p_this )
{ {
services_discovery_t *p_sd = ( services_discovery_t* )p_this; services_discovery_t *p_sd = ( services_discovery_t* )p_this;
services_discovery_sys_t *p_sys = ( services_discovery_sys_t * )
malloc( sizeof( services_discovery_sys_t ) );
p_sd->pf_run = Run; p_sd->pf_run = Run;
p_sd->p_sys = p_sys;
/* Create our playlist node */ /* Create our playlist node */
playlist_NodesPairCreate( pl_Get( p_sd ), _("Devices"), services_discovery_SetLocalizedName( p_sd, _("Devices") );
&p_sys->p_node_cat, &p_sys->p_node_one,
VLC_TRUE );
return VLC_SUCCESS; return VLC_SUCCESS;
} }
static void Close( vlc_object_t *p_this ) static void Close( vlc_object_t *p_this )
{ {
services_discovery_t *p_sd = ( services_discovery_t* )p_this;
services_discovery_sys_t *p_sys = p_sd->p_sys;
playlist_NodeDelete( pl_Get( p_sd ), p_sys->p_node_one, VLC_TRUE,
VLC_TRUE );
playlist_NodeDelete( pl_Get( p_sd ), p_sys->p_node_cat, VLC_TRUE,
VLC_TRUE );
free( p_sys );
} }
static void Run( services_discovery_t* p_sd ) static void Run( services_discovery_t* p_sd )
...@@ -916,7 +892,7 @@ bool MediaServerList::addServer( MediaServer* s ) ...@@ -916,7 +892,7 @@ bool MediaServerList::addServer( MediaServer* s )
char* name = strdup( s->getFriendlyName() ); char* name = strdup( s->getFriendlyName() );
playlist_item_t* node = playlist_NodeCreate( pl_Get( _cookie->serviceDiscovery ), playlist_item_t* node = playlist_NodeCreate( pl_Get( _cookie->serviceDiscovery ),
name, name,
_cookie->serviceDiscovery->p_sys->p_node_cat, 0 ); _cookie->serviceDiscovery->p_cat, 0 );
free( name ); free( name );
s->setPlaylistNode( node ); s->setPlaylistNode( node );
......
...@@ -278,6 +278,8 @@ int playlist_ServicesDiscoveryAdd( playlist_t *p_playlist, const char *psz_modu ...@@ -278,6 +278,8 @@ int playlist_ServicesDiscoveryAdd( playlist_t *p_playlist, const char *psz_modu
p_one = p_playlist->p_root_onelevel; p_one = p_playlist->p_root_onelevel;
PL_UNLOCK; PL_UNLOCK;
} }
p_sd->p_cat = p_cat;
p_sd->p_one = p_one;
vlc_event_attach( services_discovery_EventManager( p_sd ), vlc_event_attach( services_discovery_EventManager( p_sd ),
vlc_ServicesDiscoveryItemAdded, vlc_ServicesDiscoveryItemAdded,
......
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