Merge pull request #5039 from CEikermann/patch-1
[vuplus_xbmc] / xbmc / filesystem / MythSession.h
1 #pragma once
2 /*
3  *      Copyright (C) 2005-2013 Team XBMC
4  *      http://xbmc.org
5  *
6  *  This Program is free software; you can redistribute it and/or modify
7  *  it under the terms of the GNU General Public License as published by
8  *  the Free Software Foundation; either version 2, or (at your option)
9  *  any later version.
10  *
11  *  This Program is distributed in the hope that it will be useful,
12  *  but WITHOUT ANY WARRANTY; without even the implied warranty of
13  *  MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
14  *  GNU General Public License for more details.
15  *
16  *  You should have received a copy of the GNU General Public License
17  *  along with XBMC; see the file COPYING.  If not, see
18  *  <http://www.gnu.org/licenses/>.
19  *
20  */
21
22 #include "threads/CriticalSection.h"
23 #include "threads/Thread.h"
24
25 typedef struct cmyth_ringbuf   *cmyth_ringbuf_t;
26 typedef struct cmyth_conn      *cmyth_conn_t;
27 typedef struct cmyth_recorder  *cmyth_recorder_t;
28 typedef struct cmyth_proginfo  *cmyth_proginfo_t;
29 typedef struct cmyth_proglist  *cmyth_proglist_t;
30 typedef struct cmyth_file      *cmyth_file_t;
31 typedef struct cmyth_database  *cmyth_database_t;
32 typedef struct cmyth_timestamp *cmyth_timestamp_t;
33
34 class DllLibCMyth;
35 class CDateTime;
36 class CFileItem;
37 class CURL;
38
39 namespace XFILE
40 {
41
42 class CMythSession
43   : private CThread
44 {
45 public:
46   static CMythSession*  AquireSession(const CURL& url);
47   static void           ReleaseSession(CMythSession*);
48   static void           CheckIdle();
49   static void           LogCMyth(int level, char *msg);
50
51   class IEventListener
52   {
53   public:
54     virtual ~IEventListener() {};
55     virtual void OnEvent(int event, const std::string& data)=0;
56   };
57
58   bool             SetListener(IEventListener *listener);
59   cmyth_conn_t     GetControl();
60   cmyth_database_t GetDatabase();
61   DllLibCMyth*     GetLibrary();
62   cmyth_proglist_t GetAllRecordedPrograms();
63   void             ResetAllRecordedPrograms();
64
65   void             SetFileItemMetaData(CFileItem &item, cmyth_proginfo_t program);
66
67   CDateTime        GetValue(cmyth_timestamp_t t);
68   CStdString       GetValue(char* str);
69
70 private:
71   CMythSession(const CURL& url);
72   ~CMythSession();
73
74   virtual void Process();
75
76   bool             CanSupport(const CURL& url);
77   void             Disconnect();
78
79   void             SetSeasonAndEpisode(const cmyth_proginfo_t &program, int *season, int *epsiode);
80
81   IEventListener*  m_listener;
82   cmyth_conn_t     m_control;
83   cmyth_conn_t     m_event;
84   cmyth_database_t m_database;
85   CStdString       m_hostname;
86   CStdString       m_username;
87   CStdString       m_password;
88   int              m_port;
89   DllLibCMyth*     m_dll;
90   CCriticalSection m_section;
91   unsigned int     m_timestamp;
92   cmyth_proglist_t m_all_recorded; // Cache of all_recorded programs.
93
94   static CCriticalSection            m_section_session;
95   static std::vector<CMythSession*>  m_sessions;
96 };
97
98 }