<commit_before>/*****************************************************************************
 * upnp_cc.cpp :  UPnP discovery module
 *****************************************************************************
 * Copyright (C) 2004-2005 the VideoLAN team
 * $Id$
 *
 * Authors: <NAME> <rem # videolan.org>
 *
 * Based on original wxWindows patch for VLC, and dependent on CyberLink
 * UPnP library from :
 *          <NAME> <<EMAIL>>
 *
 * 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.
 *****************************************************************************/

/*****************************************************************************
 * Includes
 *****************************************************************************/

#include <cybergarage/upnp/media/player/MediaPlayer.h>

#undef PACKAGE_NAME
#ifdef HAVE_CONFIG_H
# include "config.h"
#endif

#include <vlc_common.h>
#include <vlc_plugin.h>
#include <vlc_playlist.h>
#include <vlc_services_discovery.h>

/* FIXME: thread-safety ?? */
/* FIXME: playlist locking */

/************************************************************************
 * Macros and definitions
 ************************************************************************/
using namespace std;
using namespace CyberLink;

/*****************************************************************************
 * Module descriptor
 *****************************************************************************/

/* Callbacks */
    static int  Open ( vlc_object_t * );
    static void Close( vlc_object_t * );

VLC_SD_PROBE_HELPER("upnp", "Universal Plug'n'Play", SD_CAT_LAN)

vlc_module_begin ()
    set_shortname( "UPnP")
    set_description( N_("Universal Plug'n'Play") )
    set_category( CAT_PLAYLIST )
    set_subcategory( SUBCAT_PLAYLIST_SD )

    set_capability( "services_discovery", 0 )
    set_callbacks( Open, Close )

    VLC_SD_PROBE_SUBMODULE

vlc_module_end ()

/*****************************************************************************
 * Run: main UPnP thread
 *****************************************************************************
 * Processes UPnP events
 *****************************************************************************/
class UPnPHandler : public MediaPlayer, public DeviceChangeListener,
                    /*public EventListener,*/ public SearchResponseListener
{
    private:
        services_discovery_t *p_sd;

        Device *GetDeviceFromUSN( const string& usn )
        {
            return getDevice( usn.substr( 0, usn.find( "::" ) ).c_str() );
        }

        playlist_item_t *FindDeviceNode( Device *dev )
        {
            return playlist_ChildSearchName( p_sd->p_cat, dev->getFriendlyName() );
        }

        playlist_item_t *FindDeviceNode( const string &usn )
        {
            return FindDeviceNode( GetDeviceFromUSN( usn ) );
        }

        playlist_item_t *AddDevice( Device *dev );
        void AddDeviceContent( Device *dev );
        void AddContent( playlist_item_t *p_parent, ContentNode *node );
        void RemoveDevice( Device *dev );

        /* CyberLink callbacks */
        virtual void deviceAdded( Device *dev );
        virtual void deviceRemoved( Device *dev );

        virtual void deviceSearchResponseReceived( SSDPPacket *packet );
        /*virtual void eventNotifyReceived( const char *uuid, long seq,
                                          const char *name,
                                          const char *value );*/

    public:
        UPnPHandler( services_discovery_t *p_this )
            : p_sd( p_this )
        {
            addDeviceChangeListener( this );
            addSearchResponseListener( this );
            //addEventListener( this );
        }
};

/*****************************************************************************
 * Open: initialize and create stuff
 *****************************************************************************/
static int Open( vlc_object_t *p_this )
{
    services_discovery_t *p_sd = ( services_discovery_t* )p_this;

    UPnPHandler *u = new UPnPHandler( p_sd );
    u->start( );
    msg_Dbg( p_sd, "upnp discovery started" );
    p_sd->p_private = u;

    return VLC_SUCCESS;
}


/*****************************************************************************
 * Close:
 *****************************************************************************/
static void Close( vlc_object_t *p_this )
{
    UPnPHandler *u = (UPnPHandler *)p_this->p_private;
    u->stop( );

    msg_Dbg( p_this, "upnp discovery started" );
}


