#ifndef _PLT_SYNC_MEDIA_BROWSER_
#define _PLT_SYNC_MEDIA_BROWSER_
#include "Neptune.h"
#include "PltCtrlPoint.h"
#include "PltMediaBrowser.h"
#include "PltMediaCache.h"
typedef NPT_Map<NPT_String, PLT_DeviceDataReference> PLT_DeviceMap;
typedef NPT_Map<NPT_String, PLT_DeviceDataReference>::Entry PLT_DeviceMapEntry;
typedef struct PLT_BrowseData {
NPT_SharedVariable shared_var;
NPT_Result res;
PLT_BrowseInfo info;
} PLT_BrowseData;
typedef NPT_Reference<PLT_BrowseData> PLT_BrowseDataReference;
class PLT_MediaContainerChangesListener
{
public:
virtual ~PLT_MediaContainerChangesListener() {}
virtual void OnContainerChanged(PLT_DeviceDataReference& device,
const char* item_id,
const char* update_id) = 0;
};
class PLT_SyncMediaBrowser : public PLT_MediaBrowser,
public PLT_MediaBrowserDelegate
{
public:
PLT_SyncMediaBrowser(PLT_CtrlPointReference& ctrlPoint,
bool use_cache = false,
PLT_MediaContainerChangesListener* listener = NULL);
virtual ~PLT_SyncMediaBrowser();
virtual NPT_Result OnDeviceAdded(PLT_DeviceDataReference& device);
virtual NPT_Result OnDeviceRemoved(PLT_DeviceDataReference& device);
virtual void OnMSStateVariablesChanged(PLT_Service* service,
NPT_List<PLT_StateVariable*>* vars);
virtual void OnBrowseResult(NPT_Result res,
PLT_DeviceDataReference& device,
PLT_BrowseInfo* info,
void* userdata);
void SetContainerListener(PLT_MediaContainerChangesListener* listener) {
m_ContainerListener = listener;
}
NPT_Result BrowseSync(PLT_DeviceDataReference& device,
const char* id,
PLT_MediaObjectListReference& list,
bool metadata = false,
NPT_Int32 start = 0,
NPT_Cardinal max_results = 0);
const NPT_Lock<PLT_DeviceMap>& GetMediaServersMap() const { return m_MediaServers; }
bool IsCached(const char* uuid, const char* object_id);
protected:
NPT_Result BrowseSync(PLT_BrowseDataReference& browse_data,
PLT_DeviceDataReference& device,
const char* object_id,
NPT_Int32 index,
NPT_Int32 count,
bool browse_metadata = false,
const char* filter = "dc:date,upnp:genre,res,res@duration,res@size,upnp:albumArtURI,upnp:album,upnp:artist,upnp:author,searchable,childCount",
const char* sort = "");
private:
NPT_Result Find(const char* ip, PLT_DeviceDataReference& device);
NPT_Result WaitForResponse(NPT_SharedVariable& shared_var);
private:
NPT_Lock<PLT_DeviceMap> m_MediaServers;
PLT_MediaContainerChangesListener* m_ContainerListener;
bool m_UseCache;
PLT_MediaCache<PLT_MediaObjectListReference,NPT_String> m_Cache;
};
class PLT_DeviceMapFinderByIp
{
public:
PLT_DeviceMapFinderByIp(const char* ip) : m_IP(ip) {}
bool operator()(const PLT_DeviceMapEntry* const& entry) const {
PLT_DeviceDataReference device = entry->GetValue();
return (device->GetURLBase().GetHost() == m_IP);
}
private:
NPT_String m_IP;
};
class PLT_DeviceMapFinderByUUID
{
public:
PLT_DeviceMapFinderByUUID(const char* uuid) : m_UUID(uuid) {}
bool operator()(const PLT_DeviceMapEntry* const& entry) const {
PLT_DeviceDataReference device = entry->GetValue();
return device->GetUUID() == m_UUID;
}
private:
NPT_String m_UUID;
};
#endif