playlist_CreateNode(): add an argument to specify an input_item_t to be linked with...
[vlc.git] / modules / services_discovery / upnp_cc.cpp
index d2817ea..cd6e7fd 100644 (file)
@@ -5,7 +5,7 @@
  * $Id$
  *
  * Authors: RĂ©mi Denis-Courmont <rem # videolan.org>
- * 
+ *
  * Based on original wxWindows patch for VLC, and dependant on CyberLink
  * UPnP library from :
  *          Satoshi Konno <skonno@cybergarage.org>
 /*****************************************************************************
  * Includes
  *****************************************************************************/
-#include <stdlib.h>                                      /* malloc(), free() */
 
 #include <cybergarage/upnp/media/player/MediaPlayer.h>
 
 #undef PACKAGE_NAME
 #include <vlc/vlc.h>
-#include <vlc/intf.h>
+#include <vlc_playlist.h>
 
 /* FIXME: thread-safety ?? */
 /* FIXME: playlist locking */
@@ -64,19 +63,6 @@ vlc_module_begin();
 
 vlc_module_end();
 
-
-/*****************************************************************************
- * Local structures
- *****************************************************************************/
-
-struct services_discovery_sys_t
-{
-    /* playlist node */
-    playlist_item_t *p_node;
-    playlist_item_t *p_node_cat;
-    playlist_t *p_playlist;
-};
-
 /*****************************************************************************
  * Local prototypes
  *****************************************************************************/
@@ -90,25 +76,11 @@ struct services_discovery_sys_t
 static int Open( vlc_object_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->p_sys  = p_sys;
 
-    /* Create our playlist node */
-    p_sys->p_playlist = (playlist_t *)vlc_object_find( p_sd,
-                                                       VLC_OBJECT_PLAYLIST,
-                                                       FIND_ANYWHERE );
-    if( !p_sys->p_playlist )
-    {
-        msg_Warn( p_sd, "unable to find playlist, cancelling UPnP listening");
-        return VLC_EGENERIC;
-    }
+    services_discovery_SetLocalizedName( p_sd, _("Devices") );
 
-    playlist_NodesPairCreate( p_sys->p_playlist, _("Devices"),
-                              &p_sys->p_node_cat, &p_sys->p_node,
-                              VLC_TRUE );
     return VLC_SUCCESS;
 }
 
@@ -118,19 +90,6 @@ static int Open( 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;
-
-    if( p_sys->p_playlist )
-    {
-        playlist_NodeDelete( p_sys->p_playlist, p_sys->p_node, VLC_TRUE,
-                             VLC_TRUE );
-        playlist_NodeDelete( p_sys->p_playlist, p_sys->p_node_cat, VLC_TRUE,
-                             VLC_TRUE );
-        vlc_object_release( p_sys->p_playlist );
-    }
-
-    free( p_sys );
 }
 
 /*****************************************************************************
@@ -143,7 +102,6 @@ class UPnPHandler : public MediaPlayer, public DeviceChangeListener,
 {
     private:
         services_discovery_t *p_sd;
-        services_discovery_sys_t *p_sys;
 
         Device *GetDeviceFromUSN( const string& usn )
         {
@@ -152,7 +110,7 @@ class UPnPHandler : public MediaPlayer, public DeviceChangeListener,
 
         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 )
@@ -176,7 +134,7 @@ class UPnPHandler : public MediaPlayer, public DeviceChangeListener,
 
     public:
         UPnPHandler( services_discovery_t *p_this )
-            : p_sd( p_this ), p_sys( p_this->p_sys )
+            : p_sd( p_this )
         {
             addDeviceChangeListener( this );
             addSearchResponseListener( this );
@@ -222,7 +180,7 @@ playlist_item_t *UPnPHandler::AddDevice( Device *dev )
      */
     char *str = strdup( dev->getFriendlyName( ) );
 
-    p_item = playlist_NodeCreate( p_sys->p_playlist, str, p_sys->p_node );
+    p_item = playlist_NodeCreate( p_playlist, str, p_sd->p_cat, 0, NULL );
     p_item->i_flags &= ~PLAYLIST_SKIP_FLAG;
     msg_Dbg( p_sd, "device %s added", str );
     free( str );
@@ -251,29 +209,26 @@ void UPnPHandler::AddContent( playlist_item_t *p_parent, ContentNode *node )
 
     msg_Dbg( p_sd, "title = %s", title );
 
-    if ( node->isItemNode() ) 
+    if ( node->isItemNode() )
     {
         ItemNode *iNode = (ItemNode *)node;
-
-       playlist_item_t *p_item;
-       p_item = playlist_ItemNew( p_sd, iNode->getResource(), title );
-    
-       playlist_NodeAddItem( p_sys->p_playlist, p_item,
-                             p_parent, PLAYLIST_APPEND, PLAYLIST_END );
-
-    } else if ( node->isContainerNode() ) 
+        input_item_t *p_input = input_ItemNew( p_sd, iNode->getResource(), title );
+        playlist_BothAddInput( p_playlist, p_input, p_parent,
+                               PLAYLIST_APPEND, PLAYLIST_END, NULL, NULL,
+                               VLC_FALSE );
+    } else if ( node->isContainerNode() )
     {
         ContainerNode *conNode = (ContainerNode *)node;
 
-       char* p_name = strdup(title); /* See other comment on strdup */
-       playlist_item_t* p_node = playlist_NodeCreate( p_sys->p_playlist,
-                                                      p_name, p_parent );
-       free(p_name);
+        char* p_name = strdup(title); /* See other comment on strdup */
+        playlist_item_t* p_node = playlist_NodeCreate( p_playlist, p_name,
+                                                       p_parent, 0, NULL );
+        free(p_name);
 
-       unsigned nContentNodes = conNode->getNContentNodes();
+        unsigned nContentNodes = conNode->getNContentNodes();
 
-       for( unsigned n = 0; n < nContentNodes; n++ )
-           AddContent( p_node, conNode->getContentNode( n ) );
+        for( unsigned n = 0; n < nContentNodes; n++ )
+           AddContent( p_node, conNode->getContentNode( n ) );
     }
 }
 
@@ -283,7 +238,7 @@ void UPnPHandler::RemoveDevice( Device *dev )
     playlist_item_t *p_item = FindDeviceNode( dev );
 
     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 );
 }