<commit_before>/*****************************************************************************
 * upnp.hpp :  UPnP discovery module (libupnp) header
 *****************************************************************************
 * Copyright (C) 2004-2010 the VideoLAN team
 * $Id$
 *
 * Authors: <NAME> <rem # videolan.org> (original plugin)
 *          <NAME> <henz # c-lab.de>
 *          <NAME> <mirsal dot ennaime at gmail dot com>
 *          <NAME> <<EMAIL>>
 *
 * UPnP Plugin using the Intel SDK (libupnp) instead of CyberLink
 *
 * 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.
 *****************************************************************************/

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

#include <vector>
#include <string>

#include <upnp/upnp.h>
#include <upnp/upnptools.h>

#include <vlc_common.h>
#include <vlc_url.h>

namespace SD
{
    class MediaServerList;
}

/*
 * libUpnp allows only one instance per process, so we have to share one for
 * both SD & Access module
 * Since the callback is bound to the UpnpClient_Handle, we have to register
 * a wrapper callback, in order for the access module to be able to initialize
 * libUpnp first.
 * When a SD wishes to use libUpnp, it will provide its own callback, that the
 * wrapper will forward.
 * This way, we always have a register callback & a client handle.
 */
class UpnpInstanceWrapper
{
public:
    // This increases the refcount before returning the instance
    static UpnpInstanceWrapper* get(vlc_object_t* p_obj, Upnp_FunPtr callback, SD::MediaServerList *opaque);
    void release(bool isSd);
    UpnpClient_Handle handle() const;

private:
    static int Callback( Upnp_EventType event_type, void* p_event, void* p_user_data );

    UpnpInstanceWrapper();
    ~UpnpInstanceWrapper();

private:
    static UpnpInstanceWrapper* s_instance;
    static vlc_mutex_t s_lock;
    UpnpClient_Handle handle_;
    SD::MediaServerList* opaque_;
    Upnp_FunPtr callback_;
    int refcount_;
};

namespace SD
{

struct MediaServerDesc
{
    MediaServerDesc(const std::string& udn, const std::string& fName, const std::string& loc);
    ~MediaServerDesc();
    std::string UDN;
    std::string friendlyName;
    std::string location;
    input_item_t* inputItem;
    bool isSatIp;
};


class MediaServerList
{
public:

    MediaServerList( services_discovery_t* p_sd );
    ~MediaServerList();

    bool addServer(MediaServerDesc *desc );
    void removeServer(const std::string &udn );
    MediaServerDesc* getServer( const std::string& udn );
    static int Callback( Upnp_EventType event_type, void* p_event, void* p_user_data );

private:
    void parseNewServer( IXML_Document* doc, const std::string& location );

private:
    services_discovery_t* p_sd_;
    std::vector<MediaServerDesc*> list_;
    vlc_mutex_t lock_;
};

}

namespace Access
{

class Upnp_i11e_cb
{
public:
    Upnp_i11e_cb( Upnp_FunPtr callback, void *cookie );
    ~Upnp_i11e_cb();
    void waitAndRelease( void );
    static int run( Upnp_EventType, void *, void *);

private:
    sem_t           sem_;<commit_msg>upnp: fix build<commit_after>/*****************************************************************************
 * upnp.hpp :  UPnP discovery module (libupnp) header
 *****************************************************************************
 * Copyright (C) 2004-2010 the VideoLAN team
 * $Id$
 *
 * Authors: <NAME> <rem # videolan.org> (original plugin)
 *          <NAME> <henz # c-lab.de>
 *          <NAME> <mirsal dot ennaime at gmail dot com>
 *          <NAME> <<EMAIL>>
 *
 * UPnP Plugin using the Intel SDK (libupnp) instead of CyberLink
 *
 * 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.
 *****************************************************************************/

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

#include <vector>
#include <string>

#include <upnp/upnp.h>
#include <upnp/upnptools.h>

#include <vlc_common.h>
#include <vlc_url.h>

namespace SD
{
    class MediaServerList;
}

/*
 * libUpnp allows only one instance per process, so we have to share one for
 * both SD & Access module
 * Since the callback is bound to the UpnpClient_Handle, we have to register
 * a wrapper callback, in order for the access module to be able to initialize
 * libUpnp first.
 * When a SD wishes to use libUpnp, it will provide its own callback, that the
 * wrapper will forward.
 * This way, we always have a register callback & a client handle.
 */
class UpnpInstanceWrapper
{
public:
    // This increases the refcount before returning the instance
    static UpnpInstanceWrapper* get(vlc_object_t* p_obj, Upnp_FunPtr callback, SD::MediaServerList *opaque);
    void release(bool isSd);
    UpnpClient_Handle handle() const;

private:
    static int Callback( Upnp_EventType event_type, void* p_event, void* p_user_data );

    UpnpInstanceWrapper();
    ~UpnpInstanceWrapper();

private:
    static UpnpInstanceWrapper* s_instance;
    static vlc_mutex_t s_lock;
    UpnpClient_Handle handle_;
    SD::MediaServerList* opaque_;
    Upnp_FunPtr callback_;
    int refcount_;
};

namespace SD
{

struct MediaServerDesc
{
    MediaServerDesc(const std::string& udn, const std::string& fName, const std::string& loc);
    ~MediaServerDesc();
    std::string UDN;
    std::string friendlyName;
    std::string location;
    input_item_t* inputItem;
    bool isSatIp;
};


class MediaServerList
{
public:

    MediaServerList( services_discovery_t* p_sd );
    ~MediaServerList();

    bool addServer(MediaServerDesc *desc );
    void removeServer(const std::string &udn );
    MediaServerDesc* getServer( const std::string& udn );
    static int Callback( Upnp_EventType event_type, void* p_event, void* p_user_data );

private:
    void parseNewServer( IXML_Document* doc, const std::string& location );

private:
    services_discovery_t* p_sd_;
    std::vector<MediaServerDesc*> list_;
    vlc_mutex_t lock_;
};

}

namespace Access
{

class Upnp_i11e_cb
{
public:
    Upnp_i11e_cb( Upnp_FunPtr callback, void *cookie );
    ~Upnp_i11e_cb();
    void waitAndRelease( void );
    static int run( Upnp_EventType, void *, void *);

private:
    vlc_sem_t       sem_;
{'fraction_non_alphanumeric': 0.14318121163597544, 'fraction_numerical': 0.006938884440886042, 'mean_word_length': 4.165403170227429, 'pattern_counts': {'":': 0, '<': 35, '<?xml version=': 0, '>': 35, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 0, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '6797113', 'n_tokens_mistral': 2252, 'n_tokens_neox': 2165, 'n_words': 789}