Platinum UPnP SDK  1.0.5.13
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 +---------------------------------------------------------------------*/
53 typedef NPT_Map<NPT_String, PLT_DeviceDataReference> PLT_DeviceMap;
54 typedef NPT_Map<NPT_String, PLT_DeviceDataReference>::Entry PLT_DeviceMapEntry;
55 
56 typedef struct PLT_BrowseData {
57  NPT_SharedVariable shared_var;
58  NPT_Result res;
59  PLT_BrowseInfo info;
60 } PLT_BrowseData;
61 
62 typedef NPT_Reference<PLT_BrowseData> PLT_BrowseDataReference;
63 
64 /*----------------------------------------------------------------------
65 | PLT_MediaContainerListener
66 +---------------------------------------------------------------------*/
67 class PLT_MediaContainerChangesListener
68 {
69 public:
70  virtual ~PLT_MediaContainerChangesListener() {}
71  virtual void OnContainerChanged(PLT_DeviceDataReference& device,
72  const char* item_id,
73  const char* update_id) = 0;
74 };
75 
76 /*----------------------------------------------------------------------
77 | PLT_SyncMediaBrowser
78 +---------------------------------------------------------------------*/
79 class PLT_SyncMediaBrowser : public PLT_MediaBrowser,
81 {
82 public:
83  PLT_SyncMediaBrowser(PLT_CtrlPointReference& ctrlPoint,
84  bool use_cache = false,
85  PLT_MediaContainerChangesListener* listener = NULL);
86  virtual ~PLT_SyncMediaBrowser();
87 
88  // PLT_MediaBrowser methods
89  virtual NPT_Result OnDeviceAdded(PLT_DeviceDataReference& device);
90  virtual NPT_Result OnDeviceRemoved(PLT_DeviceDataReference& device);
91 
92  // PLT_MediaBrowserDelegate methods
93  virtual void OnMSStateVariablesChanged(PLT_Service* service,
94  NPT_List<PLT_StateVariable*>* vars);
95  virtual void OnBrowseResult(NPT_Result res,
96  PLT_DeviceDataReference& device,
97  PLT_BrowseInfo* info,
98  void* userdata);
99 
100  // methods
101  void SetContainerListener(PLT_MediaContainerChangesListener* listener) {
102  m_ContainerListener = listener;
103  }
104  NPT_Result BrowseSync(PLT_DeviceDataReference& device,
105  const char* id,
106  PLT_MediaObjectListReference& list,
107  bool metadata = false,
108  NPT_Int32 start = 0,
109  NPT_Cardinal max_results = 0); // 0 means all
110 
111  const NPT_Lock<PLT_DeviceMap>& GetMediaServersMap() const { return m_MediaServers; }
112  bool IsCached(const char* uuid, const char* object_id);
113 
114 protected:
115  NPT_Result BrowseSync(PLT_BrowseDataReference& browse_data,
116  PLT_DeviceDataReference& device,
117  const char* object_id,
118  NPT_Int32 index,
119  NPT_Int32 count,
120  bool browse_metadata = false,
121  const char* filter = "dc:date,upnp:genre,res,res@duration,res@size,upnp:albumArtURI,upnp:album,upnp:artist,upnp:author,searchable,childCount", // explicitely specify res otherwise WMP won't return a URL!
122  const char* sort = "");
123 private:
124  NPT_Result Find(const char* ip, PLT_DeviceDataReference& device);
125  NPT_Result WaitForResponse(NPT_SharedVariable& shared_var);
126 
127 private:
128  NPT_Lock<PLT_DeviceMap> m_MediaServers;
129  PLT_MediaContainerChangesListener* m_ContainerListener;
130  bool m_UseCache;
132 };
133 
134 /*----------------------------------------------------------------------
135 | PLT_DeviceMapFinderByIp
136 +---------------------------------------------------------------------*/
137 class PLT_DeviceMapFinderByIp
138 {
139 public:
140  // methods
141  PLT_DeviceMapFinderByIp(const char* ip) : m_IP(ip) {}
142 
143  bool operator()(const PLT_DeviceMapEntry* const& entry) const {
144  const PLT_DeviceDataReference& device = entry->GetValue();
145  return (device->GetURLBase().GetHost() == m_IP);
146  }
147 
148 private:
149  // members
150  NPT_String m_IP;
151 };
152 
153 /*----------------------------------------------------------------------
154 | PLT_DeviceFinderByUUID
155 +---------------------------------------------------------------------*/
156 class PLT_DeviceMapFinderByUUID
157 {
158 public:
159  // methods
160  PLT_DeviceMapFinderByUUID(const char* uuid) : m_UUID(uuid) {}
161 
162  bool operator()(const PLT_DeviceMapEntry* const& entry) const {
163  PLT_DeviceDataReference device = entry->GetValue();
164  return device->GetUUID() == m_UUID;
165  }
166 
167 private:
168  // members
169  NPT_String m_UUID;
170 };
171 
172 #endif /* _PLT_SYNC_MEDIA_BROWSER_ */
173 
UPnP AV Media Controller implementation.
The PLT_MediaBrowser class implements a UPnP AV Media Server control point.
Definition: PltMediaBrowser.h:102
UPnP ControlPoint.
UPnP Service.
Definition: PltService.h:67
Simple Object Caching utility.
The PLT_BrowseInfo struct is used to marshall Browse or Search action response results across differe...
Definition: PltMediaBrowser.h:55
The PLT_MediaBrowserDelegate class is an interface for receiving PLT_MediaBrowser events or action re...
Definition: PltMediaBrowser.h:71