Merge pull request #2774 from popcornmix/rpi-settings
[vuplus_xbmc] / xbmc / ApplicationMessenger.h
1 #pragma once
2
3 /*
4  *      Copyright (C) 2005-2013 Team XBMC
5  *      http://www.xbmc.org
6  *
7  *  This Program is free software; you can redistribute it and/or modify
8  *  it under the terms of the GNU General Public License as published by
9  *  the Free Software Foundation; either version 2, or (at your option)
10  *  any later version.
11  *
12  *  This Program is distributed in the hope that it will be useful,
13  *  but WITHOUT ANY WARRANTY; without even the implied warranty of
14  *  MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
15  *  GNU General Public License for more details.
16  *
17  *  You should have received a copy of the GNU General Public License
18  *  along with XBMC; see the file COPYING.  If not, see
19  *  <http://www.gnu.org/licenses/>.
20  *
21  */
22
23 #include "threads/CriticalSection.h"
24 #include "utils/StdString.h"
25 #include "guilib/WindowIDs.h"
26 #include "threads/Thread.h"
27 #include "threads/Event.h"
28 #include <boost/shared_ptr.hpp>
29
30 #include <queue>
31 #include "utils/GlobalsHandling.h"
32
33 class CFileItem;
34 class CFileItemList;
35 class CGUIDialog;
36 class CGUIWindow;
37 class CGUIMessage;
38 class CVideoInfoTag;
39 class CAction;
40
41 namespace MUSIC_INFO
42 {
43   class CMusicInfoTag;
44 }
45
46 // defines here
47 #define TMSG_DIALOG_DOMODAL       100
48 #define TMSG_EXECUTE_SCRIPT       102
49 #define TMSG_EXECUTE_BUILT_IN     103
50 #define TMSG_EXECUTE_OS           104
51
52 #define TMSG_MEDIA_PLAY           200
53 #define TMSG_MEDIA_STOP           201
54 // the PAUSE is indeed a PLAYPAUSE
55 #define TMSG_MEDIA_PAUSE          202
56 #define TMSG_MEDIA_RESTART        203
57 #define TMSG_MEDIA_UNPAUSE        204
58 #define TMSG_MEDIA_PAUSE_IF_PLAYING   205
59
60 #define TMSG_PLAYLISTPLAYER_PLAY  210
61 #define TMSG_PLAYLISTPLAYER_NEXT  211
62 #define TMSG_PLAYLISTPLAYER_PREV  212
63 #define TMSG_PLAYLISTPLAYER_ADD   213
64 #define TMSG_PLAYLISTPLAYER_CLEAR 214
65 #define TMSG_PLAYLISTPLAYER_SHUFFLE   215
66 #define TMSG_PLAYLISTPLAYER_GET_ITEMS 216
67 #define TMSG_PLAYLISTPLAYER_PLAY_SONG_ID 217
68 #define TMSG_PLAYLISTPLAYER_INSERT 218
69 #define TMSG_PLAYLISTPLAYER_REMOVE 219
70 #define TMSG_PLAYLISTPLAYER_SWAP 223
71 #define TMSG_PLAYLISTPLAYER_REPEAT 224
72 #define TMSG_UPDATE_CURRENT_ITEM 225
73
74 #define TMSG_PICTURE_SHOW         220
75 #define TMSG_PICTURE_SLIDESHOW    221
76
77 #define TMSG_SHUTDOWN             300
78 #define TMSG_POWERDOWN            301
79 #define TMSG_QUIT                 302
80 #define TMSG_HIBERNATE            303
81 #define TMSG_SUSPEND              304
82 #define TMSG_RESTART              305
83 #define TMSG_RESET                306
84 #define TMSG_RESTARTAPP           307
85 #define TMSG_SWITCHTOFULLSCREEN   308
86 #define TMSG_MINIMIZE             309
87 #define TMSG_TOGGLEFULLSCREEN     310
88 #define TMSG_SETLANGUAGE          311
89 #define TMSG_RENDERER_FLUSH       312
90 #define TMSG_INHIBITIDLESHUTDOWN  313
91 #define TMSG_LOADPROFILE          314
92 #define TMSG_ACTIVATESCREENSAVER  315
93
94 #define TMSG_NETWORKMESSAGE         500
95
96 #define TMSG_GUI_DO_MODAL             600
97 #define TMSG_GUI_SHOW                 601
98 #define TMSG_GUI_ACTIVATE_WINDOW      604
99 #define TMSG_GUI_PYTHON_DIALOG        605
100 #define TMSG_GUI_WINDOW_CLOSE         606
101 #define TMSG_GUI_ACTION               607
102 #define TMSG_GUI_INFOLABEL            608
103 #define TMSG_GUI_INFOBOOL             609
104 #define TMSG_GUI_ADDON_DIALOG         610
105 #define TMSG_GUI_MESSAGE              611
106 #define TMSG_START_ANDROID_ACTIVITY   612
107
108 #define TMSG_CALLBACK             800
109
110 #define TMSG_VOLUME_SHOW          900
111 #define TMSG_SPLASH_MESSAGE       901
112
113 #define TMSG_DISPLAY_SETUP      1000
114 #define TMSG_DISPLAY_DESTROY    1001
115
116 typedef struct
117 {
118   unsigned int dwMessage;
119   unsigned int dwParam1;
120   unsigned int dwParam2;
121   CStdString strParam;
122   std::vector<CStdString> params;
123   boost::shared_ptr<CEvent> waitEvent;
124   void* lpVoid;
125 }
126 ThreadMessage;
127
128 class CDelayedMessage : public CThread
129 {
130   public:
131     CDelayedMessage(ThreadMessage& msg, unsigned int delay);
132     virtual void Process();
133
134   private:
135     unsigned int   m_delay;
136     ThreadMessage  m_msg;
137 };
138
139 struct ThreadMessageCallback
140 {
141   void (*callback)(void *userptr);
142   void *userptr;
143 };
144
145 class CApplicationMessenger;
146 namespace xbmcutil
147 {
148    template<class T> class GlobalsSingleton;
149 }
150
151 class CApplicationMessenger
152 {
153 public:
154   /*!
155    \brief The only way through which the global instance of the CApplicationMessenger should be accessed.
156    \return the global instance.
157    */
158   static CApplicationMessenger& Get();
159
160   void Cleanup();
161   // if a message has to be send to the gui, use MSG_TYPE_WINDOW instead
162   void SendMessage(ThreadMessage& msg, bool wait = false);
163   void ProcessMessages(); // only call from main thread.
164   void ProcessWindowMessages();
165
166
167   void MediaPlay(std::string filename);
168   void MediaPlay(const CFileItem &item);
169   void MediaPlay(const CFileItemList &item, int song = 0);
170   void MediaPlay(int playlistid, int song = -1);
171   void MediaStop(bool bWait = true, int playlistid = -1);
172   void MediaPause();
173   void MediaUnPause();
174   void MediaPauseIfPlaying();
175   void MediaRestart(bool bWait);
176
177   void PlayListPlayerPlay();
178   void PlayListPlayerPlay(int iSong);
179   bool PlayListPlayerPlaySongId(int songId);
180   void PlayListPlayerNext();
181   void PlayListPlayerPrevious();
182   void PlayListPlayerAdd(int playlist, const CFileItem &item);
183   void PlayListPlayerAdd(int playlist, const CFileItemList &list);
184   void PlayListPlayerClear(int playlist);
185   void PlayListPlayerShuffle(int playlist, bool shuffle);
186   void PlayListPlayerGetItems(int playlist, CFileItemList &list);
187   void PlayListPlayerInsert(int playlist, const CFileItem &item, int position); 
188   void PlayListPlayerInsert(int playlist, const CFileItemList &list, int position);
189   void PlayListPlayerRemove(int playlist, int position);
190   void PlayListPlayerSwap(int playlist, int indexItem1, int indexItem2);
191   void PlayListPlayerRepeat(int playlist, int repeatState);
192
193   void PlayFile(const CFileItem &item, bool bRestart = false); // thread safe version of g_application.PlayFile()
194   void PictureShow(std::string filename);
195   void PictureSlideShow(std::string pathname, bool addTBN = false);
196   void SetGUILanguage(const std::string &strLanguage);
197   void Shutdown();
198   void Powerdown();
199   void Quit();
200   void Hibernate();
201   void Suspend();
202   void Restart();
203   void RestartApp();
204   void Reset();
205   void InhibitIdleShutdown(bool inhibit);
206   void ActivateScreensaver();
207   void SwitchToFullscreen(); //
208   void Minimize(bool wait = false);
209   void ExecOS(const CStdString command, bool waitExit = false);
210   void UserEvent(int code);
211   //! \brief Set the tag for the currently playing song
212   void SetCurrentSongTag(const MUSIC_INFO::CMusicInfoTag& tag);
213   //! \brief Set the tag for the currently playing video
214   void SetCurrentVideoTag(const CVideoInfoTag& tag);
215   //! \brief Set the currently currently item
216   void SetCurrentItem(const CFileItem& item);
217
218   void LoadProfile(unsigned int idx);
219
220   CStdString GetResponse();
221   int SetResponse(CStdString response);
222   void ExecBuiltIn(const CStdString &command, bool wait = false);
223
224   void NetworkMessage(unsigned int dwMessage, unsigned int dwParam = 0);
225
226   void DoModal(CGUIDialog *pDialog, int iWindowID, const CStdString &param = "");
227   void Show(CGUIDialog *pDialog);
228   void Close(CGUIWindow *window, bool forceClose, bool waitResult = true, int nextWindowID = 0, bool enableSound = true);
229   void ActivateWindow(int windowID, const std::vector<CStdString> &params, bool swappingWindows);
230   void SendAction(const CAction &action, int windowID = WINDOW_INVALID, bool waitResult=true);
231
232   /*! \brief Send a GUIMessage, optionally waiting before it's processed to return.
233    Should be used to send messages to the GUI from other threads.
234    \param msg the GUIMessage to send.
235    \param windowID optional window to send the message to (defaults to no specified window).
236    \param waitResult whether to wait for the result (defaults to false).
237    */
238   void SendGUIMessage(const CGUIMessage &msg, int windowID = WINDOW_INVALID, bool waitResult=false);
239
240   std::vector<CStdString> GetInfoLabels(const std::vector<CStdString> &properties);
241   std::vector<bool> GetInfoBooleans(const std::vector<CStdString> &properties);
242
243   void ShowVolumeBar(bool up);
244
245   void SetSplashMessage(const CStdString& message);
246   void SetSplashMessage(int stringID);
247   
248   bool SetupDisplay();
249   bool DestroyDisplay();
250   void StartAndroidActivity(const std::vector<CStdString> &params);
251
252   virtual ~CApplicationMessenger();
253 private:
254   // private construction, and no assignements; use the provided singleton methods
255    friend class xbmcutil::GlobalsSingleton<CApplicationMessenger>;
256   CApplicationMessenger();
257   CApplicationMessenger(const CApplicationMessenger&);
258   CApplicationMessenger const& operator=(CApplicationMessenger const&);
259   void ProcessMessage(ThreadMessage *pMsg);
260
261   std::queue<ThreadMessage*> m_vecMessages;
262   std::queue<ThreadMessage*> m_vecWindowMessages;
263   CCriticalSection m_critSection;
264   CCriticalSection m_critBuffer;
265   CStdString bufferResponse;
266 };
267
268 XBMC_GLOBAL_REF(CApplicationMessenger,s_messenger);
269 #define s_messenger XBMC_GLOBAL_USE(CApplicationMessenger)
270
271