]> git.sesse.net Git - vlc/blob - modules/services_discovery/upnp_intel.hpp
upnp_intel: split the big cpp file in two, declaration and implementation.
[vlc] / modules / services_discovery / upnp_intel.hpp
1 /*****************************************************************************
2  * Upnp_intel.hpp :  UPnP discovery module (Intel SDK) header
3  *****************************************************************************
4  * Copyright (C) 2004-2008 the VideoLAN team
5  * $Id$
6  *
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  *
11  * UPnP Plugin using the Intel SDK (libupnp) instead of CyberLink
12  *
13  * This program is free software; you can redistribute it and/or modify
14  * it under the terms of the GNU General Public License as published by
15  * the Free Software Foundation; either version 2 of the License, or
16  * (at your option) any later version.
17  *
18  * This program is distributed in the hope that it will be useful,
19  * but WITHOUT ANY WARRANTY; without even the implied warranty of
20  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
21  * GNU General Public License for more details.
22  *
23  * You should have received a copy of the GNU General Public License
24  * along with this program; if not, write to the Free Software
25  * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston MA 02110-1301, USA.
26  *****************************************************************************/
27
28 #include <vector>
29 #include <string>
30
31 #include <upnp/upnp.h>
32 #include <upnp/upnptools.h>
33
34 #include <vlc_common.h>
35
36 // Classes
37 class Container;
38
39
40 class Lockable
41 {
42 public:
43
44     Lockable()
45     {
46         vlc_mutex_init( &_mutex );
47     }
48
49     ~Lockable()
50     {
51         vlc_mutex_destroy( &_mutex );
52     }
53
54     void lock() { vlc_mutex_lock( &_mutex ); }
55     void unlock() { vlc_mutex_unlock( &_mutex ); }
56
57 private:
58
59     vlc_mutex_t _mutex;
60 };
61
62
63 class Locker
64 {
65 public:
66     Locker( Lockable* l )
67     {
68         _lockable = l;
69         _lockable->lock();
70     }
71
72     ~Locker()
73     {
74         _lockable->unlock();
75     }
76
77 private:
78     Lockable* _lockable;
79 };
80
81
82 class MediaServer
83 {
84 public:
85
86     static void parseDeviceDescription( IXML_Document* doc,
87                                         const char*    location,
88                                         services_discovery_t* p_sd );
89
90     MediaServer( const char* UDN,
91                  const char* friendlyName,
92                  services_discovery_t* p_sd );
93
94     ~MediaServer();
95
96     const char* getUDN() const;
97     const char* getFriendlyName() const;
98
99     void setContentDirectoryEventURL( const char* url );
100     const char* getContentDirectoryEventURL() const;
101
102     void setContentDirectoryControlURL( const char* url );
103     const char* getContentDirectoryControlURL() const;
104
105     void subscribeToContentDirectory();
106     void fetchContents();
107
108     void setInputItem( input_item_t* p_input_item );
109
110     bool compareSID( const char* sid );
111
112 private:
113
114     bool _fetchContents( Container* parent );
115     void _buildPlaylist( Container* container );
116
117     IXML_Document* _browseAction( const char*, const char*,
118             const char*, const char*, const char*, const char* );
119
120     services_discovery_t* _p_sd;
121
122     Container* _contents;
123     input_item_t* _inputItem;
124
125     std::string _UDN;
126     std::string _friendlyName;
127
128     std::string _contentDirectoryEventURL;
129     std::string _contentDirectoryControlURL;
130
131     int _subscriptionTimeOut;
132     Upnp_SID _subscriptionID;
133 };
134
135
136 class MediaServerList
137 {
138 public:
139
140     MediaServerList( services_discovery_t* p_sd );
141     ~MediaServerList();
142
143     bool addServer( MediaServer* s );
144     void removeServer( const char* UDN );
145
146     MediaServer* getServer( const char* UDN );
147     MediaServer* getServerBySID( const char* );
148
149 private:
150
151     services_discovery_t* _p_sd;
152
153     std::vector<MediaServer*> _list;
154 };
155
156
157 class Item
158 {
159 public:
160
161     Item( Container*  parent,
162           const char* objectID,
163           const char* title,
164           const char* resource );
165     ~Item();
166
167     const char* getObjectID() const;
168     const char* getTitle() const;
169     const char* getResource() const;
170
171     void setInputItem( input_item_t* p_input_item );
172     input_item_t* getInputItem() const ;
173
174 private:
175
176     input_item_t* _inputItem;
177
178     Container* _parent;
179     std::string _objectID;
180     std::string _title;
181     std::string _resource;
182 };
183
184
185 class Container
186 {
187 public:
188
189     Container( Container* parent, const char* objectID, const char* title );
190     ~Container();
191
192     void addItem( Item* item );
193     void addContainer( Container* container );
194
195     const char* getObjectID() const;
196     const char* getTitle() const;
197
198     unsigned int getNumItems() const;
199     unsigned int getNumContainers() const;
200
201     Item* getItem( unsigned int i ) const;
202     Container* getContainer( unsigned int i ) const;
203     Container* getParent();
204
205     void setInputItem( input_item_t* p_input_item );
206     input_item_t* getInputItem() const;
207
208 private:
209
210     input_item_t* _inputItem;
211
212     Container* _parent;
213
214     std::string _objectID;
215     std::string _title;
216     std::vector<Item*> _items;
217     std::vector<Container*> _containers;
218 };
219