1 /*****************************************************************************
2 * upnp.hpp : UPnP discovery module (libupnp) header
3 *****************************************************************************
4 * Copyright (C) 2004-2016 VLC authors and VideoLAN
7 * Authors: Rémi Denis-Courmont <rem # videolan.org> (original plugin)
8 * Christian Henz <henz # c-lab.de>
9 * Mirsal Ennaime <mirsal dot ennaime at gmail dot com>
10 * Hugo Beauzée-Luyssen <hugo@beauzee.fr>
12 * This program is free software; you can redistribute it and/or modify it
13 * under the terms of the GNU Lesser General Public License as published by
14 * the Free Software Foundation; either version 2.1 of the License, or
15 * (at your option) any later version.
17 * This program is distributed in the hope that it will be useful,
18 * but WITHOUT ANY WARRANTY; without even the implied warranty of
19 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
20 * GNU Lesser General Public License for more details.
22 * You should have received a copy of the GNU Lesser General Public License
23 * along with this program; if not, write to the Free Software Foundation,
24 * Inc., 51 Franklin Street, Fifth Floor, Boston MA 02110-1301, USA.
25 *****************************************************************************/
34 #include <upnp/upnp.h>
35 #include <upnp/upnptools.h>
37 #include <vlc_common.h>
42 class MediaServerList
;
46 * libUpnp allows only one instance per process, so we have to share one for
47 * both SD & Access module
48 * Since the callback is bound to the UpnpClient_Handle, we have to register
49 * a wrapper callback, in order for the access module to be able to initialize
51 * When a SD wishes to use libUpnp, it will provide its own callback, that the
52 * wrapper will forward.
53 * This way, we always have a register callback & a client handle.
55 class UpnpInstanceWrapper
58 // This increases the refcount before returning the instance
59 static UpnpInstanceWrapper
* get(vlc_object_t
* p_obj
, services_discovery_t
*p_sd
);
60 void release(bool isSd
);
61 UpnpClient_Handle
handle() const;
62 static SD::MediaServerList
*lockMediaServerList();
63 static void unlockMediaServerList();
66 static int Callback( Upnp_EventType event_type
, void* p_event
, void* p_user_data
);
68 UpnpInstanceWrapper();
69 ~UpnpInstanceWrapper();
72 static UpnpInstanceWrapper
* s_instance
;
73 static vlc_mutex_t s_lock
;
74 UpnpClient_Handle m_handle
;
75 static SD::MediaServerList
* p_server_list
;
82 struct MediaServerDesc
84 MediaServerDesc( const std::string
& udn
, const std::string
& fName
,
85 const std::string
& loc
, const std::string
& iconUrl
);
88 std::string friendlyName
;
91 input_item_t
* inputItem
;
93 std::string satIpHost
;
101 MediaServerList( services_discovery_t
* p_sd
);
104 bool addServer(MediaServerDesc
*desc
);
105 void removeServer(const std::string
&udn
);
106 MediaServerDesc
* getServer( const std::string
& udn
);
107 static int Callback( Upnp_EventType event_type
, void* p_event
);
110 void parseNewServer( IXML_Document
* doc
, const std::string
& location
);
111 std::string
getIconURL( IXML_Element
* p_device_elem
, const char* psz_base_url
);
114 services_discovery_t
* const m_sd
;
115 std::vector
<MediaServerDesc
*> m_list
;
126 Upnp_i11e_cb( Upnp_FunPtr callback
, void *cookie
);
128 void waitAndRelease( void );
129 static int run( Upnp_EventType
, void *, void *);
135 Upnp_FunPtr m_callback
;
142 MediaServer( access_t
* p_access
, input_item_node_t
* node
);
144 bool fetchContents();
147 MediaServer(const MediaServer
&);
148 MediaServer
& operator=(const MediaServer
&);
150 bool addContainer( IXML_Element
* containerElement
);
151 bool addItem( IXML_Element
* itemElement
);
153 IXML_Document
* _browseAction(const char*, const char*,
154 const char*, const char*, const char* );
155 static int sendActionCb( Upnp_EventType
, void *, void *);
159 char* m_psz_objectId
;
161 input_item_node_t
* m_node
;