playlist_item_t *UPnPHandler::AddDevice( Device *dev )
{
    if( dev == NULL )
        return NULL;

    /* We are not interested in IGD devices or whatever (at the moment) */
    if ( !dev->isDeviceType( MediaServer::DEVICE_TYPE ) )
        return NULL;

    playlist_item_t *p_item = FindDeviceNode( dev );
    if ( p_item != NULL )
        return p_item;

    /* FIXME:
     * Maybe one day, VLC API will make sensible use of the const keyword;<commit_msg>Typo (thanks to <NAME>).<commit_after>/*****************************************************************************
 * upnp_cc.cpp :  UPnP discovery module
 *****************************************************************************
 * Copyright (C) 2004-2005 the VideoLAN team
 * $Id$
 *
 * Authors: <NAME> <rem # videolan.org>
 *
 * Based on original wxWindows patch for VLC, and dependent on CyberLink
 * UPnP library from :
 *          <NAME> <<EMAIL>>
 *
 * 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.
 *****************************************************************************/

/*****************************************************************************
 * Includes
 *****************************************************************************/

#include <cybergarage/upnp/media/player/MediaPlayer.h>

#undef PACKAGE_NAME
#ifdef HAVE_CONFIG_H
# include "config.h"
#endif

#include <vlc_common.h>
#include <vlc_plugin.h>
#include <vlc_playlist.h>
#include <vlc_services_discovery.h>

/* FIXME: thread-safety ?? */
/* FIXME: playlist locking */

/************************************************************************
 * Macros and definitions
 ************************************************************************/
using namespace std;
using namespace CyberLink;

/*****************************************************************************
 * Module descriptor
 *****************************************************************************/

/* Callbacks */
    static int  Open ( vlc_object_t * );
    static void Close( vlc_object_t * );

VLC_SD_PROBE_HELPER("upnp", "Universal Plug'n'Play", SD_CAT_LAN)

vlc_module_begin ()
    set_shortname( "UPnP")
    set_description( N_("Universal Plug'n'Play") )
    set_category( CAT_PLAYLIST )
    set_subcategory( SUBCAT_PLAYLIST_SD )

    set_capability( "services_discovery", 0 )
    set_callbacks( Open, Close )

    VLC_SD_PROBE_SUBMODULE

vlc_module_end ()

/*****************************************************************************
 * Run: main UPnP thread
 *****************************************************************************
 * Processes UPnP events
 *****************************************************************************/
class UPnPHandler : public MediaPlayer, public DeviceChangeListener,
                    /*public EventListener,*/ public SearchResponseListener
{
    private:
        services_discovery_t *p_sd;

        Device *GetDeviceFromUSN( const string& usn )
        {
            return getDevice( usn.substr( 0, usn.find( "::" ) ).c_str() );
        }

        playlist_item_t *FindDeviceNode( Device *dev )
        {
            return playlist_ChildSearchName( p_sd->p_cat, dev->getFriendlyName() );
        }

        playlist_item_t *FindDeviceNode( const string &usn )
        {
            return FindDeviceNode( GetDeviceFromUSN( usn ) );
        }

        playlist_item_t *AddDevice( Device *dev );
        void AddDeviceContent( Device *dev );
        void AddContent( playlist_item_t *p_parent, ContentNode *node );
        void RemoveDevice( Device *dev );

        /* CyberLink callbacks */
        virtual void deviceAdded( Device *dev );
        virtual void deviceRemoved( Device *dev );

        virtual void deviceSearchResponseReceived( SSDPPacket *packet );
        /*virtual void eventNotifyReceived( const char *uuid, long seq,
                                          const char *name,
                                          const char *value );*/

    public:
        UPnPHandler( services_discovery_t *p_this )
            : p_sd( p_this )
        {
            addDeviceChangeListener( this );
            addSearchResponseListener( this );
            //addEventListener( this );
        }
};

/*****************************************************************************
 * Open: initialize and create stuff
 *****************************************************************************/
static int Open( vlc_object_t *p_this )
{
    services_discovery_t *p_sd = ( services_discovery_t* )p_this;

    UPnPHandler *u = new UPnPHandler( p_sd );
    u->start( );
    msg_Dbg( p_sd, "upnp discovery started" );
    p_sd->p_private = u;

    return VLC_SUCCESS;
}


/*****************************************************************************
 * Close:
 *****************************************************************************/
static void Close( vlc_object_t *p_this )
{
    UPnPHandler *u = (UPnPHandler *)p_this->p_private;
    u->stop( );

    msg_Dbg( p_this, "upnp discovery stopped" );
}


playlist_item_t *UPnPHandler::AddDevice( Device *dev )
{
    if( dev == NULL )
        return NULL;

    /* We are not interested in IGD devices or whatever (at the moment) */
    if ( !dev->isDeviceType( MediaServer::DEVICE_TYPE ) )
        return NULL;

    playlist_item_t *p_item = FindDeviceNode( dev );
    if ( p_item != NULL )
        return p_item;

    /* FIXME:
     * Maybe one day, VLC API will make sensible use of the const keyword;
{'fraction_non_alphanumeric': 0.2908528501988511, 'fraction_numerical': 0.0038886433937251434, 'mean_word_length': 3.7446540880503143, 'pattern_counts': {'":': 2, '<': 24, '<?xml version=': 0, '>': 38, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 8, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '3297318', 'n_tokens_mistral': 3002, 'n_tokens_neox': 2770, 'n_words': 828}