Merge pull request #4857 from t-nelson/Gotham_13.2_backports
[vuplus_xbmc] / xbmc / filesystem / HTSPDirectory.h
1 /*
2  *      Copyright (C) 2005-2013 Team XBMC
3  *      http://xbmc.org
4  *
5  *  This Program is free software; you can redistribute it and/or modify
6  *  it under the terms of the GNU General Public License as published by
7  *  the Free Software Foundation; either version 2, or (at your option)
8  *  any later version.
9  *
10  *  This Program is distributed in the hope that it will be useful,
11  *  but WITHOUT ANY WARRANTY; without even the implied warranty of
12  *  MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
13  *  GNU General Public License for more details.
14  *
15  *  You should have received a copy of the GNU General Public License
16  *  along with XBMC; see the file COPYING.  If not, see
17  *  <http://www.gnu.org/licenses/>.
18  *
19  */
20
21 #pragma once
22 #include "IDirectory.h"
23 #include "threads/Thread.h"
24 #include "threads/CriticalSection.h"
25 #include "threads/Event.h"
26 #include "HTSPSession.h"
27 #include "boost/shared_ptr.hpp"
28
29 class CURL;
30 class CFileItem; typedef boost::shared_ptr<CFileItem> CFileItemPtr;
31
32 namespace HTSP
33 {
34   class CHTSPDirectorySession
35       : public CThread
36   {
37     public:
38       bool                    GetEvent(SEvent& event, uint32_t id);
39       SChannels               GetChannels();
40       SChannels               GetChannels(int tag);
41       SChannels               GetChannels(STag &tag);
42       STags                   GetTags();
43       htsmsg_t*               ReadResult(htsmsg_t* m);
44
45
46       static CHTSPDirectorySession* Acquire(const CURL& url);
47       static void                   Release(CHTSPDirectorySession* &session);
48       static void                   CheckIdle(DWORD idle = 60000);
49
50     protected:
51        CHTSPDirectorySession();
52       ~CHTSPDirectorySession();
53
54       bool   Open(const CURL& url);
55       void   Close();
56
57     private:
58       virtual void Process();
59       CHTSPSession            m_session;
60       SChannels               m_channels;
61       STags                   m_tags;
62       SEvents                 m_events;
63       CCriticalSection        m_section;
64       CEvent                  m_started;
65
66       struct SMessage
67       {
68         CEvent   * event;
69         htsmsg_t * msg;
70       };
71       typedef std::map<int, SMessage> SMessages;
72
73       SMessages m_queue;
74   };
75 }
76
77 namespace XFILE
78 {
79
80   class CHTSPDirectory : public IDirectory
81   {
82     public:
83       CHTSPDirectory(void);
84       virtual ~CHTSPDirectory(void);
85       virtual bool GetDirectory(const CStdString& strPath, CFileItemList &items);
86       virtual DIR_CACHE_TYPE GetCacheType(const CStdString& strPath) const { return DIR_CACHE_ONCE; };
87     private:
88       bool GetChannels(const CURL& base, CFileItemList &items);
89       bool GetChannels(const CURL& base, CFileItemList &items, HTSP::SChannels channels, int tag);
90       bool GetTag     (const CURL& base, CFileItemList &items);
91
92       HTSP::CHTSPDirectorySession* m_session;
93   };
94 }
95