xbmc
PltSyncMediaBrowser.h
Go to the documentation of this file.
1 /*****************************************************************
2 |
3 | Platinum - Synchronous Media Browser
4 |
5 | Copyright (c) 2004-2010, Plutinosoft, LLC.
6 | All rights reserved.
7 | http://www.plutinosoft.com
8 |
9 | This program is free software; you can redistribute it and/or
10 | modify it under the terms of the GNU General Public License
11 | as published by the Free Software Foundation; either version 2
12 | of the License, or (at your option) any later version.
13 |
14 | OEMs, ISVs, VARs and other distributors that combine and
15 | distribute commercially licensed software with Platinum software
16 | and do not wish to distribute the source code for the commercially
17 | licensed software under version 2, or (at your option) any later
18 | version, of the GNU General Public License (the "GPL") must enter
19 | into a commercial license agreement with Plutinosoft, LLC.
20 | licensing@plutinosoft.com
21 |
22 | This program is distributed in the hope that it will be useful,
23 | but WITHOUT ANY WARRANTY; without even the implied warranty of
24 | MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
25 | GNU General Public License for more details.
26 |
27 | You should have received a copy of the GNU General Public License
28 | along with this program; see the file LICENSE.txt. If not, write to
29 | the Free Software Foundation, Inc.,
30 | 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
31 | http://www.gnu.org/licenses/gpl-2.0.html
32 |
33 ****************************************************************/
34 
39 #ifndef _PLT_SYNC_MEDIA_BROWSER_
40 #define _PLT_SYNC_MEDIA_BROWSER_
41 
42 /*----------------------------------------------------------------------
43 | includes
44 +---------------------------------------------------------------------*/
45 #include "Neptune.h"
46 #include "PltCtrlPoint.h"
47 #include "PltMediaBrowser.h"
48 #include "PltMediaCache.h"
49 
50 /*----------------------------------------------------------------------
51 | types
52 +---------------------------------------------------------------------*/
55 
56 typedef struct PLT_BrowseData {
57  NPT_SharedVariable shared_var;
58  NPT_Result res;
59  PLT_BrowseInfo info;
61 
63 
64 typedef struct PLT_CapabilitiesData {
65  NPT_SharedVariable shared_var;
66  NPT_Result res;
67  NPT_String capabilities;
69 
71 
72 // explicitely specify res otherwise WMP won't return a URL!
73 #define PLT_DEFAULT_FILTER "dc:date,dc:description,upnp:longDescription,upnp:genre,res,res@duration,res@size,upnp:albumArtURI,upnp:rating,upnp:lastPlaybackPosition,upnp:lastPlaybackTime,upnp:playbackCount,upnp:originalTrackNumber,upnp:episodeNumber,upnp:programTitle,upnp:seriesTitle,upnp:album,upnp:artist,upnp:author,upnp:director,dc:publisher,searchable,childCount,dc:title,dc:creator,upnp:actor,res@resolution,upnp:episodeCount,upnp:episodeSeason,xbmc:lastPlayerState,xbmc:dateadded,xbmc:rating,xbmc:votes,xbmc:artwork,xbmc:uniqueidentifier,xbmc:country,xbmc:userrating"
74 
75 /*----------------------------------------------------------------------
76 | PLT_MediaContainerListener
77 +---------------------------------------------------------------------*/
79 {
80 public:
82  virtual void OnContainerChanged(PLT_DeviceDataReference& device,
83  const char* item_id,
84  const char* update_id) = 0;
85 };
86 
87 /*----------------------------------------------------------------------
88 | PLT_SyncMediaBrowser
89 +---------------------------------------------------------------------*/
92 {
93 public:
95  bool use_cache = false,
96  PLT_MediaContainerChangesListener* listener = NULL);
97  ~PLT_SyncMediaBrowser() override;
98 
99  // PLT_MediaBrowser methods
100  NPT_Result OnDeviceAdded(PLT_DeviceDataReference& device) override;
101  NPT_Result OnDeviceRemoved(PLT_DeviceDataReference& device) override;
102 
103  // PLT_MediaBrowserDelegate methods
104  void OnMSStateVariablesChanged(PLT_Service* service,
105  NPT_List<PLT_StateVariable*>* vars) override;
106  void OnBrowseResult(NPT_Result res,
107  PLT_DeviceDataReference& device,
108  PLT_BrowseInfo* info,
109  void* userdata) override;
110  void OnSearchResult(NPT_Result res,
111  PLT_DeviceDataReference& device,
112  PLT_BrowseInfo* info,
113  void* userdata) override;
114  void OnGetSearchCapabilitiesResult(NPT_Result res,
115  PLT_DeviceDataReference& device,
116  NPT_String searchCapabilities,
117  void* userdata) override;
118  void OnGetSortCapabilitiesResult(NPT_Result res,
119  PLT_DeviceDataReference& device,
120  NPT_String sortCapabilities,
121  void* userdata) override;
122 
123  // methods
124  void SetContainerListener(PLT_MediaContainerChangesListener* listener) {
125  m_ContainerListener = listener;
126  }
127  NPT_Result BrowseSync(PLT_DeviceDataReference& device,
128  const char* id,
130  bool metadata = false,
131  NPT_Int32 start = 0,
132  NPT_Cardinal max_results = 0); // 0 means all
133 
134  NPT_Result SearchSync(PLT_DeviceDataReference& device,
135  const char* container_id,
136  const char* search_criteria,
138  NPT_Int32 start = 0,
139  NPT_Cardinal max_results = 0); // 0 means all
140 
141  NPT_Result GetSearchCapabilitiesSync(PLT_DeviceDataReference& device,
142  NPT_String& searchCapabilities);
143 
144  NPT_Result GetSortCapabilitiesSync(PLT_DeviceDataReference& device,
145  NPT_String& sortCapabilities);
146 
147  const NPT_Lock<PLT_DeviceMap>& GetMediaServersMap() const { return m_MediaServers; }
148  bool IsCached(const char* uuid, const char* object_id);
149 
150 protected:
151  NPT_Result BrowseSync(PLT_BrowseDataReference& browse_data,
152  PLT_DeviceDataReference& device,
153  const char* object_id,
154  NPT_Int32 index,
155  NPT_Int32 count,
156  bool browse_metadata = false,
157  const char* filter = PLT_DEFAULT_FILTER,
158  const char* sort = "");
159 
160  NPT_Result SearchSync(PLT_BrowseDataReference& browse_data,
161  PLT_DeviceDataReference& device,
162  const char* container_id,
163  const char* search_criteria,
164  NPT_Int32 index,
165  NPT_Int32 count,
166  const char* filter = PLT_DEFAULT_FILTER); // explicitely specify res otherwise WMP won't return a URL!
167 
168 private:
169  NPT_Result Find(const char* ip, PLT_DeviceDataReference& device);
170  NPT_Result WaitForResponse(NPT_SharedVariable& shared_var);
171 
172 private:
173  NPT_Lock<PLT_DeviceMap> m_MediaServers;
174  PLT_MediaContainerChangesListener* m_ContainerListener;
175  bool m_UseCache;
177 };
178 
179 /*----------------------------------------------------------------------
180 | PLT_DeviceMapFinderByIp
181 +---------------------------------------------------------------------*/
183 {
184 public:
185  // methods
186  PLT_DeviceMapFinderByIp(const char* ip) : m_IP(ip) {}
187 
188  bool operator()(const PLT_DeviceMapEntry* const& entry) const {
189  const PLT_DeviceDataReference& device = entry->GetValue();
190  return (device->GetURLBase().GetHost() == m_IP);
191  }
192 
193 private:
194  // members
195  NPT_String m_IP;
196 };
197 
198 /*----------------------------------------------------------------------
199 | PLT_DeviceFinderByUUID
200 +---------------------------------------------------------------------*/
202 {
203 public:
204  // methods
205  PLT_DeviceMapFinderByUUID(const char* uuid) : m_UUID(uuid) {}
206 
207  bool operator()(const PLT_DeviceMapEntry* const& entry) const {
208  PLT_DeviceDataReference device = entry->GetValue();
209  return device->GetUUID() == m_UUID;
210  }
211 
212 private:
213  // members
214  NPT_String m_UUID;
215 };
216 
217 #endif /* _PLT_SYNC_MEDIA_BROWSER_ */
218 
const NPT_String & GetHost() const
Returns the host part of the URL, in its encoded form.
Definition: NptUri.h:184
UPnP AV Media Controller implementation.
The PLT_MediaBrowser class implements a UPnP AV Media Server control point.
Definition: PltMediaBrowser.h:114
The PLT_MediaCache template provides a way to hold references to object in memory.
Definition: PltMediaCache.h:55
Definition: PltSyncMediaBrowser.h:78
UPnP ControlPoint.
UPnP Service.
Definition: PltService.h:67
Simple Object Caching utility.
Definition: NptThreads.h:149
The PLT_BrowseInfo struct is used to marshall Browse or Search action response results across differe...
Definition: PltMediaBrowser.h:55
Definition: NptThreads.h:113
Definition: NptMap.h:47
Definition: PltSyncMediaBrowser.h:201
Definition: PltSyncMediaBrowser.h:182
The PLT_MediaBrowserDelegate class is an interface for receiving PLT_MediaBrowser events or action re...
Definition: PltMediaBrowser.h:71
Definition: PltSyncMediaBrowser.h:64
Definition: NptMap.h:51
Definition: PltSyncMediaBrowser.h:56
Definition: NptReferences.h:45
Definition: NptStrings.h:57
Definition: NptList.h:54
Definition: PltSyncMediaBrowser.h:90